Sunday, 7 March 2010

OSGi Tips&Tricks: OSGi profiling (YourKit, VisualVM, JProfiler, JProbe) and NoClassDefFoundError

Hello OSGi-people,

There are some OSGi profiling configuration tricks to avoid NoClassDefFoundError on bundles start. I've tested four Java Profiler tools and prepared configuration settings for them.

-agentpath:${yourkit.root.folder}\bin\win32\yjpagent.dll -Dorg.osgi.framework.bootdelegation=com.yourkit.*

-agentpath:${yourkit.root.folder}\bin\win32\yjpagent.dll

-Xbootclasspath/a:${visualvm.root.folder}\profiler3\lib\jfluid-server.jar -Dorg.osgi.framework.bootdelegation=org.netbeans.lib.profiler.*

    -agentpath:${jprofiler.root.folder}\bin\windows\jprofilerti.dll -Xbootclasspath/a:${jprofiler.root.folder}\bin\agent.jar -Dorg.osgi.framework.bootdelegation=com.jprofiler.*
    

      -agentpath:${jprobe.root.folder}\bin\ia32\jprobe.dll=${profile.jpl.file} -Dorg.osgi.framework.bootdelegation=com.jprobe.*
      

      Here you can find Apache Maven POM file with profiles for OSGi frameworks (Eclipse Equinox, Apache Felix and Knopflerfish) and Java Profile Tools configurations.

      E.g. run this command to run Equinox Framework with YourKit Profiler configuration:
      mvn -f profile.xml -P equinox,yourkit
      



      Update 2011/10/01: The last tests with YourKit Profiler 10.0 with OSGi + Declarative Services still require -Dorg.osgi.framework.bootdelegation=com.yourkit.* settings.

      Update 2012/05/29: The last tests with YourKit Profiler 11.0 with OSGi + Declarative Services do not require -Dorg.osgi.framework.bootdelegation=com.yourkit.* settings.

      Update 2012/09/06: Update -Xbootclasspath/a for VisualVM.

      Have a nice OSGi profiling!

      10 comments:

      1. YourKit v9 should work without any tricks. Just -agentpath:${yourkit.root.folder}\bin\win32 without -Dorg.osgi.framework.bootdelegation=com.yourkit.*

        --vladimir

        ReplyDelete
      2. Vladimir, if you like to profile OSGi bundles with OSGi Declarative Services (DS bundle is installed) you have to enable those options. In the other case you'll get


        org.osgi.framework.BundleException: The activator org.apache.felix.scr.impl.Activator for bundle org.apache.felix.scr is invalid
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:157)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:751)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:253)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:155)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:303)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:288)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:224)
        at java.lang.Thread.run(Thread.java:619)
        Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.felix.scr.impl.Activator
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.Class.newInstance0(Class.java:355)
        at java.lang.Class.newInstance(Class.java:308)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:152)

        ReplyDelete
      3. Thanks a lot for sharing ! I think you should use -Xbootclasspath/a instead of -Xbootclasspath for VisualVM.

        ReplyDelete
      4. As I've already written there is not need to add -Dorg.osgi.framework.bootdelegation option. YourKit profiler adds this option itself on JVM startup. It should "just work" :)

        ReplyDelete
        Replies
        1. I've tested with YourKit versions 10.x and 11.x. You are right, this option is obsolete.

          Delete
      5. Thanks Dmytro Pishchukhin and Julien. I will try this in VisualVM .

        ReplyDelete
      6. Hi Dmytro,
        could you list the limitations of Visual VM compared to YourKit? I used YourKit evaluation version and found it very good, but Visual VM seems limiting. We want to make a decision if Visual VM is sufficient or we need to spend money on YourKit. Appreciate your inputs.

        ReplyDelete
      7. Sun VisualVM

        Hello, Dmytro. I tried out the configuration you provided. It did not work out this way:

        -Xbootclasspath/a:${visualvm.root.folder}\profiler3\lib\jfluid-server.jar -Dorg.osgi.framework.bootdelegation=org.netbeans.lib.profiler.*

        The second line sets a system wide property org.osgi.framework.bootdelegation. But I had to set the framework own property with the same name. Thus, I changed

        Dorg.osgi.framework.bootdelegation=org.netbeans.lib.profiler.*

        to

        Forg.osgi.framework.bootdelegation=org.netbeans.lib.profiler.*

        After that everything worked!

        I work with Knopflerfish 3.2.0.

        Best regards
        Ewgenij Sokolovski

        ReplyDelete
        Replies
        1. Hello Ewgenij,

          your change is Knopflerfish-specific.

          Thank you for your feedback.

          Delete