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