User Tools

Site Tools


using-jp2-to-instrument-programs-based-on-apache-felix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
using-jp2-to-instrument-programs-based-on-apache-felix [2011/03/02 05:40]
weiwu
using-jp2-to-instrument-programs-based-on-apache-felix [2018/03/04 02:53] (current)
Line 1: Line 1:
-JP2 is Java Profiler developed by Binder et al. ((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.)). It can be used to count the executed bytecode ​number ​to estimate the CPU consumption of a Java program. +====== Background ====== 
-To do that, we need to modify the command executing the Java program like this:+ 
 +JP2 is an excellent and easy-to-use ​Java Profiler developed by Binder et al.((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.)). It can be used to count the numbers of executed bytecode ​instructions ​to estimate the CPU consumption of a Java program. ​The basics of calling JP2 are as follows:
  
 <​code>​ <​code>​
Line 12: Line 13:
 </​code>​ </​code>​
  
-Felix is an Apache implementation of the OSGi specifications which define a dynamic service deployment framework ((http://​felix.apache.org/​site/​index.html)). 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 <​code>​!className.startsWith("​org/​apache/​felix"​)</​code>​ to method <​code>​byte[] transform(ClassLoader loader, String className, Class<?>​ redefiningClass,​ ProtectionDomain domain, byte[] uninstrumentedBytes)</​code>​ of <​code>​ ch.usi.dag.jp2.agent.SimpleTransformer </​code>​.+====== ​Felix and SIP ======
  
-2. Add a bundle which contains all the classes of JP2 into the build.xml of SIP:+While the previous code works well and allows instrumenting programs in most situations, we faced some difficulties when instrumenting SIP communications((http://​sip-communicator.org/)). SIP Communicator is a Java VoIP and instant messaging client using Felix. Felix((http://​felix.apache.org/​site/​index.html)) is the Apache implementation of the OSGi specifications,​ which defines a dynamic service deployment framework. The OSGi specifications((http://​www.osgi.org/​)) defines a framework on which service implementations or //bundles// are plugged and managed by the framework, independently of the underlying running JVM (and its classpath). The framework handles bundle discovery, dependencies,​ requests, and responses. Each bundle communicates only with/​through the framework.  
 + 
 +We wanted to count the numbers of executed bytecode instructions of SIP communicator using JP2. When instrumenting SIP Communicator,​ we ran into several problems, which we fixed as follows. 
 + 
 + 
 + 
 +==== Not Instrumenting Felix ==== 
 + 
 +Exclude Felix classes from being instrumented,​ so Felix can run without having to know about JP2. We added: 
 +<​code>​!className.startsWith("​org/​apache/​felix"​)</​code>​  
 +to method: 
 +<​code>​byte[] transform(ClassLoader loader, String className, Class<?>​ redefiningClass,​ ProtectionDomain domain, byte[] uninstrumentedBytes)</​code>​  
 +in class: 
 +<​code>​ ch.usi.dag.jp2.agent.SimpleTransformer </​code>​ 
 + 
 + 
 + 
 +==== Telling Felix where to find JP2 for the Instrumented Bundles ==== 
 + 
 +Add a bundle which contains all the classes of JP2 into the build.xml of SIP:
 <​code>​ <​code>​
  <target name="​bundle-jp2">​  <target name="​bundle-jp2">​
Line 40: Line 58:
 </​code>​ </​code>​
  
-3. Add all the packages of JP2 to the Import-Package attribute of the MANIFEST.MF of all other bundles.+Add the JP2 bundle to felix.client.run.properties:​ 
 +<​code>​ 
 +felix.auto.start.11= \ 
 + ​reference:​file:​lib/​bundle/​bundle-jp2.jar 
 +</​code>​ 
 + 
 + 
 + 
 +==== Telling SIP Communicator Bundles about JP2 ==== 
 + 
 +  * Add all the packages of JP2 to the Import-Package attribute of the MANIFEST.MF of all other bundles.
  
-4. Set org.osgi.framework.bootdelegation to JP2 classes in the execute script:+  * Set org.osgi.framework.bootdelegation to JP2 classes in the execute script. The original JP2 jars in -XBootclasspath are still needed by -javaagent.
 <​code>​ <​code>​
 javabin=`which java` javabin=`which java`
Line 58: Line 86:
     -Dch.usi.dag.jp2.InstrumentedClasses="​sipInstrumented"​ \     -Dch.usi.dag.jp2.InstrumentedClasses="​sipInstrumented"​ \
     -Dch.usi.dag.jp2.UninstrumentedClasses="​sipUninstrumented"​ \     -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"​+    -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) # set add LIBPATH to LD_LIBRARY_PATH for any sc natives (e.g. jmf .so's)
Line 74: Line 104:
 </​code>​ </​code>​
  
 +Run this script to execute the instrumented SIP communicator.
  
using-jp2-to-instrument-programs-based-on-apache-felix.1299044445.txt.gz · Last modified: 2018/03/04 02:53 (external edit)