src/share/vm/prims/jvmtiExport.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_PRIMS_JVMTIEXPORT_HPP
aoqi@0 26 #define SHARE_VM_PRIMS_JVMTIEXPORT_HPP
aoqi@0 27
aoqi@0 28 #include "jvmtifiles/jvmti.h"
aoqi@0 29 #include "memory/allocation.hpp"
aoqi@0 30 #include "memory/iterator.hpp"
aoqi@0 31 #include "oops/oop.hpp"
aoqi@0 32 #include "oops/oopsHierarchy.hpp"
aoqi@0 33 #include "runtime/frame.hpp"
aoqi@0 34 #include "runtime/handles.hpp"
aoqi@0 35 #include "utilities/globalDefinitions.hpp"
aoqi@0 36 #include "utilities/growableArray.hpp"
aoqi@0 37 #include "utilities/macros.hpp"
aoqi@0 38
aoqi@0 39 // Must be included after jvmti.h.
aoqi@0 40 #include "code/jvmticmlr.h"
aoqi@0 41
aoqi@0 42 // Forward declarations
aoqi@0 43
aoqi@0 44 class JvmtiEventControllerPrivate;
aoqi@0 45 class JvmtiManageCapabilities;
aoqi@0 46 class JvmtiEnv;
aoqi@0 47 class JvmtiThreadState;
aoqi@0 48 class AttachOperation;
aoqi@0 49
aoqi@0 50 #define JVMTI_SUPPORT_FLAG(key) \
aoqi@0 51 private: \
aoqi@0 52 static bool _##key; \
aoqi@0 53 public: \
aoqi@0 54 inline static void set_##key(bool on) { \
aoqi@0 55 JVMTI_ONLY(_##key = (on != 0)); \
aoqi@0 56 NOT_JVMTI(report_unsupported(on)); \
aoqi@0 57 } \
aoqi@0 58 inline static bool key() { \
aoqi@0 59 JVMTI_ONLY(return _##key); \
aoqi@0 60 NOT_JVMTI(return false); \
aoqi@0 61 }
aoqi@0 62
aoqi@0 63
aoqi@0 64 // This class contains the JVMTI interface for the rest of hotspot.
aoqi@0 65 //
aoqi@0 66 class JvmtiExport : public AllStatic {
aoqi@0 67 friend class VMStructs;
aoqi@0 68 friend class CompileReplay;
aoqi@0 69
aoqi@0 70 private:
aoqi@0 71
aoqi@0 72 #if INCLUDE_JVMTI
aoqi@0 73 static int _field_access_count;
aoqi@0 74 static int _field_modification_count;
aoqi@0 75
aoqi@0 76 static bool _can_access_local_variables;
aoqi@0 77 static bool _can_hotswap_or_post_breakpoint;
aoqi@0 78 static bool _can_modify_any_class;
aoqi@0 79 static bool _can_walk_any_space;
aoqi@0 80 #endif // INCLUDE_JVMTI
aoqi@0 81
aoqi@0 82 JVMTI_SUPPORT_FLAG(can_get_source_debug_extension)
aoqi@0 83 JVMTI_SUPPORT_FLAG(can_maintain_original_method_order)
aoqi@0 84 JVMTI_SUPPORT_FLAG(can_post_interpreter_events)
aoqi@0 85 JVMTI_SUPPORT_FLAG(can_post_on_exceptions)
aoqi@0 86 JVMTI_SUPPORT_FLAG(can_post_breakpoint)
aoqi@0 87 JVMTI_SUPPORT_FLAG(can_post_field_access)
aoqi@0 88 JVMTI_SUPPORT_FLAG(can_post_field_modification)
aoqi@0 89 JVMTI_SUPPORT_FLAG(can_post_method_entry)
aoqi@0 90 JVMTI_SUPPORT_FLAG(can_post_method_exit)
aoqi@0 91 JVMTI_SUPPORT_FLAG(can_pop_frame)
aoqi@0 92 JVMTI_SUPPORT_FLAG(can_force_early_return)
aoqi@0 93
aoqi@0 94 friend class JvmtiEventControllerPrivate; // should only modify these flags
aoqi@0 95 JVMTI_SUPPORT_FLAG(should_post_single_step)
aoqi@0 96 JVMTI_SUPPORT_FLAG(should_post_field_access)
aoqi@0 97 JVMTI_SUPPORT_FLAG(should_post_field_modification)
aoqi@0 98 JVMTI_SUPPORT_FLAG(should_post_class_load)
aoqi@0 99 JVMTI_SUPPORT_FLAG(should_post_class_prepare)
aoqi@0 100 JVMTI_SUPPORT_FLAG(should_post_class_unload)
aoqi@0 101 JVMTI_SUPPORT_FLAG(should_post_native_method_bind)
aoqi@0 102 JVMTI_SUPPORT_FLAG(should_post_compiled_method_load)
aoqi@0 103 JVMTI_SUPPORT_FLAG(should_post_compiled_method_unload)
aoqi@0 104 JVMTI_SUPPORT_FLAG(should_post_dynamic_code_generated)
aoqi@0 105 JVMTI_SUPPORT_FLAG(should_post_monitor_contended_enter)
aoqi@0 106 JVMTI_SUPPORT_FLAG(should_post_monitor_contended_entered)
aoqi@0 107 JVMTI_SUPPORT_FLAG(should_post_monitor_wait)
aoqi@0 108 JVMTI_SUPPORT_FLAG(should_post_monitor_waited)
aoqi@0 109 JVMTI_SUPPORT_FLAG(should_post_data_dump)
aoqi@0 110 JVMTI_SUPPORT_FLAG(should_post_garbage_collection_start)
aoqi@0 111 JVMTI_SUPPORT_FLAG(should_post_garbage_collection_finish)
aoqi@0 112 JVMTI_SUPPORT_FLAG(should_post_on_exceptions)
aoqi@0 113
aoqi@0 114 // ------ the below maybe don't have to be (but are for now)
aoqi@0 115 // fixed conditions here ------------
aoqi@0 116 // any events can be enabled
aoqi@0 117 JVMTI_SUPPORT_FLAG(should_post_thread_life)
aoqi@0 118 JVMTI_SUPPORT_FLAG(should_post_object_free)
aoqi@0 119 JVMTI_SUPPORT_FLAG(should_post_resource_exhausted)
aoqi@0 120
aoqi@0 121 // we are holding objects on the heap - need to talk to GC - e.g.
aoqi@0 122 // breakpoint info
aoqi@0 123 JVMTI_SUPPORT_FLAG(should_clean_up_heap_objects)
aoqi@0 124 JVMTI_SUPPORT_FLAG(should_post_vm_object_alloc)
aoqi@0 125
aoqi@0 126 // If flag cannot be implemented, give an error if on=true
aoqi@0 127 static void report_unsupported(bool on);
aoqi@0 128
aoqi@0 129 // these should only be called by the friend class
aoqi@0 130 friend class JvmtiManageCapabilities;
aoqi@0 131 inline static void set_can_modify_any_class(bool on) {
aoqi@0 132 JVMTI_ONLY(_can_modify_any_class = (on != 0);)
aoqi@0 133 }
aoqi@0 134 inline static void set_can_access_local_variables(bool on) {
aoqi@0 135 JVMTI_ONLY(_can_access_local_variables = (on != 0);)
aoqi@0 136 }
aoqi@0 137 inline static void set_can_hotswap_or_post_breakpoint(bool on) {
aoqi@0 138 JVMTI_ONLY(_can_hotswap_or_post_breakpoint = (on != 0);)
aoqi@0 139 }
aoqi@0 140 inline static void set_can_walk_any_space(bool on) {
aoqi@0 141 JVMTI_ONLY(_can_walk_any_space = (on != 0);)
aoqi@0 142 }
aoqi@0 143
aoqi@0 144 enum {
aoqi@0 145 JVMTI_VERSION_MASK = 0x70000000,
aoqi@0 146 JVMTI_VERSION_VALUE = 0x30000000,
aoqi@0 147 JVMDI_VERSION_VALUE = 0x20000000
aoqi@0 148 };
aoqi@0 149
aoqi@0 150 static void post_field_modification(JavaThread *thread, Method* method, address location,
aoqi@0 151 KlassHandle field_klass, Handle object, jfieldID field,
aoqi@0 152 char sig_type, jvalue *value);
aoqi@0 153
aoqi@0 154
aoqi@0 155 // posts a DynamicCodeGenerated event (internal/private implementation).
aoqi@0 156 // The public post_dynamic_code_generated* functions make use of the
aoqi@0 157 // internal implementation. Also called from JvmtiDeferredEvent::post()
aoqi@0 158 static void post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) NOT_JVMTI_RETURN;
aoqi@0 159
aoqi@0 160 private:
aoqi@0 161
aoqi@0 162 // GenerateEvents support to allow posting of CompiledMethodLoad and
aoqi@0 163 // DynamicCodeGenerated events for a given environment.
aoqi@0 164 friend class JvmtiCodeBlobEvents;
aoqi@0 165
aoqi@0 166 static void post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,
aoqi@0 167 const void *code_begin, const jint map_length,
aoqi@0 168 const jvmtiAddrLocationMap* map) NOT_JVMTI_RETURN;
aoqi@0 169 static void post_dynamic_code_generated(JvmtiEnv* env, const char *name, const void *code_begin,
aoqi@0 170 const void *code_end) NOT_JVMTI_RETURN;
aoqi@0 171
aoqi@0 172 // The RedefineClasses() API breaks some invariants in the "regular"
aoqi@0 173 // system. For example, there are sanity checks when GC'ing nmethods
aoqi@0 174 // that require the containing class to be unloading. However, when a
aoqi@0 175 // method is redefined, the old method and nmethod can become GC'able
aoqi@0 176 // without the containing class unloading. The state of becoming
aoqi@0 177 // GC'able can be asynchronous to the RedefineClasses() call since
aoqi@0 178 // the old method may still be running and cannot be GC'ed until
aoqi@0 179 // after all old invocations have finished. Additionally, a method
aoqi@0 180 // that has not been redefined may have an nmethod that depends on
aoqi@0 181 // the redefined method. The dependent nmethod will get deopted in
aoqi@0 182 // this case and may also be GC'able without the containing class
aoqi@0 183 // being unloaded.
aoqi@0 184 //
aoqi@0 185 // This flag indicates whether RedefineClasses() has ever redefined
aoqi@0 186 // one or more classes during the lifetime of the VM. The flag should
aoqi@0 187 // only be set by the friend class and can be queried by other sub
aoqi@0 188 // systems as needed to relax invariant checks.
aoqi@0 189 static bool _has_redefined_a_class;
aoqi@0 190 friend class VM_RedefineClasses;
aoqi@0 191 inline static void set_has_redefined_a_class() {
aoqi@0 192 JVMTI_ONLY(_has_redefined_a_class = true;)
aoqi@0 193 }
aoqi@0 194 // Flag to indicate if the compiler has recorded all dependencies. When the
aoqi@0 195 // can_redefine_classes capability is enabled in the OnLoad phase then the compiler
aoqi@0 196 // records all dependencies from startup. However if the capability is first
aoqi@0 197 // enabled some time later then the dependencies recorded by the compiler
aoqi@0 198 // are incomplete. This flag is used by RedefineClasses to know if the
aoqi@0 199 // dependency information is complete or not.
aoqi@0 200 static bool _all_dependencies_are_recorded;
aoqi@0 201
aoqi@0 202 public:
aoqi@0 203 inline static bool has_redefined_a_class() {
aoqi@0 204 JVMTI_ONLY(return _has_redefined_a_class);
aoqi@0 205 NOT_JVMTI(return false);
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 inline static bool all_dependencies_are_recorded() {
aoqi@0 209 return _all_dependencies_are_recorded;
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 inline static void set_all_dependencies_are_recorded(bool on) {
aoqi@0 213 _all_dependencies_are_recorded = (on != 0);
aoqi@0 214 }
aoqi@0 215
aoqi@0 216
aoqi@0 217 // let JVMTI know that the JVM_OnLoad code is running
aoqi@0 218 static void enter_onload_phase() NOT_JVMTI_RETURN;
aoqi@0 219
aoqi@0 220 // let JVMTI know that the VM isn't up yet (and JVM_OnLoad code isn't running)
aoqi@0 221 static void enter_primordial_phase() NOT_JVMTI_RETURN;
aoqi@0 222
aoqi@0 223 // let JVMTI know that the VM isn't up yet but JNI is live
aoqi@0 224 static void enter_start_phase() NOT_JVMTI_RETURN;
aoqi@0 225
aoqi@0 226 // let JVMTI know that the VM is fully up and running now
aoqi@0 227 static void enter_live_phase() NOT_JVMTI_RETURN;
aoqi@0 228
aoqi@0 229 // ------ can_* conditions (below) are set at OnLoad and never changed ------------
aoqi@0 230 inline static bool can_modify_any_class() {
aoqi@0 231 JVMTI_ONLY(return _can_modify_any_class);
aoqi@0 232 NOT_JVMTI(return false);
aoqi@0 233 }
aoqi@0 234 inline static bool can_access_local_variables() {
aoqi@0 235 JVMTI_ONLY(return _can_access_local_variables);
aoqi@0 236 NOT_JVMTI(return false);
aoqi@0 237 }
aoqi@0 238 inline static bool can_hotswap_or_post_breakpoint() {
aoqi@0 239 JVMTI_ONLY(return _can_hotswap_or_post_breakpoint);
aoqi@0 240 NOT_JVMTI(return false);
aoqi@0 241 }
aoqi@0 242 inline static bool can_walk_any_space() {
aoqi@0 243 JVMTI_ONLY(return _can_walk_any_space);
aoqi@0 244 NOT_JVMTI(return false);
aoqi@0 245 }
aoqi@0 246
aoqi@0 247 // field access management
aoqi@0 248 static address get_field_access_count_addr() NOT_JVMTI_RETURN_(0);
aoqi@0 249
aoqi@0 250 // field modification management
aoqi@0 251 static address get_field_modification_count_addr() NOT_JVMTI_RETURN_(0);
aoqi@0 252
aoqi@0 253 // -----------------
aoqi@0 254
aoqi@0 255 static bool is_jvmti_version(jint version) {
aoqi@0 256 JVMTI_ONLY(return (version & JVMTI_VERSION_MASK) == JVMTI_VERSION_VALUE);
aoqi@0 257 NOT_JVMTI(return false);
aoqi@0 258 }
aoqi@0 259 static bool is_jvmdi_version(jint version) {
aoqi@0 260 JVMTI_ONLY(return (version & JVMTI_VERSION_MASK) == JVMDI_VERSION_VALUE);
aoqi@0 261 NOT_JVMTI(return false);
aoqi@0 262 }
aoqi@0 263 static jint get_jvmti_interface(JavaVM *jvm, void **penv, jint version) NOT_JVMTI_RETURN_(0);
aoqi@0 264 static void decode_version_values(jint version, int * major, int * minor,
aoqi@0 265 int * micro) NOT_JVMTI_RETURN;
aoqi@0 266
aoqi@0 267 // single stepping management methods
aoqi@0 268 static void at_single_stepping_point(JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN;
aoqi@0 269 static void expose_single_stepping(JavaThread *thread) NOT_JVMTI_RETURN;
aoqi@0 270 static bool hide_single_stepping(JavaThread *thread) NOT_JVMTI_RETURN_(false);
aoqi@0 271
aoqi@0 272 // Methods that notify the debugger that something interesting has happened in the VM.
aoqi@0 273 static void post_vm_start () NOT_JVMTI_RETURN;
aoqi@0 274 static void post_vm_initialized () NOT_JVMTI_RETURN;
aoqi@0 275 static void post_vm_death () NOT_JVMTI_RETURN;
aoqi@0 276
aoqi@0 277 static void post_single_step (JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN;
aoqi@0 278 static void post_raw_breakpoint (JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN;
aoqi@0 279
aoqi@0 280 static void post_exception_throw (JavaThread *thread, Method* method, address location, oop exception) NOT_JVMTI_RETURN;
aoqi@0 281 static void notice_unwind_due_to_exception (JavaThread *thread, Method* method, address location, oop exception, bool in_handler_frame) NOT_JVMTI_RETURN;
aoqi@0 282
aoqi@0 283 static oop jni_GetField_probe (JavaThread *thread, jobject jobj,
aoqi@0 284 oop obj, Klass* klass, jfieldID fieldID, bool is_static)
aoqi@0 285 NOT_JVMTI_RETURN_(NULL);
aoqi@0 286 static oop jni_GetField_probe_nh (JavaThread *thread, jobject jobj,
aoqi@0 287 oop obj, Klass* klass, jfieldID fieldID, bool is_static)
aoqi@0 288 NOT_JVMTI_RETURN_(NULL);
aoqi@0 289 static void post_field_access_by_jni (JavaThread *thread, oop obj,
aoqi@0 290 Klass* klass, jfieldID fieldID, bool is_static) NOT_JVMTI_RETURN;
aoqi@0 291 static void post_field_access (JavaThread *thread, Method* method,
aoqi@0 292 address location, KlassHandle field_klass, Handle object, jfieldID field) NOT_JVMTI_RETURN;
aoqi@0 293 static oop jni_SetField_probe (JavaThread *thread, jobject jobj,
aoqi@0 294 oop obj, Klass* klass, jfieldID fieldID, bool is_static, char sig_type,
aoqi@0 295 jvalue *value) NOT_JVMTI_RETURN_(NULL);
aoqi@0 296 static oop jni_SetField_probe_nh (JavaThread *thread, jobject jobj,
aoqi@0 297 oop obj, Klass* klass, jfieldID fieldID, bool is_static, char sig_type,
aoqi@0 298 jvalue *value) NOT_JVMTI_RETURN_(NULL);
aoqi@0 299 static void post_field_modification_by_jni(JavaThread *thread, oop obj,
aoqi@0 300 Klass* klass, jfieldID fieldID, bool is_static, char sig_type,
aoqi@0 301 jvalue *value);
aoqi@0 302 static void post_raw_field_modification(JavaThread *thread, Method* method,
aoqi@0 303 address location, KlassHandle field_klass, Handle object, jfieldID field,
aoqi@0 304 char sig_type, jvalue *value) NOT_JVMTI_RETURN;
aoqi@0 305
aoqi@0 306 static void post_method_entry (JavaThread *thread, Method* method, frame current_frame) NOT_JVMTI_RETURN;
aoqi@0 307 static void post_method_exit (JavaThread *thread, Method* method, frame current_frame) NOT_JVMTI_RETURN;
aoqi@0 308
aoqi@0 309 static void post_class_load (JavaThread *thread, Klass* klass) NOT_JVMTI_RETURN;
aoqi@0 310 static void post_class_unload (Klass* klass) NOT_JVMTI_RETURN;
aoqi@0 311 static void post_class_prepare (JavaThread *thread, Klass* klass) NOT_JVMTI_RETURN;
aoqi@0 312
aoqi@0 313 static void post_thread_start (JavaThread *thread) NOT_JVMTI_RETURN;
aoqi@0 314 static void post_thread_end (JavaThread *thread) NOT_JVMTI_RETURN;
aoqi@0 315
aoqi@0 316 // Support for java.lang.instrument agent loading.
aoqi@0 317 static bool _should_post_class_file_load_hook;
aoqi@0 318 inline static void set_should_post_class_file_load_hook(bool on) { _should_post_class_file_load_hook = on; }
aoqi@0 319 inline static bool should_post_class_file_load_hook() {
aoqi@0 320 JVMTI_ONLY(return _should_post_class_file_load_hook);
aoqi@0 321 NOT_JVMTI(return false;)
aoqi@0 322 }
aoqi@0 323 static void post_class_file_load_hook(Symbol* h_name, Handle class_loader,
aoqi@0 324 Handle h_protection_domain,
aoqi@0 325 unsigned char **data_ptr, unsigned char **end_ptr,
aoqi@0 326 JvmtiCachedClassFileData **cache_ptr) NOT_JVMTI_RETURN;
aoqi@0 327 static void post_native_method_bind(Method* method, address* function_ptr) NOT_JVMTI_RETURN;
aoqi@0 328 static void post_compiled_method_load(nmethod *nm) NOT_JVMTI_RETURN;
aoqi@0 329 static void post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) NOT_JVMTI_RETURN;
aoqi@0 330
aoqi@0 331 // used to post a CompiledMethodUnload event
aoqi@0 332 static void post_compiled_method_unload(jmethodID mid, const void *code_begin) NOT_JVMTI_RETURN;
aoqi@0 333
aoqi@0 334 // similiar to post_dynamic_code_generated except that it can be used to
aoqi@0 335 // post a DynamicCodeGenerated event while holding locks in the VM. Any event
aoqi@0 336 // posted using this function is recorded by the enclosing event collector
aoqi@0 337 // -- JvmtiDynamicCodeEventCollector.
aoqi@0 338 static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) NOT_JVMTI_RETURN;
aoqi@0 339
aoqi@0 340 static void post_garbage_collection_finish() NOT_JVMTI_RETURN;
aoqi@0 341 static void post_garbage_collection_start() NOT_JVMTI_RETURN;
aoqi@0 342 static void post_data_dump() NOT_JVMTI_RETURN;
aoqi@0 343 static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
aoqi@0 344 static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;
aoqi@0 345 static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) NOT_JVMTI_RETURN;
aoqi@0 346 static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) NOT_JVMTI_RETURN;
aoqi@0 347 static void post_object_free(JvmtiEnv* env, jlong tag) NOT_JVMTI_RETURN;
aoqi@0 348 static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) NOT_JVMTI_RETURN;
aoqi@0 349 static void record_vm_internal_object_allocation(oop object) NOT_JVMTI_RETURN;
aoqi@0 350 // Post objects collected by vm_object_alloc_event_collector.
aoqi@0 351 static void post_vm_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;
aoqi@0 352 // Collects vm internal objects for later event posting.
aoqi@0 353 inline static void vm_object_alloc_event_collector(oop object) {
aoqi@0 354 if (should_post_vm_object_alloc()) {
aoqi@0 355 record_vm_internal_object_allocation(object);
aoqi@0 356 }
aoqi@0 357 }
aoqi@0 358 inline static void post_array_size_exhausted() {
aoqi@0 359 if (should_post_resource_exhausted()) {
aoqi@0 360 post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
aoqi@0 361 "Requested array size exceeds VM limit");
aoqi@0 362 }
aoqi@0 363 }
aoqi@0 364
aoqi@0 365 static void cleanup_thread (JavaThread* thread) NOT_JVMTI_RETURN;
aoqi@0 366
aoqi@0 367 static void oops_do(OopClosure* f) NOT_JVMTI_RETURN;
aoqi@0 368 static void weak_oops_do(BoolObjectClosure* b, OopClosure* f) NOT_JVMTI_RETURN;
aoqi@0 369 static void gc_epilogue() NOT_JVMTI_RETURN;
aoqi@0 370
aoqi@0 371 static void transition_pending_onload_raw_monitors() NOT_JVMTI_RETURN;
aoqi@0 372
aoqi@0 373 // attach support
aoqi@0 374 static jint load_agent_library(AttachOperation* op, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR);
aoqi@0 375
aoqi@0 376 // SetNativeMethodPrefix support
aoqi@0 377 static char** get_all_native_method_prefixes(int* count_ptr) NOT_JVMTI_RETURN_(NULL);
aoqi@0 378 };
aoqi@0 379
aoqi@0 380 // Support class used by JvmtiDynamicCodeEventCollector and others. It
aoqi@0 381 // describes a single code blob by name and address range.
aoqi@0 382 class JvmtiCodeBlobDesc : public CHeapObj<mtInternal> {
aoqi@0 383 private:
aoqi@0 384 char _name[64];
aoqi@0 385 address _code_begin;
aoqi@0 386 address _code_end;
aoqi@0 387
aoqi@0 388 public:
aoqi@0 389 JvmtiCodeBlobDesc(const char *name, address code_begin, address code_end) {
aoqi@0 390 assert(name != NULL, "all code blobs must be named");
aoqi@0 391 strncpy(_name, name, sizeof(_name));
aoqi@0 392 _name[sizeof(_name)-1] = '\0';
aoqi@0 393 _code_begin = code_begin;
aoqi@0 394 _code_end = code_end;
aoqi@0 395 }
aoqi@0 396 char* name() { return _name; }
aoqi@0 397 address code_begin() { return _code_begin; }
aoqi@0 398 address code_end() { return _code_end; }
aoqi@0 399 };
aoqi@0 400
aoqi@0 401 // JvmtiEventCollector is a helper class to setup thread for
aoqi@0 402 // event collection.
aoqi@0 403 class JvmtiEventCollector : public StackObj {
aoqi@0 404 private:
aoqi@0 405 JvmtiEventCollector* _prev; // Save previous one to support nested event collector.
aoqi@0 406
aoqi@0 407 public:
aoqi@0 408 void setup_jvmti_thread_state(); // Set this collector in current thread.
aoqi@0 409 void unset_jvmti_thread_state(); // Reset previous collector in current thread.
aoqi@0 410 virtual bool is_dynamic_code_event() { return false; }
aoqi@0 411 virtual bool is_vm_object_alloc_event(){ return false; }
aoqi@0 412 JvmtiEventCollector *get_prev() { return _prev; }
aoqi@0 413 };
aoqi@0 414
aoqi@0 415 // A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport
aoqi@0 416 // interface. It collects "dynamic code generated" events that are posted
aoqi@0 417 // while holding locks. When the event collector goes out of scope the
aoqi@0 418 // events will be posted.
aoqi@0 419 //
aoqi@0 420 // Usage :-
aoqi@0 421 //
aoqi@0 422 // {
aoqi@0 423 // JvmtiDynamicCodeEventCollector event_collector;
aoqi@0 424 // :
aoqi@0 425 // { MutexLocker ml(...)
aoqi@0 426 // :
aoqi@0 427 // JvmtiExport::post_dynamic_code_generated_while_holding_locks(...)
aoqi@0 428 // }
aoqi@0 429 // // event collector goes out of scope => post events to profiler.
aoqi@0 430 // }
aoqi@0 431
aoqi@0 432 class JvmtiDynamicCodeEventCollector : public JvmtiEventCollector {
aoqi@0 433 private:
aoqi@0 434 GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs; // collected code blob events
aoqi@0 435
aoqi@0 436 friend class JvmtiExport;
aoqi@0 437 void register_stub(const char* name, address start, address end);
aoqi@0 438
aoqi@0 439 public:
aoqi@0 440 JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN;
aoqi@0 441 ~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN;
aoqi@0 442 bool is_dynamic_code_event() { return true; }
aoqi@0 443
aoqi@0 444 };
aoqi@0 445
aoqi@0 446 // Used to record vm internally allocated object oops and post
aoqi@0 447 // vm object alloc event for objects visible to java world.
aoqi@0 448 // Constructor enables JvmtiThreadState flag and all vm allocated
aoqi@0 449 // objects are recorded in a growable array. When destructor is
aoqi@0 450 // called the vm object alloc event is posted for each objects
aoqi@0 451 // visible to java world.
aoqi@0 452 // See jvm.cpp file for its usage.
aoqi@0 453 //
aoqi@0 454 class JvmtiVMObjectAllocEventCollector : public JvmtiEventCollector {
aoqi@0 455 private:
aoqi@0 456 GrowableArray<oop>* _allocated; // field to record vm internally allocated object oop.
aoqi@0 457 bool _enable; // This flag is enabled in constructor and disabled
aoqi@0 458 // in destructor before posting event. To avoid
aoqi@0 459 // collection of objects allocated while running java code inside
aoqi@0 460 // agent post_vm_object_alloc() event handler.
aoqi@0 461
aoqi@0 462 //GC support
aoqi@0 463 void oops_do(OopClosure* f);
aoqi@0 464
aoqi@0 465 friend class JvmtiExport;
aoqi@0 466 // Record vm allocated object oop.
aoqi@0 467 inline void record_allocation(oop obj);
aoqi@0 468
aoqi@0 469 //GC support
aoqi@0 470 static void oops_do_for_all_threads(OopClosure* f);
aoqi@0 471
aoqi@0 472 public:
aoqi@0 473 JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN;
aoqi@0 474 ~JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN;
aoqi@0 475 bool is_vm_object_alloc_event() { return true; }
aoqi@0 476
aoqi@0 477 bool is_enabled() { return _enable; }
aoqi@0 478 void set_enabled(bool on) { _enable = on; }
aoqi@0 479 };
aoqi@0 480
aoqi@0 481
aoqi@0 482
aoqi@0 483 // Marker class to disable the posting of VMObjectAlloc events
aoqi@0 484 // within its scope.
aoqi@0 485 //
aoqi@0 486 // Usage :-
aoqi@0 487 //
aoqi@0 488 // {
aoqi@0 489 // NoJvmtiVMObjectAllocMark njm;
aoqi@0 490 // :
aoqi@0 491 // // VMObjAlloc event will not be posted
aoqi@0 492 // JvmtiExport::vm_object_alloc_event_collector(obj);
aoqi@0 493 // :
aoqi@0 494 // }
aoqi@0 495
aoqi@0 496 class NoJvmtiVMObjectAllocMark : public StackObj {
aoqi@0 497 private:
aoqi@0 498 // enclosing collector if enabled, NULL otherwise
aoqi@0 499 JvmtiVMObjectAllocEventCollector *_collector;
aoqi@0 500
aoqi@0 501 bool was_enabled() { return _collector != NULL; }
aoqi@0 502
aoqi@0 503 public:
aoqi@0 504 NoJvmtiVMObjectAllocMark() NOT_JVMTI_RETURN;
aoqi@0 505 ~NoJvmtiVMObjectAllocMark() NOT_JVMTI_RETURN;
aoqi@0 506 };
aoqi@0 507
aoqi@0 508
aoqi@0 509 // Base class for reporting GC events to JVMTI.
aoqi@0 510 class JvmtiGCMarker : public StackObj {
aoqi@0 511 public:
aoqi@0 512 JvmtiGCMarker() NOT_JVMTI_RETURN;
aoqi@0 513 ~JvmtiGCMarker() NOT_JVMTI_RETURN;
aoqi@0 514 };
aoqi@0 515
aoqi@0 516 // JvmtiHideSingleStepping is a helper class for hiding
aoqi@0 517 // internal single step events.
aoqi@0 518 class JvmtiHideSingleStepping : public StackObj {
aoqi@0 519 private:
aoqi@0 520 bool _single_step_hidden;
aoqi@0 521 JavaThread * _thread;
aoqi@0 522
aoqi@0 523 public:
aoqi@0 524 JvmtiHideSingleStepping(JavaThread * thread) {
aoqi@0 525 assert(thread != NULL, "sanity check");
aoqi@0 526
aoqi@0 527 _single_step_hidden = false;
aoqi@0 528 _thread = thread;
aoqi@0 529 if (JvmtiExport::should_post_single_step()) {
aoqi@0 530 _single_step_hidden = JvmtiExport::hide_single_stepping(_thread);
aoqi@0 531 }
aoqi@0 532 }
aoqi@0 533
aoqi@0 534 ~JvmtiHideSingleStepping() {
aoqi@0 535 if (_single_step_hidden) {
aoqi@0 536 JvmtiExport::expose_single_stepping(_thread);
aoqi@0 537 }
aoqi@0 538 }
aoqi@0 539 };
aoqi@0 540
aoqi@0 541 #endif // SHARE_VM_PRIMS_JVMTIEXPORT_HPP

mercurial