[Rev 08] RFR: 6656: Allow capturing field values with path syntax

Marcus Hirt hirt at openjdk.java.net
Mon Jan 20 15:26:49 UTC 2020


On Mon, 20 Jan 2020 15:26:45 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:

>> This patch implements [JMC-6656: Allow capturing field values with path syntax](https://bugs.openjdk.java.net/browse/JMC-6656).
>> 
>> In the xml configuration, a field capture looks like:
>> <field>
>>   <name>a field value</name>
>>   <description>a field value capture with a path syntax</description>
>>   <expression>this.field.prop</expression>
>> </field>
>> See `org/openjdk/jmc/agent/test/jfrprobes_template.xml` for more examples.
>> 
>> There are currently two limitations to pay attention to:
>> 
>> 1. Instrumentation point cannot be in synthesized classes:
>> Instrumented classes are first loaded by obtaining the bytecode and inspected reflectively to resolve typing information. This fails if the class load is unable to provide the bytecode when `ClassLoader.getResouce()` is called. The cases where it might fail are unlikely to be for classes like proxies or auxiliaries for Java frameworks that have no visible equivalent.
>> 
>> 2. Instrumentation is unable to access nestmates' private fields:
>> Before [nest-base access control](https://openjdk.java.net/jeps/181) was introduced in Java 11, accessing nestmates' private fields is, while lexically correct, forbidden by the JVM. The Java compiler works around by inserting synthetic getters/setters. However, it's not for a BCI agent since changing the class structure is not allowed during class transformation.
>> 
>> Please let me know your thoughts. Thank you very much!
> 
> The pull request has been updated with a new target base due to a merge or a rebase.

core/org.openjdk.jmc.agent/src/main/java/org/openjdk/jmc/agent/Transformer.java line 72:

> 71: 				// Don't reuse this class loader instance. We want the loader and its class to unload after we're done.
> 72: 				classBeingRedefined = new InspectionClassLoader(loader)
> 73: 						.loadClass(TypeUtils.getCanonicalName(className));

We only need to parse/load the class if we are looking up fields. Can't we do this later, and only if we need it lazily? It's seems a bit premature to do it here in the Transformer.

-------------

Changes requested by hirt (Lead).

PR: https://git.openjdk.java.net/jmc/pull/20


More information about the jmc-dev mailing list