annotate src/share/vm/prims/jvmtiEnvBase.hpp @ 0:a61af66fc99e

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