src/share/vm/prims/jvmtiEnvBase.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 8856
ac27a9c85bea
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 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_JVMTIENVBASE_HPP
aoqi@0 26 #define SHARE_VM_PRIMS_JVMTIENVBASE_HPP
aoqi@0 27
aoqi@0 28 #include "classfile/classLoader.hpp"
aoqi@0 29 #include "prims/jvmtiEnvThreadState.hpp"
aoqi@0 30 #include "prims/jvmtiEventController.hpp"
aoqi@0 31 #include "prims/jvmtiThreadState.hpp"
aoqi@0 32 #include "runtime/fieldDescriptor.hpp"
aoqi@0 33 #include "runtime/frame.hpp"
aoqi@0 34 #include "runtime/handles.inline.hpp"
aoqi@0 35 #include "runtime/thread.hpp"
aoqi@0 36 #include "runtime/vm_operations.hpp"
aoqi@0 37 #include "utilities/growableArray.hpp"
aoqi@0 38 #include "utilities/macros.hpp"
aoqi@0 39
aoqi@0 40 //
aoqi@0 41 // Forward Declarations
aoqi@0 42 //
aoqi@0 43
aoqi@0 44 class JvmtiEnv;
aoqi@0 45 class JvmtiThreadState;
aoqi@0 46 class JvmtiRawMonitor; // for jvmtiEnv.hpp
aoqi@0 47 class JvmtiEventControllerPrivate;
aoqi@0 48 class JvmtiTagMap;
aoqi@0 49
aoqi@0 50
aoqi@0 51
aoqi@0 52 // One JvmtiEnv object is created per jvmti attachment;
aoqi@0 53 // done via JNI GetEnv() call. Multiple attachments are
aoqi@0 54 // allowed in jvmti.
aoqi@0 55
aoqi@0 56 class JvmtiEnvBase : public CHeapObj<mtInternal> {
aoqi@0 57
aoqi@0 58 private:
aoqi@0 59
aoqi@0 60 #if INCLUDE_JVMTI
aoqi@0 61 static JvmtiEnvBase* _head_environment; // head of environment list
aoqi@0 62 #endif // INCLUDE_JVMTI
aoqi@0 63
aoqi@0 64 static bool _globally_initialized;
aoqi@0 65 static jvmtiPhase _phase;
aoqi@0 66 static volatile int _dying_thread_env_iteration_count;
aoqi@0 67
aoqi@0 68 public:
aoqi@0 69
aoqi@0 70 enum {
aoqi@0 71 JDK15_JVMTI_VERSION = JVMTI_VERSION_1_0 + 33, /* version: 1.0.33 */
aoqi@0 72 JDK16_JVMTI_VERSION = JVMTI_VERSION_1_1 + 102, /* version: 1.1.102 */
aoqi@0 73 JDK17_JVMTI_VERSION = JVMTI_VERSION_1_2 + 2 /* version: 1.2.2 */
aoqi@0 74 };
aoqi@0 75
aoqi@0 76 static jvmtiPhase get_phase() { return _phase; }
aoqi@0 77 static void set_phase(jvmtiPhase phase) { _phase = phase; }
aoqi@0 78 static bool is_vm_live() { return _phase == JVMTI_PHASE_LIVE; }
aoqi@0 79
aoqi@0 80 static void entering_dying_thread_env_iteration() { ++_dying_thread_env_iteration_count; }
aoqi@0 81 static void leaving_dying_thread_env_iteration() { --_dying_thread_env_iteration_count; }
aoqi@0 82 static bool is_inside_dying_thread_env_iteration(){ return _dying_thread_env_iteration_count > 0; }
aoqi@0 83
aoqi@0 84 private:
aoqi@0 85
aoqi@0 86 enum {
aoqi@0 87 JVMTI_MAGIC = 0x71EE,
aoqi@0 88 DISPOSED_MAGIC = 0xDEFC,
aoqi@0 89 BAD_MAGIC = 0xDEAD
aoqi@0 90 };
aoqi@0 91
aoqi@0 92 jvmtiEnv _jvmti_external;
aoqi@0 93 jint _magic;
aoqi@0 94 jint _version; // version value passed to JNI GetEnv()
aoqi@0 95 JvmtiEnvBase* _next;
aoqi@0 96 bool _is_retransformable;
aoqi@0 97 const void *_env_local_storage; // per env agent allocated data.
aoqi@0 98 jvmtiEventCallbacks _event_callbacks;
aoqi@0 99 jvmtiExtEventCallbacks _ext_event_callbacks;
aoqi@0 100 JvmtiTagMap* _tag_map;
aoqi@0 101 JvmtiEnvEventEnable _env_event_enable;
aoqi@0 102 jvmtiCapabilities _current_capabilities;
aoqi@0 103 jvmtiCapabilities _prohibited_capabilities;
aoqi@0 104 volatile bool _class_file_load_hook_ever_enabled;
aoqi@0 105 static volatile bool _needs_clean_up;
aoqi@0 106 char** _native_method_prefixes;
aoqi@0 107 int _native_method_prefix_count;
aoqi@0 108
aoqi@0 109 protected:
aoqi@0 110 JvmtiEnvBase(jint version);
aoqi@0 111 ~JvmtiEnvBase();
aoqi@0 112 void dispose();
aoqi@0 113 void env_dispose();
aoqi@0 114
aoqi@0 115 void set_env_local_storage(const void* data) { _env_local_storage = data; }
aoqi@0 116 const void* get_env_local_storage() { return _env_local_storage; }
aoqi@0 117
aoqi@0 118 void record_class_file_load_hook_enabled();
aoqi@0 119 void record_first_time_class_file_load_hook_enabled();
aoqi@0 120
aoqi@0 121 char** get_native_method_prefixes() { return _native_method_prefixes; }
aoqi@0 122 int get_native_method_prefix_count() { return _native_method_prefix_count; }
aoqi@0 123 jvmtiError set_native_method_prefixes(jint prefix_count, char** prefixes);
aoqi@0 124
aoqi@0 125 private:
aoqi@0 126 friend class JvmtiEventControllerPrivate;
aoqi@0 127 void initialize();
aoqi@0 128 void set_event_callbacks(const jvmtiEventCallbacks* callbacks, jint size_of_callbacks);
aoqi@0 129 static void globally_initialize();
aoqi@0 130 static void periodic_clean_up();
aoqi@0 131
aoqi@0 132 friend class JvmtiEnvIterator;
aoqi@0 133 JvmtiEnv* next_environment() { return (JvmtiEnv*)_next; }
aoqi@0 134 void set_next_environment(JvmtiEnvBase* env) { _next = env; }
aoqi@0 135 static JvmtiEnv* head_environment() {
aoqi@0 136 JVMTI_ONLY(return (JvmtiEnv*)_head_environment);
aoqi@0 137 NOT_JVMTI(return NULL);
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 public:
aoqi@0 141
aoqi@0 142 bool is_valid();
aoqi@0 143
aoqi@0 144 bool use_version_1_0_semantics(); // agent asked for version 1.0
aoqi@0 145 bool use_version_1_1_semantics(); // agent asked for version 1.1
aoqi@0 146 bool use_version_1_2_semantics(); // agent asked for version 1.2
aoqi@0 147
aoqi@0 148 bool is_retransformable() { return _is_retransformable; }
aoqi@0 149
aoqi@0 150 static ByteSize jvmti_external_offset() {
aoqi@0 151 return byte_offset_of(JvmtiEnvBase, _jvmti_external);
aoqi@0 152 };
aoqi@0 153
aoqi@0 154 static JvmtiEnv* JvmtiEnv_from_jvmti_env(jvmtiEnv *env) {
aoqi@0 155 return (JvmtiEnv*)((intptr_t)env - in_bytes(jvmti_external_offset()));
aoqi@0 156 };
aoqi@0 157
aoqi@0 158 jvmtiCapabilities *get_capabilities() { return &_current_capabilities; }
aoqi@0 159
aoqi@0 160 jvmtiCapabilities *get_prohibited_capabilities() { return &_prohibited_capabilities; }
aoqi@0 161
aoqi@0 162 static char** get_all_native_method_prefixes(int* count_ptr);
aoqi@0 163
aoqi@0 164 // This test will answer true when all environments have been disposed and some have
aoqi@0 165 // not yet been deallocated. As a result, this test should only be used as an
aoqi@0 166 // optimization for the no environment case.
aoqi@0 167 static bool environments_might_exist() {
aoqi@0 168 return head_environment() != NULL;
aoqi@0 169 }
aoqi@0 170
aoqi@0 171 static void check_for_periodic_clean_up();
aoqi@0 172
aoqi@0 173 JvmtiEnvEventEnable *env_event_enable() {
aoqi@0 174 return &_env_event_enable;
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 jvmtiError allocate(jlong size, unsigned char** mem_ptr) {
aoqi@0 178 if (size < 0) {
aoqi@0 179 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 180 }
aoqi@0 181 if (size == 0) {
aoqi@0 182 *mem_ptr = NULL;
aoqi@0 183 } else {
aoqi@0 184 *mem_ptr = (unsigned char *)os::malloc((size_t)size, mtInternal);
aoqi@0 185 if (*mem_ptr == NULL) {
aoqi@0 186 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 187 }
aoqi@0 188 }
aoqi@0 189 return JVMTI_ERROR_NONE;
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 jvmtiError deallocate(unsigned char* mem) {
aoqi@0 193 if (mem != NULL) {
aoqi@0 194 os::free(mem, mtInternal);
aoqi@0 195 }
aoqi@0 196 return JVMTI_ERROR_NONE;
aoqi@0 197 }
aoqi@0 198
aoqi@0 199
aoqi@0 200 // Memory functions
aoqi@0 201 unsigned char* jvmtiMalloc(jlong size); // don't use this - call allocate
aoqi@0 202
aoqi@0 203 // method to create a local handle
aoqi@0 204 jobject jni_reference(Handle hndl) {
aoqi@0 205 return JNIHandles::make_local(hndl());
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 // method to create a local handle.
aoqi@0 209 // This function allows caller to specify which
aoqi@0 210 // threads local handle table to use.
aoqi@0 211 jobject jni_reference(JavaThread *thread, Handle hndl) {
aoqi@0 212 return JNIHandles::make_local(thread, hndl());
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 // method to destroy a local handle
aoqi@0 216 void destroy_jni_reference(jobject jobj) {
aoqi@0 217 JNIHandles::destroy_local(jobj);
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 // method to destroy a local handle.
aoqi@0 221 // This function allows caller to specify which
aoqi@0 222 // threads local handle table to use although currently it is
aoqi@0 223 // not used.
aoqi@0 224 void destroy_jni_reference(JavaThread *thread, jobject jobj) {
aoqi@0 225 destroy_jni_reference(jobj);
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 jvmtiEnv* jvmti_external() { return &_jvmti_external; };
aoqi@0 229
aoqi@0 230 // Event Dispatch
aoqi@0 231
aoqi@0 232 bool has_callback(jvmtiEvent event_type) {
aoqi@0 233 assert(event_type >= JVMTI_MIN_EVENT_TYPE_VAL &&
aoqi@0 234 event_type <= JVMTI_MAX_EVENT_TYPE_VAL, "checking");
aoqi@0 235 return ((void**)&_event_callbacks)[event_type-JVMTI_MIN_EVENT_TYPE_VAL] != NULL;
aoqi@0 236 }
aoqi@0 237
aoqi@0 238 jvmtiEventCallbacks* callbacks() {
aoqi@0 239 return &_event_callbacks;
aoqi@0 240 }
aoqi@0 241
aoqi@0 242 jvmtiExtEventCallbacks* ext_callbacks() {
aoqi@0 243 return &_ext_event_callbacks;
aoqi@0 244 }
aoqi@0 245
aoqi@0 246 void set_tag_map(JvmtiTagMap* tag_map) {
aoqi@0 247 _tag_map = tag_map;
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 JvmtiTagMap* tag_map() {
aoqi@0 251 return _tag_map;
aoqi@0 252 }
aoqi@0 253
aoqi@0 254
aoqi@0 255 // return true if event is enabled globally or for any thread
aoqi@0 256 // True only if there is a callback for it.
aoqi@0 257 bool is_enabled(jvmtiEvent event_type) {
aoqi@0 258 return _env_event_enable.is_enabled(event_type);
aoqi@0 259 }
aoqi@0 260
aoqi@0 261 // Random Utilities
aoqi@0 262
aoqi@0 263 protected:
aoqi@0 264 // helper methods for creating arrays of global JNI Handles from local Handles
aoqi@0 265 // allocated into environment specific storage
aoqi@0 266 jobject * new_jobjectArray(int length, Handle *handles);
aoqi@0 267 jthread * new_jthreadArray(int length, Handle *handles);
aoqi@0 268 jthreadGroup * new_jthreadGroupArray(int length, Handle *handles);
aoqi@0 269
aoqi@0 270 // convert from JNIHandle to JavaThread *
aoqi@0 271 JavaThread * get_JavaThread(jthread jni_thread);
aoqi@0 272
aoqi@0 273 // convert to a jni jclass from a non-null Klass*
aoqi@0 274 jclass get_jni_class_non_null(Klass* k);
aoqi@0 275
aoqi@0 276 jint count_locked_objects(JavaThread *java_thread, Handle hobj);
aoqi@0 277 jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread,
aoqi@0 278 JavaThread* java_thread,
aoqi@0 279 javaVFrame *jvf,
aoqi@0 280 GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list,
aoqi@0 281 jint depth);
aoqi@0 282 vframe* vframeFor(JavaThread* java_thread, jint depth);
aoqi@0 283
aoqi@0 284 public:
aoqi@0 285 // get a field descriptor for the specified class and field
aoqi@0 286 static bool get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd);
aoqi@0 287 // test for suspend - most (all?) of these should go away
aoqi@0 288 static bool is_thread_fully_suspended(JavaThread *thread,
aoqi@0 289 bool wait_for_suspend,
aoqi@0 290 uint32_t *bits);
aoqi@0 291
aoqi@0 292
aoqi@0 293 // JVMTI API helper functions which are called at safepoint or thread is suspended.
aoqi@0 294 jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr);
aoqi@0 295 jvmtiError get_frame_location(JavaThread* java_thread, jint depth,
aoqi@0 296 jmethodID* method_ptr, jlocation* location_ptr);
aoqi@0 297 jvmtiError get_object_monitor_usage(JavaThread *calling_thread,
aoqi@0 298 jobject object, jvmtiMonitorUsage* info_ptr);
aoqi@0 299 jvmtiError get_stack_trace(JavaThread *java_thread,
aoqi@0 300 jint stack_depth, jint max_count,
aoqi@0 301 jvmtiFrameInfo* frame_buffer, jint* count_ptr);
aoqi@0 302 jvmtiError get_current_contended_monitor(JavaThread *calling_thread,
aoqi@0 303 JavaThread *java_thread,
aoqi@0 304 jobject *monitor_ptr);
aoqi@0 305 jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
aoqi@0 306 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list);
aoqi@0 307 jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
aoqi@0 308 jvalue value, TosState tos, Handle* ret_ob_h);
aoqi@0 309 jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos);
aoqi@0 310 };
aoqi@0 311
aoqi@0 312 // This class is the only safe means of iterating through environments.
aoqi@0 313 // Note that this iteratation includes invalid environments pending
aoqi@0 314 // deallocation -- in fact, some uses depend on this behavior.
aoqi@0 315
aoqi@0 316 class JvmtiEnvIterator : public StackObj {
aoqi@0 317 private:
aoqi@0 318 bool _entry_was_marked;
aoqi@0 319 public:
aoqi@0 320 JvmtiEnvIterator() {
aoqi@0 321 if (Threads::number_of_threads() == 0) {
aoqi@0 322 _entry_was_marked = false; // we are single-threaded, no need
aoqi@0 323 } else {
aoqi@0 324 Thread::current()->entering_jvmti_env_iteration();
aoqi@0 325 _entry_was_marked = true;
aoqi@0 326 }
aoqi@0 327 }
aoqi@0 328 ~JvmtiEnvIterator() {
aoqi@0 329 if (_entry_was_marked) {
aoqi@0 330 Thread::current()->leaving_jvmti_env_iteration();
aoqi@0 331 }
aoqi@0 332 }
aoqi@0 333 JvmtiEnv* first() { return JvmtiEnvBase::head_environment(); }
aoqi@0 334 JvmtiEnv* next(JvmtiEnvBase* env) { return env->next_environment(); }
aoqi@0 335 };
aoqi@0 336
aoqi@0 337
aoqi@0 338 // VM operation to get monitor information with stack depth.
aoqi@0 339 class VM_GetOwnedMonitorInfo : public VM_Operation {
aoqi@0 340 private:
aoqi@0 341 JvmtiEnv *_env;
aoqi@0 342 JavaThread* _calling_thread;
aoqi@0 343 JavaThread *_java_thread;
aoqi@0 344 jvmtiError _result;
aoqi@0 345 GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
aoqi@0 346
aoqi@0 347 public:
aoqi@0 348 VM_GetOwnedMonitorInfo(JvmtiEnv* env, JavaThread* calling_thread,
aoqi@0 349 JavaThread* java_thread,
aoqi@0 350 GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list) {
aoqi@0 351 _env = env;
aoqi@0 352 _calling_thread = calling_thread;
aoqi@0 353 _java_thread = java_thread;
aoqi@0 354 _owned_monitors_list = owned_monitor_list;
aoqi@0 355 _result = JVMTI_ERROR_NONE;
aoqi@0 356 }
aoqi@0 357 VMOp_Type type() const { return VMOp_GetOwnedMonitorInfo; }
aoqi@0 358 void doit() {
aoqi@0 359 ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread,
aoqi@0 360 _owned_monitors_list);
aoqi@0 361 }
aoqi@0 362 jvmtiError result() { return _result; }
aoqi@0 363 };
aoqi@0 364
aoqi@0 365
aoqi@0 366 // VM operation to get object monitor usage.
aoqi@0 367 class VM_GetObjectMonitorUsage : public VM_Operation {
aoqi@0 368 private:
aoqi@0 369 JvmtiEnv *_env;
aoqi@0 370 jobject _object;
aoqi@0 371 JavaThread* _calling_thread;
aoqi@0 372 jvmtiMonitorUsage* _info_ptr;
aoqi@0 373 jvmtiError _result;
aoqi@0 374
aoqi@0 375 public:
aoqi@0 376 VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
aoqi@0 377 _env = env;
aoqi@0 378 _object = object;
aoqi@0 379 _calling_thread = calling_thread;
aoqi@0 380 _info_ptr = info_ptr;
aoqi@0 381 }
aoqi@0 382 VMOp_Type type() const { return VMOp_GetObjectMonitorUsage; }
aoqi@0 383 jvmtiError result() { return _result; }
aoqi@0 384 void doit() {
aoqi@0 385 _result = ((JvmtiEnvBase*) _env)->get_object_monitor_usage(_calling_thread, _object, _info_ptr);
aoqi@0 386 }
aoqi@0 387
aoqi@0 388 };
aoqi@0 389
aoqi@0 390 // VM operation to get current contended monitor.
aoqi@0 391 class VM_GetCurrentContendedMonitor : public VM_Operation {
aoqi@0 392 private:
aoqi@0 393 JvmtiEnv *_env;
aoqi@0 394 JavaThread *_calling_thread;
aoqi@0 395 JavaThread *_java_thread;
aoqi@0 396 jobject *_owned_monitor_ptr;
aoqi@0 397 jvmtiError _result;
aoqi@0 398
aoqi@0 399 public:
aoqi@0 400 VM_GetCurrentContendedMonitor(JvmtiEnv *env, JavaThread *calling_thread, JavaThread *java_thread, jobject *mon_ptr) {
aoqi@0 401 _env = env;
aoqi@0 402 _calling_thread = calling_thread;
aoqi@0 403 _java_thread = java_thread;
aoqi@0 404 _owned_monitor_ptr = mon_ptr;
aoqi@0 405 }
aoqi@0 406 VMOp_Type type() const { return VMOp_GetCurrentContendedMonitor; }
aoqi@0 407 jvmtiError result() { return _result; }
aoqi@0 408 void doit() {
aoqi@0 409 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 410 if (Threads::includes(_java_thread) && !_java_thread->is_exiting() &&
aoqi@0 411 _java_thread->threadObj() != NULL) {
aoqi@0 412 _result = ((JvmtiEnvBase *)_env)->get_current_contended_monitor(_calling_thread,_java_thread,_owned_monitor_ptr);
aoqi@0 413 }
aoqi@0 414 }
aoqi@0 415 };
aoqi@0 416
aoqi@0 417 // VM operation to get stack trace at safepoint.
aoqi@0 418 class VM_GetStackTrace : public VM_Operation {
aoqi@0 419 private:
aoqi@0 420 JvmtiEnv *_env;
aoqi@0 421 JavaThread *_java_thread;
aoqi@0 422 jint _start_depth;
aoqi@0 423 jint _max_count;
aoqi@0 424 jvmtiFrameInfo *_frame_buffer;
aoqi@0 425 jint *_count_ptr;
aoqi@0 426 jvmtiError _result;
aoqi@0 427
aoqi@0 428 public:
aoqi@0 429 VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread,
aoqi@0 430 jint start_depth, jint max_count,
aoqi@0 431 jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
aoqi@0 432 _env = env;
aoqi@0 433 _java_thread = java_thread;
aoqi@0 434 _start_depth = start_depth;
aoqi@0 435 _max_count = max_count;
aoqi@0 436 _frame_buffer = frame_buffer;
aoqi@0 437 _count_ptr = count_ptr;
aoqi@0 438 }
aoqi@0 439 jvmtiError result() { return _result; }
aoqi@0 440 VMOp_Type type() const { return VMOp_GetStackTrace; }
aoqi@0 441 void doit() {
aoqi@0 442 _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread,
aoqi@0 443 _start_depth, _max_count,
aoqi@0 444 _frame_buffer, _count_ptr);
aoqi@0 445 }
aoqi@0 446 };
aoqi@0 447
aoqi@0 448 // forward declaration
aoqi@0 449 struct StackInfoNode;
aoqi@0 450
aoqi@0 451 // VM operation to get stack trace at safepoint.
aoqi@0 452 class VM_GetMultipleStackTraces : public VM_Operation {
aoqi@0 453 private:
aoqi@0 454 JvmtiEnv *_env;
aoqi@0 455 jint _max_frame_count;
aoqi@0 456 jvmtiStackInfo *_stack_info;
aoqi@0 457 jvmtiError _result;
aoqi@0 458 int _frame_count_total;
aoqi@0 459 struct StackInfoNode *_head;
aoqi@0 460
aoqi@0 461 JvmtiEnvBase *env() { return (JvmtiEnvBase *)_env; }
aoqi@0 462 jint max_frame_count() { return _max_frame_count; }
aoqi@0 463 struct StackInfoNode *head() { return _head; }
aoqi@0 464 void set_head(StackInfoNode *head) { _head = head; }
aoqi@0 465
aoqi@0 466 protected:
aoqi@0 467 void set_result(jvmtiError result) { _result = result; }
aoqi@0 468 void fill_frames(jthread jt, JavaThread *thr, oop thread_oop);
aoqi@0 469 void allocate_and_fill_stacks(jint thread_count);
aoqi@0 470
aoqi@0 471 public:
aoqi@0 472 VM_GetMultipleStackTraces(JvmtiEnv *env, jint max_frame_count) {
aoqi@0 473 _env = env;
aoqi@0 474 _max_frame_count = max_frame_count;
aoqi@0 475 _frame_count_total = 0;
aoqi@0 476 _head = NULL;
aoqi@0 477 _result = JVMTI_ERROR_NONE;
aoqi@0 478 }
aoqi@0 479 VMOp_Type type() const { return VMOp_GetMultipleStackTraces; }
aoqi@0 480 jvmtiStackInfo *stack_info() { return _stack_info; }
aoqi@0 481 jvmtiError result() { return _result; }
aoqi@0 482 };
aoqi@0 483
aoqi@0 484
aoqi@0 485 // VM operation to get stack trace at safepoint.
aoqi@0 486 class VM_GetAllStackTraces : public VM_GetMultipleStackTraces {
aoqi@0 487 private:
aoqi@0 488 JavaThread *_calling_thread;
aoqi@0 489 jint _final_thread_count;
aoqi@0 490
aoqi@0 491 public:
aoqi@0 492 VM_GetAllStackTraces(JvmtiEnv *env, JavaThread *calling_thread,
aoqi@0 493 jint max_frame_count)
aoqi@0 494 : VM_GetMultipleStackTraces(env, max_frame_count) {
aoqi@0 495 _calling_thread = calling_thread;
aoqi@0 496 }
aoqi@0 497 VMOp_Type type() const { return VMOp_GetAllStackTraces; }
aoqi@0 498 void doit();
aoqi@0 499 jint final_thread_count() { return _final_thread_count; }
aoqi@0 500 };
aoqi@0 501
aoqi@0 502 // VM operation to get stack trace at safepoint.
aoqi@0 503 class VM_GetThreadListStackTraces : public VM_GetMultipleStackTraces {
aoqi@0 504 private:
aoqi@0 505 jint _thread_count;
aoqi@0 506 const jthread* _thread_list;
aoqi@0 507
aoqi@0 508 public:
aoqi@0 509 VM_GetThreadListStackTraces(JvmtiEnv *env, jint thread_count, const jthread* thread_list, jint max_frame_count)
aoqi@0 510 : VM_GetMultipleStackTraces(env, max_frame_count) {
aoqi@0 511 _thread_count = thread_count;
aoqi@0 512 _thread_list = thread_list;
aoqi@0 513 }
aoqi@0 514 VMOp_Type type() const { return VMOp_GetThreadListStackTraces; }
aoqi@0 515 void doit();
aoqi@0 516 };
aoqi@0 517
aoqi@0 518
aoqi@0 519 // VM operation to count stack frames at safepoint.
aoqi@0 520 class VM_GetFrameCount : public VM_Operation {
aoqi@0 521 private:
aoqi@0 522 JvmtiEnv *_env;
aoqi@0 523 JvmtiThreadState *_state;
aoqi@0 524 jint *_count_ptr;
aoqi@0 525 jvmtiError _result;
aoqi@0 526
aoqi@0 527 public:
aoqi@0 528 VM_GetFrameCount(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) {
aoqi@0 529 _env = env;
aoqi@0 530 _state = state;
aoqi@0 531 _count_ptr = count_ptr;
aoqi@0 532 }
aoqi@0 533 VMOp_Type type() const { return VMOp_GetFrameCount; }
aoqi@0 534 jvmtiError result() { return _result; }
aoqi@0 535 void doit() {
aoqi@0 536 _result = ((JvmtiEnvBase*)_env)->get_frame_count(_state, _count_ptr);
aoqi@0 537 }
aoqi@0 538 };
aoqi@0 539
aoqi@0 540 // VM operation to frame location at safepoint.
aoqi@0 541 class VM_GetFrameLocation : public VM_Operation {
aoqi@0 542 private:
aoqi@0 543 JvmtiEnv *_env;
aoqi@0 544 JavaThread* _java_thread;
aoqi@0 545 jint _depth;
aoqi@0 546 jmethodID* _method_ptr;
aoqi@0 547 jlocation* _location_ptr;
aoqi@0 548 jvmtiError _result;
aoqi@0 549
aoqi@0 550 public:
aoqi@0 551 VM_GetFrameLocation(JvmtiEnv *env, JavaThread* java_thread, jint depth,
aoqi@0 552 jmethodID* method_ptr, jlocation* location_ptr) {
aoqi@0 553 _env = env;
aoqi@0 554 _java_thread = java_thread;
aoqi@0 555 _depth = depth;
aoqi@0 556 _method_ptr = method_ptr;
aoqi@0 557 _location_ptr = location_ptr;
aoqi@0 558 }
aoqi@0 559 VMOp_Type type() const { return VMOp_GetFrameLocation; }
aoqi@0 560 jvmtiError result() { return _result; }
aoqi@0 561 void doit() {
aoqi@0 562 _result = ((JvmtiEnvBase*)_env)->get_frame_location(_java_thread, _depth,
aoqi@0 563 _method_ptr, _location_ptr);
aoqi@0 564 }
aoqi@0 565 };
aoqi@0 566
aoqi@0 567
aoqi@0 568 // ResourceTracker
aoqi@0 569 //
aoqi@0 570 // ResourceTracker works a little like a ResourceMark. All allocates
aoqi@0 571 // using the resource tracker are recorded. If an allocate using the
aoqi@0 572 // resource tracker fails the destructor will free any resources
aoqi@0 573 // that were allocated using the tracker.
aoqi@0 574 // The motive for this class is to avoid messy error recovery code
aoqi@0 575 // in situations where multiple allocations are done in sequence. If
aoqi@0 576 // the second or subsequent allocation fails it avoids any code to
aoqi@0 577 // release memory allocated in the previous calls.
aoqi@0 578 //
aoqi@0 579 // Usage :-
aoqi@0 580 // ResourceTracker rt(env);
aoqi@0 581 // :
aoqi@0 582 // err = rt.allocate(1024, &ptr);
aoqi@0 583
aoqi@0 584 class ResourceTracker : public StackObj {
aoqi@0 585 private:
aoqi@0 586 JvmtiEnv* _env;
aoqi@0 587 GrowableArray<unsigned char*> *_allocations;
aoqi@0 588 bool _failed;
aoqi@0 589 public:
aoqi@0 590 ResourceTracker(JvmtiEnv* env);
aoqi@0 591 ~ResourceTracker();
aoqi@0 592 jvmtiError allocate(jlong size, unsigned char** mem_ptr);
aoqi@0 593 unsigned char* allocate(jlong size);
aoqi@0 594 char* strdup(const char* str);
aoqi@0 595 };
aoqi@0 596
aoqi@0 597
aoqi@0 598 // Jvmti monitor closure to collect off stack monitors.
aoqi@0 599 class JvmtiMonitorClosure: public MonitorClosure {
aoqi@0 600 private:
aoqi@0 601 JavaThread *_java_thread;
aoqi@0 602 JavaThread *_calling_thread;
aoqi@0 603 GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
aoqi@0 604 jvmtiError _error;
aoqi@0 605 JvmtiEnvBase *_env;
aoqi@0 606
aoqi@0 607 public:
aoqi@0 608 JvmtiMonitorClosure(JavaThread* thread, JavaThread *calling_thread,
aoqi@0 609 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors,
aoqi@0 610 JvmtiEnvBase *env) {
aoqi@0 611 _java_thread = thread;
aoqi@0 612 _calling_thread = calling_thread;
aoqi@0 613 _owned_monitors_list = owned_monitors;
aoqi@0 614 _error = JVMTI_ERROR_NONE;
aoqi@0 615 _env = env;
aoqi@0 616 }
aoqi@0 617 void do_monitor(ObjectMonitor* mon);
aoqi@0 618 jvmtiError error() { return _error;}
aoqi@0 619 };
aoqi@0 620
aoqi@0 621 #endif // SHARE_VM_PRIMS_JVMTIENVBASE_HPP

mercurial