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