User Tools

Site Tools


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 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 cannot find the classes of JP2. We tried different methods to make JP2 classes accessible to the bundles and found a working way:

1. Not instrument Felix classes, so they can be executed without know JP2. We need to add


to method

byte[] transform(ClassLoader loader, String className, Class<?> redefiningClass, ProtectionDomain domain, byte[] uninstrumentedBytes)




2. Add a bundle which contains all the classes of JP2 into the build.xml of SIP:

	<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="" />
				<attribute name="Export-Package" value="ch.usi.dag.jp2.agent,ch.usi.dag.jp2.rewriting,ch.usi.dag.jp2.runtime,," />
				<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" />

3. Add all the packages of JP2 to the Import-Packgae attribute of the MANIFEST.MF of all other bundles.

4. Set org.osgi.framework.bootdelegation to JP2 classes in the execute script.

W. Binder and J. Hulaas, “Using bytecode instruction counting as portable cpu consumption metric”, Electronic Notes In Theoretical Computer Science, vol. 153, pp. 57-77, May 2006.
using-jp2-to-instrument-programs-based-on-apache-felix.1299044211.txt.gz · Last modified: 2018/03/04 02:53 (external edit)