This is an old revision of the document!
JP2 is a Java Profiler developed by Binder et al. 1). It can be used to count the executed bytecode number to estimate the CPU consumption of a Java program. To do that, we need to modify the command executing the Java program like this:
java -Xmx2g \ -javaagent:$JP2_HOME/lib/javaagent.jar \ -Xbootclasspath/p:$JP2_HOME/lib/Thread_JP2.jar:$JP2_HOME/lib/asm-all-3.3.jar:$JP2_HOME/lib/jp2.jar \ -Dch.usi.dag.jp2.Output="program.output.gz" \ -Dch.usi.dag.jp2.InstrumentedClasses="ProgramInstrumented" \ -Dch.usi.dag.jp2.UninstrumentedClasses="ProgramUninstrumented" \ -cp YourClasspath YourMainClass
Felix is an Apache implementation of the OSGi specifications which define a dynamic service deployment framework 2). The basic idea of OSGi is providing a framework on which the service implementations or bundles are plugged. The framework handles the service requests and responses. Each bundle communicates only with the framework. SIP communications 3)is a Java VoIP and instant messaging client using Felix.
While using JP2 to count the executed bytecode number of SIP communicator in the way above, the bundles of SIP could find the classes of JP2. We tried different methods to make JP2 classes accessible to the bundles and found a working way:
!className.startsWith("org/apache/felix")
to method
byte[] transform(ClassLoader loader, String className, Class<?> redefiningClass, ProtectionDomain domain, byte[] uninstrumentedBytes)
in
ch.usi.dag.jp2.agent.SimpleTransformer
.
<target name="bundle-jp2"> <jar compress="true" destfile="${bundles.dest}/bundle-jp2.jar" filesetmanifest="skip"> <zipfileset src="${lib.noinst}/jp2/asm-all-3.3.jar" prefix="" /> <zipfileset src="${lib.noinst}/jp2/bcel-5.2.jar" prefix="" /> <zipfileset src="${lib.noinst}/jp2/javaagent.jar" prefix="" /> <zipfileset src="${lib.noinst}/jp2/jp2.jar" prefix="" /> <zipfileset src="${lib.noinst}/jp2/jre-tool.jar" prefix="" /> <zipfileset src="${lib.noinst}/jp2/Thread_JP2.jar" prefix="" /> <zipfileset src="${lib.noinst}/jp2/thread-tool.jar" prefix="" /> <manifest> <attribute name="Export-Package" value="ch.usi.dag.jp2.agent,ch.usi.dag.jp2.rewriting,ch.usi.dag.jp2.runtime,ch.usi.dag.jp2.tools.jre,ch.usi.dag.jp2.tools.thread" /> <attribute name="Bundle-Name" value="JP2" /> <attribute name="Bundle-Description" value="Java Instrument Library." /> <attribute name="Bundle-Version" value="1.0" /> <attribute name="System-Bundle" value="yes" /> </manifest> </jar> </target>
felix.auto.start.11= \ reference:file:lib/bundle/bundle-jp2.jar
javabin=`which java` SCDIR=$WORKING-DIR LIBPATH=$SCDIR/lib BUNDLEPATH=$SCDIR/sc-bundles CLASSPATH=$LIBPATH/jdic_stub.jar:$LIBPATH/jdic-all.jar:$LIBPATH/felix.jar:$LIBPATH/bcprovider.jar:$SCDIR/sc-bundles/sc-launcher.jar:$SCDIR/sc-bundles/util.jar FELIX_CONFIG=$LIBPATH/felix.client.run.properties LOG_CONFIG=$LIBPATH/logging.properties COMMAND="$javabin -Xmx2g \ -javaagent:$LIBPATH/javaagent.jar \ -Xbootclasspath/p:$LIBPATH/Thread_JP2.jar:$LIBPATH/asm-all-3.3.jar:$LIBPATH/jp2.jar \ -Dch.usi.dag.jp2.Output="sip.output.gz" \ -Dch.usi.dag.jp2.InstrumentedClasses="sipInstrumented" \ -Dch.usi.dag.jp2.UninstrumentedClasses="sipUninstrumented" \ -Dch.usi.dag.jp2.InsterestedPackage="net.java.sip" -classpath $CLASSPATH -Dorg.osgi.framework.bootdelegation=ch.usi.* \ -Djna.library.path=$LIBPATH/native -Dfelix.config.properties=file:$FELIX_CONFIG -Djava.util.logging.config.file=$LOG_CONFIG \ net.java.sip.communicator.launcher.SIPCommunicator" # set add LIBPATH to LD_LIBRARY_PATH for any sc natives (e.g. jmf .so's) export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBPATH/native # make LD_PRELOAD use libaoss so that java doesn't hog on the audio device. export LD_PRELOAD=/usr/lib/libaoss.so # create .sip-commnicator/log in home or otherwise java.util.logging will freak mkdir -p $HOME/.sip-communicator/log cd $SCDIR exec $COMMAND $*
Run this script to execute the instrumented SIP communicator.