src/share/vm/prims/jvmtiEnvBase.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 8856
ac27a9c85bea
child 9756
2be326848943
permissions
-rw-r--r--

Merge

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

mercurial