Accessing module internals from bytecode rewriting agent
Jeremy Manson
jeremymanson at google.com
Tue Apr 25 06:22:48 UTC 2017
Just to underline this - the conversation with Martin about this came from
my trying to test my allocation instrumenter
<https://github.com/google/allocation-instrumenter> with JDK 9.
The instrument API specifically supports a Boot-Class-Path attribute in the
MANIFEST, as well as Instrumentation.appendToBootStrapClassLoaderSearch. I
had been using that as a way to make it possible to rewrite JDK internals
(add allocation instrumentation to them). I hadn't finished testing when
Martin sent this email, but I hadn't been able to get those things to work,
and what byteman does is pretty similar to what I was trying to test.
It sure would be nice if there were still a supported way to rewrite system
internals. Bytecode rewriting is the recommended way to track allocations
<http://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#bci>, and
it is very reasonable to want to do this kind of thing in the system
classes.
Jeremy
On Mon, Apr 24, 2017 at 8:26 PM, Martin Buchholz <martinrb at google.com>
wrote:
> We've been playing with byteman. If I have a simple rule that accesses a
> private field,
>
> RULE trace java.util.PriorityQueue_add
> CLASS java.util.PriorityQueue
> METHOD add
> AT EXIT
> IF true
> DO traceln(java.util.Arrays.toString($0.queue))
> ENDRULE
>
> Then with jdk8 I get output like:
>
> [1, 2, 3]
>
> but in jdk9 we fail with
>
> java.lang.IllegalArgumentException: illegal lookupClass: class
> java.util.PriorityQueue
>
> Bytecode rewriting agents have the power to inject code into classes; they
> should somehow also be able to reflectively inspect those same classes!
> But how? We ran into similar problems trying to port java agents at Google
> to jdk9.
>
> Details:
> JAVA_TOOL_OPTIONS="-javaagent:${BYTEMAN_JAR}=script:${
> BYTEMAN_SCRIPT},boot:${BYTEMAN_JAR}"
>
> [java] java.lang.IllegalArgumentException: illegal lookupClass:
> class java.util.PriorityQueue
> [java] at java.base/java.lang.invoke.MethodHandleStatics.
> newIllegalArgumentException(MethodHandleStatics.java:123)
> [java] at java.base/java.lang.invoke.MethodHandles$Lookup.
> checkUnprivilegedlookupClass(MethodHandles.java:1003)
> [java] at java.base/java.lang.invoke.MethodHandles$Lookup.<init>(
> MethodHandles.java:750)
> [java] at java.base/java.lang.invoke.MethodHandles.privateLookupIn(
> MethodHandles.java:205)
> [java] at org.jboss.byteman.jigsaw/org.jboss.byteman.jigsaw.
> JigsawAccessEnabler.createFieldGetter(JigsawAccessEnabler.java)
> [java] at org.jboss.byteman.rule.Rule.addAccessibleFieldGetter(Rule.
> java:1043)
> [java] at org.jboss.byteman.rule.expression.FieldExpression.
> lookupField(FieldExpression.java:549)
> [java] at org.jboss.byteman.rule.expression.FieldExpression.
> typeCheckAny(FieldExpression.java:201)
> [java] at org.jboss.byteman.rule.expression.FieldExpression.
> typeCheck(FieldExpression.java:110)
> [java] at org.jboss.byteman.rule.expression.MethodExpression.
> findMethod(MethodExpression.java:297)
>
>
More information about the core-libs-dev
mailing list