0N/A/*
1879N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_PRIMS_JVMTIENVBASE_HPP
1879N/A#define SHARE_VM_PRIMS_JVMTIENVBASE_HPP
1879N/A
1879N/A#include "classfile/classLoader.hpp"
1879N/A#include "prims/jvmtiEnvThreadState.hpp"
1879N/A#include "prims/jvmtiEventController.hpp"
1879N/A#include "prims/jvmtiThreadState.hpp"
1879N/A#include "runtime/fieldDescriptor.hpp"
1879N/A#include "runtime/frame.hpp"
1879N/A#include "runtime/handles.inline.hpp"
1879N/A#include "runtime/thread.hpp"
1879N/A#include "runtime/vm_operations.hpp"
1879N/A#include "utilities/growableArray.hpp"
0N/A
0N/A//
0N/A// Forward Declarations
0N/A//
0N/A
0N/Aclass JvmtiEnv;
0N/Aclass JvmtiThreadState;
0N/Aclass JvmtiRawMonitor; // for jvmtiEnv.hpp
0N/Aclass JvmtiEventControllerPrivate;
0N/Aclass JvmtiTagMap;
0N/A
0N/A
0N/A
0N/A// One JvmtiEnv object is created per jvmti attachment;
0N/A// done via JNI GetEnv() call. Multiple attachments are
0N/A// allowed in jvmti.
0N/A
3863N/Aclass JvmtiEnvBase : public CHeapObj<mtInternal> {
0N/A
0N/A private:
0N/A
0N/A static JvmtiEnvBase* _head_environment; // head of environment list
0N/A
0N/A static bool _globally_initialized;
0N/A static jvmtiPhase _phase;
0N/A static volatile int _dying_thread_env_iteration_count;
0N/A
0N/A public:
0N/A
0N/A enum {
0N/A JDK15_JVMTI_VERSION = JVMTI_VERSION_1_0 + 33, /* version: 1.0.33 */
1895N/A JDK16_JVMTI_VERSION = JVMTI_VERSION_1_1 + 102, /* version: 1.1.102 */
1895N/A JDK17_JVMTI_VERSION = JVMTI_VERSION_1_2 + 1 /* version: 1.2.1 */
0N/A };
0N/A
0N/A static jvmtiPhase get_phase() { return _phase; }
0N/A static void set_phase(jvmtiPhase phase) { _phase = phase; }
0N/A static bool is_vm_live() { return _phase == JVMTI_PHASE_LIVE; }
0N/A
0N/A static void entering_dying_thread_env_iteration() { ++_dying_thread_env_iteration_count; }
0N/A static void leaving_dying_thread_env_iteration() { --_dying_thread_env_iteration_count; }
0N/A static bool is_inside_dying_thread_env_iteration(){ return _dying_thread_env_iteration_count > 0; }
0N/A
0N/A private:
0N/A
0N/A enum {
0N/A JVMTI_MAGIC = 0x71EE,
0N/A DISPOSED_MAGIC = 0xDEFC,
0N/A BAD_MAGIC = 0xDEAD
0N/A };
0N/A
0N/A jvmtiEnv _jvmti_external;
0N/A jint _magic;
1121N/A jint _version; // version value passed to JNI GetEnv()
0N/A JvmtiEnvBase* _next;
0N/A bool _is_retransformable;
0N/A const void *_env_local_storage; // per env agent allocated data.
0N/A jvmtiEventCallbacks _event_callbacks;
0N/A jvmtiExtEventCallbacks _ext_event_callbacks;
0N/A JvmtiTagMap* _tag_map;
0N/A JvmtiEnvEventEnable _env_event_enable;
0N/A jvmtiCapabilities _current_capabilities;
0N/A jvmtiCapabilities _prohibited_capabilities;
0N/A volatile bool _class_file_load_hook_ever_enabled;
0N/A static volatile bool _needs_clean_up;
0N/A char** _native_method_prefixes;
0N/A int _native_method_prefix_count;
0N/A
0N/A protected:
1121N/A JvmtiEnvBase(jint version);
0N/A ~JvmtiEnvBase();
0N/A void dispose();
0N/A void env_dispose();
0N/A
0N/A void set_env_local_storage(const void* data) { _env_local_storage = data; }
0N/A const void* get_env_local_storage() { return _env_local_storage; }
0N/A
0N/A void record_class_file_load_hook_enabled();
0N/A void record_first_time_class_file_load_hook_enabled();
0N/A
0N/A char** get_native_method_prefixes() { return _native_method_prefixes; }
0N/A int get_native_method_prefix_count() { return _native_method_prefix_count; }
0N/A jvmtiError set_native_method_prefixes(jint prefix_count, char** prefixes);
0N/A
0N/A private:
0N/A friend class JvmtiEventControllerPrivate;
0N/A void initialize();
0N/A void set_event_callbacks(const jvmtiEventCallbacks* callbacks, jint size_of_callbacks);
0N/A static void globally_initialize();
0N/A static void periodic_clean_up();
0N/A
0N/A friend class JvmtiEnvIterator;
0N/A JvmtiEnv* next_environment() { return (JvmtiEnv*)_next; }
0N/A void set_next_environment(JvmtiEnvBase* env) { _next = env; }
0N/A static JvmtiEnv* head_environment() { return (JvmtiEnv*)_head_environment; }
0N/A
0N/A public:
0N/A
611N/A bool is_valid();
0N/A
1121N/A bool use_version_1_0_semantics(); // agent asked for version 1.0
1121N/A bool use_version_1_1_semantics(); // agent asked for version 1.1
1895N/A bool use_version_1_2_semantics(); // agent asked for version 1.2
1121N/A
0N/A bool is_retransformable() { return _is_retransformable; }
0N/A
0N/A static ByteSize jvmti_external_offset() {
0N/A return byte_offset_of(JvmtiEnvBase, _jvmti_external);
0N/A };
0N/A
0N/A static JvmtiEnv* JvmtiEnv_from_jvmti_env(jvmtiEnv *env) {
0N/A return (JvmtiEnv*)((intptr_t)env - in_bytes(jvmti_external_offset()));
0N/A };
0N/A
0N/A jvmtiCapabilities *get_capabilities() { return &_current_capabilities; }
0N/A
0N/A jvmtiCapabilities *get_prohibited_capabilities() { return &_prohibited_capabilities; }
0N/A
0N/A static char** get_all_native_method_prefixes(int* count_ptr);
0N/A
0N/A // This test will answer true when all environments have been disposed and some have
0N/A // not yet been deallocated. As a result, this test should only be used as an
0N/A // optimization for the no environment case.
0N/A static bool environments_might_exist() {
0N/A return head_environment() != NULL;
0N/A }
0N/A
0N/A static void check_for_periodic_clean_up();
0N/A
0N/A JvmtiEnvEventEnable *env_event_enable() {
0N/A return &_env_event_enable;
0N/A }
0N/A
0N/A jvmtiError allocate(jlong size, unsigned char** mem_ptr) {
0N/A if (size < 0) {
0N/A return JVMTI_ERROR_ILLEGAL_ARGUMENT;
0N/A }
0N/A if (size == 0) {
0N/A *mem_ptr = NULL;
0N/A } else {
3863N/A *mem_ptr = (unsigned char *)os::malloc((size_t)size, mtInternal);
0N/A if (*mem_ptr == NULL) {
0N/A return JVMTI_ERROR_OUT_OF_MEMORY;
0N/A }
0N/A }
0N/A return JVMTI_ERROR_NONE;
0N/A }
0N/A
0N/A jvmtiError deallocate(unsigned char* mem) {
0N/A if (mem != NULL) {
3863N/A os::free(mem, mtInternal);
0N/A }
0N/A return JVMTI_ERROR_NONE;
0N/A }
0N/A
0N/A
0N/A // Memory functions
0N/A unsigned char* jvmtiMalloc(jlong size); // don't use this - call allocate
0N/A
0N/A // method to create a local handle
0N/A jobject jni_reference(Handle hndl) {
0N/A return JNIHandles::make_local(hndl());
0N/A }
0N/A
0N/A // method to create a local handle.
0N/A // This function allows caller to specify which
0N/A // threads local handle table to use.
0N/A jobject jni_reference(JavaThread *thread, Handle hndl) {
0N/A return JNIHandles::make_local(thread, hndl());
0N/A }
0N/A
0N/A // method to destroy a local handle
0N/A void destroy_jni_reference(jobject jobj) {
0N/A JNIHandles::destroy_local(jobj);
0N/A }
0N/A
0N/A // method to destroy a local handle.
0N/A // This function allows caller to specify which
0N/A // threads local handle table to use although currently it is
0N/A // not used.
0N/A void destroy_jni_reference(JavaThread *thread, jobject jobj) {
0N/A destroy_jni_reference(jobj);
0N/A }
0N/A
0N/A jvmtiEnv* jvmti_external() { return &_jvmti_external; };
0N/A
0N/A// Event Dispatch
0N/A
0N/A bool has_callback(jvmtiEvent event_type) {
0N/A assert(event_type >= JVMTI_MIN_EVENT_TYPE_VAL &&
0N/A event_type <= JVMTI_MAX_EVENT_TYPE_VAL, "checking");
0N/A return ((void**)&_event_callbacks)[event_type-JVMTI_MIN_EVENT_TYPE_VAL] != NULL;
0N/A }
0N/A
0N/A jvmtiEventCallbacks* callbacks() {
0N/A return &_event_callbacks;
0N/A }
0N/A
0N/A jvmtiExtEventCallbacks* ext_callbacks() {
0N/A return &_ext_event_callbacks;
0N/A }
0N/A
0N/A void set_tag_map(JvmtiTagMap* tag_map) {
0N/A _tag_map = tag_map;
0N/A }
0N/A
0N/A JvmtiTagMap* tag_map() {
0N/A return _tag_map;
0N/A }
0N/A
0N/A
0N/A // return true if event is enabled globally or for any thread
0N/A // True only if there is a callback for it.
0N/A bool is_enabled(jvmtiEvent event_type) {
0N/A return _env_event_enable.is_enabled(event_type);
0N/A }
0N/A
0N/A// Random Utilities
0N/A
0N/A protected:
0N/A // helper methods for creating arrays of global JNI Handles from local Handles
0N/A // allocated into environment specific storage
0N/A jobject * new_jobjectArray(int length, Handle *handles);
0N/A jthread * new_jthreadArray(int length, Handle *handles);
0N/A jthreadGroup * new_jthreadGroupArray(int length, Handle *handles);
0N/A
0N/A // convert from JNIHandle to JavaThread *
0N/A JavaThread * get_JavaThread(jthread jni_thread);
0N/A
0N/A // convert to a jni jclass from a non-null klassOop
0N/A jclass get_jni_class_non_null(klassOop k);
0N/A
0N/A jint count_locked_objects(JavaThread *java_thread, Handle hobj);
0N/A jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread,
0N/A JavaThread* java_thread,
0N/A javaVFrame *jvf,
0N/A GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list,
0N/A jint depth);
0N/A vframe* vframeFor(JavaThread* java_thread, jint depth);
0N/A
0N/A public:
0N/A // get a field descriptor for the specified class and field
0N/A static bool get_field_descriptor(klassOop k, jfieldID field, fieldDescriptor* fd);
0N/A // test for suspend - most (all?) of these should go away
0N/A static bool is_thread_fully_suspended(JavaThread *thread,
0N/A bool wait_for_suspend,
0N/A uint32_t *bits);
0N/A
0N/A
0N/A // JVMTI API helper functions which are called at safepoint or thread is suspended.
0N/A jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr);
0N/A jvmtiError get_frame_location(JavaThread* java_thread, jint depth,
0N/A jmethodID* method_ptr, jlocation* location_ptr);
0N/A jvmtiError get_object_monitor_usage(JavaThread *calling_thread,
0N/A jobject object, jvmtiMonitorUsage* info_ptr);
0N/A jvmtiError get_stack_trace(JavaThread *java_thread,
0N/A jint stack_depth, jint max_count,
0N/A jvmtiFrameInfo* frame_buffer, jint* count_ptr);
0N/A jvmtiError get_current_contended_monitor(JavaThread *calling_thread,
0N/A JavaThread *java_thread,
0N/A jobject *monitor_ptr);
0N/A jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
0N/A GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list);
0N/A jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
0N/A jvalue value, TosState tos, Handle* ret_ob_h);
0N/A jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos);
0N/A};
0N/A
0N/A// This class is the only safe means of iterating through environments.
0N/A// Note that this iteratation includes invalid environments pending
0N/A// deallocation -- in fact, some uses depend on this behavior.
0N/A
0N/Aclass JvmtiEnvIterator : public StackObj {
0N/A private:
0N/A bool _entry_was_marked;
0N/A public:
0N/A JvmtiEnvIterator() {
0N/A if (Threads::number_of_threads() == 0) {
0N/A _entry_was_marked = false; // we are single-threaded, no need
0N/A } else {
0N/A Thread::current()->entering_jvmti_env_iteration();
0N/A _entry_was_marked = true;
0N/A }
0N/A }
0N/A ~JvmtiEnvIterator() {
0N/A if (_entry_was_marked) {
0N/A Thread::current()->leaving_jvmti_env_iteration();
0N/A }
0N/A }
0N/A JvmtiEnv* first() { return JvmtiEnvBase::head_environment(); }
0N/A JvmtiEnv* next(JvmtiEnvBase* env) { return env->next_environment(); }
0N/A};
0N/A
0N/A
0N/A// VM operation to get monitor information with stack depth.
0N/Aclass VM_GetOwnedMonitorInfo : public VM_Operation {
0N/Aprivate:
0N/A JvmtiEnv *_env;
0N/A JavaThread* _calling_thread;
0N/A JavaThread *_java_thread;
0N/A jvmtiError _result;
0N/A GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
0N/A
0N/Apublic:
0N/A VM_GetOwnedMonitorInfo(JvmtiEnv* env, JavaThread* calling_thread,
0N/A JavaThread* java_thread,
0N/A GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list) {
0N/A _env = env;
0N/A _calling_thread = calling_thread;
0N/A _java_thread = java_thread;
0N/A _owned_monitors_list = owned_monitor_list;
0N/A _result = JVMTI_ERROR_NONE;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetOwnedMonitorInfo; }
0N/A void doit() {
0N/A ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread,
0N/A _owned_monitors_list);
0N/A }
0N/A jvmtiError result() { return _result; }
0N/A};
0N/A
0N/A
0N/A// VM operation to get object monitor usage.
0N/Aclass VM_GetObjectMonitorUsage : public VM_Operation {
0N/Aprivate:
0N/A JvmtiEnv *_env;
0N/A jobject _object;
0N/A JavaThread* _calling_thread;
0N/A jvmtiMonitorUsage* _info_ptr;
0N/A jvmtiError _result;
0N/A
0N/Apublic:
0N/A VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
0N/A _env = env;
0N/A _object = object;
0N/A _calling_thread = calling_thread;
0N/A _info_ptr = info_ptr;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetObjectMonitorUsage; }
0N/A jvmtiError result() { return _result; }
0N/A void doit() {
0N/A _result = ((JvmtiEnvBase*) _env)->get_object_monitor_usage(_calling_thread, _object, _info_ptr);
0N/A }
0N/A
0N/A};
0N/A
0N/A// VM operation to get current contended monitor.
0N/Aclass VM_GetCurrentContendedMonitor : public VM_Operation {
0N/Aprivate:
0N/A JvmtiEnv *_env;
0N/A JavaThread *_calling_thread;
0N/A JavaThread *_java_thread;
0N/A jobject *_owned_monitor_ptr;
0N/A jvmtiError _result;
0N/A
0N/Apublic:
0N/A VM_GetCurrentContendedMonitor(JvmtiEnv *env, JavaThread *calling_thread, JavaThread *java_thread, jobject *mon_ptr) {
0N/A _env = env;
0N/A _calling_thread = calling_thread;
0N/A _java_thread = java_thread;
0N/A _owned_monitor_ptr = mon_ptr;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetCurrentContendedMonitor; }
0N/A jvmtiError result() { return _result; }
0N/A void doit() {
0N/A _result = ((JvmtiEnvBase *)_env)->get_current_contended_monitor(_calling_thread,_java_thread,_owned_monitor_ptr);
0N/A }
0N/A};
0N/A
0N/A// VM operation to get stack trace at safepoint.
0N/Aclass VM_GetStackTrace : public VM_Operation {
0N/Aprivate:
0N/A JvmtiEnv *_env;
0N/A JavaThread *_java_thread;
0N/A jint _start_depth;
0N/A jint _max_count;
0N/A jvmtiFrameInfo *_frame_buffer;
0N/A jint *_count_ptr;
0N/A jvmtiError _result;
0N/A
0N/Apublic:
0N/A VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread,
0N/A jint start_depth, jint max_count,
0N/A jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
0N/A _env = env;
0N/A _java_thread = java_thread;
0N/A _start_depth = start_depth;
0N/A _max_count = max_count;
0N/A _frame_buffer = frame_buffer;
0N/A _count_ptr = count_ptr;
0N/A }
0N/A jvmtiError result() { return _result; }
0N/A VMOp_Type type() const { return VMOp_GetStackTrace; }
0N/A void doit() {
0N/A _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread,
0N/A _start_depth, _max_count,
0N/A _frame_buffer, _count_ptr);
0N/A }
0N/A};
0N/A
0N/A// forward declaration
0N/Astruct StackInfoNode;
0N/A
0N/A// VM operation to get stack trace at safepoint.
0N/Aclass VM_GetMultipleStackTraces : public VM_Operation {
0N/Aprivate:
0N/A JvmtiEnv *_env;
0N/A jint _max_frame_count;
0N/A jvmtiStackInfo *_stack_info;
0N/A jvmtiError _result;
0N/A int _frame_count_total;
0N/A struct StackInfoNode *_head;
0N/A
0N/A JvmtiEnvBase *env() { return (JvmtiEnvBase *)_env; }
0N/A jint max_frame_count() { return _max_frame_count; }
0N/A struct StackInfoNode *head() { return _head; }
0N/A void set_head(StackInfoNode *head) { _head = head; }
0N/A
0N/Aprotected:
0N/A void set_result(jvmtiError result) { _result = result; }
0N/A void fill_frames(jthread jt, JavaThread *thr, oop thread_oop);
0N/A void allocate_and_fill_stacks(jint thread_count);
0N/A
0N/Apublic:
0N/A VM_GetMultipleStackTraces(JvmtiEnv *env, jint max_frame_count) {
0N/A _env = env;
0N/A _max_frame_count = max_frame_count;
0N/A _frame_count_total = 0;
0N/A _head = NULL;
0N/A _result = JVMTI_ERROR_NONE;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetMultipleStackTraces; }
0N/A jvmtiStackInfo *stack_info() { return _stack_info; }
0N/A jvmtiError result() { return _result; }
0N/A};
0N/A
0N/A
0N/A// VM operation to get stack trace at safepoint.
0N/Aclass VM_GetAllStackTraces : public VM_GetMultipleStackTraces {
0N/Aprivate:
0N/A JavaThread *_calling_thread;
0N/A jint _final_thread_count;
0N/A
0N/Apublic:
0N/A VM_GetAllStackTraces(JvmtiEnv *env, JavaThread *calling_thread,
0N/A jint max_frame_count)
0N/A : VM_GetMultipleStackTraces(env, max_frame_count) {
0N/A _calling_thread = calling_thread;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetAllStackTraces; }
0N/A void doit();
0N/A jint final_thread_count() { return _final_thread_count; }
0N/A};
0N/A
0N/A// VM operation to get stack trace at safepoint.
0N/Aclass VM_GetThreadListStackTraces : public VM_GetMultipleStackTraces {
0N/Aprivate:
0N/A jint _thread_count;
0N/A const jthread* _thread_list;
0N/A
0N/Apublic:
0N/A VM_GetThreadListStackTraces(JvmtiEnv *env, jint thread_count, const jthread* thread_list, jint max_frame_count)
0N/A : VM_GetMultipleStackTraces(env, max_frame_count) {
0N/A _thread_count = thread_count;
0N/A _thread_list = thread_list;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetThreadListStackTraces; }
0N/A void doit();
0N/A};
0N/A
0N/A
0N/A// VM operation to count stack frames at safepoint.
0N/Aclass VM_GetFrameCount : public VM_Operation {
0N/Aprivate:
0N/A JvmtiEnv *_env;
0N/A JvmtiThreadState *_state;
0N/A jint *_count_ptr;
0N/A jvmtiError _result;
0N/A
0N/Apublic:
0N/A VM_GetFrameCount(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) {
0N/A _env = env;
0N/A _state = state;
0N/A _count_ptr = count_ptr;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetFrameCount; }
0N/A jvmtiError result() { return _result; }
0N/A void doit() {
0N/A _result = ((JvmtiEnvBase*)_env)->get_frame_count(_state, _count_ptr);
0N/A }
0N/A};
0N/A
0N/A// VM operation to frame location at safepoint.
0N/Aclass VM_GetFrameLocation : public VM_Operation {
0N/Aprivate:
0N/A JvmtiEnv *_env;
0N/A JavaThread* _java_thread;
0N/A jint _depth;
0N/A jmethodID* _method_ptr;
0N/A jlocation* _location_ptr;
0N/A jvmtiError _result;
0N/A
0N/Apublic:
0N/A VM_GetFrameLocation(JvmtiEnv *env, JavaThread* java_thread, jint depth,
0N/A jmethodID* method_ptr, jlocation* location_ptr) {
0N/A _env = env;
0N/A _java_thread = java_thread;
0N/A _depth = depth;
0N/A _method_ptr = method_ptr;
0N/A _location_ptr = location_ptr;
0N/A }
0N/A VMOp_Type type() const { return VMOp_GetFrameLocation; }
0N/A jvmtiError result() { return _result; }
0N/A void doit() {
0N/A _result = ((JvmtiEnvBase*)_env)->get_frame_location(_java_thread, _depth,
0N/A _method_ptr, _location_ptr);
0N/A }
0N/A};
0N/A
0N/A
0N/A// ResourceTracker
0N/A//
0N/A// ResourceTracker works a little like a ResourceMark. All allocates
0N/A// using the resource tracker are recorded. If an allocate using the
0N/A// resource tracker fails the destructor will free any resources
0N/A// that were allocated using the tracker.
0N/A// The motive for this class is to avoid messy error recovery code
0N/A// in situations where multiple allocations are done in sequence. If
0N/A// the second or subsequent allocation fails it avoids any code to
0N/A// release memory allocated in the previous calls.
0N/A//
0N/A// Usage :-
0N/A// ResourceTracker rt(env);
0N/A// :
0N/A// err = rt.allocate(1024, &ptr);
0N/A
0N/Aclass ResourceTracker : public StackObj {
0N/A private:
0N/A JvmtiEnv* _env;
0N/A GrowableArray<unsigned char*> *_allocations;
0N/A bool _failed;
0N/A public:
0N/A ResourceTracker(JvmtiEnv* env);
0N/A ~ResourceTracker();
0N/A jvmtiError allocate(jlong size, unsigned char** mem_ptr);
0N/A unsigned char* allocate(jlong size);
0N/A char* strdup(const char* str);
0N/A};
0N/A
0N/A
0N/A// Jvmti monitor closure to collect off stack monitors.
0N/Aclass JvmtiMonitorClosure: public MonitorClosure {
0N/A private:
0N/A JavaThread *_java_thread;
0N/A JavaThread *_calling_thread;
0N/A GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
0N/A jvmtiError _error;
0N/A JvmtiEnvBase *_env;
0N/A
0N/A public:
0N/A JvmtiMonitorClosure(JavaThread* thread, JavaThread *calling_thread,
0N/A GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors,
0N/A JvmtiEnvBase *env) {
0N/A _java_thread = thread;
0N/A _calling_thread = calling_thread;
0N/A _owned_monitors_list = owned_monitors;
0N/A _error = JVMTI_ERROR_NONE;
0N/A _env = env;
0N/A }
0N/A void do_monitor(ObjectMonitor* mon);
0N/A jvmtiError error() { return _error;}
0N/A};
0N/A
1879N/A#endif // SHARE_VM_PRIMS_JVMTIENVBASE_HPP