-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write an instrumentation agent to modify JCL code #3
Write an instrumentation agent to modify JCL code #3
Comments
Attaching the simple experiment that uses javassist to modify calls in method for reference. Pasting the README from the zip here. This readme contains a simple experiment that uses Java Instrumentation using javassist API to redefine a method in a class to call different method. There are two ways we can attach the agent to the JVM, static and dynamic. In static agent load (Agent provided by Step 1: Unzip the test.
Demo.java contains our main application which will create new object of type Person every second and call a method Step 2: Compile the test code.
Step 3: Compile the agent and prepare the RedefinitionAgent.jar (You can use any name)
Step 4: Now compile the LoadAgent.java which would be used to load the agent dynamically.
Now as we have everything ready for the experiment, let's try both static and dynamic loading of agent. Experiment 1 : Static Loading of agent
Experiment 2 : Dynamic Loading of agent (Need two terminals) Terminal 1
Terminal 2
Process in Terminal 2 will attach the agent to JVM in Terminal 1. If you observe the output in Terminal 1, you will see change
|
Giving an update on where the agent is at. The code can be found here
Also I will add that the agent currently assumes that Qasim's changes to JITHelper already exist in that file. He highlights those changes in his most recent comments for #5. So to run the agent these need to be added as well. Currently the java agent successfully rewrites method.invoke but fails to rewrite ExpectException.evaluate. To see the problem follow these steps:
and replace it with this:
This will stop the method.invoke changes from being overwritten so that we can focus on the ExpectException failure.
This failure doesn't include much information but I believe the cause to come from the difference in version between junit-4.12 (java 5) and our code. To generate the asm code you see in EvaluateDebugAdapter.visitCode and InvokeDebugAdapter.visitCode I use a tool called the asmifier. I run the asmifier on the new expectExcetion code that @qasimy123 wrote but the problem is that since this code is version 11, ASM will generate different asm code then it would if it were java 5, and trying to insert this java 11 asm code into a java 5 class causes problems at some point. To test this out, I fed the asmifier the original java 5 ExpectException class, and had our agent "rewrite" identical code using asm. This passed without error. I then took the exact same java 5 code and compiled it using java11 without any other changes. Using the asm code from this new class results in the same ClassFormatError above. Its not that asm isn't backwords compatible, its just that the way it would write java 11 methods is different from java 5 so at some point this causes a conflict. You can see the difference between identical java 5 and java 11 junit ExpectException files here. |
JVM bytecode is backwards compatible, so if it works on an earlier JVM version I see no reason it shouldn't with a later JVM version. Are you sure the bytecodes you're adding are valid? Perhaps you can try a trivial modification to |
Given Qasim's latest changes that move most of the heavy lifting to JITHelper, I have updated the agent code and it now runs successfully. I'm going to go through the code and clean it up where I can but if @r30shah or @fjeremic have time to take a look and review it before we move to the next steps that would be great. I'm now looking in to using Maven to generate the jar and handle the dependencies so that we can automate this process as well. |
@ShaneKilloran I can check the current status of agent can change the calls we targeted in this issue and can easily compile the jar with Maven. Can you also add |
@ShaneKilloran One of the issues we discussed in past, was to set the Jit option
|
Write an instrumentation agent in java that can modify JCL code in [1] and redirect it to [2]. You use either ASM[3] or javassist[4] to achieve that.
Aim of this work item is to get familiar with such Instrumentation API and prepare a foundation for our tool that will be attached to JVM and when sees the failure in the test, starts limiting down to the failing method and optimization.
For this issue, currently we can use the same demo code that we tried out in the code-sprint and produced a failure that throws Null Pointer Exception and debug the issue without need to recompile the JCL code.
[1]. https://github.com/ibmruntimes/openj9-openjdk-jdk11/blob/ddc29ca76069082bf6b57e52628e3c2ae05d7694/src/java.base/share/classes/java/lang/reflect/Method.java#L566
[2].
openj9-jit-debug-agent/jcl/src/java.base/share/classes/com/ibm/jit/JITHelpers.java
Line 1183 in 994ce53
[3]. https://asm.ow2.io
[4]. https://www.javassist.org/
The text was updated successfully, but these errors were encountered: