cancel
Showing results for 
Search instead for 
Did you mean: 

Bytecode injection into SAP AS Java

Former Member
0 Kudos

Hi,

I am trying to inject bytecode into all methods loaded by the JVM using java agent, so that i can dynamically know the sequence of methods that have been called.

I have overloaded the

transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException

function to do the injection.

The overloaded method pushes a line of code into all the methods loaded by the class loader. After that, whenever any of the method is called in the Server, correspondingly the new line of code is called as well. That provides information as to which method is called and when it is called.

The java profiler provides only a static information about the number classes loaded, which function was called, but it does not provide a sequence of the calls.

The newly inserted line of code, will call a singleton class and dump the context information to it.

I am facing a problem. The java agent works fine for other java programs, but when loaded along with a SAP Java Stack, the server crashed in less than 30 seconds.

Is there any better way of extracting the information about the classes and methods called dynamically, i.e; the sequence in which they are called ?

Regards,

Sunil

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Sunhil

What you are trying to do sounds like a massive undertaking... There might be millions of methods across all the classes loaded by all the classloaders in the VM...

What is the purpose of this? Why do you need to know the order of each method called? Determining order in such a way is also not a wise decision - you may have many threads invoking methods at the same time, and the order in which they appear in your log will depend on the race-condition in which they reach the logger (singleton)... Your results might be different each time...

If you can localize your query to your own code, you may determine the order of method invocation that lead to your query being called, by querying the stack at that point...


		Exception e = new Exception();
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		System.out.println(sw.toString()); //or send this to a log somewhere...

There must be an easier way to solve your problem than going down this route...