< prev index next >

src/hotspot/share/prims/jvmtiManageCapabilities.cpp

Print this page

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"

 26 #include "jvmtifiles/jvmtiEnv.hpp"
 27 #include "logging/log.hpp"
 28 #include "prims/jvmtiExport.hpp"
 29 #include "prims/jvmtiManageCapabilities.hpp"
 30 
 31 static const jint CAPA_SIZE = (JVMTI_INTERNAL_CAPABILITY_COUNT + 7) / 8;
 32 
 33   // capabilities which are always potentially available
 34 jvmtiCapabilities JvmtiManageCapabilities::always_capabilities;
 35 
 36   // capabilities which are potentially available during OnLoad
 37 jvmtiCapabilities JvmtiManageCapabilities::onload_capabilities;
 38 
 39   // capabilities which are always potentially available
 40   // but to only one environment
 41 jvmtiCapabilities JvmtiManageCapabilities::always_solo_capabilities;
 42 
 43   // capabilities which are potentially available during OnLoad
 44   // but to only one environment
 45 jvmtiCapabilities JvmtiManageCapabilities::onload_solo_capabilities;

112 #if INCLUDE_JVMCI
113   if (UseJVMCICompiler) {
114     jc.can_pop_frame = 0;
115     jc.can_force_early_return = 0;
116   }
117 #endif // INCLUDE_JVMCI
118 #endif // !ZERO
119   jc.can_get_source_debug_extension = 1;
120   jc.can_access_local_variables = 1;
121   jc.can_maintain_original_method_order = 1;
122   jc.can_generate_single_step_events = 1;
123   jc.can_generate_exception_events = 1;
124   jc.can_generate_frame_pop_events = 1;
125   jc.can_generate_method_entry_events = 1;
126   jc.can_generate_method_exit_events = 1;
127   jc.can_get_owned_monitor_info = 1;
128   jc.can_get_owned_monitor_stack_depth_info = 1;
129   jc.can_get_current_contended_monitor = 1;
130   jc.can_generate_early_vmstart = 1;
131   jc.can_generate_early_class_hook_events = 1;

132   return jc;
133 }
134 
135 
136 jvmtiCapabilities JvmtiManageCapabilities::init_always_solo_capabilities() {
137   jvmtiCapabilities jc;
138 
139   memset(&jc, 0, sizeof(jc));
140   jc.can_suspend = 1;
141   jc.can_generate_sampled_object_alloc_events = 1;
142   return jc;
143 }
144 
145 
146 jvmtiCapabilities JvmtiManageCapabilities::init_onload_solo_capabilities() {
147   jvmtiCapabilities jc;
148 
149   memset(&jc, 0, sizeof(jc));
150   jc.can_generate_field_modification_events = 1;
151   jc.can_generate_field_access_events = 1;

252   // add to the set of ever acquired capabilities
253   either(&acquired_capabilities, desired, &acquired_capabilities);
254 
255   // onload capabilities that got added are now permanent - so, also remove from onload
256   both(&onload_capabilities, desired, &temp);
257   either(&always_capabilities, &temp, &always_capabilities);
258   exclude(&onload_capabilities, &temp, &onload_capabilities);
259 
260   // same for solo capabilities (transferred capabilities in the remaining sets handled as part of standard grab - below)
261   both(&onload_solo_capabilities, desired, &temp);
262   either(&always_solo_capabilities, &temp, &always_solo_capabilities);
263   exclude(&onload_solo_capabilities, &temp, &onload_solo_capabilities);
264 
265   // remove solo capabilities that are now taken
266   exclude(&always_solo_remaining_capabilities, desired, &always_solo_remaining_capabilities);
267   exclude(&onload_solo_remaining_capabilities, desired, &onload_solo_remaining_capabilities);
268 
269   // return the result
270   either(current, desired, result);
271 




272   update();
273 
274   return JVMTI_ERROR_NONE;
275 }
276 
277 
278 void JvmtiManageCapabilities::relinquish_capabilities(const jvmtiCapabilities *current,
279                                                       const jvmtiCapabilities *unwanted,
280                                                       jvmtiCapabilities *result) {
281   jvmtiCapabilities to_trash;
282   jvmtiCapabilities temp;
283 
284   // can't give up what you don't have
285   both(current, unwanted, &to_trash);
286 
287   // restore solo capabilities but only those that belong
288   either(&always_solo_remaining_capabilities, both(&always_solo_capabilities, &to_trash, &temp),
289          &always_solo_remaining_capabilities);
290   either(&onload_solo_remaining_capabilities, both(&onload_solo_capabilities, &to_trash, &temp),
291          &onload_solo_remaining_capabilities);

347     avail.can_generate_all_class_hook_events);
348   JvmtiExport::set_can_walk_any_space(
349     avail.can_tag_objects);   // disable sharing in onload phase
350   // This controls whether the compilers keep extra locals live to
351   // improve the debugging experience so only set them if the selected
352   // capabilities look like a debugger.
353   JvmtiExport::set_can_access_local_variables(
354     avail.can_access_local_variables ||
355     avail.can_generate_breakpoint_events ||
356     avail.can_generate_frame_pop_events);
357   JvmtiExport::set_can_post_on_exceptions(
358     avail.can_generate_exception_events ||
359     avail.can_generate_frame_pop_events ||
360     avail.can_generate_method_exit_events);
361   JvmtiExport::set_can_post_breakpoint(avail.can_generate_breakpoint_events);
362   JvmtiExport::set_can_post_field_access(avail.can_generate_field_access_events);
363   JvmtiExport::set_can_post_field_modification(avail.can_generate_field_modification_events);
364   JvmtiExport::set_can_post_method_entry(avail.can_generate_method_entry_events);
365   JvmtiExport::set_can_post_method_exit(avail.can_generate_method_exit_events ||
366                                         avail.can_generate_frame_pop_events);

367   JvmtiExport::set_can_pop_frame(avail.can_pop_frame);
368   JvmtiExport::set_can_force_early_return(avail.can_force_early_return);

369   JvmtiExport::set_should_clean_up_heap_objects(avail.can_generate_breakpoint_events);
370   JvmtiExport::set_can_get_owned_monitor_info(avail.can_get_owned_monitor_info ||
371                                               avail.can_get_owned_monitor_stack_depth_info);
372 }
373 
374 #ifndef PRODUCT
375 
376 void JvmtiManageCapabilities:: print(const jvmtiCapabilities* cap) {
377   log_trace(jvmti)("----- capabilities -----");
378   if (cap->can_tag_objects)
379     log_trace(jvmti)("can_tag_objects");
380   if (cap->can_generate_field_modification_events)
381     log_trace(jvmti)("can_generate_field_modification_events");
382   if (cap->can_generate_field_access_events)
383     log_trace(jvmti)("can_generate_field_access_events");
384   if (cap->can_get_bytecodes)
385     log_trace(jvmti)("can_get_bytecodes");
386   if (cap->can_get_synthetic_attribute)
387     log_trace(jvmti)("can_get_synthetic_attribute");
388   if (cap->can_get_owned_monitor_info)

442   if (cap->can_generate_compiled_method_load_events)
443     log_trace(jvmti)("can_generate_compiled_method_load_events");
444   if (cap->can_generate_monitor_events)
445     log_trace(jvmti)("can_generate_monitor_events");
446   if (cap->can_generate_vm_object_alloc_events)
447     log_trace(jvmti)("can_generate_vm_object_alloc_events");
448   if (cap->can_generate_native_method_bind_events)
449     log_trace(jvmti)("can_generate_native_method_bind_events");
450   if (cap->can_generate_garbage_collection_events)
451     log_trace(jvmti)("can_generate_garbage_collection_events");
452   if (cap->can_generate_object_free_events)
453     log_trace(jvmti)("can_generate_object_free_events");
454   if (cap->can_generate_resource_exhaustion_heap_events)
455     log_trace(jvmti)("can_generate_resource_exhaustion_heap_events");
456   if (cap->can_generate_resource_exhaustion_threads_events)
457     log_trace(jvmti)("can_generate_resource_exhaustion_threads_events");
458   if (cap->can_generate_early_vmstart)
459     log_trace(jvmti)("can_generate_early_vmstart");
460   if (cap->can_generate_early_class_hook_events)
461     log_trace(jvmti)("can_generate_early_class_hook_events");


462 }
463 
464 #endif

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/javaClasses.hpp"
 27 #include "jvmtifiles/jvmtiEnv.hpp"
 28 #include "logging/log.hpp"
 29 #include "prims/jvmtiExport.hpp"
 30 #include "prims/jvmtiManageCapabilities.hpp"
 31 
 32 static const jint CAPA_SIZE = (JVMTI_INTERNAL_CAPABILITY_COUNT + 7) / 8;
 33 
 34   // capabilities which are always potentially available
 35 jvmtiCapabilities JvmtiManageCapabilities::always_capabilities;
 36 
 37   // capabilities which are potentially available during OnLoad
 38 jvmtiCapabilities JvmtiManageCapabilities::onload_capabilities;
 39 
 40   // capabilities which are always potentially available
 41   // but to only one environment
 42 jvmtiCapabilities JvmtiManageCapabilities::always_solo_capabilities;
 43 
 44   // capabilities which are potentially available during OnLoad
 45   // but to only one environment
 46 jvmtiCapabilities JvmtiManageCapabilities::onload_solo_capabilities;

113 #if INCLUDE_JVMCI
114   if (UseJVMCICompiler) {
115     jc.can_pop_frame = 0;
116     jc.can_force_early_return = 0;
117   }
118 #endif // INCLUDE_JVMCI
119 #endif // !ZERO
120   jc.can_get_source_debug_extension = 1;
121   jc.can_access_local_variables = 1;
122   jc.can_maintain_original_method_order = 1;
123   jc.can_generate_single_step_events = 1;
124   jc.can_generate_exception_events = 1;
125   jc.can_generate_frame_pop_events = 1;
126   jc.can_generate_method_entry_events = 1;
127   jc.can_generate_method_exit_events = 1;
128   jc.can_get_owned_monitor_info = 1;
129   jc.can_get_owned_monitor_stack_depth_info = 1;
130   jc.can_get_current_contended_monitor = 1;
131   jc.can_generate_early_vmstart = 1;
132   jc.can_generate_early_class_hook_events = 1;
133   jc.can_support_virtual_threads = 1;
134   return jc;
135 }
136 
137 
138 jvmtiCapabilities JvmtiManageCapabilities::init_always_solo_capabilities() {
139   jvmtiCapabilities jc;
140 
141   memset(&jc, 0, sizeof(jc));
142   jc.can_suspend = 1;
143   jc.can_generate_sampled_object_alloc_events = 1;
144   return jc;
145 }
146 
147 
148 jvmtiCapabilities JvmtiManageCapabilities::init_onload_solo_capabilities() {
149   jvmtiCapabilities jc;
150 
151   memset(&jc, 0, sizeof(jc));
152   jc.can_generate_field_modification_events = 1;
153   jc.can_generate_field_access_events = 1;

254   // add to the set of ever acquired capabilities
255   either(&acquired_capabilities, desired, &acquired_capabilities);
256 
257   // onload capabilities that got added are now permanent - so, also remove from onload
258   both(&onload_capabilities, desired, &temp);
259   either(&always_capabilities, &temp, &always_capabilities);
260   exclude(&onload_capabilities, &temp, &onload_capabilities);
261 
262   // same for solo capabilities (transferred capabilities in the remaining sets handled as part of standard grab - below)
263   both(&onload_solo_capabilities, desired, &temp);
264   either(&always_solo_capabilities, &temp, &always_solo_capabilities);
265   exclude(&onload_solo_capabilities, &temp, &onload_solo_capabilities);
266 
267   // remove solo capabilities that are now taken
268   exclude(&always_solo_remaining_capabilities, desired, &always_solo_remaining_capabilities);
269   exclude(&onload_solo_remaining_capabilities, desired, &onload_solo_remaining_capabilities);
270 
271   // return the result
272   either(current, desired, result);
273 
274   // special case for virtual thread events
275   // TBD: There can be a performance impact after check for can_support_virtual_threads has been removed.
276   java_lang_VirtualThread::set_notify_jvmti_events(true);
277 
278   update();
279 
280   return JVMTI_ERROR_NONE;
281 }
282 
283 
284 void JvmtiManageCapabilities::relinquish_capabilities(const jvmtiCapabilities *current,
285                                                       const jvmtiCapabilities *unwanted,
286                                                       jvmtiCapabilities *result) {
287   jvmtiCapabilities to_trash;
288   jvmtiCapabilities temp;
289 
290   // can't give up what you don't have
291   both(current, unwanted, &to_trash);
292 
293   // restore solo capabilities but only those that belong
294   either(&always_solo_remaining_capabilities, both(&always_solo_capabilities, &to_trash, &temp),
295          &always_solo_remaining_capabilities);
296   either(&onload_solo_remaining_capabilities, both(&onload_solo_capabilities, &to_trash, &temp),
297          &onload_solo_remaining_capabilities);

353     avail.can_generate_all_class_hook_events);
354   JvmtiExport::set_can_walk_any_space(
355     avail.can_tag_objects);   // disable sharing in onload phase
356   // This controls whether the compilers keep extra locals live to
357   // improve the debugging experience so only set them if the selected
358   // capabilities look like a debugger.
359   JvmtiExport::set_can_access_local_variables(
360     avail.can_access_local_variables ||
361     avail.can_generate_breakpoint_events ||
362     avail.can_generate_frame_pop_events);
363   JvmtiExport::set_can_post_on_exceptions(
364     avail.can_generate_exception_events ||
365     avail.can_generate_frame_pop_events ||
366     avail.can_generate_method_exit_events);
367   JvmtiExport::set_can_post_breakpoint(avail.can_generate_breakpoint_events);
368   JvmtiExport::set_can_post_field_access(avail.can_generate_field_access_events);
369   JvmtiExport::set_can_post_field_modification(avail.can_generate_field_modification_events);
370   JvmtiExport::set_can_post_method_entry(avail.can_generate_method_entry_events);
371   JvmtiExport::set_can_post_method_exit(avail.can_generate_method_exit_events ||
372                                         avail.can_generate_frame_pop_events);
373   JvmtiExport::set_can_post_frame_pop(avail.can_generate_frame_pop_events);
374   JvmtiExport::set_can_pop_frame(avail.can_pop_frame);
375   JvmtiExport::set_can_force_early_return(avail.can_force_early_return);
376   JvmtiExport::set_can_support_virtual_threads(avail.can_support_virtual_threads);
377   JvmtiExport::set_should_clean_up_heap_objects(avail.can_generate_breakpoint_events);
378   JvmtiExport::set_can_get_owned_monitor_info(avail.can_get_owned_monitor_info ||
379                                               avail.can_get_owned_monitor_stack_depth_info);
380 }
381 
382 #ifndef PRODUCT
383 
384 void JvmtiManageCapabilities:: print(const jvmtiCapabilities* cap) {
385   log_trace(jvmti)("----- capabilities -----");
386   if (cap->can_tag_objects)
387     log_trace(jvmti)("can_tag_objects");
388   if (cap->can_generate_field_modification_events)
389     log_trace(jvmti)("can_generate_field_modification_events");
390   if (cap->can_generate_field_access_events)
391     log_trace(jvmti)("can_generate_field_access_events");
392   if (cap->can_get_bytecodes)
393     log_trace(jvmti)("can_get_bytecodes");
394   if (cap->can_get_synthetic_attribute)
395     log_trace(jvmti)("can_get_synthetic_attribute");
396   if (cap->can_get_owned_monitor_info)

450   if (cap->can_generate_compiled_method_load_events)
451     log_trace(jvmti)("can_generate_compiled_method_load_events");
452   if (cap->can_generate_monitor_events)
453     log_trace(jvmti)("can_generate_monitor_events");
454   if (cap->can_generate_vm_object_alloc_events)
455     log_trace(jvmti)("can_generate_vm_object_alloc_events");
456   if (cap->can_generate_native_method_bind_events)
457     log_trace(jvmti)("can_generate_native_method_bind_events");
458   if (cap->can_generate_garbage_collection_events)
459     log_trace(jvmti)("can_generate_garbage_collection_events");
460   if (cap->can_generate_object_free_events)
461     log_trace(jvmti)("can_generate_object_free_events");
462   if (cap->can_generate_resource_exhaustion_heap_events)
463     log_trace(jvmti)("can_generate_resource_exhaustion_heap_events");
464   if (cap->can_generate_resource_exhaustion_threads_events)
465     log_trace(jvmti)("can_generate_resource_exhaustion_threads_events");
466   if (cap->can_generate_early_vmstart)
467     log_trace(jvmti)("can_generate_early_vmstart");
468   if (cap->can_generate_early_class_hook_events)
469     log_trace(jvmti)("can_generate_early_class_hook_events");
470   if (cap->can_support_virtual_threads)
471     log_trace(jvmti)("can_support_virtual_threads");
472 }
473 
474 #endif
< prev index next >