annotate src/share/vm/prims/jvmtiEventController.cpp @ 12355:cefad50507d8

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