< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.hpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 284   jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread,
 285                                    JavaThread* java_thread,
 286                                    javaVFrame *jvf,
 287                                    GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list,
 288                                    jint depth);
 289   vframe* vframeFor(JavaThread* java_thread, jint depth);
 290 
 291  public:
 292   // get a field descriptor for the specified class and field
 293   static bool get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd);
 294 
 295   // JVMTI API helper functions which are called at safepoint or thread is suspended.
 296   jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr);
 297   jvmtiError get_frame_location(JavaThread* java_thread, jint depth,
 298                                               jmethodID* method_ptr, jlocation* location_ptr);
 299   jvmtiError get_object_monitor_usage(JavaThread *calling_thread,
 300                                                     jobject object, jvmtiMonitorUsage* info_ptr);
 301   jvmtiError get_stack_trace(JavaThread *java_thread,
 302                                            jint stack_depth, jint max_count,
 303                                            jvmtiFrameInfo* frame_buffer, jint* count_ptr);
 304   jvmtiError get_current_contended_monitor(JavaThread *calling_thread,
 305                                                          JavaThread *java_thread,
 306                                                          jobject *monitor_ptr);
 307   jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
 308                           GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list);
 309   jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
 310                              jvalue value, TosState tos, Handle* ret_ob_h);
 311   jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos);
 312 };
 313 
 314 // This class is the only safe means of iterating through environments.
 315 // Note that this iteratation includes invalid environments pending
 316 // deallocation -- in fact, some uses depend on this behavior.
 317 
 318 class JvmtiEnvIterator : public StackObj {
 319  private:
 320   bool _entry_was_marked;
 321  public:
 322   JvmtiEnvIterator() {
 323     if (Threads::number_of_threads() == 0) {
 324       _entry_was_marked = false; // we are single-threaded, no need
 325     } else {
 326       Thread::current()->entering_jvmti_env_iteration();
 327       _entry_was_marked = true;


 359   JvmtiThreadState* _state;
 360   jint _depth;
 361   jvmtiError _result;
 362 
 363 public:
 364   VM_SetFramePop(JvmtiEnv *env, JvmtiThreadState* state, jint depth) {
 365     _env = env;
 366     _state = state;
 367     _depth = depth;
 368     _result = JVMTI_ERROR_NONE;
 369   }
 370   // Nested operation must be allowed for the VM_EnterInterpOnlyMode that is
 371   // called from the JvmtiEventControllerPrivate::recompute_thread_enabled.
 372   bool allow_nested_vm_operations() const { return true; }
 373   VMOp_Type type() const { return VMOp_SetFramePop; }
 374   jvmtiError result() { return _result; }
 375   void doit();
 376 };
 377 
 378 
 379 // VM operation to get monitor information with stack depth.
 380 class VM_GetOwnedMonitorInfo : public VM_Operation {
 381 private:
 382   JvmtiEnv *_env;
 383   JavaThread* _calling_thread;
 384   JavaThread *_java_thread;
 385   jvmtiError _result;
 386   GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
 387 
 388 public:
 389   VM_GetOwnedMonitorInfo(JvmtiEnv* env, JavaThread* calling_thread,
 390                                    JavaThread* java_thread,
 391                                    GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list) {
 392     _env = env;
 393     _calling_thread = calling_thread;
 394     _java_thread = java_thread;
 395     _owned_monitors_list = owned_monitor_list;
 396     _result = JVMTI_ERROR_NONE;
 397   }
 398   VMOp_Type type() const { return VMOp_GetOwnedMonitorInfo; }
 399   void doit();
 400   jvmtiError result() { return _result; }
 401 };
 402 
 403 
 404 // VM operation to get object monitor usage.
 405 class VM_GetObjectMonitorUsage : public VM_Operation {
 406 private:
 407   JvmtiEnv *_env;
 408   jobject _object;
 409   JavaThread* _calling_thread;
 410   jvmtiMonitorUsage* _info_ptr;
 411   jvmtiError _result;
 412 
 413 public:
 414   VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
 415     _env = env;
 416     _object = object;
 417     _calling_thread = calling_thread;
 418     _info_ptr = info_ptr;
 419   }
 420   VMOp_Type type() const { return VMOp_GetObjectMonitorUsage; }
 421   jvmtiError result() { return _result; }
 422   void doit() {
 423     _result = ((JvmtiEnvBase*) _env)->get_object_monitor_usage(_calling_thread, _object, _info_ptr);
 424   }
 425 
 426 };
 427 
 428 // VM operation to get current contended monitor.
 429 class VM_GetCurrentContendedMonitor : public VM_Operation {
 430 private:
 431   JvmtiEnv *_env;
 432   JavaThread *_calling_thread;
 433   JavaThread *_java_thread;
 434   jobject *_owned_monitor_ptr;
 435   jvmtiError _result;
 436 
 437 public:
 438   VM_GetCurrentContendedMonitor(JvmtiEnv *env, JavaThread *calling_thread, JavaThread *java_thread, jobject *mon_ptr) {
 439     _env = env;
 440     _calling_thread = calling_thread;
 441     _java_thread = java_thread;
 442     _owned_monitor_ptr = mon_ptr;
 443   }
 444   VMOp_Type type() const { return VMOp_GetCurrentContendedMonitor; }
 445   jvmtiError result() { return _result; }
 446   void doit();
 447 };
 448 
 449 // VM operation to get stack trace at safepoint.
 450 class VM_GetStackTrace : public VM_Operation {
 451 private:
 452   JvmtiEnv *_env;
 453   JavaThread *_java_thread;
 454   jint _start_depth;
 455   jint _max_count;
 456   jvmtiFrameInfo *_frame_buffer;
 457   jint *_count_ptr;
 458   jvmtiError _result;
 459 
 460 public:
 461   VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread,
 462                    jint start_depth, jint max_count,
 463                    jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
 464     _env = env;
 465     _java_thread = java_thread;
 466     _start_depth = start_depth;


   1 /*
   2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 284   jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread,
 285                                    JavaThread* java_thread,
 286                                    javaVFrame *jvf,
 287                                    GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list,
 288                                    jint depth);
 289   vframe* vframeFor(JavaThread* java_thread, jint depth);
 290 
 291  public:
 292   // get a field descriptor for the specified class and field
 293   static bool get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd);
 294 
 295   // JVMTI API helper functions which are called at safepoint or thread is suspended.
 296   jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr);
 297   jvmtiError get_frame_location(JavaThread* java_thread, jint depth,
 298                                               jmethodID* method_ptr, jlocation* location_ptr);
 299   jvmtiError get_object_monitor_usage(JavaThread *calling_thread,
 300                                                     jobject object, jvmtiMonitorUsage* info_ptr);
 301   jvmtiError get_stack_trace(JavaThread *java_thread,
 302                                            jint stack_depth, jint max_count,
 303                                            jvmtiFrameInfo* frame_buffer, jint* count_ptr);
 304   jvmtiError get_current_contended_monitor(JavaThread *java_thread,

 305                                                          jobject *monitor_ptr);
 306   jvmtiError get_owned_monitors(JavaThread* java_thread,
 307                           GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list);
 308   jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
 309                              jvalue value, TosState tos, Handle* ret_ob_h);
 310   jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos);
 311 };
 312 
 313 // This class is the only safe means of iterating through environments.
 314 // Note that this iteratation includes invalid environments pending
 315 // deallocation -- in fact, some uses depend on this behavior.
 316 
 317 class JvmtiEnvIterator : public StackObj {
 318  private:
 319   bool _entry_was_marked;
 320  public:
 321   JvmtiEnvIterator() {
 322     if (Threads::number_of_threads() == 0) {
 323       _entry_was_marked = false; // we are single-threaded, no need
 324     } else {
 325       Thread::current()->entering_jvmti_env_iteration();
 326       _entry_was_marked = true;


 358   JvmtiThreadState* _state;
 359   jint _depth;
 360   jvmtiError _result;
 361 
 362 public:
 363   VM_SetFramePop(JvmtiEnv *env, JvmtiThreadState* state, jint depth) {
 364     _env = env;
 365     _state = state;
 366     _depth = depth;
 367     _result = JVMTI_ERROR_NONE;
 368   }
 369   // Nested operation must be allowed for the VM_EnterInterpOnlyMode that is
 370   // called from the JvmtiEventControllerPrivate::recompute_thread_enabled.
 371   bool allow_nested_vm_operations() const { return true; }
 372   VMOp_Type type() const { return VMOp_SetFramePop; }
 373   jvmtiError result() { return _result; }
 374   void doit();
 375 };
 376 
 377 
 378 // HandshakeClosure to get monitor information with stack depth.
 379 class GetOwnedMonitorInfoClosure : public HandshakeClosure {
 380 private:
 381   JvmtiEnv *_env;


 382   jvmtiError _result;
 383   GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
 384 
 385 public:
 386   GetOwnedMonitorInfoClosure(JvmtiEnv* env,
 387                              GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list)
 388     : HandshakeClosure("GetOwnedMonitorInfo"),
 389       _env(env), _result(JVMTI_ERROR_NONE), _owned_monitors_list(owned_monitor_list) {}
 390   void do_thread(Thread *target);






 391   jvmtiError result() { return _result; }
 392 };
 393 
 394 
 395 // VM operation to get object monitor usage.
 396 class VM_GetObjectMonitorUsage : public VM_Operation {
 397 private:
 398   JvmtiEnv *_env;
 399   jobject _object;
 400   JavaThread* _calling_thread;
 401   jvmtiMonitorUsage* _info_ptr;
 402   jvmtiError _result;
 403 
 404 public:
 405   VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
 406     _env = env;
 407     _object = object;
 408     _calling_thread = calling_thread;
 409     _info_ptr = info_ptr;
 410   }
 411   VMOp_Type type() const { return VMOp_GetObjectMonitorUsage; }
 412   jvmtiError result() { return _result; }
 413   void doit() {
 414     _result = ((JvmtiEnvBase*) _env)->get_object_monitor_usage(_calling_thread, _object, _info_ptr);
 415   }
 416 
 417 };
 418 
 419 // HandshakeClosure to get current contended monitor.
 420 class GetCurrentContendedMonitorClosure : public HandshakeClosure {
 421 private:
 422   JvmtiEnv *_env;


 423   jobject *_owned_monitor_ptr;
 424   jvmtiError _result;
 425 
 426 public:
 427   GetCurrentContendedMonitorClosure(JvmtiEnv *env, jobject *mon_ptr)
 428     : HandshakeClosure("GetOneCurrentContendedMonitor"),
 429       _env(env), _owned_monitor_ptr(mon_ptr),
 430       _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {}



 431   jvmtiError result() { return _result; }
 432   void do_thread(Thread *target);
 433 };
 434 
 435 // VM operation to get stack trace at safepoint.
 436 class VM_GetStackTrace : public VM_Operation {
 437 private:
 438   JvmtiEnv *_env;
 439   JavaThread *_java_thread;
 440   jint _start_depth;
 441   jint _max_count;
 442   jvmtiFrameInfo *_frame_buffer;
 443   jint *_count_ptr;
 444   jvmtiError _result;
 445 
 446 public:
 447   VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread,
 448                    jint start_depth, jint max_count,
 449                    jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
 450     _env = env;
 451     _java_thread = java_thread;
 452     _start_depth = start_depth;


< prev index next >