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