annotate src/share/vm/prims/jvmtiEnvBase.hpp @ 1122:dcb15a6f342d

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