author | kamg |
Mon, 06 Dec 2010 20:21:15 -0500 | |
changeset 7413 | 59b978f8fbdf |
parent 7397 | 5b173b4ca846 |
child 7897 | 201a8b00ec91 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4761
diff
changeset
|
2 |
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4761
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4761
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4761
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "interpreter/interpreter.hpp" |
|
27 |
#include "jvmtifiles/jvmtiEnv.hpp" |
|
28 |
#include "memory/resourceArea.hpp" |
|
29 |
#include "prims/jvmtiEventController.hpp" |
|
30 |
#include "prims/jvmtiEventController.inline.hpp" |
|
31 |
#include "prims/jvmtiExport.hpp" |
|
32 |
#include "prims/jvmtiImpl.hpp" |
|
33 |
#include "prims/jvmtiThreadState.inline.hpp" |
|
34 |
#include "runtime/frame.hpp" |
|
35 |
#include "runtime/thread.hpp" |
|
36 |
#include "runtime/vframe.hpp" |
|
37 |
#include "runtime/vframe_hp.hpp" |
|
38 |
#include "runtime/vmThread.hpp" |
|
39 |
#include "runtime/vm_operations.hpp" |
|
1 | 40 |
|
41 |
#ifdef JVMTI_TRACE |
|
42 |
#define EC_TRACE(out) if (JvmtiTrace::trace_event_controller()) { SafeResourceMark rm; tty->print_cr out; } while (0) |
|
43 |
#else |
|
44 |
#define EC_TRACE(out) |
|
45 |
#endif /*JVMTI_TRACE */ |
|
46 |
||
47 |
// bits for standard events |
|
48 |
||
49 |
static const jlong SINGLE_STEP_BIT = (((jlong)1) << (JVMTI_EVENT_SINGLE_STEP - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
50 |
static const jlong FRAME_POP_BIT = (((jlong)1) << (JVMTI_EVENT_FRAME_POP - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
51 |
static const jlong BREAKPOINT_BIT = (((jlong)1) << (JVMTI_EVENT_BREAKPOINT - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
52 |
static const jlong FIELD_ACCESS_BIT = (((jlong)1) << (JVMTI_EVENT_FIELD_ACCESS - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
53 |
static const jlong FIELD_MODIFICATION_BIT = (((jlong)1) << (JVMTI_EVENT_FIELD_MODIFICATION - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
54 |
static const jlong METHOD_ENTRY_BIT = (((jlong)1) << (JVMTI_EVENT_METHOD_ENTRY - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
55 |
static const jlong METHOD_EXIT_BIT = (((jlong)1) << (JVMTI_EVENT_METHOD_EXIT - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
56 |
static const jlong CLASS_FILE_LOAD_HOOK_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
57 |
static const jlong NATIVE_METHOD_BIND_BIT = (((jlong)1) << (JVMTI_EVENT_NATIVE_METHOD_BIND - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
58 |
static const jlong VM_START_BIT = (((jlong)1) << (JVMTI_EVENT_VM_START - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
59 |
static const jlong VM_INIT_BIT = (((jlong)1) << (JVMTI_EVENT_VM_INIT - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
60 |
static const jlong VM_DEATH_BIT = (((jlong)1) << (JVMTI_EVENT_VM_DEATH - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
61 |
static const jlong CLASS_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_LOAD - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
62 |
static const jlong CLASS_PREPARE_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_PREPARE - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
63 |
static const jlong THREAD_START_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_START - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
64 |
static const jlong THREAD_END_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_END - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
65 |
static const jlong EXCEPTION_THROW_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
66 |
static const jlong EXCEPTION_CATCH_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION_CATCH - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
67 |
static const jlong MONITOR_CONTENDED_ENTER_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTER - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
68 |
static const jlong MONITOR_CONTENDED_ENTERED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
69 |
static const jlong MONITOR_WAIT_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAIT - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
70 |
static const jlong MONITOR_WAITED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAITED - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
71 |
static const jlong DYNAMIC_CODE_GENERATED_BIT = (((jlong)1) << (JVMTI_EVENT_DYNAMIC_CODE_GENERATED - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
72 |
static const jlong DATA_DUMP_BIT = (((jlong)1) << (JVMTI_EVENT_DATA_DUMP_REQUEST - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
73 |
static const jlong COMPILED_METHOD_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_LOAD - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
74 |
static const jlong COMPILED_METHOD_UNLOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
75 |
static const jlong GARBAGE_COLLECTION_START_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_START - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
76 |
static const jlong GARBAGE_COLLECTION_FINISH_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
77 |
static const jlong OBJECT_FREE_BIT = (((jlong)1) << (JVMTI_EVENT_OBJECT_FREE - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
78 |
static const jlong RESOURCE_EXHAUSTED_BIT = (((jlong)1) << (JVMTI_EVENT_RESOURCE_EXHAUSTED - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
79 |
static const jlong VM_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_VM_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
80 |
||
81 |
// bits for extension events |
|
82 |
static const jlong CLASS_UNLOAD_BIT = (((jlong)1) << (EXT_EVENT_CLASS_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL)); |
|
83 |
||
84 |
||
85 |
static const jlong MONITOR_BITS = MONITOR_CONTENDED_ENTER_BIT | MONITOR_CONTENDED_ENTERED_BIT | |
|
86 |
MONITOR_WAIT_BIT | MONITOR_WAITED_BIT; |
|
87 |
static const jlong EXCEPTION_BITS = EXCEPTION_THROW_BIT | EXCEPTION_CATCH_BIT; |
|
88 |
static const jlong INTERP_EVENT_BITS = SINGLE_STEP_BIT | METHOD_ENTRY_BIT | METHOD_EXIT_BIT | |
|
89 |
FRAME_POP_BIT | FIELD_ACCESS_BIT | FIELD_MODIFICATION_BIT; |
|
90 |
static const jlong THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS | |
|
91 |
BREAKPOINT_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT | THREAD_END_BIT; |
|
92 |
static const jlong NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT; |
|
93 |
static const jlong EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT | |
|
94 |
VM_START_BIT | VM_INIT_BIT | VM_DEATH_BIT | NATIVE_METHOD_BIND_BIT | |
|
95 |
THREAD_START_BIT | THREAD_END_BIT | |
|
96 |
DYNAMIC_CODE_GENERATED_BIT; |
|
97 |
static const jlong GLOBAL_EVENT_BITS = ~THREAD_FILTERED_EVENT_BITS; |
|
4761
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
98 |
static const jlong SHOULD_POST_ON_EXCEPTIONS_BITS = EXCEPTION_BITS | METHOD_EXIT_BIT | FRAME_POP_BIT; |
1 | 99 |
|
100 |
/////////////////////////////////////////////////////////////// |
|
101 |
// |
|
102 |
// JvmtiEventEnabled |
|
103 |
// |
|
104 |
||
105 |
JvmtiEventEnabled::JvmtiEventEnabled() { |
|
106 |
clear(); |
|
107 |
} |
|
108 |
||
109 |
||
110 |
void JvmtiEventEnabled::clear() { |
|
111 |
_enabled_bits = 0; |
|
112 |
#ifndef PRODUCT |
|
113 |
_init_guard = JEE_INIT_GUARD; |
|
114 |
#endif |
|
115 |
} |
|
116 |
||
117 |
void JvmtiEventEnabled::set_enabled(jvmtiEvent event_type, bool enabled) { |
|
118 |
jlong bits = get_bits(); |
|
119 |
jlong mask = bit_for(event_type); |
|
120 |
if (enabled) { |
|
121 |
bits |= mask; |
|
122 |
} else { |
|
123 |
bits &= ~mask; |
|
124 |
} |
|
125 |
set_bits(bits); |
|
126 |
} |
|
127 |
||
128 |
||
129 |
/////////////////////////////////////////////////////////////// |
|
130 |
// |
|
131 |
// JvmtiEnvThreadEventEnable |
|
132 |
// |
|
133 |
||
134 |
JvmtiEnvThreadEventEnable::JvmtiEnvThreadEventEnable() { |
|
135 |
_event_user_enabled.clear(); |
|
136 |
_event_enabled.clear(); |
|
137 |
} |
|
138 |
||
139 |
||
140 |
JvmtiEnvThreadEventEnable::~JvmtiEnvThreadEventEnable() { |
|
141 |
_event_user_enabled.clear(); |
|
142 |
_event_enabled.clear(); |
|
143 |
} |
|
144 |
||
145 |
||
146 |
/////////////////////////////////////////////////////////////// |
|
147 |
// |
|
148 |
// JvmtiThreadEventEnable |
|
149 |
// |
|
150 |
||
151 |
JvmtiThreadEventEnable::JvmtiThreadEventEnable() { |
|
152 |
_event_enabled.clear(); |
|
153 |
} |
|
154 |
||
155 |
||
156 |
JvmtiThreadEventEnable::~JvmtiThreadEventEnable() { |
|
157 |
_event_enabled.clear(); |
|
158 |
} |
|
159 |
||
160 |
||
161 |
/////////////////////////////////////////////////////////////// |
|
162 |
// |
|
163 |
// JvmtiEnvEventEnable |
|
164 |
// |
|
165 |
||
166 |
JvmtiEnvEventEnable::JvmtiEnvEventEnable() { |
|
167 |
_event_user_enabled.clear(); |
|
168 |
_event_callback_enabled.clear(); |
|
169 |
_event_enabled.clear(); |
|
170 |
} |
|
171 |
||
172 |
||
173 |
JvmtiEnvEventEnable::~JvmtiEnvEventEnable() { |
|
174 |
_event_user_enabled.clear(); |
|
175 |
_event_callback_enabled.clear(); |
|
176 |
_event_enabled.clear(); |
|
177 |
} |
|
178 |
||
179 |
||
180 |
/////////////////////////////////////////////////////////////// |
|
181 |
// |
|
182 |
// VM_EnterInterpOnlyMode |
|
183 |
// |
|
184 |
||
185 |
class VM_EnterInterpOnlyMode : public VM_Operation { |
|
186 |
private: |
|
187 |
JvmtiThreadState *_state; |
|
188 |
||
189 |
public: |
|
190 |
VM_EnterInterpOnlyMode(JvmtiThreadState *state); |
|
191 |
||
192 |
bool allow_nested_vm_operations() const { return true; } |
|
193 |
VMOp_Type type() const { return VMOp_EnterInterpOnlyMode; } |
|
194 |
void doit(); |
|
195 |
||
196 |
// to do: this same function is in jvmtiImpl - should be in one place |
|
197 |
bool can_be_deoptimized(vframe* vf) { |
|
198 |
return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized()); |
|
199 |
} |
|
200 |
}; |
|
201 |
||
202 |
VM_EnterInterpOnlyMode::VM_EnterInterpOnlyMode(JvmtiThreadState *state) |
|
203 |
: _state(state) |
|
204 |
{ |
|
205 |
} |
|
206 |
||
207 |
||
208 |
void VM_EnterInterpOnlyMode::doit() { |
|
209 |
// Set up the current stack depth for later tracking |
|
210 |
_state->invalidate_cur_stack_depth(); |
|
211 |
||
212 |
_state->enter_interp_only_mode(); |
|
213 |
||
214 |
JavaThread *thread = _state->get_thread(); |
|
215 |
if (thread->has_last_Java_frame()) { |
|
216 |
// If running in fullspeed mode, single stepping is implemented |
|
217 |
// as follows: first, the interpreter does not dispatch to |
|
218 |
// compiled code for threads that have single stepping enabled; |
|
219 |
// second, we deoptimize all methods on the thread's stack when |
|
220 |
// interpreted-only mode is enabled the first time for a given |
|
221 |
// thread (nothing to do if no Java frames yet). |
|
222 |
int num_marked = 0; |
|
223 |
ResourceMark resMark; |
|
224 |
RegisterMap rm(thread, false); |
|
225 |
for (vframe* vf = thread->last_java_vframe(&rm); vf; vf = vf->sender()) { |
|
226 |
if (can_be_deoptimized(vf)) { |
|
227 |
((compiledVFrame*) vf)->code()->mark_for_deoptimization(); |
|
228 |
++num_marked; |
|
229 |
} |
|
230 |
} |
|
231 |
if (num_marked > 0) { |
|
232 |
VM_Deoptimize op; |
|
233 |
VMThread::execute(&op); |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
||
239 |
/////////////////////////////////////////////////////////////// |
|
240 |
// |
|
241 |
// VM_ChangeSingleStep |
|
242 |
// |
|
243 |
||
244 |
class VM_ChangeSingleStep : public VM_Operation { |
|
245 |
private: |
|
246 |
bool _on; |
|
247 |
||
248 |
public: |
|
249 |
VM_ChangeSingleStep(bool on); |
|
250 |
VMOp_Type type() const { return VMOp_ChangeSingleStep; } |
|
251 |
bool allow_nested_vm_operations() const { return true; } |
|
252 |
void doit(); // method definition is after definition of JvmtiEventControllerPrivate because of scoping |
|
253 |
}; |
|
254 |
||
255 |
||
256 |
VM_ChangeSingleStep::VM_ChangeSingleStep(bool on) |
|
257 |
: _on(on != 0) |
|
258 |
{ |
|
259 |
} |
|
260 |
||
261 |
||
262 |
||
263 |
||
264 |
/////////////////////////////////////////////////////////////// |
|
265 |
// |
|
266 |
// JvmtiEventControllerPrivate |
|
267 |
// |
|
268 |
// Private internal implementation methods for JvmtiEventController. |
|
269 |
// |
|
270 |
// These methods are thread safe either because they are called |
|
271 |
// in early VM initialization which is single threaded, or they |
|
272 |
// hold the JvmtiThreadState_lock. |
|
273 |
// |
|
274 |
||
275 |
class JvmtiEventControllerPrivate : public AllStatic { |
|
276 |
static bool _initialized; |
|
277 |
public: |
|
278 |
static void set_should_post_single_step(bool on); |
|
279 |
static void enter_interp_only_mode(JvmtiThreadState *state); |
|
280 |
static void leave_interp_only_mode(JvmtiThreadState *state); |
|
281 |
static void recompute_enabled(); |
|
282 |
static jlong recompute_env_enabled(JvmtiEnvBase* env); |
|
283 |
static jlong recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state); |
|
284 |
static jlong recompute_thread_enabled(JvmtiThreadState *state); |
|
285 |
static void event_init(); |
|
286 |
||
287 |
static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, |
|
288 |
jvmtiEvent event_type, bool enabled); |
|
289 |
static void set_event_callbacks(JvmtiEnvBase *env, |
|
290 |
const jvmtiEventCallbacks* callbacks, |
|
291 |
jint size_of_callbacks); |
|
292 |
||
293 |
static void set_extension_event_callback(JvmtiEnvBase *env, |
|
294 |
jint extension_event_index, |
|
295 |
jvmtiExtensionEvent callback); |
|
296 |
||
297 |
static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); |
|
298 |
static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); |
|
299 |
static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); |
|
300 |
static void change_field_watch(jvmtiEvent event_type, bool added); |
|
301 |
||
302 |
static void thread_started(JavaThread *thread); |
|
303 |
static void thread_ended(JavaThread *thread); |
|
304 |
||
305 |
static void env_initialize(JvmtiEnvBase *env); |
|
306 |
static void env_dispose(JvmtiEnvBase *env); |
|
307 |
||
308 |
static void vm_start(); |
|
309 |
static void vm_init(); |
|
310 |
static void vm_death(); |
|
311 |
||
312 |
static void trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed); |
|
313 |
static void trace_changed(jlong now_enabled, jlong changed); |
|
314 |
}; |
|
315 |
||
316 |
bool JvmtiEventControllerPrivate::_initialized = false; |
|
317 |
||
318 |
void JvmtiEventControllerPrivate::set_should_post_single_step(bool on) { |
|
319 |
// we have permission to do this, VM op doesn't |
|
320 |
JvmtiExport::set_should_post_single_step(on); |
|
321 |
} |
|
322 |
||
323 |
||
324 |
// This change must always be occur when at a safepoint. |
|
325 |
// Being at a safepoint causes the interpreter to use the |
|
326 |
// safepoint dispatch table which we overload to find single |
|
327 |
// step points. Just to be sure that it has been set, we |
|
328 |
// call notice_safepoints when turning on single stepping. |
|
329 |
// When we leave our current safepoint, should_post_single_step |
|
330 |
// will be checked by the interpreter, and the table kept |
|
331 |
// or changed accordingly. |
|
332 |
void VM_ChangeSingleStep::doit() { |
|
333 |
JvmtiEventControllerPrivate::set_should_post_single_step(_on); |
|
334 |
if (_on) { |
|
335 |
Interpreter::notice_safepoints(); |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
||
340 |
void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state) { |
|
341 |
EC_TRACE(("JVMTI [%s] # Entering interpreter only mode", |
|
342 |
JvmtiTrace::safe_get_thread_name(state->get_thread()))); |
|
343 |
||
344 |
VM_EnterInterpOnlyMode op(state); |
|
345 |
VMThread::execute(&op); |
|
346 |
} |
|
347 |
||
348 |
||
349 |
void |
|
350 |
JvmtiEventControllerPrivate::leave_interp_only_mode(JvmtiThreadState *state) { |
|
351 |
EC_TRACE(("JVMTI [%s] # Leaving interpreter only mode", |
|
352 |
JvmtiTrace::safe_get_thread_name(state->get_thread()))); |
|
353 |
state->leave_interp_only_mode(); |
|
354 |
} |
|
355 |
||
356 |
||
357 |
void |
|
358 |
JvmtiEventControllerPrivate::trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed) { |
|
359 |
#ifdef JVMTI_TRACE |
|
360 |
if (JvmtiTrace::trace_event_controller()) { |
|
361 |
SafeResourceMark rm; |
|
362 |
// traces standard events only |
|
363 |
for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { |
|
364 |
jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei); |
|
365 |
if (changed & bit) { |
|
366 |
// it changed, print it |
|
367 |
tty->print_cr("JVMTI [%s] # %s event %s", |
|
368 |
JvmtiTrace::safe_get_thread_name(state->get_thread()), |
|
369 |
(now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei)); |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
#endif /*JVMTI_TRACE */ |
|
374 |
} |
|
375 |
||
376 |
||
377 |
void |
|
378 |
JvmtiEventControllerPrivate::trace_changed(jlong now_enabled, jlong changed) { |
|
379 |
#ifdef JVMTI_TRACE |
|
380 |
if (JvmtiTrace::trace_event_controller()) { |
|
381 |
SafeResourceMark rm; |
|
382 |
// traces standard events only |
|
383 |
for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { |
|
384 |
jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei); |
|
385 |
if (changed & bit) { |
|
386 |
// it changed, print it |
|
387 |
tty->print_cr("JVMTI [-] # %s event %s", |
|
388 |
(now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei)); |
|
389 |
} |
|
390 |
} |
|
391 |
} |
|
392 |
#endif /*JVMTI_TRACE */ |
|
393 |
} |
|
394 |
||
395 |
||
396 |
// For the specified env: compute the currently truly enabled events |
|
397 |
// set external state accordingly. |
|
398 |
// Return value and set value must include all events. |
|
399 |
// But outside this class, only non-thread-filtered events can be queried.. |
|
400 |
jlong |
|
401 |
JvmtiEventControllerPrivate::recompute_env_enabled(JvmtiEnvBase* env) { |
|
402 |
jlong was_enabled = env->env_event_enable()->_event_enabled.get_bits(); |
|
403 |
jlong now_enabled = |
|
404 |
env->env_event_enable()->_event_callback_enabled.get_bits() & |
|
405 |
env->env_event_enable()->_event_user_enabled.get_bits(); |
|
406 |
||
407 |
switch (JvmtiEnv::get_phase()) { |
|
408 |
case JVMTI_PHASE_PRIMORDIAL: |
|
409 |
case JVMTI_PHASE_ONLOAD: |
|
410 |
// only these events allowed in primordial or onload phase |
|
411 |
now_enabled &= (EARLY_EVENT_BITS & ~THREAD_FILTERED_EVENT_BITS); |
|
412 |
break; |
|
413 |
case JVMTI_PHASE_START: |
|
414 |
// only these events allowed in start phase |
|
415 |
now_enabled &= EARLY_EVENT_BITS; |
|
416 |
break; |
|
417 |
case JVMTI_PHASE_LIVE: |
|
418 |
// all events allowed during live phase |
|
419 |
break; |
|
420 |
case JVMTI_PHASE_DEAD: |
|
421 |
// no events allowed when dead |
|
422 |
now_enabled = 0; |
|
423 |
break; |
|
424 |
default: |
|
425 |
assert(false, "no other phases - sanity check"); |
|
426 |
break; |
|
427 |
} |
|
428 |
||
429 |
// will we really send these events to this env |
|
430 |
env->env_event_enable()->_event_enabled.set_bits(now_enabled); |
|
431 |
||
432 |
trace_changed(now_enabled, (now_enabled ^ was_enabled) & ~THREAD_FILTERED_EVENT_BITS); |
|
433 |
||
434 |
return now_enabled; |
|
435 |
} |
|
436 |
||
437 |
||
438 |
// For the specified env and thread: compute the currently truly enabled events |
|
439 |
// set external state accordingly. Only thread-filtered events are included. |
|
440 |
jlong |
|
441 |
JvmtiEventControllerPrivate::recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state) { |
|
442 |
JvmtiEnv *env = ets->get_env(); |
|
443 |
||
444 |
jlong was_enabled = ets->event_enable()->_event_enabled.get_bits(); |
|
445 |
jlong now_enabled = THREAD_FILTERED_EVENT_BITS & |
|
446 |
env->env_event_enable()->_event_callback_enabled.get_bits() & |
|
447 |
(env->env_event_enable()->_event_user_enabled.get_bits() | |
|
448 |
ets->event_enable()->_event_user_enabled.get_bits()); |
|
449 |
||
450 |
// for frame pops and field watchs, computed enabled state |
|
451 |
// is only true if an event has been requested |
|
452 |
if (!ets->has_frame_pops()) { |
|
453 |
now_enabled &= ~FRAME_POP_BIT; |
|
454 |
} |
|
455 |
if (*((int *)JvmtiExport::get_field_access_count_addr()) == 0) { |
|
456 |
now_enabled &= ~FIELD_ACCESS_BIT; |
|
457 |
} |
|
458 |
if (*((int *)JvmtiExport::get_field_modification_count_addr()) == 0) { |
|
459 |
now_enabled &= ~FIELD_MODIFICATION_BIT; |
|
460 |
} |
|
461 |
||
462 |
switch (JvmtiEnv::get_phase()) { |
|
463 |
case JVMTI_PHASE_DEAD: |
|
464 |
// no events allowed when dead |
|
465 |
now_enabled = 0; |
|
466 |
break; |
|
467 |
} |
|
468 |
||
469 |
// if anything changed do update |
|
470 |
if (now_enabled != was_enabled) { |
|
471 |
||
472 |
// will we really send these events to this thread x env |
|
473 |
ets->event_enable()->_event_enabled.set_bits(now_enabled); |
|
474 |
||
475 |
// If the enabled status of the single step or breakpoint events changed, |
|
476 |
// the location status may need to change as well. |
|
477 |
jlong changed = now_enabled ^ was_enabled; |
|
478 |
if (changed & SINGLE_STEP_BIT) { |
|
479 |
ets->reset_current_location(JVMTI_EVENT_SINGLE_STEP, (now_enabled & SINGLE_STEP_BIT) != 0); |
|
480 |
} |
|
481 |
if (changed & BREAKPOINT_BIT) { |
|
482 |
ets->reset_current_location(JVMTI_EVENT_BREAKPOINT, (now_enabled & BREAKPOINT_BIT) != 0); |
|
483 |
} |
|
484 |
trace_changed(state, now_enabled, changed); |
|
485 |
} |
|
486 |
return now_enabled; |
|
487 |
} |
|
488 |
||
489 |
||
490 |
// For the specified thread: compute the currently truly enabled events |
|
491 |
// set external state accordingly. Only thread-filtered events are included. |
|
492 |
jlong |
|
493 |
JvmtiEventControllerPrivate::recompute_thread_enabled(JvmtiThreadState *state) { |
|
2135
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1
diff
changeset
|
494 |
if (state == NULL) { |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1
diff
changeset
|
495 |
// associated JavaThread is exiting |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1
diff
changeset
|
496 |
return (jlong)0; |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1
diff
changeset
|
497 |
} |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1
diff
changeset
|
498 |
|
1 | 499 |
jlong was_any_env_enabled = state->thread_event_enable()->_event_enabled.get_bits(); |
500 |
jlong any_env_enabled = 0; |
|
501 |
||
502 |
{ |
|
503 |
// This iteration will include JvmtiEnvThreadStates whoses environments |
|
504 |
// have been disposed. These JvmtiEnvThreadStates must not be filtered |
|
505 |
// as recompute must be called on them to disable their events, |
|
506 |
JvmtiEnvThreadStateIterator it(state); |
|
507 |
for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { |
|
508 |
any_env_enabled |= recompute_env_thread_enabled(ets, state); |
|
509 |
} |
|
510 |
} |
|
511 |
||
512 |
if (any_env_enabled != was_any_env_enabled) { |
|
513 |
// mark if event is truly enabled on this thread in any environment |
|
514 |
state->thread_event_enable()->_event_enabled.set_bits(any_env_enabled); |
|
515 |
||
516 |
// compute interp_only mode |
|
517 |
bool should_be_interp = (any_env_enabled & INTERP_EVENT_BITS) != 0; |
|
518 |
bool is_now_interp = state->is_interp_only_mode(); |
|
519 |
||
520 |
if (should_be_interp != is_now_interp) { |
|
521 |
if (should_be_interp) { |
|
522 |
enter_interp_only_mode(state); |
|
523 |
} else { |
|
524 |
leave_interp_only_mode(state); |
|
525 |
} |
|
526 |
} |
|
4761
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
527 |
|
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
528 |
// update the JavaThread cached value for thread-specific should_post_on_exceptions value |
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
529 |
bool should_post_on_exceptions = (any_env_enabled & SHOULD_POST_ON_EXCEPTIONS_BITS) != 0; |
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
530 |
state->set_should_post_on_exceptions(should_post_on_exceptions); |
1 | 531 |
} |
4761
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
532 |
|
1 | 533 |
return any_env_enabled; |
534 |
} |
|
535 |
||
536 |
||
537 |
// Compute truly enabled events - meaning if the event can and could be |
|
538 |
// sent. An event is truly enabled if it is user enabled on the thread |
|
539 |
// or globally user enabled, but only if there is a callback or event hook |
|
540 |
// for it and, for field watch and frame pop, one has been set. |
|
541 |
// Compute if truly enabled, per thread, per environment, per combination |
|
542 |
// (thread x environment), and overall. These merges are true if any is true. |
|
543 |
// True per thread if some environment has callback set and the event is globally |
|
544 |
// enabled or enabled for this thread. |
|
545 |
// True per environment if the callback is set and the event is globally |
|
546 |
// enabled in this environment or enabled for any thread in this environment. |
|
547 |
// True per combination if the environment has the callback set and the |
|
548 |
// event is globally enabled in this environment or the event is enabled |
|
549 |
// for this thread and environment. |
|
550 |
// |
|
551 |
// All states transitions dependent on these transitions are also handled here. |
|
552 |
void |
|
553 |
JvmtiEventControllerPrivate::recompute_enabled() { |
|
554 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
555 |
||
556 |
// event enabled for any thread in any environment |
|
557 |
jlong was_any_env_thread_enabled = JvmtiEventController::_universal_global_event_enabled.get_bits(); |
|
558 |
jlong any_env_thread_enabled = 0; |
|
559 |
||
560 |
EC_TRACE(("JVMTI [-] # recompute enabled - before %llx", was_any_env_thread_enabled)); |
|
561 |
||
562 |
// compute non-thread-filters events. |
|
563 |
// This must be done separately from thread-filtered events, since some |
|
564 |
// events can occur before any threads exist. |
|
565 |
JvmtiEnvIterator it; |
|
566 |
for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) { |
|
567 |
any_env_thread_enabled |= recompute_env_enabled(env); |
|
568 |
} |
|
569 |
||
570 |
// We need to create any missing jvmti_thread_state if there are globally set thread |
|
571 |
// filtered events and there weren't last time |
|
572 |
if ( (any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) != 0 && |
|
573 |
(was_any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) == 0) { |
|
574 |
assert(JvmtiEnv::is_vm_live() || (JvmtiEnv::get_phase()==JVMTI_PHASE_START), |
|
575 |
"thread filtered events should not be enabled when VM not in start or live phase"); |
|
576 |
{ |
|
577 |
MutexLocker mu(Threads_lock); //hold the Threads_lock for the iteration |
|
578 |
for (JavaThread *tp = Threads::first(); tp != NULL; tp = tp->next()) { |
|
2135
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1
diff
changeset
|
579 |
// state_for_while_locked() makes tp->is_exiting() check |
1 | 580 |
JvmtiThreadState::state_for_while_locked(tp); // create the thread state if missing |
581 |
} |
|
582 |
}// release Threads_lock |
|
583 |
} |
|
584 |
||
585 |
// compute and set thread-filtered events |
|
586 |
for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) { |
|
587 |
any_env_thread_enabled |= recompute_thread_enabled(state); |
|
588 |
} |
|
589 |
||
590 |
// set universal state (across all envs and threads) |
|
591 |
jlong delta = any_env_thread_enabled ^ was_any_env_thread_enabled; |
|
592 |
if (delta != 0) { |
|
593 |
JvmtiExport::set_should_post_field_access((any_env_thread_enabled & FIELD_ACCESS_BIT) != 0); |
|
594 |
JvmtiExport::set_should_post_field_modification((any_env_thread_enabled & FIELD_MODIFICATION_BIT) != 0); |
|
595 |
JvmtiExport::set_should_post_class_load((any_env_thread_enabled & CLASS_LOAD_BIT) != 0); |
|
596 |
JvmtiExport::set_should_post_class_file_load_hook((any_env_thread_enabled & CLASS_FILE_LOAD_HOOK_BIT) != 0); |
|
597 |
JvmtiExport::set_should_post_native_method_bind((any_env_thread_enabled & NATIVE_METHOD_BIND_BIT) != 0); |
|
598 |
JvmtiExport::set_should_post_dynamic_code_generated((any_env_thread_enabled & DYNAMIC_CODE_GENERATED_BIT) != 0); |
|
599 |
JvmtiExport::set_should_post_data_dump((any_env_thread_enabled & DATA_DUMP_BIT) != 0); |
|
600 |
JvmtiExport::set_should_post_class_prepare((any_env_thread_enabled & CLASS_PREPARE_BIT) != 0); |
|
601 |
JvmtiExport::set_should_post_class_unload((any_env_thread_enabled & CLASS_UNLOAD_BIT) != 0); |
|
602 |
JvmtiExport::set_should_post_monitor_contended_enter((any_env_thread_enabled & MONITOR_CONTENDED_ENTER_BIT) != 0); |
|
603 |
JvmtiExport::set_should_post_monitor_contended_entered((any_env_thread_enabled & MONITOR_CONTENDED_ENTERED_BIT) != 0); |
|
604 |
JvmtiExport::set_should_post_monitor_wait((any_env_thread_enabled & MONITOR_WAIT_BIT) != 0); |
|
605 |
JvmtiExport::set_should_post_monitor_waited((any_env_thread_enabled & MONITOR_WAITED_BIT) != 0); |
|
606 |
JvmtiExport::set_should_post_garbage_collection_start((any_env_thread_enabled & GARBAGE_COLLECTION_START_BIT) != 0); |
|
607 |
JvmtiExport::set_should_post_garbage_collection_finish((any_env_thread_enabled & GARBAGE_COLLECTION_FINISH_BIT) != 0); |
|
608 |
JvmtiExport::set_should_post_object_free((any_env_thread_enabled & OBJECT_FREE_BIT) != 0); |
|
609 |
JvmtiExport::set_should_post_resource_exhausted((any_env_thread_enabled & RESOURCE_EXHAUSTED_BIT) != 0); |
|
610 |
JvmtiExport::set_should_post_compiled_method_load((any_env_thread_enabled & COMPILED_METHOD_LOAD_BIT) != 0); |
|
611 |
JvmtiExport::set_should_post_compiled_method_unload((any_env_thread_enabled & COMPILED_METHOD_UNLOAD_BIT) != 0); |
|
612 |
JvmtiExport::set_should_post_vm_object_alloc((any_env_thread_enabled & VM_OBJECT_ALLOC_BIT) != 0); |
|
613 |
||
614 |
// need this if we want thread events or we need them to init data |
|
615 |
JvmtiExport::set_should_post_thread_life((any_env_thread_enabled & NEED_THREAD_LIFE_EVENTS) != 0); |
|
616 |
||
617 |
// If single stepping is turned on or off, execute the VM op to change it. |
|
618 |
if (delta & SINGLE_STEP_BIT) { |
|
619 |
switch (JvmtiEnv::get_phase()) { |
|
620 |
case JVMTI_PHASE_DEAD: |
|
621 |
// If the VM is dying we can't execute VM ops |
|
622 |
break; |
|
623 |
case JVMTI_PHASE_LIVE: { |
|
624 |
VM_ChangeSingleStep op((any_env_thread_enabled & SINGLE_STEP_BIT) != 0); |
|
625 |
VMThread::execute(&op); |
|
626 |
break; |
|
627 |
} |
|
628 |
default: |
|
629 |
assert(false, "should never come here before live phase"); |
|
630 |
break; |
|
631 |
} |
|
632 |
} |
|
633 |
||
634 |
// set global truly enabled, that is, any thread in any environment |
|
635 |
JvmtiEventController::_universal_global_event_enabled.set_bits(any_env_thread_enabled); |
|
4761
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
636 |
|
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
637 |
// set global should_post_on_exceptions |
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
638 |
JvmtiExport::set_should_post_on_exceptions((any_env_thread_enabled & SHOULD_POST_ON_EXCEPTIONS_BITS) != 0); |
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
2135
diff
changeset
|
639 |
|
1 | 640 |
} |
641 |
||
642 |
EC_TRACE(("JVMTI [-] # recompute enabled - after %llx", any_env_thread_enabled)); |
|
643 |
} |
|
644 |
||
645 |
||
646 |
void |
|
647 |
JvmtiEventControllerPrivate::thread_started(JavaThread *thread) { |
|
648 |
assert(thread->is_Java_thread(), "Must be JavaThread"); |
|
649 |
assert(thread == Thread::current(), "must be current thread"); |
|
650 |
assert(JvmtiEnvBase::environments_might_exist(), "to enter event controller, JVM TI environments must exist"); |
|
651 |
||
652 |
EC_TRACE(("JVMTI [%s] # thread started", JvmtiTrace::safe_get_thread_name(thread))); |
|
653 |
||
654 |
// if we have any thread filtered events globally enabled, create/update the thread state |
|
655 |
if ((JvmtiEventController::_universal_global_event_enabled.get_bits() & THREAD_FILTERED_EVENT_BITS) != 0) { |
|
656 |
MutexLocker mu(JvmtiThreadState_lock); |
|
657 |
// create the thread state if missing |
|
658 |
JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread); |
|
659 |
if (state != NULL) { // skip threads with no JVMTI thread state |
|
660 |
recompute_thread_enabled(state); |
|
661 |
} |
|
662 |
} |
|
663 |
} |
|
664 |
||
665 |
||
666 |
void |
|
667 |
JvmtiEventControllerPrivate::thread_ended(JavaThread *thread) { |
|
668 |
// Removes the JvmtiThreadState associated with the specified thread. |
|
669 |
// May be called after all environments have been disposed. |
|
670 |
||
671 |
EC_TRACE(("JVMTI [%s] # thread ended", JvmtiTrace::safe_get_thread_name(thread))); |
|
672 |
||
673 |
JvmtiThreadState *state = thread->jvmti_thread_state(); |
|
674 |
if (state != NULL) { |
|
675 |
MutexLocker mu(JvmtiThreadState_lock); |
|
676 |
delete state; |
|
677 |
} |
|
678 |
} |
|
679 |
||
680 |
void JvmtiEventControllerPrivate::set_event_callbacks(JvmtiEnvBase *env, |
|
681 |
const jvmtiEventCallbacks* callbacks, |
|
682 |
jint size_of_callbacks) { |
|
683 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
684 |
EC_TRACE(("JVMTI [*] # set event callbacks")); |
|
685 |
||
686 |
env->set_event_callbacks(callbacks, size_of_callbacks); |
|
687 |
jlong enabled_bits = 0; |
|
688 |
for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { |
|
689 |
jvmtiEvent evt_t = (jvmtiEvent)ei; |
|
690 |
if (env->has_callback(evt_t)) { |
|
691 |
enabled_bits |= JvmtiEventEnabled::bit_for(evt_t); |
|
692 |
} |
|
693 |
} |
|
694 |
env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits); |
|
695 |
recompute_enabled(); |
|
696 |
} |
|
697 |
||
698 |
void |
|
699 |
JvmtiEventControllerPrivate::set_extension_event_callback(JvmtiEnvBase *env, |
|
700 |
jint extension_event_index, |
|
701 |
jvmtiExtensionEvent callback) |
|
702 |
{ |
|
703 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
704 |
EC_TRACE(("JVMTI [*] # set extension event callback")); |
|
705 |
||
706 |
// extension events are allocated below JVMTI_MIN_EVENT_TYPE_VAL |
|
707 |
assert(extension_event_index >= (jint)EXT_MIN_EVENT_TYPE_VAL && |
|
708 |
extension_event_index <= (jint)EXT_MAX_EVENT_TYPE_VAL, "sanity check"); |
|
709 |
||
710 |
||
711 |
// As the bits for both standard (jvmtiEvent) and extension |
|
712 |
// (jvmtiExtEvents) are stored in the same word we cast here to |
|
713 |
// jvmtiEvent to set/clear the bit for this extension event. |
|
714 |
jvmtiEvent event_type = (jvmtiEvent)extension_event_index; |
|
715 |
||
716 |
// Prevent a possible race condition where events are re-enabled by a call to |
|
717 |
// set event callbacks, where the DisposeEnvironment occurs after the boiler-plate |
|
718 |
// environment check and before the lock is acquired. |
|
719 |
// We can safely do the is_valid check now, as JvmtiThreadState_lock is held. |
|
720 |
bool enabling = (callback != NULL) && (env->is_valid()); |
|
721 |
env->env_event_enable()->set_user_enabled(event_type, enabling); |
|
722 |
||
723 |
// update the callback |
|
724 |
jvmtiExtEventCallbacks* ext_callbacks = env->ext_callbacks(); |
|
725 |
switch (extension_event_index) { |
|
726 |
case EXT_EVENT_CLASS_UNLOAD : |
|
727 |
ext_callbacks->ClassUnload = callback; |
|
728 |
break; |
|
729 |
default: |
|
730 |
ShouldNotReachHere(); |
|
731 |
} |
|
732 |
||
733 |
// update the callback enable/disable bit |
|
734 |
jlong enabled_bits = env->env_event_enable()->_event_callback_enabled.get_bits(); |
|
735 |
jlong bit_for = JvmtiEventEnabled::bit_for(event_type); |
|
736 |
if (enabling) { |
|
737 |
enabled_bits |= bit_for; |
|
738 |
} else { |
|
739 |
enabled_bits &= ~bit_for; |
|
740 |
} |
|
741 |
env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits); |
|
742 |
||
743 |
recompute_enabled(); |
|
744 |
} |
|
745 |
||
746 |
||
747 |
void |
|
748 |
JvmtiEventControllerPrivate::env_initialize(JvmtiEnvBase *env) { |
|
749 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
750 |
EC_TRACE(("JVMTI [*] # env initialize")); |
|
751 |
||
752 |
if (JvmtiEnvBase::is_vm_live()) { |
|
753 |
// if we didn't initialize event info already (this is a late |
|
754 |
// launched environment), do it now. |
|
755 |
event_init(); |
|
756 |
} |
|
757 |
||
758 |
env->initialize(); |
|
759 |
||
760 |
// add the JvmtiEnvThreadState to each JvmtiThreadState |
|
761 |
for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) { |
|
762 |
state->add_env(env); |
|
763 |
assert((JvmtiEnv*)(state->env_thread_state(env)->get_env()) == env, "sanity check"); |
|
764 |
} |
|
765 |
JvmtiEventControllerPrivate::recompute_enabled(); |
|
766 |
} |
|
767 |
||
768 |
||
769 |
void |
|
770 |
JvmtiEventControllerPrivate::env_dispose(JvmtiEnvBase *env) { |
|
771 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
772 |
EC_TRACE(("JVMTI [*] # env dispose")); |
|
773 |
||
774 |
// Before the environment is marked disposed, disable all events on this |
|
775 |
// environment (by zapping the callbacks). As a result, the disposed |
|
776 |
// environment will not call event handlers. |
|
777 |
set_event_callbacks(env, NULL, 0); |
|
778 |
for (jint extension_event_index = EXT_MIN_EVENT_TYPE_VAL; |
|
779 |
extension_event_index <= EXT_MAX_EVENT_TYPE_VAL; |
|
780 |
++extension_event_index) { |
|
781 |
set_extension_event_callback(env, extension_event_index, NULL); |
|
782 |
} |
|
783 |
||
784 |
// Let the environment finish disposing itself. |
|
785 |
env->env_dispose(); |
|
786 |
} |
|
787 |
||
788 |
||
789 |
void |
|
790 |
JvmtiEventControllerPrivate::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, |
|
791 |
jvmtiEvent event_type, bool enabled) { |
|
792 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
793 |
||
794 |
EC_TRACE(("JVMTI [%s] # user %s event %s", |
|
795 |
thread==NULL? "ALL": JvmtiTrace::safe_get_thread_name(thread), |
|
796 |
enabled? "enabled" : "disabled", JvmtiTrace::event_name(event_type))); |
|
797 |
||
798 |
if (thread == NULL) { |
|
799 |
env->env_event_enable()->set_user_enabled(event_type, enabled); |
|
800 |
} else { |
|
801 |
// create the thread state (if it didn't exist before) |
|
802 |
JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread); |
|
803 |
if (state != NULL) { |
|
804 |
state->env_thread_state(env)->event_enable()->set_user_enabled(event_type, enabled); |
|
805 |
} |
|
806 |
} |
|
807 |
recompute_enabled(); |
|
808 |
} |
|
809 |
||
810 |
||
811 |
void |
|
812 |
JvmtiEventControllerPrivate::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { |
|
813 |
EC_TRACE(("JVMTI [%s] # set frame pop - frame=%d", |
|
814 |
JvmtiTrace::safe_get_thread_name(ets->get_thread()), |
|
815 |
fpop.frame_number() )); |
|
816 |
||
817 |
ets->get_frame_pops()->set(fpop); |
|
818 |
recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); |
|
819 |
} |
|
820 |
||
821 |
||
822 |
void |
|
823 |
JvmtiEventControllerPrivate::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { |
|
824 |
EC_TRACE(("JVMTI [%s] # clear frame pop - frame=%d", |
|
825 |
JvmtiTrace::safe_get_thread_name(ets->get_thread()), |
|
826 |
fpop.frame_number() )); |
|
827 |
||
828 |
ets->get_frame_pops()->clear(fpop); |
|
829 |
recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); |
|
830 |
} |
|
831 |
||
832 |
||
833 |
void |
|
834 |
JvmtiEventControllerPrivate::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { |
|
835 |
int cleared_cnt = ets->get_frame_pops()->clear_to(fpop); |
|
836 |
||
837 |
EC_TRACE(("JVMTI [%s] # clear to frame pop - frame=%d, count=%d", |
|
838 |
JvmtiTrace::safe_get_thread_name(ets->get_thread()), |
|
839 |
fpop.frame_number(), |
|
840 |
cleared_cnt )); |
|
841 |
||
842 |
if (cleared_cnt > 0) { |
|
843 |
recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); |
|
844 |
} |
|
845 |
} |
|
846 |
||
847 |
void |
|
848 |
JvmtiEventControllerPrivate::change_field_watch(jvmtiEvent event_type, bool added) { |
|
849 |
int *count_addr; |
|
850 |
||
851 |
switch (event_type) { |
|
852 |
case JVMTI_EVENT_FIELD_MODIFICATION: |
|
853 |
count_addr = (int *)JvmtiExport::get_field_modification_count_addr(); |
|
854 |
break; |
|
855 |
case JVMTI_EVENT_FIELD_ACCESS: |
|
856 |
count_addr = (int *)JvmtiExport::get_field_access_count_addr(); |
|
857 |
break; |
|
858 |
default: |
|
859 |
assert(false, "incorrect event"); |
|
860 |
return; |
|
861 |
} |
|
862 |
||
863 |
EC_TRACE(("JVMTI [-] # change field watch - %s %s count=%d", |
|
864 |
event_type==JVMTI_EVENT_FIELD_MODIFICATION? "modification" : "access", |
|
865 |
added? "add" : "remove", |
|
866 |
*count_addr)); |
|
867 |
||
868 |
if (added) { |
|
869 |
(*count_addr)++; |
|
870 |
if (*count_addr == 1) { |
|
871 |
recompute_enabled(); |
|
872 |
} |
|
873 |
} else { |
|
874 |
if (*count_addr > 0) { |
|
875 |
(*count_addr)--; |
|
876 |
if (*count_addr == 0) { |
|
877 |
recompute_enabled(); |
|
878 |
} |
|
879 |
} else { |
|
880 |
assert(false, "field watch out of phase"); |
|
881 |
} |
|
882 |
} |
|
883 |
} |
|
884 |
||
885 |
void |
|
886 |
JvmtiEventControllerPrivate::event_init() { |
|
887 |
assert(JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
888 |
||
889 |
if (_initialized) { |
|
890 |
return; |
|
891 |
} |
|
892 |
||
893 |
EC_TRACE(("JVMTI [-] # VM live")); |
|
894 |
||
895 |
#ifdef ASSERT |
|
896 |
// check that our idea and the spec's idea of threaded events match |
|
897 |
for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { |
|
898 |
jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei); |
|
899 |
assert(((THREAD_FILTERED_EVENT_BITS & bit) != 0) == JvmtiUtil::event_threaded(ei), |
|
900 |
"thread filtered event list does not match"); |
|
901 |
} |
|
902 |
#endif |
|
903 |
||
904 |
_initialized = true; |
|
905 |
} |
|
906 |
||
907 |
void |
|
908 |
JvmtiEventControllerPrivate::vm_start() { |
|
909 |
// some events are now able to be enabled (phase has changed) |
|
910 |
JvmtiEventControllerPrivate::recompute_enabled(); |
|
911 |
} |
|
912 |
||
913 |
||
914 |
void |
|
915 |
JvmtiEventControllerPrivate::vm_init() { |
|
916 |
event_init(); |
|
917 |
||
918 |
// all the events are now able to be enabled (phase has changed) |
|
919 |
JvmtiEventControllerPrivate::recompute_enabled(); |
|
920 |
} |
|
921 |
||
922 |
||
923 |
void |
|
924 |
JvmtiEventControllerPrivate::vm_death() { |
|
925 |
// events are disabled (phase has changed) |
|
926 |
JvmtiEventControllerPrivate::recompute_enabled(); |
|
927 |
} |
|
928 |
||
929 |
||
930 |
/////////////////////////////////////////////////////////////// |
|
931 |
// |
|
932 |
// JvmtiEventController |
|
933 |
// |
|
934 |
||
935 |
JvmtiEventEnabled JvmtiEventController::_universal_global_event_enabled; |
|
936 |
||
937 |
bool |
|
938 |
JvmtiEventController::is_global_event(jvmtiEvent event_type) { |
|
939 |
assert(is_valid_event_type(event_type), "invalid event type"); |
|
940 |
jlong bit_for = ((jlong)1) << (event_type - TOTAL_MIN_EVENT_TYPE_VAL); |
|
941 |
return((bit_for & GLOBAL_EVENT_BITS)!=0); |
|
942 |
} |
|
943 |
||
944 |
void |
|
945 |
JvmtiEventController::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, jvmtiEvent event_type, bool enabled) { |
|
946 |
if (Threads::number_of_threads() == 0) { |
|
947 |
// during early VM start-up locks don't exist, but we are safely single threaded, |
|
948 |
// call the functionality without holding the JvmtiThreadState_lock. |
|
949 |
JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled); |
|
950 |
} else { |
|
951 |
MutexLocker mu(JvmtiThreadState_lock); |
|
952 |
JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled); |
|
953 |
} |
|
954 |
} |
|
955 |
||
956 |
||
957 |
void |
|
958 |
JvmtiEventController::set_event_callbacks(JvmtiEnvBase *env, |
|
959 |
const jvmtiEventCallbacks* callbacks, |
|
960 |
jint size_of_callbacks) { |
|
961 |
if (Threads::number_of_threads() == 0) { |
|
962 |
// during early VM start-up locks don't exist, but we are safely single threaded, |
|
963 |
// call the functionality without holding the JvmtiThreadState_lock. |
|
964 |
JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks); |
|
965 |
} else { |
|
966 |
MutexLocker mu(JvmtiThreadState_lock); |
|
967 |
JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks); |
|
968 |
} |
|
969 |
} |
|
970 |
||
971 |
void |
|
972 |
JvmtiEventController::set_extension_event_callback(JvmtiEnvBase *env, |
|
973 |
jint extension_event_index, |
|
974 |
jvmtiExtensionEvent callback) { |
|
975 |
if (Threads::number_of_threads() == 0) { |
|
976 |
JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback); |
|
977 |
} else { |
|
978 |
MutexLocker mu(JvmtiThreadState_lock); |
|
979 |
JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback); |
|
980 |
} |
|
981 |
} |
|
982 |
||
983 |
||
984 |
||
985 |
||
986 |
void |
|
987 |
JvmtiEventController::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { |
|
988 |
MutexLocker mu(JvmtiThreadState_lock); |
|
989 |
JvmtiEventControllerPrivate::set_frame_pop(ets, fpop); |
|
990 |
} |
|
991 |
||
992 |
||
993 |
void |
|
994 |
JvmtiEventController::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { |
|
995 |
MutexLocker mu(JvmtiThreadState_lock); |
|
996 |
JvmtiEventControllerPrivate::clear_frame_pop(ets, fpop); |
|
997 |
} |
|
998 |
||
999 |
||
1000 |
void |
|
1001 |
JvmtiEventController::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { |
|
1002 |
MutexLocker mu(JvmtiThreadState_lock); |
|
1003 |
JvmtiEventControllerPrivate::clear_to_frame_pop(ets, fpop); |
|
1004 |
} |
|
1005 |
||
1006 |
void |
|
1007 |
JvmtiEventController::change_field_watch(jvmtiEvent event_type, bool added) { |
|
1008 |
MutexLocker mu(JvmtiThreadState_lock); |
|
1009 |
JvmtiEventControllerPrivate::change_field_watch(event_type, added); |
|
1010 |
} |
|
1011 |
||
1012 |
void |
|
1013 |
JvmtiEventController::thread_started(JavaThread *thread) { |
|
1014 |
// operates only on the current thread |
|
1015 |
// JvmtiThreadState_lock grabbed only if needed. |
|
1016 |
JvmtiEventControllerPrivate::thread_started(thread); |
|
1017 |
} |
|
1018 |
||
1019 |
void |
|
1020 |
JvmtiEventController::thread_ended(JavaThread *thread) { |
|
1021 |
// operates only on the current thread |
|
1022 |
// JvmtiThreadState_lock grabbed only if needed. |
|
1023 |
JvmtiEventControllerPrivate::thread_ended(thread); |
|
1024 |
} |
|
1025 |
||
1026 |
void |
|
1027 |
JvmtiEventController::env_initialize(JvmtiEnvBase *env) { |
|
1028 |
if (Threads::number_of_threads() == 0) { |
|
1029 |
// during early VM start-up locks don't exist, but we are safely single threaded, |
|
1030 |
// call the functionality without holding the JvmtiThreadState_lock. |
|
1031 |
JvmtiEventControllerPrivate::env_initialize(env); |
|
1032 |
} else { |
|
1033 |
MutexLocker mu(JvmtiThreadState_lock); |
|
1034 |
JvmtiEventControllerPrivate::env_initialize(env); |
|
1035 |
} |
|
1036 |
} |
|
1037 |
||
1038 |
void |
|
1039 |
JvmtiEventController::env_dispose(JvmtiEnvBase *env) { |
|
1040 |
if (Threads::number_of_threads() == 0) { |
|
1041 |
// during early VM start-up locks don't exist, but we are safely single threaded, |
|
1042 |
// call the functionality without holding the JvmtiThreadState_lock. |
|
1043 |
JvmtiEventControllerPrivate::env_dispose(env); |
|
1044 |
} else { |
|
1045 |
MutexLocker mu(JvmtiThreadState_lock); |
|
1046 |
JvmtiEventControllerPrivate::env_dispose(env); |
|
1047 |
} |
|
1048 |
} |
|
1049 |
||
1050 |
||
1051 |
void |
|
1052 |
JvmtiEventController::vm_start() { |
|
1053 |
if (JvmtiEnvBase::environments_might_exist()) { |
|
1054 |
MutexLocker mu(JvmtiThreadState_lock); |
|
1055 |
JvmtiEventControllerPrivate::vm_start(); |
|
1056 |
} |
|
1057 |
} |
|
1058 |
||
1059 |
void |
|
1060 |
JvmtiEventController::vm_init() { |
|
1061 |
if (JvmtiEnvBase::environments_might_exist()) { |
|
1062 |
MutexLocker mu(JvmtiThreadState_lock); |
|
1063 |
JvmtiEventControllerPrivate::vm_init(); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
||
1067 |
void |
|
1068 |
JvmtiEventController::vm_death() { |
|
1069 |
if (JvmtiEnvBase::environments_might_exist()) { |
|
1070 |
MutexLocker mu(JvmtiThreadState_lock); |
|
1071 |
JvmtiEventControllerPrivate::vm_death(); |
|
1072 |
} |
|
1073 |
} |