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.
- YourKit (http://www.yourkit.com/) v.8.0.x
-agentpath:${yourkit.root.folder}\bin\win32\yjpagent.dll -Dorg.osgi.framework.bootdelegation=com.yourkit.*
- YourKit (http://www.yourkit.com/) v.10+
-agentpath:${yourkit.root.folder}\bin\win32\yjpagent.dll
- Sun VisualVM (https://visualvm.dev.java.net/) v.1.2.2
-Xbootclasspath/a:${visualvm.root.folder}\profiler3\lib\jfluid-server.jar -Dorg.osgi.framework.bootdelegation=org.netbeans.lib.profiler.*
- JProfiler (http://www.ej-technologies.com/products/jprofiler/overview.html) v.6.0.x
-agentpath:${jprofiler.root.folder}\bin\windows\jprofilerti.dll -Xbootclasspath/a:${jprofiler.root.folder}\bin\agent.jar -Dorg.osgi.framework.bootdelegation=com.jprofiler.*
- JProbe (http://www.quest.com/jprobe/) v.8.3
-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!

YourKit v9 should work without any tricks. Just -agentpath:${yourkit.root.folder}\bin\win32 without -Dorg.osgi.framework.bootdelegation=com.yourkit.*
ReplyDelete--vladimir
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
ReplyDeleteorg.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)
Thanks a lot for sharing ! I think you should use -Xbootclasspath/a instead of -Xbootclasspath for VisualVM.
ReplyDeleteJulien is right
ReplyDeleteAs 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" :)
ReplyDeleteI've tested with YourKit versions 10.x and 11.x. You are right, this option is obsolete.
DeleteThanks Dmytro Pishchukhin and Julien. I will try this in VisualVM .
ReplyDelete