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