src/share/vm/prims/jvmtiEnvBase.hpp

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 4230
39556eae08af
child 5745
c1d7040a1183
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

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

mercurial