Accessing module internals from bytecode rewriting agent

Jeremy Manson jeremymanson at
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
<> 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
<>, and
it is very reasonable to want to do this kind of thing in the system


On Mon, Apr 24, 2017 at 8:26 PM, Martin Buchholz <martinrb at>

> 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
> IF true
> DO traceln(java.util.Arrays.toString($0.queue))
> 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:${
>      [java] java.lang.IllegalArgumentException: illegal lookupClass:
> class java.util.PriorityQueue
>      [java] at java.base/java.lang.invoke.MethodHandleStatics.
> newIllegalArgumentException(
>      [java] at java.base/java.lang.invoke.MethodHandles$Lookup.
> checkUnprivilegedlookupClass(
>      [java] at java.base/java.lang.invoke.MethodHandles$Lookup.<init>(
>      [java] at java.base/java.lang.invoke.MethodHandles.privateLookupIn(
>      [java] at org.jboss.byteman.jigsaw/org.jboss.byteman.jigsaw.
> JigsawAccessEnabler.createFieldGetter(
>      [java] at org.jboss.byteman.rule.Rule.addAccessibleFieldGetter(Rule.
> java:1043)
>      [java] at org.jboss.byteman.rule.expression.FieldExpression.
> lookupField(
>      [java] at org.jboss.byteman.rule.expression.FieldExpression.
> typeCheckAny(
>      [java] at org.jboss.byteman.rule.expression.FieldExpression.
> typeCheck(
>      [java] at org.jboss.byteman.rule.expression.MethodExpression.
> findMethod(

More information about the jigsaw-dev mailing list