src/share/vm/prims/jvmtiEnvBase.hpp

Thu, 23 Jun 2011 17:14:06 -0700

author
jrose
date
Thu, 23 Jun 2011 17:14:06 -0700
changeset 2982
ddd894528dbc
parent 2330
684faacebf20
child 3137
e6b1331a51d2
permissions
-rw-r--r--

7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
Reviewed-by: never

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

mercurial