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