Mercurial > hg > graal-compiler
annotate src/share/vm/prims/jvmtiEventController.cpp @ 878:abe076e3636f
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
Summary: JVM_FindClassFromBootLoader returns null if class not found
Reviewed-by: acorn, alanb, dholmes
author | mchung |
---|---|
date | Mon, 27 Jul 2009 09:06:22 -0700 |
parents | ea20d7ce26b0 |
children | 6deeaebad47a |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact 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; | |
85 | |
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) { | |
609
ea20d7ce26b0
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
0
diff
changeset
|
481 if (state == NULL) { |
ea20d7ce26b0
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
0
diff
changeset
|
482 // associated JavaThread is exiting |
ea20d7ce26b0
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
0
diff
changeset
|
483 return (jlong)0; |
ea20d7ce26b0
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
0
diff
changeset
|
484 } |
ea20d7ce26b0
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
0
diff
changeset
|
485 |
0 | 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 } | |
514 } | |
515 return any_env_enabled; | |
516 } | |
517 | |
518 | |
519 // Compute truly enabled events - meaning if the event can and could be | |
520 // sent. An event is truly enabled if it is user enabled on the thread | |
521 // or globally user enabled, but only if there is a callback or event hook | |
522 // for it and, for field watch and frame pop, one has been set. | |
523 // Compute if truly enabled, per thread, per environment, per combination | |
524 // (thread x environment), and overall. These merges are true if any is true. | |
525 // True per thread if some environment has callback set and the event is globally | |
526 // enabled or enabled for this thread. | |
527 // True per environment if the callback is set and the event is globally | |
528 // enabled in this environment or enabled for any thread in this environment. | |
529 // True per combination if the environment has the callback set and the | |
530 // event is globally enabled in this environment or the event is enabled | |
531 // for this thread and environment. | |
532 // | |
533 // All states transitions dependent on these transitions are also handled here. | |
534 void | |
535 JvmtiEventControllerPrivate::recompute_enabled() { | |
536 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); | |
537 | |
538 // event enabled for any thread in any environment | |
539 jlong was_any_env_thread_enabled = JvmtiEventController::_universal_global_event_enabled.get_bits(); | |
540 jlong any_env_thread_enabled = 0; | |
541 | |
542 EC_TRACE(("JVMTI [-] # recompute enabled - before %llx", was_any_env_thread_enabled)); | |
543 | |
544 // compute non-thread-filters events. | |
545 // This must be done separately from thread-filtered events, since some | |
546 // events can occur before any threads exist. | |
547 JvmtiEnvIterator it; | |
548 for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) { | |
549 any_env_thread_enabled |= recompute_env_enabled(env); | |
550 } | |
551 | |
552 // We need to create any missing jvmti_thread_state if there are globally set thread | |
553 // filtered events and there weren't last time | |
554 if ( (any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) != 0 && | |
555 (was_any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) == 0) { | |
556 assert(JvmtiEnv::is_vm_live() || (JvmtiEnv::get_phase()==JVMTI_PHASE_START), | |
557 "thread filtered events should not be enabled when VM not in start or live phase"); | |
558 { | |
559 MutexLocker mu(Threads_lock); //hold the Threads_lock for the iteration | |
560 for (JavaThread *tp = Threads::first(); tp != NULL; tp = tp->next()) { | |
609
ea20d7ce26b0
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
0
diff
changeset
|
561 // state_for_while_locked() makes tp->is_exiting() check |
0 | 562 JvmtiThreadState::state_for_while_locked(tp); // create the thread state if missing |
563 } | |
564 }// release Threads_lock | |
565 } | |
566 | |
567 // compute and set thread-filtered events | |
568 for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) { | |
569 any_env_thread_enabled |= recompute_thread_enabled(state); | |
570 } | |
571 | |
572 // set universal state (across all envs and threads) | |
573 jlong delta = any_env_thread_enabled ^ was_any_env_thread_enabled; | |
574 if (delta != 0) { | |
575 JvmtiExport::set_should_post_field_access((any_env_thread_enabled & FIELD_ACCESS_BIT) != 0); | |
576 JvmtiExport::set_should_post_field_modification((any_env_thread_enabled & FIELD_MODIFICATION_BIT) != 0); | |
577 JvmtiExport::set_should_post_class_load((any_env_thread_enabled & CLASS_LOAD_BIT) != 0); | |
578 JvmtiExport::set_should_post_class_file_load_hook((any_env_thread_enabled & CLASS_FILE_LOAD_HOOK_BIT) != 0); | |
579 JvmtiExport::set_should_post_native_method_bind((any_env_thread_enabled & NATIVE_METHOD_BIND_BIT) != 0); | |
580 JvmtiExport::set_should_post_dynamic_code_generated((any_env_thread_enabled & DYNAMIC_CODE_GENERATED_BIT) != 0); | |
581 JvmtiExport::set_should_post_data_dump((any_env_thread_enabled & DATA_DUMP_BIT) != 0); | |
582 JvmtiExport::set_should_post_class_prepare((any_env_thread_enabled & CLASS_PREPARE_BIT) != 0); | |
583 JvmtiExport::set_should_post_class_unload((any_env_thread_enabled & CLASS_UNLOAD_BIT) != 0); | |
584 JvmtiExport::set_should_post_monitor_contended_enter((any_env_thread_enabled & MONITOR_CONTENDED_ENTER_BIT) != 0); | |
585 JvmtiExport::set_should_post_monitor_contended_entered((any_env_thread_enabled & MONITOR_CONTENDED_ENTERED_BIT) != 0); | |
586 JvmtiExport::set_should_post_monitor_wait((any_env_thread_enabled & MONITOR_WAIT_BIT) != 0); | |
587 JvmtiExport::set_should_post_monitor_waited((any_env_thread_enabled & MONITOR_WAITED_BIT) != 0); | |
588 JvmtiExport::set_should_post_garbage_collection_start((any_env_thread_enabled & GARBAGE_COLLECTION_START_BIT) != 0); | |
589 JvmtiExport::set_should_post_garbage_collection_finish((any_env_thread_enabled & GARBAGE_COLLECTION_FINISH_BIT) != 0); | |
590 JvmtiExport::set_should_post_object_free((any_env_thread_enabled & OBJECT_FREE_BIT) != 0); | |
591 JvmtiExport::set_should_post_resource_exhausted((any_env_thread_enabled & RESOURCE_EXHAUSTED_BIT) != 0); | |
592 JvmtiExport::set_should_post_compiled_method_load((any_env_thread_enabled & COMPILED_METHOD_LOAD_BIT) != 0); | |
593 JvmtiExport::set_should_post_compiled_method_unload((any_env_thread_enabled & COMPILED_METHOD_UNLOAD_BIT) != 0); | |
594 JvmtiExport::set_should_post_vm_object_alloc((any_env_thread_enabled & VM_OBJECT_ALLOC_BIT) != 0); | |
595 | |
596 // need this if we want thread events or we need them to init data | |
597 JvmtiExport::set_should_post_thread_life((any_env_thread_enabled & NEED_THREAD_LIFE_EVENTS) != 0); | |
598 | |
599 // If single stepping is turned on or off, execute the VM op to change it. | |
600 if (delta & SINGLE_STEP_BIT) { | |
601 switch (JvmtiEnv::get_phase()) { | |
602 case JVMTI_PHASE_DEAD: | |
603 // If the VM is dying we can't execute VM ops | |
604 break; | |
605 case JVMTI_PHASE_LIVE: { | |
606 VM_ChangeSingleStep op((any_env_thread_enabled & SINGLE_STEP_BIT) != 0); | |
607 VMThread::execute(&op); | |
608 break; | |
609 } | |
610 default: | |
611 assert(false, "should never come here before live phase"); | |
612 break; | |
613 } | |
614 } | |
615 | |
616 // set global truly enabled, that is, any thread in any environment | |
617 JvmtiEventController::_universal_global_event_enabled.set_bits(any_env_thread_enabled); | |
618 } | |
619 | |
620 EC_TRACE(("JVMTI [-] # recompute enabled - after %llx", any_env_thread_enabled)); | |
621 } | |
622 | |
623 | |
624 void | |
625 JvmtiEventControllerPrivate::thread_started(JavaThread *thread) { | |
626 assert(thread->is_Java_thread(), "Must be JavaThread"); | |
627 assert(thread == Thread::current(), "must be current thread"); | |
628 assert(JvmtiEnvBase::environments_might_exist(), "to enter event controller, JVM TI environments must exist"); | |
629 | |
630 EC_TRACE(("JVMTI [%s] # thread started", JvmtiTrace::safe_get_thread_name(thread))); | |
631 | |
632 // if we have any thread filtered events globally enabled, create/update the thread state | |
633 if ((JvmtiEventController::_universal_global_event_enabled.get_bits() & THREAD_FILTERED_EVENT_BITS) != 0) { | |
634 MutexLocker mu(JvmtiThreadState_lock); | |
635 // create the thread state if missing | |
636 JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread); | |
637 if (state != NULL) { // skip threads with no JVMTI thread state | |
638 recompute_thread_enabled(state); | |
639 } | |
640 } | |
641 } | |
642 | |
643 | |
644 void | |
645 JvmtiEventControllerPrivate::thread_ended(JavaThread *thread) { | |
646 // Removes the JvmtiThreadState associated with the specified thread. | |
647 // May be called after all environments have been disposed. | |
648 | |
649 EC_TRACE(("JVMTI [%s] # thread ended", JvmtiTrace::safe_get_thread_name(thread))); | |
650 | |
651 JvmtiThreadState *state = thread->jvmti_thread_state(); | |
652 if (state != NULL) { | |
653 MutexLocker mu(JvmtiThreadState_lock); | |
654 delete state; | |
655 } | |
656 } | |
657 | |
658 void JvmtiEventControllerPrivate::set_event_callbacks(JvmtiEnvBase *env, | |
659 const jvmtiEventCallbacks* callbacks, | |
660 jint size_of_callbacks) { | |
661 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); | |
662 EC_TRACE(("JVMTI [*] # set event callbacks")); | |
663 | |
664 env->set_event_callbacks(callbacks, size_of_callbacks); | |
665 jlong enabled_bits = 0; | |
666 for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { | |
667 jvmtiEvent evt_t = (jvmtiEvent)ei; | |
668 if (env->has_callback(evt_t)) { | |
669 enabled_bits |= JvmtiEventEnabled::bit_for(evt_t); | |
670 } | |
671 } | |
672 env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits); | |
673 recompute_enabled(); | |
674 } | |
675 | |
676 void | |
677 JvmtiEventControllerPrivate::set_extension_event_callback(JvmtiEnvBase *env, | |
678 jint extension_event_index, | |
679 jvmtiExtensionEvent callback) | |
680 { | |
681 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); | |
682 EC_TRACE(("JVMTI [*] # set extension event callback")); | |
683 | |
684 // extension events are allocated below JVMTI_MIN_EVENT_TYPE_VAL | |
685 assert(extension_event_index >= (jint)EXT_MIN_EVENT_TYPE_VAL && | |
686 extension_event_index <= (jint)EXT_MAX_EVENT_TYPE_VAL, "sanity check"); | |
687 | |
688 | |
689 // As the bits for both standard (jvmtiEvent) and extension | |
690 // (jvmtiExtEvents) are stored in the same word we cast here to | |
691 // jvmtiEvent to set/clear the bit for this extension event. | |
692 jvmtiEvent event_type = (jvmtiEvent)extension_event_index; | |
693 | |
694 // Prevent a possible race condition where events are re-enabled by a call to | |
695 // set event callbacks, where the DisposeEnvironment occurs after the boiler-plate | |
696 // environment check and before the lock is acquired. | |
697 // We can safely do the is_valid check now, as JvmtiThreadState_lock is held. | |
698 bool enabling = (callback != NULL) && (env->is_valid()); | |
699 env->env_event_enable()->set_user_enabled(event_type, enabling); | |
700 | |
701 // update the callback | |
702 jvmtiExtEventCallbacks* ext_callbacks = env->ext_callbacks(); | |
703 switch (extension_event_index) { | |
704 case EXT_EVENT_CLASS_UNLOAD : | |
705 ext_callbacks->ClassUnload = callback; | |
706 break; | |
707 default: | |
708 ShouldNotReachHere(); | |
709 } | |
710 | |
711 // update the callback enable/disable bit | |
712 jlong enabled_bits = env->env_event_enable()->_event_callback_enabled.get_bits(); | |
713 jlong bit_for = JvmtiEventEnabled::bit_for(event_type); | |
714 if (enabling) { | |
715 enabled_bits |= bit_for; | |
716 } else { | |
717 enabled_bits &= ~bit_for; | |
718 } | |
719 env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits); | |
720 | |
721 recompute_enabled(); | |
722 } | |
723 | |
724 | |
725 void | |
726 JvmtiEventControllerPrivate::env_initialize(JvmtiEnvBase *env) { | |
727 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); | |
728 EC_TRACE(("JVMTI [*] # env initialize")); | |
729 | |
730 if (JvmtiEnvBase::is_vm_live()) { | |
731 // if we didn't initialize event info already (this is a late | |
732 // launched environment), do it now. | |
733 event_init(); | |
734 } | |
735 | |
736 env->initialize(); | |
737 | |
738 // add the JvmtiEnvThreadState to each JvmtiThreadState | |
739 for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) { | |
740 state->add_env(env); | |
741 assert((JvmtiEnv*)(state->env_thread_state(env)->get_env()) == env, "sanity check"); | |
742 } | |
743 JvmtiEventControllerPrivate::recompute_enabled(); | |
744 } | |
745 | |
746 | |
747 void | |
748 JvmtiEventControllerPrivate::env_dispose(JvmtiEnvBase *env) { | |
749 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); | |
750 EC_TRACE(("JVMTI [*] # env dispose")); | |
751 | |
752 // Before the environment is marked disposed, disable all events on this | |
753 // environment (by zapping the callbacks). As a result, the disposed | |
754 // environment will not call event handlers. | |
755 set_event_callbacks(env, NULL, 0); | |
756 for (jint extension_event_index = EXT_MIN_EVENT_TYPE_VAL; | |
757 extension_event_index <= EXT_MAX_EVENT_TYPE_VAL; | |
758 ++extension_event_index) { | |
759 set_extension_event_callback(env, extension_event_index, NULL); | |
760 } | |
761 | |
762 // Let the environment finish disposing itself. | |
763 env->env_dispose(); | |
764 } | |
765 | |
766 | |
767 void | |
768 JvmtiEventControllerPrivate::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, | |
769 jvmtiEvent event_type, bool enabled) { | |
770 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); | |
771 | |
772 EC_TRACE(("JVMTI [%s] # user %s event %s", | |
773 thread==NULL? "ALL": JvmtiTrace::safe_get_thread_name(thread), | |
774 enabled? "enabled" : "disabled", JvmtiTrace::event_name(event_type))); | |
775 | |
776 if (thread == NULL) { | |
777 env->env_event_enable()->set_user_enabled(event_type, enabled); | |
778 } else { | |
779 // create the thread state (if it didn't exist before) | |
780 JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread); | |
781 if (state != NULL) { | |
782 state->env_thread_state(env)->event_enable()->set_user_enabled(event_type, enabled); | |
783 } | |
784 } | |
785 recompute_enabled(); | |
786 } | |
787 | |
788 | |
789 void | |
790 JvmtiEventControllerPrivate::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { | |
791 EC_TRACE(("JVMTI [%s] # set frame pop - frame=%d", | |
792 JvmtiTrace::safe_get_thread_name(ets->get_thread()), | |
793 fpop.frame_number() )); | |
794 | |
795 ets->get_frame_pops()->set(fpop); | |
796 recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); | |
797 } | |
798 | |
799 | |
800 void | |
801 JvmtiEventControllerPrivate::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { | |
802 EC_TRACE(("JVMTI [%s] # clear frame pop - frame=%d", | |
803 JvmtiTrace::safe_get_thread_name(ets->get_thread()), | |
804 fpop.frame_number() )); | |
805 | |
806 ets->get_frame_pops()->clear(fpop); | |
807 recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); | |
808 } | |
809 | |
810 | |
811 void | |
812 JvmtiEventControllerPrivate::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { | |
813 int cleared_cnt = ets->get_frame_pops()->clear_to(fpop); | |
814 | |
815 EC_TRACE(("JVMTI [%s] # clear to frame pop - frame=%d, count=%d", | |
816 JvmtiTrace::safe_get_thread_name(ets->get_thread()), | |
817 fpop.frame_number(), | |
818 cleared_cnt )); | |
819 | |
820 if (cleared_cnt > 0) { | |
821 recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); | |
822 } | |
823 } | |
824 | |
825 void | |
826 JvmtiEventControllerPrivate::change_field_watch(jvmtiEvent event_type, bool added) { | |
827 int *count_addr; | |
828 | |
829 switch (event_type) { | |
830 case JVMTI_EVENT_FIELD_MODIFICATION: | |
831 count_addr = (int *)JvmtiExport::get_field_modification_count_addr(); | |
832 break; | |
833 case JVMTI_EVENT_FIELD_ACCESS: | |
834 count_addr = (int *)JvmtiExport::get_field_access_count_addr(); | |
835 break; | |
836 default: | |
837 assert(false, "incorrect event"); | |
838 return; | |
839 } | |
840 | |
841 EC_TRACE(("JVMTI [-] # change field watch - %s %s count=%d", | |
842 event_type==JVMTI_EVENT_FIELD_MODIFICATION? "modification" : "access", | |
843 added? "add" : "remove", | |
844 *count_addr)); | |
845 | |
846 if (added) { | |
847 (*count_addr)++; | |
848 if (*count_addr == 1) { | |
849 recompute_enabled(); | |
850 } | |
851 } else { | |
852 if (*count_addr > 0) { | |
853 (*count_addr)--; | |
854 if (*count_addr == 0) { | |
855 recompute_enabled(); | |
856 } | |
857 } else { | |
858 assert(false, "field watch out of phase"); | |
859 } | |
860 } | |
861 } | |
862 | |
863 void | |
864 JvmtiEventControllerPrivate::event_init() { | |
865 assert(JvmtiThreadState_lock->is_locked(), "sanity check"); | |
866 | |
867 if (_initialized) { | |
868 return; | |
869 } | |
870 | |
871 EC_TRACE(("JVMTI [-] # VM live")); | |
872 | |
873 #ifdef ASSERT | |
874 // check that our idea and the spec's idea of threaded events match | |
875 for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { | |
876 jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei); | |
877 assert(((THREAD_FILTERED_EVENT_BITS & bit) != 0) == JvmtiUtil::event_threaded(ei), | |
878 "thread filtered event list does not match"); | |
879 } | |
880 #endif | |
881 | |
882 _initialized = true; | |
883 } | |
884 | |
885 void | |
886 JvmtiEventControllerPrivate::vm_start() { | |
887 // some events are now able to be enabled (phase has changed) | |
888 JvmtiEventControllerPrivate::recompute_enabled(); | |
889 } | |
890 | |
891 | |
892 void | |
893 JvmtiEventControllerPrivate::vm_init() { | |
894 event_init(); | |
895 | |
896 // all the events are now able to be enabled (phase has changed) | |
897 JvmtiEventControllerPrivate::recompute_enabled(); | |
898 } | |
899 | |
900 | |
901 void | |
902 JvmtiEventControllerPrivate::vm_death() { | |
903 // events are disabled (phase has changed) | |
904 JvmtiEventControllerPrivate::recompute_enabled(); | |
905 } | |
906 | |
907 | |
908 /////////////////////////////////////////////////////////////// | |
909 // | |
910 // JvmtiEventController | |
911 // | |
912 | |
913 JvmtiEventEnabled JvmtiEventController::_universal_global_event_enabled; | |
914 | |
915 bool | |
916 JvmtiEventController::is_global_event(jvmtiEvent event_type) { | |
917 assert(is_valid_event_type(event_type), "invalid event type"); | |
918 jlong bit_for = ((jlong)1) << (event_type - TOTAL_MIN_EVENT_TYPE_VAL); | |
919 return((bit_for & GLOBAL_EVENT_BITS)!=0); | |
920 } | |
921 | |
922 void | |
923 JvmtiEventController::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, jvmtiEvent event_type, bool enabled) { | |
924 if (Threads::number_of_threads() == 0) { | |
925 // during early VM start-up locks don't exist, but we are safely single threaded, | |
926 // call the functionality without holding the JvmtiThreadState_lock. | |
927 JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled); | |
928 } else { | |
929 MutexLocker mu(JvmtiThreadState_lock); | |
930 JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled); | |
931 } | |
932 } | |
933 | |
934 | |
935 void | |
936 JvmtiEventController::set_event_callbacks(JvmtiEnvBase *env, | |
937 const jvmtiEventCallbacks* callbacks, | |
938 jint size_of_callbacks) { | |
939 if (Threads::number_of_threads() == 0) { | |
940 // during early VM start-up locks don't exist, but we are safely single threaded, | |
941 // call the functionality without holding the JvmtiThreadState_lock. | |
942 JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks); | |
943 } else { | |
944 MutexLocker mu(JvmtiThreadState_lock); | |
945 JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks); | |
946 } | |
947 } | |
948 | |
949 void | |
950 JvmtiEventController::set_extension_event_callback(JvmtiEnvBase *env, | |
951 jint extension_event_index, | |
952 jvmtiExtensionEvent callback) { | |
953 if (Threads::number_of_threads() == 0) { | |
954 JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback); | |
955 } else { | |
956 MutexLocker mu(JvmtiThreadState_lock); | |
957 JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback); | |
958 } | |
959 } | |
960 | |
961 | |
962 | |
963 | |
964 void | |
965 JvmtiEventController::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { | |
966 MutexLocker mu(JvmtiThreadState_lock); | |
967 JvmtiEventControllerPrivate::set_frame_pop(ets, fpop); | |
968 } | |
969 | |
970 | |
971 void | |
972 JvmtiEventController::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { | |
973 MutexLocker mu(JvmtiThreadState_lock); | |
974 JvmtiEventControllerPrivate::clear_frame_pop(ets, fpop); | |
975 } | |
976 | |
977 | |
978 void | |
979 JvmtiEventController::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { | |
980 MutexLocker mu(JvmtiThreadState_lock); | |
981 JvmtiEventControllerPrivate::clear_to_frame_pop(ets, fpop); | |
982 } | |
983 | |
984 void | |
985 JvmtiEventController::change_field_watch(jvmtiEvent event_type, bool added) { | |
986 MutexLocker mu(JvmtiThreadState_lock); | |
987 JvmtiEventControllerPrivate::change_field_watch(event_type, added); | |
988 } | |
989 | |
990 void | |
991 JvmtiEventController::thread_started(JavaThread *thread) { | |
992 // operates only on the current thread | |
993 // JvmtiThreadState_lock grabbed only if needed. | |
994 JvmtiEventControllerPrivate::thread_started(thread); | |
995 } | |
996 | |
997 void | |
998 JvmtiEventController::thread_ended(JavaThread *thread) { | |
999 // operates only on the current thread | |
1000 // JvmtiThreadState_lock grabbed only if needed. | |
1001 JvmtiEventControllerPrivate::thread_ended(thread); | |
1002 } | |
1003 | |
1004 void | |
1005 JvmtiEventController::env_initialize(JvmtiEnvBase *env) { | |
1006 if (Threads::number_of_threads() == 0) { | |
1007 // during early VM start-up locks don't exist, but we are safely single threaded, | |
1008 // call the functionality without holding the JvmtiThreadState_lock. | |
1009 JvmtiEventControllerPrivate::env_initialize(env); | |
1010 } else { | |
1011 MutexLocker mu(JvmtiThreadState_lock); | |
1012 JvmtiEventControllerPrivate::env_initialize(env); | |
1013 } | |
1014 } | |
1015 | |
1016 void | |
1017 JvmtiEventController::env_dispose(JvmtiEnvBase *env) { | |
1018 if (Threads::number_of_threads() == 0) { | |
1019 // during early VM start-up locks don't exist, but we are safely single threaded, | |
1020 // call the functionality without holding the JvmtiThreadState_lock. | |
1021 JvmtiEventControllerPrivate::env_dispose(env); | |
1022 } else { | |
1023 MutexLocker mu(JvmtiThreadState_lock); | |
1024 JvmtiEventControllerPrivate::env_dispose(env); | |
1025 } | |
1026 } | |
1027 | |
1028 | |
1029 void | |
1030 JvmtiEventController::vm_start() { | |
1031 if (JvmtiEnvBase::environments_might_exist()) { | |
1032 MutexLocker mu(JvmtiThreadState_lock); | |
1033 JvmtiEventControllerPrivate::vm_start(); | |
1034 } | |
1035 } | |
1036 | |
1037 void | |
1038 JvmtiEventController::vm_init() { | |
1039 if (JvmtiEnvBase::environments_might_exist()) { | |
1040 MutexLocker mu(JvmtiThreadState_lock); | |
1041 JvmtiEventControllerPrivate::vm_init(); | |
1042 } | |
1043 } | |
1044 | |
1045 void | |
1046 JvmtiEventController::vm_death() { | |
1047 if (JvmtiEnvBase::environments_might_exist()) { | |
1048 MutexLocker mu(JvmtiThreadState_lock); | |
1049 JvmtiEventControllerPrivate::vm_death(); | |
1050 } | |
1051 } |