JDK-8153749 : New capability can_generate_early_class_hook_events
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: jvmti
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-04-07
  • Updated: 2017-05-17
  • Resolved: 2016-04-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b120Fixed
Related Reports
Relates :  
Relates :  
Description
Some agents need to get a CFLH event for classes loaded in the primordial phase. This is not possible in JDK 9 because existing agents may instrument code in the primordial or start phase before the module system has completed initialization.

One way that we could allow this is if we introduce a new capability, say  can_generate_early_class_hook_events. If this capability and can_generate_all_class_hook_events are enabled then the CFLH event could be posted in the primordial phase.
Comments
The suggested fix is: Updated JVMTI spec: http://cr.openjdk.java.net/~sspitsyn/webrevs/2016/hotspot/8153749-Jigsaw-newcap.hs2/jvmti.html Hotspot webrev: http://cr.openjdk.java.net/~sspitsyn/webrevs/2016/hotspot/8153749-Jigsaw-newcap.hs2/ Jdk webrev: http://cr.openjdk.java.net/~sspitsyn/webrevs/2016/jdk/8153749-Jigsaw-newcap.jdk1/ Patch: diff -r 5469b15d97f4 src/share/vm/prims/jvmti.xml --- a/src/share/vm/prims/jvmti.xml Tue Apr 12 07:17:44 2016 +0200 +++ b/src/share/vm/prims/jvmti.xml Thu Apr 14 14:57:29 2016 -0700 @@ -9994,6 +9994,17 @@ See <eventlink id="VMStart"/>. </description> </capabilityfield> + <capabilityfield id="can_generate_early_class_hook_events" since="9"> + <description> + Can generate the <eventlink id="ClassFileLoadHook"/> events + in the primordial phase. If this capability and + <internallink id="jvmtiCapabilities.can_generate_all_class_hook_events" + ><code>can_generate_all_class_hook_events</code></internallink> + are enabled then the <eventlink id="ClassFileLoadHook"/> events + could be posted for classes loaded in the primordial phase. + See <eventlink id="ClassFileLoadHook"/>. + </description> + </capabilityfield> </capabilitiestypedef> <function id="GetPotentialCapabilities" jkernel="yes" phase="onload" num="140"> @@ -12404,7 +12415,7 @@ </parameters> </event> - <event label="Class File Load Hook" phase="start" + <event label="Class File Load Hook" phase="any" id="ClassFileLoadHook" const="JVMTI_EVENT_CLASS_FILE_LOAD_HOOK" num="54"> <description> This event is sent when the VM obtains class file data, @@ -12420,7 +12431,13 @@ <internallink id="bci">bytecode instrumentation</internallink> for usage information. <p/> - This event may be sent before the VM is initialized (the start + When the capabilities + <internallink id="jvmtiCapabilities.can_generate_early_class_hook_events"> + <code>can_generate_early_class_hook_events</code></internallink> and + <internallink id="jvmtiCapabilities.can_generate_all_class_hook_events"> + <code>can_generate_all_class_hook_events</code></internallink> + are enabled then this event may be sent in the primordial phase. + Otherwise, this event may be sent before the VM is initialized (the start <functionlink id="GetPhase">phase</functionlink>). Some classes might not be compatible with the function (eg. ROMized classes) and this event will not be @@ -12470,6 +12487,7 @@ <origin>jvmpi</origin> <capabilities> <capability id="can_generate_all_class_hook_events"></capability> + <capability id="can_generate_early_class_hook_events"></capability> </capabilities> <parameters> <param id="jni_env"> @@ -12542,7 +12560,7 @@ <event label="VM Start Event" id="VMStart" const="JVMTI_EVENT_VM_START" num="57" phase="start"> <description> - The VM initialization event signals the start of the VM. + The VM start event signals the start of the VM. At this time JNI is live but the VM is not yet fully initialized. Once this event is generated, the agent is free to call any JNI function. This event signals the beginning of the start phase, @@ -14419,6 +14437,10 @@ - Add new capability can_generate_early_vmstart - Allow CompiledMethodLoad events at start phase </change> + <change date="14 April 2016" version="9.0.0"> + Support for modules: + - Add new capability can_generate_early_class_hook_events + </change> </changehistory> </specification> diff -r 5469b15d97f4 src/share/vm/prims/jvmtiEnvBase.hpp --- a/src/share/vm/prims/jvmtiEnvBase.hpp Tue Apr 12 07:17:44 2016 +0200 +++ b/src/share/vm/prims/jvmtiEnvBase.hpp Thu Apr 14 14:57:29 2016 -0700 @@ -162,6 +162,11 @@ jvmtiCapabilities *get_prohibited_capabilities() { return &_prohibited_capabilities; } + bool early_class_hook_env() { + return get_capabilities()->can_generate_early_class_hook_events != 0 + && get_capabilities()->can_generate_all_class_hook_events != 0; + } + bool early_vmstart_env() { return get_capabilities()->can_generate_early_vmstart != 0; } diff -r 5469b15d97f4 src/share/vm/prims/jvmtiExport.cpp --- a/src/share/vm/prims/jvmtiExport.cpp Tue Apr 12 07:17:44 2016 +0200 +++ b/src/share/vm/prims/jvmtiExport.cpp Thu Apr 14 14:57:29 2016 -0700 @@ -665,7 +665,7 @@ } void post_to_env(JvmtiEnv* env, bool caching_needed) { - if (env->phase() == JVMTI_PHASE_PRIMORDIAL) { + if (env->phase() == JVMTI_PHASE_PRIMORDIAL && !env->early_class_hook_env()) { return; } unsigned char *new_data = NULL; diff -r 5469b15d97f4 src/share/vm/prims/jvmtiManageCapabilities.cpp --- a/src/share/vm/prims/jvmtiManageCapabilities.cpp Tue Apr 12 07:17:44 2016 +0200 +++ b/src/share/vm/prims/jvmtiManageCapabilities.cpp Thu Apr 14 14:57:29 2016 -0700 @@ -134,6 +134,7 @@ jc.can_get_owned_monitor_stack_depth_info = 1; jc.can_get_current_contended_monitor = 1; jc.can_generate_early_vmstart = 1; + jc.can_generate_early_class_hook_events = 1; return jc; } @@ -454,6 +455,8 @@ tty->print_cr("can_generate_resource_exhaustion_threads_events"); if (cap->can_generate_early_vmstart) tty->print_cr("can_generate_early_vmstart"); + if (cap->can_generate_early_class_hook_events) + tty->print_cr("can_generate_early_class_hook_events"); } #endif
14-04-2016

The enhancement needs a ccc filed. This is the CCC request: http://ccc.us.oracle.com/8153749
14-04-2016