author | jcoomes |
Thu, 11 Dec 2008 12:05:08 -0800 | |
changeset 1668 | 8ec481b8f514 |
parent 1497 | cd3234c89e59 |
child 2131 | 98f9cef66a34 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
670 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
# include "incls/_precompiled.incl" |
|
26 |
# include "incls/_frame.cpp.incl" |
|
27 |
||
28 |
RegisterMap::RegisterMap(JavaThread *thread, bool update_map) { |
|
29 |
_thread = thread; |
|
30 |
_update_map = update_map; |
|
31 |
clear(); |
|
32 |
debug_only(_update_for_id = NULL;) |
|
33 |
#ifndef PRODUCT |
|
34 |
for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL; |
|
35 |
#endif /* PRODUCT */ |
|
36 |
} |
|
37 |
||
38 |
RegisterMap::RegisterMap(const RegisterMap* map) { |
|
39 |
assert(map != this, "bad initialization parameter"); |
|
40 |
assert(map != NULL, "RegisterMap must be present"); |
|
41 |
_thread = map->thread(); |
|
42 |
_update_map = map->update_map(); |
|
43 |
_include_argument_oops = map->include_argument_oops(); |
|
44 |
debug_only(_update_for_id = map->_update_for_id;) |
|
45 |
pd_initialize_from(map); |
|
46 |
if (update_map()) { |
|
47 |
for(int i = 0; i < location_valid_size; i++) { |
|
48 |
LocationValidType bits = !update_map() ? 0 : map->_location_valid[i]; |
|
49 |
_location_valid[i] = bits; |
|
50 |
// for whichever bits are set, pull in the corresponding map->_location |
|
51 |
int j = i*location_valid_type_size; |
|
52 |
while (bits != 0) { |
|
53 |
if ((bits & 1) != 0) { |
|
54 |
assert(0 <= j && j < reg_count, "range check"); |
|
55 |
_location[j] = map->_location[j]; |
|
56 |
} |
|
57 |
bits >>= 1; |
|
58 |
j += 1; |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
void RegisterMap::clear() { |
|
65 |
set_include_argument_oops(true); |
|
66 |
if (_update_map) { |
|
67 |
for(int i = 0; i < location_valid_size; i++) { |
|
68 |
_location_valid[i] = 0; |
|
69 |
} |
|
70 |
pd_clear(); |
|
71 |
} else { |
|
72 |
pd_initialize(); |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
#ifndef PRODUCT |
|
77 |
||
78 |
void RegisterMap::print_on(outputStream* st) const { |
|
79 |
st->print_cr("Register map"); |
|
80 |
for(int i = 0; i < reg_count; i++) { |
|
81 |
||
82 |
VMReg r = VMRegImpl::as_VMReg(i); |
|
83 |
intptr_t* src = (intptr_t*) location(r); |
|
84 |
if (src != NULL) { |
|
85 |
||
1497 | 86 |
r->print_on(st); |
87 |
st->print(" [" INTPTR_FORMAT "] = ", src); |
|
1 | 88 |
if (((uintptr_t)src & (sizeof(*src)-1)) != 0) { |
1497 | 89 |
st->print_cr("<misaligned>"); |
1 | 90 |
} else { |
1497 | 91 |
st->print_cr(INTPTR_FORMAT, *src); |
1 | 92 |
} |
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
void RegisterMap::print() const { |
|
98 |
print_on(tty); |
|
99 |
} |
|
100 |
||
101 |
#endif |
|
102 |
// This returns the pc that if you were in the debugger you'd see. Not |
|
103 |
// the idealized value in the frame object. This undoes the magic conversion |
|
104 |
// that happens for deoptimized frames. In addition it makes the value the |
|
105 |
// hardware would want to see in the native frame. The only user (at this point) |
|
106 |
// is deoptimization. It likely no one else should ever use it. |
|
107 |
||
108 |
address frame::raw_pc() const { |
|
109 |
if (is_deoptimized_frame()) { |
|
110 |
return ((nmethod*) cb())->deopt_handler_begin() - pc_return_offset; |
|
111 |
} else { |
|
112 |
return (pc() - pc_return_offset); |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
// Change the pc in a frame object. This does not change the actual pc in |
|
117 |
// actual frame. To do that use patch_pc. |
|
118 |
// |
|
119 |
void frame::set_pc(address newpc ) { |
|
120 |
#ifdef ASSERT |
|
121 |
if (_cb != NULL && _cb->is_nmethod()) { |
|
122 |
assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation"); |
|
123 |
} |
|
124 |
#endif // ASSERT |
|
125 |
||
126 |
// Unsafe to use the is_deoptimzed tester after changing pc |
|
127 |
_deopt_state = unknown; |
|
128 |
_pc = newpc; |
|
129 |
_cb = CodeCache::find_blob_unsafe(_pc); |
|
130 |
||
131 |
} |
|
132 |
||
133 |
// type testers |
|
134 |
bool frame::is_deoptimized_frame() const { |
|
135 |
assert(_deopt_state != unknown, "not answerable"); |
|
136 |
return _deopt_state == is_deoptimized; |
|
137 |
} |
|
138 |
||
139 |
bool frame::is_native_frame() const { |
|
140 |
return (_cb != NULL && |
|
141 |
_cb->is_nmethod() && |
|
142 |
((nmethod*)_cb)->is_native_method()); |
|
143 |
} |
|
144 |
||
145 |
bool frame::is_java_frame() const { |
|
146 |
if (is_interpreted_frame()) return true; |
|
147 |
if (is_compiled_frame()) return true; |
|
148 |
return false; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
bool frame::is_compiled_frame() const { |
|
153 |
if (_cb != NULL && |
|
154 |
_cb->is_nmethod() && |
|
155 |
((nmethod*)_cb)->is_java_method()) { |
|
156 |
return true; |
|
157 |
} |
|
158 |
return false; |
|
159 |
} |
|
160 |
||
161 |
||
162 |
bool frame::is_runtime_frame() const { |
|
163 |
return (_cb != NULL && _cb->is_runtime_stub()); |
|
164 |
} |
|
165 |
||
166 |
bool frame::is_safepoint_blob_frame() const { |
|
167 |
return (_cb != NULL && _cb->is_safepoint_stub()); |
|
168 |
} |
|
169 |
||
170 |
// testers |
|
171 |
||
172 |
bool frame::is_first_java_frame() const { |
|
173 |
RegisterMap map(JavaThread::current(), false); // No update |
|
174 |
frame s; |
|
175 |
for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)); |
|
176 |
return s.is_first_frame(); |
|
177 |
} |
|
178 |
||
179 |
||
180 |
bool frame::entry_frame_is_first() const { |
|
181 |
return entry_frame_call_wrapper()->anchor()->last_Java_sp() == NULL; |
|
182 |
} |
|
183 |
||
184 |
||
185 |
bool frame::should_be_deoptimized() const { |
|
186 |
if (_deopt_state == is_deoptimized || |
|
187 |
!is_compiled_frame() ) return false; |
|
188 |
assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod"); |
|
189 |
nmethod* nm = (nmethod *)_cb; |
|
190 |
if (TraceDependencies) { |
|
191 |
tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false"); |
|
192 |
nm->print_value_on(tty); |
|
193 |
tty->cr(); |
|
194 |
} |
|
195 |
||
196 |
if( !nm->is_marked_for_deoptimization() ) |
|
197 |
return false; |
|
198 |
||
199 |
// If at the return point, then the frame has already been popped, and |
|
200 |
// only the return needs to be executed. Don't deoptimize here. |
|
201 |
return !nm->is_at_poll_return(pc()); |
|
202 |
} |
|
203 |
||
204 |
bool frame::can_be_deoptimized() const { |
|
205 |
if (!is_compiled_frame()) return false; |
|
206 |
nmethod* nm = (nmethod*)_cb; |
|
207 |
||
208 |
if( !nm->can_be_deoptimized() ) |
|
209 |
return false; |
|
210 |
||
211 |
return !nm->is_at_poll_return(pc()); |
|
212 |
} |
|
213 |
||
214 |
void frame::deoptimize(JavaThread* thread, bool thread_is_known_safe) { |
|
215 |
// Schedule deoptimization of an nmethod activation with this frame. |
|
216 |
||
217 |
// Store the original pc before an patch (or request to self-deopt) |
|
218 |
// in the published location of the frame. |
|
219 |
||
220 |
assert(_cb != NULL && _cb->is_nmethod(), "must be"); |
|
221 |
nmethod* nm = (nmethod*)_cb; |
|
222 |
||
223 |
// This is a fix for register window patching race |
|
224 |
if (NeedsDeoptSuspend && !thread_is_known_safe) { |
|
225 |
||
226 |
// It is possible especially with DeoptimizeALot/DeoptimizeRandom that |
|
227 |
// we could see the frame again and ask for it to be deoptimized since |
|
228 |
// it might move for a long time. That is harmless and we just ignore it. |
|
229 |
if (id() == thread->must_deopt_id()) { |
|
230 |
assert(thread->is_deopt_suspend(), "lost suspension"); |
|
231 |
return; |
|
232 |
} |
|
233 |
||
234 |
// We are at a safepoint so the target thread can only be |
|
235 |
// in 4 states: |
|
236 |
// blocked - no problem |
|
237 |
// blocked_trans - no problem (i.e. could have woken up from blocked |
|
238 |
// during a safepoint). |
|
239 |
// native - register window pc patching race |
|
240 |
// native_trans - momentary state |
|
241 |
// |
|
242 |
// We could just wait out a thread in native_trans to block. |
|
243 |
// Then we'd have all the issues that the safepoint code has as to |
|
244 |
// whether to spin or block. It isn't worth it. Just treat it like |
|
245 |
// native and be done with it. |
|
246 |
// |
|
247 |
JavaThreadState state = thread->thread_state(); |
|
248 |
if (state == _thread_in_native || state == _thread_in_native_trans) { |
|
249 |
// Since we are at a safepoint the target thread will stop itself |
|
250 |
// before it can return to java as long as we remain at the safepoint. |
|
251 |
// Therefore we can put an additional request for the thread to stop |
|
252 |
// no matter what no (like a suspend). This will cause the thread |
|
253 |
// to notice it needs to do the deopt on its own once it leaves native. |
|
254 |
// |
|
255 |
// The only reason we must do this is because on machine with register |
|
256 |
// windows we have a race with patching the return address and the |
|
257 |
// window coming live as the thread returns to the Java code (but still |
|
258 |
// in native mode) and then blocks. It is only this top most frame |
|
259 |
// that is at risk. So in truth we could add an additional check to |
|
260 |
// see if this frame is one that is at risk. |
|
261 |
RegisterMap map(thread, false); |
|
262 |
frame at_risk = thread->last_frame().sender(&map); |
|
263 |
if (id() == at_risk.id()) { |
|
264 |
thread->set_must_deopt_id(id()); |
|
265 |
thread->set_deopt_suspend(); |
|
266 |
return; |
|
267 |
} |
|
268 |
} |
|
269 |
} // NeedsDeoptSuspend |
|
270 |
||
271 |
||
272 |
address deopt = nm->deopt_handler_begin(); |
|
273 |
// Save the original pc before we patch in the new one |
|
274 |
nm->set_original_pc(this, pc()); |
|
275 |
patch_pc(thread, deopt); |
|
276 |
#ifdef ASSERT |
|
277 |
{ |
|
278 |
RegisterMap map(thread, false); |
|
279 |
frame check = thread->last_frame(); |
|
280 |
while (id() != check.id()) { |
|
281 |
check = check.sender(&map); |
|
282 |
} |
|
283 |
assert(check.is_deoptimized_frame(), "missed deopt"); |
|
284 |
} |
|
285 |
#endif // ASSERT |
|
286 |
} |
|
287 |
||
288 |
frame frame::java_sender() const { |
|
289 |
RegisterMap map(JavaThread::current(), false); |
|
290 |
frame s; |
|
291 |
for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ; |
|
292 |
guarantee(s.is_java_frame(), "tried to get caller of first java frame"); |
|
293 |
return s; |
|
294 |
} |
|
295 |
||
296 |
frame frame::real_sender(RegisterMap* map) const { |
|
297 |
frame result = sender(map); |
|
298 |
while (result.is_runtime_frame()) { |
|
299 |
result = result.sender(map); |
|
300 |
} |
|
301 |
return result; |
|
302 |
} |
|
303 |
||
304 |
// Note: called by profiler - NOT for current thread |
|
305 |
frame frame::profile_find_Java_sender_frame(JavaThread *thread) { |
|
306 |
// If we don't recognize this frame, walk back up the stack until we do |
|
307 |
RegisterMap map(thread, false); |
|
308 |
frame first_java_frame = frame(); |
|
309 |
||
310 |
// Find the first Java frame on the stack starting with input frame |
|
311 |
if (is_java_frame()) { |
|
312 |
// top frame is compiled frame or deoptimized frame |
|
313 |
first_java_frame = *this; |
|
314 |
} else if (safe_for_sender(thread)) { |
|
315 |
for (frame sender_frame = sender(&map); |
|
316 |
sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame(); |
|
317 |
sender_frame = sender_frame.sender(&map)) { |
|
318 |
if (sender_frame.is_java_frame()) { |
|
319 |
first_java_frame = sender_frame; |
|
320 |
break; |
|
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
return first_java_frame; |
|
325 |
} |
|
326 |
||
327 |
// Interpreter frames |
|
328 |
||
329 |
||
330 |
void frame::interpreter_frame_set_locals(intptr_t* locs) { |
|
331 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
332 |
*interpreter_frame_locals_addr() = locs; |
|
333 |
} |
|
334 |
||
335 |
methodOop frame::interpreter_frame_method() const { |
|
336 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
337 |
methodOop m = *interpreter_frame_method_addr(); |
|
338 |
assert(m->is_perm(), "bad methodOop in interpreter frame"); |
|
339 |
assert(m->is_method(), "not a methodOop"); |
|
340 |
return m; |
|
341 |
} |
|
342 |
||
343 |
void frame::interpreter_frame_set_method(methodOop method) { |
|
344 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
345 |
*interpreter_frame_method_addr() = method; |
|
346 |
} |
|
347 |
||
348 |
void frame::interpreter_frame_set_bcx(intptr_t bcx) { |
|
349 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
350 |
if (ProfileInterpreter) { |
|
351 |
bool formerly_bci = is_bci(interpreter_frame_bcx()); |
|
352 |
bool is_now_bci = is_bci(bcx); |
|
353 |
*interpreter_frame_bcx_addr() = bcx; |
|
354 |
||
355 |
intptr_t mdx = interpreter_frame_mdx(); |
|
356 |
||
357 |
if (mdx != 0) { |
|
358 |
if (formerly_bci) { |
|
359 |
if (!is_now_bci) { |
|
360 |
// The bcx was just converted from bci to bcp. |
|
361 |
// Convert the mdx in parallel. |
|
362 |
methodDataOop mdo = interpreter_frame_method()->method_data(); |
|
363 |
assert(mdo != NULL, ""); |
|
364 |
int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one. |
|
365 |
address mdp = mdo->di_to_dp(mdi); |
|
366 |
interpreter_frame_set_mdx((intptr_t)mdp); |
|
367 |
} |
|
368 |
} else { |
|
369 |
if (is_now_bci) { |
|
370 |
// The bcx was just converted from bcp to bci. |
|
371 |
// Convert the mdx in parallel. |
|
372 |
methodDataOop mdo = interpreter_frame_method()->method_data(); |
|
373 |
assert(mdo != NULL, ""); |
|
374 |
int mdi = mdo->dp_to_di((address)mdx); |
|
375 |
interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0. |
|
376 |
} |
|
377 |
} |
|
378 |
} |
|
379 |
} else { |
|
380 |
*interpreter_frame_bcx_addr() = bcx; |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
jint frame::interpreter_frame_bci() const { |
|
385 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
386 |
intptr_t bcx = interpreter_frame_bcx(); |
|
387 |
return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx); |
|
388 |
} |
|
389 |
||
390 |
void frame::interpreter_frame_set_bci(jint bci) { |
|
391 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
392 |
assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC"); |
|
393 |
interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci)); |
|
394 |
} |
|
395 |
||
396 |
address frame::interpreter_frame_bcp() const { |
|
397 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
398 |
intptr_t bcx = interpreter_frame_bcx(); |
|
399 |
return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx; |
|
400 |
} |
|
401 |
||
402 |
void frame::interpreter_frame_set_bcp(address bcp) { |
|
403 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
404 |
assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC"); |
|
405 |
interpreter_frame_set_bcx((intptr_t)bcp); |
|
406 |
} |
|
407 |
||
408 |
void frame::interpreter_frame_set_mdx(intptr_t mdx) { |
|
409 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
410 |
assert(ProfileInterpreter, "must be profiling interpreter"); |
|
411 |
*interpreter_frame_mdx_addr() = mdx; |
|
412 |
} |
|
413 |
||
414 |
address frame::interpreter_frame_mdp() const { |
|
415 |
assert(ProfileInterpreter, "must be profiling interpreter"); |
|
416 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
417 |
intptr_t bcx = interpreter_frame_bcx(); |
|
418 |
intptr_t mdx = interpreter_frame_mdx(); |
|
419 |
||
420 |
assert(!is_bci(bcx), "should not access mdp during GC"); |
|
421 |
return (address)mdx; |
|
422 |
} |
|
423 |
||
424 |
void frame::interpreter_frame_set_mdp(address mdp) { |
|
425 |
assert(is_interpreted_frame(), "interpreted frame expected"); |
|
426 |
if (mdp == NULL) { |
|
427 |
// Always allow the mdp to be cleared. |
|
428 |
interpreter_frame_set_mdx((intptr_t)mdp); |
|
429 |
} |
|
430 |
intptr_t bcx = interpreter_frame_bcx(); |
|
431 |
assert(!is_bci(bcx), "should not set mdp during GC"); |
|
432 |
interpreter_frame_set_mdx((intptr_t)mdp); |
|
433 |
} |
|
434 |
||
435 |
BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const { |
|
436 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
437 |
#ifdef ASSERT |
|
438 |
interpreter_frame_verify_monitor(current); |
|
439 |
#endif |
|
440 |
BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size()); |
|
441 |
return next; |
|
442 |
} |
|
443 |
||
444 |
BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const { |
|
445 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
446 |
#ifdef ASSERT |
|
447 |
// // This verification needs to be checked before being enabled |
|
448 |
// interpreter_frame_verify_monitor(current); |
|
449 |
#endif |
|
450 |
BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size()); |
|
451 |
return previous; |
|
452 |
} |
|
453 |
||
454 |
// Interpreter locals and expression stack locations. |
|
455 |
||
456 |
intptr_t* frame::interpreter_frame_local_at(int index) const { |
|
457 |
const int n = Interpreter::local_offset_in_bytes(index)/wordSize; |
|
458 |
return &((*interpreter_frame_locals_addr())[n]); |
|
459 |
} |
|
460 |
||
461 |
frame::Tag frame::interpreter_frame_local_tag(int index) const { |
|
462 |
const int n = Interpreter::local_tag_offset_in_bytes(index)/wordSize; |
|
463 |
return (Tag)(*interpreter_frame_locals_addr()) [n]; |
|
464 |
} |
|
465 |
||
466 |
void frame::interpreter_frame_set_local_tag(int index, Tag tag) const { |
|
467 |
const int n = Interpreter::local_tag_offset_in_bytes(index)/wordSize; |
|
468 |
(*interpreter_frame_locals_addr())[n] = (intptr_t)tag; |
|
469 |
} |
|
470 |
||
471 |
intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const { |
|
472 |
const int i = offset * interpreter_frame_expression_stack_direction(); |
|
473 |
const int n = ((i * Interpreter::stackElementSize()) + |
|
474 |
Interpreter::value_offset_in_bytes())/wordSize; |
|
475 |
return &(interpreter_frame_expression_stack()[n]); |
|
476 |
} |
|
477 |
||
478 |
frame::Tag frame::interpreter_frame_expression_stack_tag(jint offset) const { |
|
479 |
const int i = offset * interpreter_frame_expression_stack_direction(); |
|
480 |
const int n = ((i * Interpreter::stackElementSize()) + |
|
481 |
Interpreter::tag_offset_in_bytes())/wordSize; |
|
482 |
return (Tag)(interpreter_frame_expression_stack()[n]); |
|
483 |
} |
|
484 |
||
485 |
void frame::interpreter_frame_set_expression_stack_tag(jint offset, |
|
486 |
Tag tag) const { |
|
487 |
const int i = offset * interpreter_frame_expression_stack_direction(); |
|
488 |
const int n = ((i * Interpreter::stackElementSize()) + |
|
489 |
Interpreter::tag_offset_in_bytes())/wordSize; |
|
490 |
interpreter_frame_expression_stack()[n] = (intptr_t)tag; |
|
491 |
} |
|
492 |
||
493 |
jint frame::interpreter_frame_expression_stack_size() const { |
|
494 |
// Number of elements on the interpreter expression stack |
|
495 |
// Callers should span by stackElementWords |
|
496 |
int element_size = Interpreter::stackElementWords(); |
|
497 |
if (frame::interpreter_frame_expression_stack_direction() < 0) { |
|
498 |
return (interpreter_frame_expression_stack() - |
|
499 |
interpreter_frame_tos_address() + 1)/element_size; |
|
500 |
} else { |
|
501 |
return (interpreter_frame_tos_address() - |
|
502 |
interpreter_frame_expression_stack() + 1)/element_size; |
|
503 |
} |
|
504 |
} |
|
505 |
||
506 |
||
507 |
// (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp) |
|
508 |
||
509 |
const char* frame::print_name() const { |
|
510 |
if (is_native_frame()) return "Native"; |
|
511 |
if (is_interpreted_frame()) return "Interpreted"; |
|
512 |
if (is_compiled_frame()) { |
|
513 |
if (is_deoptimized_frame()) return "Deoptimized"; |
|
514 |
return "Compiled"; |
|
515 |
} |
|
516 |
if (sp() == NULL) return "Empty"; |
|
517 |
return "C"; |
|
518 |
} |
|
519 |
||
520 |
void frame::print_value_on(outputStream* st, JavaThread *thread) const { |
|
521 |
NOT_PRODUCT(address begin = pc()-40;) |
|
522 |
NOT_PRODUCT(address end = NULL;) |
|
523 |
||
524 |
st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp()); |
|
525 |
if (sp() != NULL) |
|
526 |
st->print(", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), pc()); |
|
527 |
||
528 |
if (StubRoutines::contains(pc())) { |
|
529 |
st->print_cr(")"); |
|
530 |
st->print("("); |
|
531 |
StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); |
|
532 |
st->print("~Stub::%s", desc->name()); |
|
533 |
NOT_PRODUCT(begin = desc->begin(); end = desc->end();) |
|
534 |
} else if (Interpreter::contains(pc())) { |
|
535 |
st->print_cr(")"); |
|
536 |
st->print("("); |
|
537 |
InterpreterCodelet* desc = Interpreter::codelet_containing(pc()); |
|
538 |
if (desc != NULL) { |
|
539 |
st->print("~"); |
|
540 |
desc->print(); |
|
541 |
NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();) |
|
542 |
} else { |
|
543 |
st->print("~interpreter"); |
|
544 |
} |
|
545 |
} |
|
546 |
st->print_cr(")"); |
|
547 |
||
548 |
if (_cb != NULL) { |
|
549 |
st->print(" "); |
|
550 |
_cb->print_value_on(st); |
|
551 |
st->cr(); |
|
552 |
#ifndef PRODUCT |
|
553 |
if (end == NULL) { |
|
554 |
begin = _cb->instructions_begin(); |
|
555 |
end = _cb->instructions_end(); |
|
556 |
} |
|
557 |
#endif |
|
558 |
} |
|
559 |
NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);) |
|
560 |
} |
|
561 |
||
562 |
||
563 |
void frame::print_on(outputStream* st) const { |
|
564 |
print_value_on(st,NULL); |
|
565 |
if (is_interpreted_frame()) { |
|
566 |
interpreter_frame_print_on(st); |
|
567 |
} |
|
568 |
} |
|
569 |
||
570 |
||
571 |
void frame::interpreter_frame_print_on(outputStream* st) const { |
|
572 |
#ifndef PRODUCT |
|
573 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
574 |
jint i; |
|
575 |
for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) { |
|
576 |
intptr_t x = *interpreter_frame_local_at(i); |
|
577 |
st->print(" - local [" INTPTR_FORMAT "]", x); |
|
578 |
if (TaggedStackInterpreter) { |
|
579 |
Tag x = interpreter_frame_local_tag(i); |
|
580 |
st->print(" - local tag [" INTPTR_FORMAT "]", x); |
|
581 |
} |
|
582 |
st->fill_to(23); |
|
583 |
st->print_cr("; #%d", i); |
|
584 |
} |
|
585 |
for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) { |
|
586 |
intptr_t x = *interpreter_frame_expression_stack_at(i); |
|
587 |
st->print(" - stack [" INTPTR_FORMAT "]", x); |
|
588 |
if (TaggedStackInterpreter) { |
|
589 |
Tag x = interpreter_frame_expression_stack_tag(i); |
|
590 |
st->print(" - stack tag [" INTPTR_FORMAT "]", x); |
|
591 |
} |
|
592 |
st->fill_to(23); |
|
593 |
st->print_cr("; #%d", i); |
|
594 |
} |
|
595 |
// locks for synchronization |
|
596 |
for (BasicObjectLock* current = interpreter_frame_monitor_end(); |
|
597 |
current < interpreter_frame_monitor_begin(); |
|
598 |
current = next_monitor_in_interpreter_frame(current)) { |
|
599 |
st->print_cr(" [ - obj "); |
|
600 |
current->obj()->print_value_on(st); |
|
601 |
st->cr(); |
|
602 |
st->print_cr(" - lock "); |
|
603 |
current->lock()->print_on(st); |
|
604 |
st->cr(); |
|
605 |
} |
|
606 |
// monitor |
|
607 |
st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin()); |
|
608 |
// bcp |
|
609 |
st->print(" - bcp [" INTPTR_FORMAT "]", interpreter_frame_bcp()); |
|
610 |
st->fill_to(23); |
|
611 |
st->print_cr("; @%d", interpreter_frame_bci()); |
|
612 |
// locals |
|
613 |
st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0)); |
|
614 |
// method |
|
615 |
st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method()); |
|
616 |
st->fill_to(23); |
|
617 |
st->print("; "); |
|
618 |
interpreter_frame_method()->print_name(st); |
|
619 |
st->cr(); |
|
620 |
#endif |
|
621 |
} |
|
622 |
||
623 |
// Return whether the frame is in the VM or os indicating a Hotspot problem. |
|
624 |
// Otherwise, it's likely a bug in the native library that the Java code calls, |
|
625 |
// hopefully indicating where to submit bugs. |
|
626 |
static void print_C_frame(outputStream* st, char* buf, int buflen, address pc) { |
|
627 |
// C/C++ frame |
|
628 |
bool in_vm = os::address_is_in_vm(pc); |
|
629 |
st->print(in_vm ? "V" : "C"); |
|
630 |
||
631 |
int offset; |
|
632 |
bool found; |
|
633 |
||
634 |
// libname |
|
635 |
found = os::dll_address_to_library_name(pc, buf, buflen, &offset); |
|
636 |
if (found) { |
|
637 |
// skip directory names |
|
638 |
const char *p1, *p2; |
|
639 |
p1 = buf; |
|
640 |
int len = (int)strlen(os::file_separator()); |
|
641 |
while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len; |
|
642 |
st->print(" [%s+0x%x]", p1, offset); |
|
643 |
} else { |
|
644 |
st->print(" " PTR_FORMAT, pc); |
|
645 |
} |
|
646 |
||
647 |
// function name - os::dll_address_to_function_name() may return confusing |
|
648 |
// names if pc is within jvm.dll or libjvm.so, because JVM only has |
|
649 |
// JVM_xxxx and a few other symbols in the dynamic symbol table. Do this |
|
650 |
// only for native libraries. |
|
651 |
if (!in_vm) { |
|
652 |
found = os::dll_address_to_function_name(pc, buf, buflen, &offset); |
|
653 |
||
654 |
if (found) { |
|
655 |
st->print(" %s+0x%x", buf, offset); |
|
656 |
} |
|
657 |
} |
|
658 |
} |
|
659 |
||
660 |
// frame::print_on_error() is called by fatal error handler. Notice that we may |
|
661 |
// crash inside this function if stack frame is corrupted. The fatal error |
|
662 |
// handler can catch and handle the crash. Here we assume the frame is valid. |
|
663 |
// |
|
664 |
// First letter indicates type of the frame: |
|
665 |
// J: Java frame (compiled) |
|
666 |
// j: Java frame (interpreted) |
|
667 |
// V: VM frame (C/C++) |
|
668 |
// v: Other frames running VM generated code (e.g. stubs, adapters, etc.) |
|
669 |
// C: C/C++ frame |
|
670 |
// |
|
671 |
// We don't need detailed frame type as that in frame::print_name(). "C" |
|
672 |
// suggests the problem is in user lib; everything else is likely a VM bug. |
|
673 |
||
674 |
void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const { |
|
675 |
if (_cb != NULL) { |
|
676 |
if (Interpreter::contains(pc())) { |
|
677 |
methodOop m = this->interpreter_frame_method(); |
|
678 |
if (m != NULL) { |
|
679 |
m->name_and_sig_as_C_string(buf, buflen); |
|
680 |
st->print("j %s", buf); |
|
681 |
st->print("+%d", this->interpreter_frame_bci()); |
|
682 |
} else { |
|
683 |
st->print("j " PTR_FORMAT, pc()); |
|
684 |
} |
|
685 |
} else if (StubRoutines::contains(pc())) { |
|
686 |
StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); |
|
687 |
if (desc != NULL) { |
|
688 |
st->print("v ~StubRoutines::%s", desc->name()); |
|
689 |
} else { |
|
690 |
st->print("v ~StubRoutines::" PTR_FORMAT, pc()); |
|
691 |
} |
|
692 |
} else if (_cb->is_buffer_blob()) { |
|
693 |
st->print("v ~BufferBlob::%s", ((BufferBlob *)_cb)->name()); |
|
694 |
} else if (_cb->is_nmethod()) { |
|
695 |
methodOop m = ((nmethod *)_cb)->method(); |
|
696 |
if (m != NULL) { |
|
697 |
m->name_and_sig_as_C_string(buf, buflen); |
|
698 |
st->print("J %s", buf); |
|
699 |
} else { |
|
700 |
st->print("J " PTR_FORMAT, pc()); |
|
701 |
} |
|
702 |
} else if (_cb->is_runtime_stub()) { |
|
703 |
st->print("v ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name()); |
|
704 |
} else if (_cb->is_deoptimization_stub()) { |
|
705 |
st->print("v ~DeoptimizationBlob"); |
|
706 |
} else if (_cb->is_exception_stub()) { |
|
707 |
st->print("v ~ExceptionBlob"); |
|
708 |
} else if (_cb->is_safepoint_stub()) { |
|
709 |
st->print("v ~SafepointBlob"); |
|
710 |
} else { |
|
711 |
st->print("v blob " PTR_FORMAT, pc()); |
|
712 |
} |
|
713 |
} else { |
|
714 |
print_C_frame(st, buf, buflen, pc()); |
|
715 |
} |
|
716 |
} |
|
717 |
||
718 |
||
719 |
/* |
|
720 |
The interpreter_frame_expression_stack_at method in the case of SPARC needs the |
|
721 |
max_stack value of the method in order to compute the expression stack address. |
|
722 |
It uses the methodOop in order to get the max_stack value but during GC this |
|
723 |
methodOop value saved on the frame is changed by reverse_and_push and hence cannot |
|
724 |
be used. So we save the max_stack value in the FrameClosure object and pass it |
|
725 |
down to the interpreter_frame_expression_stack_at method |
|
726 |
*/ |
|
727 |
class InterpreterFrameClosure : public OffsetClosure { |
|
728 |
private: |
|
729 |
frame* _fr; |
|
730 |
OopClosure* _f; |
|
731 |
int _max_locals; |
|
732 |
int _max_stack; |
|
733 |
||
734 |
public: |
|
735 |
InterpreterFrameClosure(frame* fr, int max_locals, int max_stack, |
|
736 |
OopClosure* f) { |
|
737 |
_fr = fr; |
|
738 |
_max_locals = max_locals; |
|
739 |
_max_stack = max_stack; |
|
740 |
_f = f; |
|
741 |
} |
|
742 |
||
743 |
void offset_do(int offset) { |
|
744 |
oop* addr; |
|
745 |
if (offset < _max_locals) { |
|
746 |
addr = (oop*) _fr->interpreter_frame_local_at(offset); |
|
747 |
assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame"); |
|
748 |
_f->do_oop(addr); |
|
749 |
} else { |
|
750 |
addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals)); |
|
751 |
// In case of exceptions, the expression stack is invalid and the esp will be reset to express |
|
752 |
// this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel). |
|
753 |
bool in_stack; |
|
754 |
if (frame::interpreter_frame_expression_stack_direction() > 0) { |
|
755 |
in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address(); |
|
756 |
} else { |
|
757 |
in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address(); |
|
758 |
} |
|
759 |
if (in_stack) { |
|
760 |
_f->do_oop(addr); |
|
761 |
} |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
int max_locals() { return _max_locals; } |
|
766 |
frame* fr() { return _fr; } |
|
767 |
}; |
|
768 |
||
769 |
||
770 |
class InterpretedArgumentOopFinder: public SignatureInfo { |
|
771 |
private: |
|
772 |
OopClosure* _f; // Closure to invoke |
|
773 |
int _offset; // TOS-relative offset, decremented with each argument |
|
774 |
bool _is_static; // true if the callee is a static method |
|
775 |
frame* _fr; |
|
776 |
||
777 |
void set(int size, BasicType type) { |
|
778 |
_offset -= size; |
|
779 |
if (type == T_OBJECT || type == T_ARRAY) oop_offset_do(); |
|
780 |
} |
|
781 |
||
782 |
void oop_offset_do() { |
|
783 |
oop* addr; |
|
784 |
addr = (oop*)_fr->interpreter_frame_tos_at(_offset); |
|
785 |
_f->do_oop(addr); |
|
786 |
} |
|
787 |
||
788 |
public: |
|
789 |
InterpretedArgumentOopFinder(symbolHandle signature, bool is_static, frame* fr, OopClosure* f) : SignatureInfo(signature) { |
|
790 |
// compute size of arguments |
|
791 |
int args_size = ArgumentSizeComputer(signature).size() + (is_static ? 0 : 1); |
|
792 |
assert(!fr->is_interpreted_frame() || |
|
793 |
args_size <= fr->interpreter_frame_expression_stack_size(), |
|
794 |
"args cannot be on stack anymore"); |
|
795 |
// initialize InterpretedArgumentOopFinder |
|
796 |
_f = f; |
|
797 |
_fr = fr; |
|
798 |
_offset = args_size; |
|
799 |
_is_static = is_static; |
|
800 |
} |
|
801 |
||
802 |
void oops_do() { |
|
803 |
if (!_is_static) { |
|
804 |
--_offset; |
|
805 |
oop_offset_do(); |
|
806 |
} |
|
807 |
iterate_parameters(); |
|
808 |
} |
|
809 |
}; |
|
810 |
||
811 |
||
812 |
// Entry frame has following form (n arguments) |
|
813 |
// +-----------+ |
|
814 |
// sp -> | last arg | |
|
815 |
// +-----------+ |
|
816 |
// : ::: : |
|
817 |
// +-----------+ |
|
818 |
// (sp+n)->| first arg| |
|
819 |
// +-----------+ |
|
820 |
||
821 |
||
822 |
||
823 |
// visits and GC's all the arguments in entry frame |
|
824 |
class EntryFrameOopFinder: public SignatureInfo { |
|
825 |
private: |
|
826 |
bool _is_static; |
|
827 |
int _offset; |
|
828 |
frame* _fr; |
|
829 |
OopClosure* _f; |
|
830 |
||
831 |
void set(int size, BasicType type) { |
|
832 |
assert (_offset >= 0, "illegal offset"); |
|
833 |
if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset); |
|
834 |
_offset -= size; |
|
835 |
} |
|
836 |
||
837 |
void oop_at_offset_do(int offset) { |
|
838 |
assert (offset >= 0, "illegal offset") |
|
839 |
oop* addr = (oop*) _fr->entry_frame_argument_at(offset); |
|
840 |
_f->do_oop(addr); |
|
841 |
} |
|
842 |
||
843 |
public: |
|
844 |
EntryFrameOopFinder(frame* frame, symbolHandle signature, bool is_static) : SignatureInfo(signature) { |
|
845 |
_f = NULL; // will be set later |
|
846 |
_fr = frame; |
|
847 |
_is_static = is_static; |
|
848 |
_offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0 |
|
849 |
} |
|
850 |
||
851 |
void arguments_do(OopClosure* f) { |
|
852 |
_f = f; |
|
853 |
if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver |
|
854 |
iterate_parameters(); |
|
855 |
} |
|
856 |
||
857 |
}; |
|
858 |
||
859 |
oop* frame::interpreter_callee_receiver_addr(symbolHandle signature) { |
|
860 |
ArgumentSizeComputer asc(signature); |
|
861 |
int size = asc.size(); |
|
862 |
return (oop *)interpreter_frame_tos_at(size); |
|
863 |
} |
|
864 |
||
865 |
||
866 |
void frame::oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) { |
|
867 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
868 |
assert(map != NULL, "map must be set"); |
|
869 |
Thread *thread = Thread::current(); |
|
870 |
methodHandle m (thread, interpreter_frame_method()); |
|
871 |
jint bci = interpreter_frame_bci(); |
|
872 |
||
873 |
assert(Universe::heap()->is_in(m()), "must be valid oop"); |
|
874 |
assert(m->is_method(), "checking frame value"); |
|
875 |
assert((m->is_native() && bci == 0) || (!m->is_native() && bci >= 0 && bci < m->code_size()), "invalid bci value"); |
|
876 |
||
877 |
// Handle the monitor elements in the activation |
|
878 |
for ( |
|
879 |
BasicObjectLock* current = interpreter_frame_monitor_end(); |
|
880 |
current < interpreter_frame_monitor_begin(); |
|
881 |
current = next_monitor_in_interpreter_frame(current) |
|
882 |
) { |
|
883 |
#ifdef ASSERT |
|
884 |
interpreter_frame_verify_monitor(current); |
|
885 |
#endif |
|
886 |
current->oops_do(f); |
|
887 |
} |
|
888 |
||
889 |
// process fixed part |
|
890 |
f->do_oop((oop*)interpreter_frame_method_addr()); |
|
891 |
f->do_oop((oop*)interpreter_frame_cache_addr()); |
|
892 |
||
893 |
// Hmm what about the mdp? |
|
894 |
#ifdef CC_INTERP |
|
895 |
// Interpreter frame in the midst of a call have a methodOop within the |
|
896 |
// object. |
|
897 |
interpreterState istate = get_interpreterState(); |
|
898 |
if (istate->msg() == BytecodeInterpreter::call_method) { |
|
899 |
f->do_oop((oop*)&istate->_result._to_call._callee); |
|
900 |
} |
|
901 |
||
902 |
#endif /* CC_INTERP */ |
|
903 |
||
904 |
if (m->is_native()) { |
|
905 |
#ifdef CC_INTERP |
|
906 |
f->do_oop((oop*)&istate->_oop_temp); |
|
907 |
#else |
|
908 |
f->do_oop((oop*)( fp() + interpreter_frame_oop_temp_offset )); |
|
909 |
#endif /* CC_INTERP */ |
|
910 |
} |
|
911 |
||
912 |
int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); |
|
913 |
||
914 |
symbolHandle signature; |
|
915 |
bool is_static = false; |
|
916 |
||
917 |
// Process a callee's arguments if we are at a call site |
|
918 |
// (i.e., if we are at an invoke bytecode) |
|
919 |
// This is used sometimes for calling into the VM, not for another |
|
920 |
// interpreted or compiled frame. |
|
921 |
if (!m->is_native()) { |
|
922 |
Bytecode_invoke *call = Bytecode_invoke_at_check(m, bci); |
|
923 |
if (call != NULL) { |
|
924 |
signature = symbolHandle(thread, call->signature()); |
|
925 |
is_static = call->is_invokestatic(); |
|
926 |
if (map->include_argument_oops() && |
|
927 |
interpreter_frame_expression_stack_size() > 0) { |
|
928 |
ResourceMark rm(thread); // is this right ??? |
|
929 |
// we are at a call site & the expression stack is not empty |
|
930 |
// => process callee's arguments |
|
931 |
// |
|
932 |
// Note: The expression stack can be empty if an exception |
|
933 |
// occured during method resolution/execution. In all |
|
934 |
// cases we empty the expression stack completely be- |
|
935 |
// fore handling the exception (the exception handling |
|
936 |
// code in the interpreter calls a blocking runtime |
|
937 |
// routine which can cause this code to be executed). |
|
938 |
// (was bug gri 7/27/98) |
|
939 |
oops_interpreted_arguments_do(signature, is_static, f); |
|
940 |
} |
|
941 |
} |
|
942 |
} |
|
943 |
||
944 |
if (TaggedStackInterpreter) { |
|
945 |
// process locals & expression stack |
|
946 |
InterpreterOopMap *mask = NULL; |
|
947 |
#ifdef ASSERT |
|
948 |
InterpreterOopMap oopmap_mask; |
|
949 |
OopMapCache::compute_one_oop_map(m, bci, &oopmap_mask); |
|
950 |
mask = &oopmap_mask; |
|
951 |
#endif // ASSERT |
|
952 |
oops_interpreted_locals_do(f, max_locals, mask); |
|
953 |
oops_interpreted_expressions_do(f, signature, is_static, |
|
954 |
m->max_stack(), |
|
955 |
max_locals, mask); |
|
956 |
} else { |
|
957 |
InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f); |
|
958 |
||
959 |
// process locals & expression stack |
|
960 |
InterpreterOopMap mask; |
|
961 |
if (query_oop_map_cache) { |
|
962 |
m->mask_for(bci, &mask); |
|
963 |
} else { |
|
964 |
OopMapCache::compute_one_oop_map(m, bci, &mask); |
|
965 |
} |
|
966 |
mask.iterate_oop(&blk); |
|
967 |
} |
|
968 |
} |
|
969 |
||
970 |
||
971 |
void frame::oops_interpreted_locals_do(OopClosure *f, |
|
972 |
int max_locals, |
|
973 |
InterpreterOopMap *mask) { |
|
974 |
// Process locals then interpreter expression stack |
|
975 |
for (int i = 0; i < max_locals; i++ ) { |
|
976 |
Tag tag = interpreter_frame_local_tag(i); |
|
977 |
if (tag == TagReference) { |
|
978 |
oop* addr = (oop*) interpreter_frame_local_at(i); |
|
979 |
assert((intptr_t*)addr >= sp(), "must be inside the frame"); |
|
980 |
f->do_oop(addr); |
|
981 |
#ifdef ASSERT |
|
982 |
} else { |
|
983 |
assert(tag == TagValue, "bad tag value for locals"); |
|
984 |
oop* p = (oop*) interpreter_frame_local_at(i); |
|
985 |
// Not always true - too bad. May have dead oops without tags in locals. |
|
986 |
// assert(*p == NULL || !(*p)->is_oop(), "oop not tagged on interpreter locals"); |
|
987 |
assert(*p == NULL || !mask->is_oop(i), "local oop map mismatch"); |
|
988 |
#endif // ASSERT |
|
989 |
} |
|
990 |
} |
|
991 |
} |
|
992 |
||
993 |
void frame::oops_interpreted_expressions_do(OopClosure *f, |
|
994 |
symbolHandle signature, |
|
995 |
bool is_static, |
|
996 |
int max_stack, |
|
997 |
int max_locals, |
|
998 |
InterpreterOopMap *mask) { |
|
999 |
// There is no stack no matter what the esp is pointing to (native methods |
|
1000 |
// might look like expression stack is nonempty). |
|
1001 |
if (max_stack == 0) return; |
|
1002 |
||
1003 |
// Point the top of the expression stack above arguments to a call so |
|
1004 |
// arguments aren't gc'ed as both stack values for callee and callee |
|
1005 |
// arguments in callee's locals. |
|
1006 |
int args_size = 0; |
|
1007 |
if (!signature.is_null()) { |
|
1008 |
args_size = ArgumentSizeComputer(signature).size() + (is_static ? 0 : 1); |
|
1009 |
} |
|
1010 |
||
1011 |
intptr_t *tos_addr = interpreter_frame_tos_at(args_size); |
|
1012 |
assert(args_size != 0 || tos_addr == interpreter_frame_tos_address(), "these are same"); |
|
1013 |
intptr_t *frst_expr = interpreter_frame_expression_stack_at(0); |
|
1014 |
// In case of exceptions, the expression stack is invalid and the esp |
|
1015 |
// will be reset to express this condition. Therefore, we call f only |
|
1016 |
// if addr is 'inside' the stack (i.e., addr >= esp for Intel). |
|
1017 |
bool in_stack; |
|
1018 |
if (interpreter_frame_expression_stack_direction() > 0) { |
|
1019 |
in_stack = (intptr_t*)frst_expr <= tos_addr; |
|
1020 |
} else { |
|
1021 |
in_stack = (intptr_t*)frst_expr >= tos_addr; |
|
1022 |
} |
|
1023 |
if (!in_stack) return; |
|
1024 |
||
1025 |
jint stack_size = interpreter_frame_expression_stack_size() - args_size; |
|
1026 |
for (int j = 0; j < stack_size; j++) { |
|
1027 |
Tag tag = interpreter_frame_expression_stack_tag(j); |
|
1028 |
if (tag == TagReference) { |
|
1029 |
oop *addr = (oop*) interpreter_frame_expression_stack_at(j); |
|
1030 |
f->do_oop(addr); |
|
1031 |
#ifdef ASSERT |
|
1032 |
} else { |
|
1033 |
assert(tag == TagValue, "bad tag value for stack element"); |
|
1034 |
oop *p = (oop*) interpreter_frame_expression_stack_at((j)); |
|
1035 |
assert(*p == NULL || !mask->is_oop(j+max_locals), "stack oop map mismatch"); |
|
1036 |
#endif // ASSERT |
|
1037 |
} |
|
1038 |
} |
|
1039 |
} |
|
1040 |
||
1041 |
void frame::oops_interpreted_arguments_do(symbolHandle signature, bool is_static, OopClosure* f) { |
|
1042 |
InterpretedArgumentOopFinder finder(signature, is_static, this, f); |
|
1043 |
finder.oops_do(); |
|
1044 |
} |
|
1045 |
||
1046 |
void frame::oops_code_blob_do(OopClosure* f, const RegisterMap* reg_map) { |
|
1047 |
assert(_cb != NULL, "sanity check"); |
|
1048 |
if (_cb->oop_maps() != NULL) { |
|
1049 |
OopMapSet::oops_do(this, reg_map, f); |
|
1050 |
||
1051 |
// Preserve potential arguments for a callee. We handle this by dispatching |
|
1052 |
// on the codeblob. For c2i, we do |
|
1053 |
if (reg_map->include_argument_oops()) { |
|
1054 |
_cb->preserve_callee_argument_oops(*this, reg_map, f); |
|
1055 |
} |
|
1056 |
} |
|
1057 |
// In cases where perm gen is collected, GC will want to mark |
|
1058 |
// oops referenced from nmethods active on thread stacks so as to |
|
1059 |
// prevent them from being collected. However, this visit should be |
|
1060 |
// restricted to certain phases of the collection only. The |
|
1061 |
// closure answers whether it wants nmethods to be traced. |
|
1062 |
// (All CodeBlob subtypes other than NMethod currently have |
|
1063 |
// an empty oops_do() method. |
|
1064 |
if (f->do_nmethods()) { |
|
1065 |
_cb->oops_do(f); |
|
1066 |
} |
|
1067 |
} |
|
1068 |
||
1069 |
void frame::nmethods_code_blob_do() { |
|
1070 |
assert(_cb != NULL, "sanity check"); |
|
1071 |
||
1072 |
// If we see an activation belonging to a non_entrant nmethod, we mark it. |
|
1073 |
if (_cb->is_nmethod() && ((nmethod *)_cb)->is_not_entrant()) { |
|
1074 |
((nmethod*)_cb)->mark_as_seen_on_stack(); |
|
1075 |
} |
|
1076 |
} |
|
1077 |
||
1078 |
class CompiledArgumentOopFinder: public SignatureInfo { |
|
1079 |
protected: |
|
1080 |
OopClosure* _f; |
|
1081 |
int _offset; // the current offset, incremented with each argument |
|
1082 |
bool _is_static; // true if the callee is a static method |
|
1083 |
frame _fr; |
|
1084 |
RegisterMap* _reg_map; |
|
1085 |
int _arg_size; |
|
1086 |
VMRegPair* _regs; // VMReg list of arguments |
|
1087 |
||
1088 |
void set(int size, BasicType type) { |
|
1089 |
if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset(); |
|
1090 |
_offset += size; |
|
1091 |
} |
|
1092 |
||
1093 |
virtual void handle_oop_offset() { |
|
1094 |
// Extract low order register number from register array. |
|
1095 |
// In LP64-land, the high-order bits are valid but unhelpful. |
|
1096 |
VMReg reg = _regs[_offset].first(); |
|
1097 |
oop *loc = _fr.oopmapreg_to_location(reg, _reg_map); |
|
1098 |
_f->do_oop(loc); |
|
1099 |
} |
|
1100 |
||
1101 |
public: |
|
1102 |
CompiledArgumentOopFinder(symbolHandle signature, bool is_static, OopClosure* f, frame fr, const RegisterMap* reg_map) |
|
1103 |
: SignatureInfo(signature) { |
|
1104 |
||
1105 |
// initialize CompiledArgumentOopFinder |
|
1106 |
_f = f; |
|
1107 |
_offset = 0; |
|
1108 |
_is_static = is_static; |
|
1109 |
_fr = fr; |
|
1110 |
_reg_map = (RegisterMap*)reg_map; |
|
1111 |
_arg_size = ArgumentSizeComputer(signature).size() + (is_static ? 0 : 1); |
|
1112 |
||
1113 |
int arg_size; |
|
1114 |
_regs = SharedRuntime::find_callee_arguments(signature(), is_static, &arg_size); |
|
1115 |
assert(arg_size == _arg_size, "wrong arg size"); |
|
1116 |
} |
|
1117 |
||
1118 |
void oops_do() { |
|
1119 |
if (!_is_static) { |
|
1120 |
handle_oop_offset(); |
|
1121 |
_offset++; |
|
1122 |
} |
|
1123 |
iterate_parameters(); |
|
1124 |
} |
|
1125 |
}; |
|
1126 |
||
1127 |
void frame::oops_compiled_arguments_do(symbolHandle signature, bool is_static, const RegisterMap* reg_map, OopClosure* f) { |
|
1128 |
ResourceMark rm; |
|
1129 |
CompiledArgumentOopFinder finder(signature, is_static, f, *this, reg_map); |
|
1130 |
finder.oops_do(); |
|
1131 |
} |
|
1132 |
||
1133 |
||
1134 |
// Get receiver out of callers frame, i.e. find parameter 0 in callers |
|
1135 |
// frame. Consult ADLC for where parameter 0 is to be found. Then |
|
1136 |
// check local reg_map for it being a callee-save register or argument |
|
1137 |
// register, both of which are saved in the local frame. If not found |
|
1138 |
// there, it must be an in-stack argument of the caller. |
|
1139 |
// Note: caller.sp() points to callee-arguments |
|
1140 |
oop frame::retrieve_receiver(RegisterMap* reg_map) { |
|
1141 |
frame caller = *this; |
|
1142 |
||
1143 |
// First consult the ADLC on where it puts parameter 0 for this signature. |
|
1144 |
VMReg reg = SharedRuntime::name_for_receiver(); |
|
1145 |
oop r = *caller.oopmapreg_to_location(reg, reg_map); |
|
1146 |
assert( Universe::heap()->is_in_or_null(r), "bad receiver" ); |
|
1147 |
return r; |
|
1148 |
} |
|
1149 |
||
1150 |
||
1151 |
oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const { |
|
1152 |
if(reg->is_reg()) { |
|
1153 |
// If it is passed in a register, it got spilled in the stub frame. |
|
1154 |
return (oop *)reg_map->location(reg); |
|
1155 |
} else { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1156 |
int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1157 |
return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes); |
1 | 1158 |
} |
1159 |
} |
|
1160 |
||
1161 |
BasicLock* frame::compiled_synchronized_native_monitor(nmethod* nm) { |
|
1162 |
if (nm == NULL) { |
|
1163 |
assert(_cb != NULL && _cb->is_nmethod() && |
|
1164 |
nm->method()->is_native() && |
|
1165 |
nm->method()->is_synchronized(), |
|
1166 |
"should not call this otherwise"); |
|
1167 |
nm = (nmethod*) _cb; |
|
1168 |
} |
|
1169 |
int byte_offset = in_bytes(nm->compiled_synchronized_native_basic_lock_sp_offset()); |
|
1170 |
assert(byte_offset >= 0, "should not see invalid offset"); |
|
1171 |
return (BasicLock*) &sp()[byte_offset / wordSize]; |
|
1172 |
} |
|
1173 |
||
1174 |
oop frame::compiled_synchronized_native_monitor_owner(nmethod* nm) { |
|
1175 |
if (nm == NULL) { |
|
1176 |
assert(_cb != NULL && _cb->is_nmethod() && |
|
1177 |
nm->method()->is_native() && |
|
1178 |
nm->method()->is_synchronized(), |
|
1179 |
"should not call this otherwise"); |
|
1180 |
nm = (nmethod*) _cb; |
|
1181 |
} |
|
1182 |
int byte_offset = in_bytes(nm->compiled_synchronized_native_basic_lock_owner_sp_offset()); |
|
1183 |
assert(byte_offset >= 0, "should not see invalid offset"); |
|
1184 |
oop owner = ((oop*) sp())[byte_offset / wordSize]; |
|
1185 |
assert( Universe::heap()->is_in(owner), "bad receiver" ); |
|
1186 |
return owner; |
|
1187 |
} |
|
1188 |
||
1189 |
void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) { |
|
1190 |
assert(map != NULL, "map must be set"); |
|
1191 |
if (map->include_argument_oops()) { |
|
1192 |
// must collect argument oops, as nobody else is doing it |
|
1193 |
Thread *thread = Thread::current(); |
|
1194 |
methodHandle m (thread, entry_frame_call_wrapper()->callee_method()); |
|
1195 |
symbolHandle signature (thread, m->signature()); |
|
1196 |
EntryFrameOopFinder finder(this, signature, m->is_static()); |
|
1197 |
finder.arguments_do(f); |
|
1198 |
} |
|
1199 |
// Traverse the Handle Block saved in the entry frame |
|
1200 |
entry_frame_call_wrapper()->oops_do(f); |
|
1201 |
} |
|
1202 |
||
1203 |
||
1204 |
void frame::oops_do_internal(OopClosure* f, RegisterMap* map, bool use_interpreter_oop_map_cache) { |
|
1205 |
if (is_interpreted_frame()) { oops_interpreted_do(f, map, use_interpreter_oop_map_cache); |
|
1206 |
} else if (is_entry_frame()) { oops_entry_do (f, map); |
|
1207 |
} else if (CodeCache::contains(pc())) { oops_code_blob_do (f, map); |
|
1208 |
} else { |
|
1209 |
ShouldNotReachHere(); |
|
1210 |
} |
|
1211 |
} |
|
1212 |
||
1213 |
void frame::nmethods_do() { |
|
1214 |
if (_cb != NULL && _cb->is_nmethod()) { |
|
1215 |
nmethods_code_blob_do(); |
|
1216 |
} |
|
1217 |
} |
|
1218 |
||
1219 |
||
1220 |
void frame::gc_prologue() { |
|
1221 |
if (is_interpreted_frame()) { |
|
1222 |
// set bcx to bci to become methodOop position independent during GC |
|
1223 |
interpreter_frame_set_bcx(interpreter_frame_bci()); |
|
1224 |
} |
|
1225 |
} |
|
1226 |
||
1227 |
||
1228 |
void frame::gc_epilogue() { |
|
1229 |
if (is_interpreted_frame()) { |
|
1230 |
// set bcx back to bcp for interpreter |
|
1231 |
interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp()); |
|
1232 |
} |
|
1233 |
// call processor specific epilog function |
|
1234 |
pd_gc_epilog(); |
|
1235 |
} |
|
1236 |
||
1237 |
||
1238 |
# ifdef ENABLE_ZAP_DEAD_LOCALS |
|
1239 |
||
1240 |
void frame::CheckValueClosure::do_oop(oop* p) { |
|
1241 |
if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) { |
|
1242 |
warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); |
|
1243 |
} |
|
1244 |
} |
|
1245 |
frame::CheckValueClosure frame::_check_value; |
|
1246 |
||
1247 |
||
1248 |
void frame::CheckOopClosure::do_oop(oop* p) { |
|
1249 |
if (*p != NULL && !(*p)->is_oop()) { |
|
1250 |
warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); |
|
1251 |
} |
|
1252 |
} |
|
1253 |
frame::CheckOopClosure frame::_check_oop; |
|
1254 |
||
1255 |
void frame::check_derived_oop(oop* base, oop* derived) { |
|
1256 |
_check_oop.do_oop(base); |
|
1257 |
} |
|
1258 |
||
1259 |
||
1260 |
void frame::ZapDeadClosure::do_oop(oop* p) { |
|
1261 |
if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p); |
|
1262 |
// Need cast because on _LP64 the conversion to oop is ambiguous. Constant |
|
1263 |
// can be either long or int. |
|
1264 |
*p = (oop)(int)0xbabebabe; |
|
1265 |
} |
|
1266 |
frame::ZapDeadClosure frame::_zap_dead; |
|
1267 |
||
1268 |
void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) { |
|
1269 |
assert(thread == Thread::current(), "need to synchronize to do this to another thread"); |
|
1270 |
// Tracing - part 1 |
|
1271 |
if (TraceZapDeadLocals) { |
|
1272 |
ResourceMark rm(thread); |
|
1273 |
tty->print_cr("--------------------------------------------------------------------------------"); |
|
1274 |
tty->print("Zapping dead locals in "); |
|
1275 |
print_on(tty); |
|
1276 |
tty->cr(); |
|
1277 |
} |
|
1278 |
// Zapping |
|
1279 |
if (is_entry_frame ()) zap_dead_entry_locals (thread, map); |
|
1280 |
else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map); |
|
1281 |
else if (is_compiled_frame()) zap_dead_compiled_locals (thread, map); |
|
1282 |
||
1283 |
else |
|
1284 |
// could be is_runtime_frame |
|
1285 |
// so remove error: ShouldNotReachHere(); |
|
1286 |
; |
|
1287 |
// Tracing - part 2 |
|
1288 |
if (TraceZapDeadLocals) { |
|
1289 |
tty->cr(); |
|
1290 |
} |
|
1291 |
} |
|
1292 |
||
1293 |
||
1294 |
void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) { |
|
1295 |
// get current interpreter 'pc' |
|
1296 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
1297 |
methodOop m = interpreter_frame_method(); |
|
1298 |
int bci = interpreter_frame_bci(); |
|
1299 |
||
1300 |
int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); |
|
1301 |
||
1302 |
if (TaggedStackInterpreter) { |
|
1303 |
InterpreterOopMap *mask = NULL; |
|
1304 |
#ifdef ASSERT |
|
1305 |
InterpreterOopMap oopmap_mask; |
|
1306 |
methodHandle method(thread, m); |
|
1307 |
OopMapCache::compute_one_oop_map(method, bci, &oopmap_mask); |
|
1308 |
mask = &oopmap_mask; |
|
1309 |
#endif // ASSERT |
|
1310 |
oops_interpreted_locals_do(&_check_oop, max_locals, mask); |
|
1311 |
} else { |
|
1312 |
// process dynamic part |
|
1313 |
InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(), |
|
1314 |
&_check_value); |
|
1315 |
InterpreterFrameClosure oop_blk(this, max_locals, m->max_stack(), |
|
1316 |
&_check_oop ); |
|
1317 |
InterpreterFrameClosure dead_blk(this, max_locals, m->max_stack(), |
|
1318 |
&_zap_dead ); |
|
1319 |
||
1320 |
// get frame map |
|
1321 |
InterpreterOopMap mask; |
|
1322 |
m->mask_for(bci, &mask); |
|
1323 |
mask.iterate_all( &oop_blk, &value_blk, &dead_blk); |
|
1324 |
} |
|
1325 |
} |
|
1326 |
||
1327 |
||
1328 |
void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) { |
|
1329 |
||
1330 |
ResourceMark rm(thread); |
|
1331 |
assert(_cb != NULL, "sanity check"); |
|
1332 |
if (_cb->oop_maps() != NULL) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1333 |
OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value); |
1 | 1334 |
} |
1335 |
} |
|
1336 |
||
1337 |
||
1338 |
void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) { |
|
1339 |
if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented"); |
|
1340 |
} |
|
1341 |
||
1342 |
||
1343 |
void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) { |
|
1344 |
if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented"); |
|
1345 |
} |
|
1346 |
||
1347 |
# endif // ENABLE_ZAP_DEAD_LOCALS |
|
1348 |
||
1349 |
void frame::verify(const RegisterMap* map) { |
|
1350 |
// for now make sure receiver type is correct |
|
1351 |
if (is_interpreted_frame()) { |
|
1352 |
methodOop method = interpreter_frame_method(); |
|
1353 |
guarantee(method->is_method(), "method is wrong in frame::verify"); |
|
1354 |
if (!method->is_static()) { |
|
1355 |
// fetch the receiver |
|
1356 |
oop* p = (oop*) interpreter_frame_local_at(0); |
|
1357 |
// make sure we have the right receiver type |
|
1358 |
} |
|
1359 |
} |
|
1360 |
COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");) |
|
1361 |
oops_do_internal(&VerifyOopClosure::verify_oop, (RegisterMap*)map, false); |
|
1362 |
} |
|
1363 |
||
1364 |
||
1365 |
#ifdef ASSERT |
|
1366 |
bool frame::verify_return_pc(address x) { |
|
1367 |
if (StubRoutines::returns_to_call_stub(x)) { |
|
1368 |
return true; |
|
1369 |
} |
|
1370 |
if (CodeCache::contains(x)) { |
|
1371 |
return true; |
|
1372 |
} |
|
1373 |
if (Interpreter::contains(x)) { |
|
1374 |
return true; |
|
1375 |
} |
|
1376 |
return false; |
|
1377 |
} |
|
1378 |
#endif |
|
1379 |
||
1380 |
||
1381 |
#ifdef ASSERT |
|
1382 |
void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const { |
|
1383 |
assert(is_interpreted_frame(), "Not an interpreted frame"); |
|
1384 |
// verify that the value is in the right part of the frame |
|
1385 |
address low_mark = (address) interpreter_frame_monitor_end(); |
|
1386 |
address high_mark = (address) interpreter_frame_monitor_begin(); |
|
1387 |
address current = (address) value; |
|
1388 |
||
1389 |
const int monitor_size = frame::interpreter_frame_monitor_size(); |
|
1390 |
guarantee((high_mark - current) % monitor_size == 0 , "Misaligned top of BasicObjectLock*"); |
|
1391 |
guarantee( high_mark > current , "Current BasicObjectLock* higher than high_mark"); |
|
1392 |
||
1393 |
guarantee((current - low_mark) % monitor_size == 0 , "Misaligned bottom of BasicObjectLock*"); |
|
1394 |
guarantee( current >= low_mark , "Current BasicObjectLock* below than low_mark"); |
|
1395 |
} |
|
1396 |
#endif |
|
1397 |
||
1398 |
||
1399 |
//----------------------------------------------------------------------------------- |
|
1400 |
// StackFrameStream implementation |
|
1401 |
||
1402 |
StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) { |
|
1403 |
assert(thread->has_last_Java_frame(), "sanity check"); |
|
1404 |
_fr = thread->last_frame(); |
|
1405 |
_is_done = false; |
|
1406 |
} |