src/share/vm/prims/jvmtiEnvBase.hpp

Wed, 28 Nov 2012 17:50:21 -0500

author
coleenp
date
Wed, 28 Nov 2012 17:50:21 -0500
changeset 4295
59c790074993
parent 4230
39556eae08af
child 4542
db9981fd3124
permissions
-rw-r--r--

8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
Summary: Make metaspace::contains be lock free and used to see if something is in metaspace, also compare Method* with vtbl pointer.
Reviewed-by: dholmes, sspitsyn, dcubed, jmasa

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

mercurial