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.*


-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!


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


      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(
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(
        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(
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
        at java.lang.reflect.Constructor.newInstance(
        at java.lang.Class.newInstance0(
        at java.lang.Class.newInstance(
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(

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

      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" :)

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

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

      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.

      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




        After that everything worked!

        I work with Knopflerfish 3.2.0.

        Best regards
        Ewgenij Sokolovski

        1. Hello Ewgenij,

          your change is Knopflerfish-specific.

          Thank you for your feedback.

      8. In YourKit 12.0.6 I still needed to add both the agent and bootdelegation properties to get this working properly in my Felix OSGI application.