author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 24424 | hotspot/src/share/vm/prims/jvmtiEnvThreadState.cpp@2658d7834c6e |
child 48105 | 8d15b1369c7a |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22519
924605caa9a8
8030027: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Linux-amd64: SIGSEGV in JavaThread::last_java_vframe(RegisterMap*)+0xfa
sspitsyn
parents:
22234
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "interpreter/interpreter.hpp" |
|
28 |
#include "jvmtifiles/jvmtiEnv.hpp" |
|
29 |
#include "memory/resourceArea.hpp" |
|
30 |
#include "prims/jvmtiEnvThreadState.hpp" |
|
31 |
#include "prims/jvmtiEventController.inline.hpp" |
|
32 |
#include "prims/jvmtiImpl.hpp" |
|
33 |
#include "runtime/handles.hpp" |
|
34 |
#include "runtime/handles.inline.hpp" |
|
35 |
#include "runtime/interfaceSupport.hpp" |
|
36 |
#include "runtime/javaCalls.hpp" |
|
37 |
#include "runtime/signature.hpp" |
|
38 |
#include "runtime/vframe.hpp" |
|
39 |
#include "runtime/vm_operations.hpp" |
|
1 | 40 |
|
41 |
||
42 |
/////////////////////////////////////////////////////////////// |
|
43 |
// |
|
44 |
// class JvmtiFramePop |
|
45 |
// |
|
46 |
||
47 |
#ifndef PRODUCT |
|
48 |
void JvmtiFramePop::print() { |
|
49 |
tty->print_cr("_frame_number=%d", _frame_number); |
|
50 |
} |
|
51 |
#endif |
|
52 |
||
53 |
||
54 |
/////////////////////////////////////////////////////////////// |
|
55 |
// |
|
56 |
// class JvmtiFramePops - private methods |
|
57 |
// |
|
58 |
||
59 |
void |
|
60 |
JvmtiFramePops::set(JvmtiFramePop& fp) { |
|
61 |
if (_pops->find(fp.frame_number()) < 0) { |
|
62 |
_pops->append(fp.frame_number()); |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
||
67 |
void |
|
68 |
JvmtiFramePops::clear(JvmtiFramePop& fp) { |
|
69 |
assert(_pops->length() > 0, "No more frame pops"); |
|
70 |
||
71 |
_pops->remove(fp.frame_number()); |
|
72 |
} |
|
73 |
||
74 |
||
75 |
int |
|
76 |
JvmtiFramePops::clear_to(JvmtiFramePop& fp) { |
|
77 |
int cleared = 0; |
|
78 |
int index = 0; |
|
79 |
while (index < _pops->length()) { |
|
80 |
JvmtiFramePop pop = JvmtiFramePop(_pops->at(index)); |
|
81 |
if (pop.above_on_stack(fp)) { |
|
82 |
_pops->remove_at(index); |
|
83 |
++cleared; |
|
84 |
} else { |
|
85 |
++index; |
|
86 |
} |
|
87 |
} |
|
88 |
return cleared; |
|
89 |
} |
|
90 |
||
91 |
||
92 |
/////////////////////////////////////////////////////////////// |
|
93 |
// |
|
94 |
// class JvmtiFramePops - public methods |
|
95 |
// |
|
96 |
||
97 |
JvmtiFramePops::JvmtiFramePops() { |
|
13195 | 98 |
_pops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int> (2, true); |
1 | 99 |
} |
100 |
||
101 |
JvmtiFramePops::~JvmtiFramePops() { |
|
102 |
// return memory to c_heap. |
|
103 |
delete _pops; |
|
104 |
} |
|
105 |
||
106 |
||
107 |
#ifndef PRODUCT |
|
108 |
void JvmtiFramePops::print() { |
|
109 |
ResourceMark rm; |
|
110 |
||
111 |
int n = _pops->length(); |
|
112 |
for (int i=0; i<n; i++) { |
|
113 |
JvmtiFramePop fp = JvmtiFramePop(_pops->at(i)); |
|
114 |
tty->print("%d: ", i); |
|
115 |
fp.print(); |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23180
diff
changeset
|
116 |
tty->cr(); |
1 | 117 |
} |
118 |
} |
|
119 |
#endif |
|
120 |
||
121 |
/////////////////////////////////////////////////////////////// |
|
122 |
// |
|
123 |
// class JvmtiEnvThreadState |
|
124 |
// |
|
125 |
// Instances of JvmtiEnvThreadState hang off of each JvmtiThreadState, |
|
126 |
// one per JvmtiEnv. |
|
127 |
// |
|
128 |
||
129 |
JvmtiEnvThreadState::JvmtiEnvThreadState(JavaThread *thread, JvmtiEnvBase *env) : |
|
130 |
_event_enable() { |
|
131 |
_thread = thread; |
|
132 |
_env = (JvmtiEnv*)env; |
|
133 |
_next = NULL; |
|
134 |
_frame_pops = NULL; |
|
135 |
_current_bci = 0; |
|
136 |
_current_method_id = NULL; |
|
137 |
_breakpoint_posted = false; |
|
138 |
_single_stepping_posted = false; |
|
139 |
_agent_thread_local_storage_data = NULL; |
|
140 |
} |
|
141 |
||
142 |
JvmtiEnvThreadState::~JvmtiEnvThreadState() { |
|
143 |
delete _frame_pops; |
|
144 |
_frame_pops = NULL; |
|
145 |
} |
|
146 |
||
147 |
// Given that a new (potential) event has come in, |
|
148 |
// maintain the current JVMTI location on a per-thread per-env basis |
|
149 |
// and use it to filter out duplicate events: |
|
150 |
// - instruction rewrites |
|
151 |
// - breakpoint followed by single step |
|
152 |
// - single step at a breakpoint |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
153 |
void JvmtiEnvThreadState::compare_and_set_current_location(Method* new_method, |
1 | 154 |
address new_location, jvmtiEvent event) { |
155 |
||
156 |
int new_bci = new_location - new_method->code_base(); |
|
157 |
||
158 |
// The method is identified and stored as a jmethodID which is safe in this |
|
159 |
// case because the class cannot be unloaded while a method is executing. |
|
160 |
jmethodID new_method_id = new_method->jmethod_id(); |
|
161 |
||
162 |
// the last breakpoint or single step was at this same location |
|
163 |
if (_current_bci == new_bci && _current_method_id == new_method_id) { |
|
164 |
switch (event) { |
|
165 |
case JVMTI_EVENT_BREAKPOINT: |
|
166 |
// Repeat breakpoint is complicated. If we previously posted a breakpoint |
|
167 |
// event at this location and if we also single stepped at this location |
|
168 |
// then we skip the duplicate breakpoint. |
|
169 |
_breakpoint_posted = _breakpoint_posted && _single_stepping_posted; |
|
170 |
break; |
|
171 |
case JVMTI_EVENT_SINGLE_STEP: |
|
172 |
// Repeat single step is easy: just don't post it again. |
|
173 |
// If step is pending for popframe then it may not be |
|
174 |
// a repeat step. The new_bci and method_id is same as current_bci |
|
175 |
// and current method_id after pop and step for recursive calls. |
|
176 |
// This has been handled by clearing the location |
|
177 |
_single_stepping_posted = true; |
|
178 |
break; |
|
179 |
default: |
|
180 |
assert(false, "invalid event value passed"); |
|
181 |
break; |
|
182 |
} |
|
183 |
return; |
|
184 |
} |
|
185 |
||
186 |
set_current_location(new_method_id, new_bci); |
|
187 |
_breakpoint_posted = false; |
|
188 |
_single_stepping_posted = false; |
|
189 |
} |
|
190 |
||
191 |
||
192 |
JvmtiFramePops* JvmtiEnvThreadState::get_frame_pops() { |
|
23180
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
193 |
assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(), |
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
194 |
"frame pop data only accessible from same thread or at safepoint"); |
1 | 195 |
if (_frame_pops == NULL) { |
196 |
_frame_pops = new JvmtiFramePops(); |
|
197 |
assert(_frame_pops != NULL, "_frame_pops != NULL"); |
|
198 |
} |
|
199 |
return _frame_pops; |
|
200 |
} |
|
201 |
||
202 |
||
203 |
bool JvmtiEnvThreadState::has_frame_pops() { |
|
204 |
return _frame_pops == NULL? false : (_frame_pops->length() > 0); |
|
205 |
} |
|
206 |
||
207 |
void JvmtiEnvThreadState::set_frame_pop(int frame_number) { |
|
23180
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
208 |
assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(), |
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
209 |
"frame pop data only accessible from same thread or at safepoint"); |
1 | 210 |
JvmtiFramePop fpop(frame_number); |
211 |
JvmtiEventController::set_frame_pop(this, fpop); |
|
212 |
} |
|
213 |
||
214 |
||
215 |
void JvmtiEnvThreadState::clear_frame_pop(int frame_number) { |
|
23180
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
216 |
assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(), |
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
217 |
"frame pop data only accessible from same thread or at safepoint"); |
1 | 218 |
JvmtiFramePop fpop(frame_number); |
219 |
JvmtiEventController::clear_frame_pop(this, fpop); |
|
220 |
} |
|
221 |
||
222 |
||
223 |
void JvmtiEnvThreadState::clear_to_frame_pop(int frame_number) { |
|
23180
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
224 |
assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(), |
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
225 |
"frame pop data only accessible from same thread or at safepoint"); |
1 | 226 |
JvmtiFramePop fpop(frame_number); |
227 |
JvmtiEventController::clear_to_frame_pop(this, fpop); |
|
228 |
} |
|
229 |
||
230 |
||
231 |
bool JvmtiEnvThreadState::is_frame_pop(int cur_frame_number) { |
|
23180
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
232 |
assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(), |
e87156376bed
6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents:
22519
diff
changeset
|
233 |
"frame pop data only accessible from same thread or at safepoint"); |
1 | 234 |
if (!get_thread()->is_interp_only_mode() || _frame_pops == NULL) { |
235 |
return false; |
|
236 |
} |
|
237 |
JvmtiFramePop fp(cur_frame_number); |
|
238 |
return get_frame_pops()->contains(fp); |
|
239 |
} |
|
240 |
||
241 |
||
242 |
class VM_GetCurrentLocation : public VM_Operation { |
|
243 |
private: |
|
244 |
JavaThread *_thread; |
|
245 |
jmethodID _method_id; |
|
246 |
int _bci; |
|
247 |
||
248 |
public: |
|
249 |
VM_GetCurrentLocation(JavaThread *thread) { |
|
250 |
_thread = thread; |
|
251 |
} |
|
252 |
VMOp_Type type() const { return VMOp_GetCurrentLocation; } |
|
253 |
void doit() { |
|
254 |
ResourceMark rmark; // _thread != Thread::current() |
|
255 |
RegisterMap rm(_thread, false); |
|
21914
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
256 |
// There can be a race condition between a VM_Operation reaching a safepoint |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
257 |
// and the target thread exiting from Java execution. |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
258 |
// We must recheck the last Java frame still exists. |
22519
924605caa9a8
8030027: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Linux-amd64: SIGSEGV in JavaThread::last_java_vframe(RegisterMap*)+0xfa
sspitsyn
parents:
22234
diff
changeset
|
259 |
if (!_thread->is_exiting() && _thread->has_last_Java_frame()) { |
21914
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
260 |
javaVFrame* vf = _thread->last_java_vframe(&rm); |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
261 |
assert(vf != NULL, "must have last java frame"); |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
262 |
Method* method = vf->method(); |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
263 |
_method_id = method->jmethod_id(); |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
264 |
_bci = vf->bci(); |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
265 |
} else { |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
266 |
// Clear current location as the target thread has no Java frames anymore. |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
267 |
_method_id = (jmethodID)NULL; |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
268 |
_bci = 0; |
b60984ed653b
8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents:
13728
diff
changeset
|
269 |
} |
1 | 270 |
} |
271 |
void get_current_location(jmethodID *method_id, int *bci) { |
|
272 |
*method_id = _method_id; |
|
273 |
*bci = _bci; |
|
274 |
} |
|
275 |
}; |
|
276 |
||
277 |
void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool enabled) { |
|
278 |
assert(event_type == JVMTI_EVENT_SINGLE_STEP || event_type == JVMTI_EVENT_BREAKPOINT, |
|
279 |
"must be single-step or breakpoint event"); |
|
280 |
||
281 |
// Current location is used to detect the following: |
|
282 |
// 1) a breakpoint event followed by single-stepping to the same bci |
|
283 |
// 2) single-step to a bytecode that will be transformed to a fast version |
|
284 |
// We skip to avoid posting the duplicate single-stepping event. |
|
285 |
||
286 |
// If single-stepping is disabled, clear current location so that |
|
287 |
// single-stepping to the same method and bcp at a later time will be |
|
288 |
// detected if single-stepping is enabled at that time (see 4388912). |
|
289 |
||
290 |
// If single-stepping is enabled, set the current location to the |
|
291 |
// current method and bcp. This covers the following type of case, |
|
292 |
// e.g., the debugger stepi command: |
|
293 |
// - bytecode single stepped |
|
294 |
// - SINGLE_STEP event posted and SINGLE_STEP event disabled |
|
295 |
// - SINGLE_STEP event reenabled |
|
296 |
// - bytecode rewritten to fast version |
|
297 |
||
298 |
// If breakpoint event is disabled, clear current location only if |
|
299 |
// single-stepping is not enabled. Otherwise, keep the thread location |
|
300 |
// to detect any duplicate events. |
|
301 |
||
302 |
if (enabled) { |
|
303 |
// If enabling breakpoint, no need to reset. |
|
304 |
// Can't do anything if empty stack. |
|
305 |
if (event_type == JVMTI_EVENT_SINGLE_STEP && _thread->has_last_Java_frame()) { |
|
306 |
jmethodID method_id; |
|
307 |
int bci; |
|
308 |
// The java thread stack may not be walkable for a running thread |
|
309 |
// so get current location at safepoint. |
|
310 |
VM_GetCurrentLocation op(_thread); |
|
311 |
VMThread::execute(&op); |
|
312 |
op.get_current_location(&method_id, &bci); |
|
313 |
set_current_location(method_id, bci); |
|
314 |
} |
|
315 |
} else if (event_type == JVMTI_EVENT_SINGLE_STEP || !is_enabled(JVMTI_EVENT_SINGLE_STEP)) { |
|
316 |
// If this is to disable breakpoint, also check if single-step is not enabled |
|
317 |
clear_current_location(); |
|
318 |
} |
|
319 |
} |