296 } 297 } 298 299 bool frame::is_interpreted_frame() const { 300 return Interpreter::contains(pc()); 301 } 302 303 int frame::frame_size(RegisterMap* map) const { 304 frame sender = this->sender(map); 305 return sender.sp() - sp(); 306 } 307 308 intptr_t* frame::entry_frame_argument_at(int offset) const { 309 // convert offset to index to deal with tsi 310 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); 311 // Entry frame's arguments are always in relation to unextended_sp() 312 return &unextended_sp()[index]; 313 } 314 315 // sender_sp 316 #ifdef CC_INTERP 317 intptr_t* frame::interpreter_frame_sender_sp() const { 318 assert(is_interpreted_frame(), "interpreted frame expected"); 319 // QQQ why does this specialize method exist if frame::sender_sp() does same thing? 320 // seems odd and if we always know interpreted vs. non then sender_sp() is really 321 // doing too much work. 322 return get_interpreterState()->sender_sp(); 323 } 324 325 // monitor elements 326 327 BasicObjectLock* frame::interpreter_frame_monitor_begin() const { 328 return get_interpreterState()->monitor_base(); 329 } 330 331 BasicObjectLock* frame::interpreter_frame_monitor_end() const { 332 return (BasicObjectLock*) get_interpreterState()->stack_base(); 333 } 334 335 #else // CC_INTERP 336 337 intptr_t* frame::interpreter_frame_sender_sp() const { 338 assert(is_interpreted_frame(), "interpreted frame expected"); 339 return (intptr_t*) at(interpreter_frame_sender_sp_offset); 340 } 341 342 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) { 343 assert(is_interpreted_frame(), "interpreted frame expected"); 344 ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp); 345 } 346 347 348 // monitor elements 349 350 BasicObjectLock* frame::interpreter_frame_monitor_begin() const { 351 return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset); 352 } 353 354 BasicObjectLock* frame::interpreter_frame_monitor_end() const { 355 BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset); 356 // make sure the pointer points inside the frame 357 assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer"); 358 assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer"); 359 return result; 360 } 361 362 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) { 363 *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value; 364 } 365 366 // Used by template based interpreter deoptimization 367 void frame::interpreter_frame_set_last_sp(intptr_t* sp) { 368 *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp; 369 } 370 #endif // CC_INTERP 371 372 frame frame::sender_for_entry_frame(RegisterMap* map) const { 373 assert(map != NULL, "map must be set"); 374 // Java frame called from C; skip all C frames and return top C 375 // frame of that chunk as the sender 376 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); 377 assert(!entry_frame_is_first(), "next Java fp must be non zero"); 378 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); 379 map->clear(); 380 assert(map->include_argument_oops(), "should be set by clear"); 381 if (jfa->last_Java_pc() != NULL ) { 382 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); 383 return fr; 384 } 385 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp()); 386 return fr; 387 } 388 389 //------------------------------------------------------------------------------ 390 // frame::verify_deopt_original_pc 506 //------------------------------------------------------------------------------ 507 // frame::sender 508 frame frame::sender(RegisterMap* map) const { 509 // Default is we done have to follow them. The sender_for_xxx will 510 // update it accordingly 511 map->set_include_argument_oops(false); 512 513 if (is_entry_frame()) return sender_for_entry_frame(map); 514 if (is_interpreted_frame()) return sender_for_interpreter_frame(map); 515 assert(_cb == CodeCache::find_blob(pc()),"Must be the same"); 516 517 if (_cb != NULL) { 518 return sender_for_compiled_frame(map); 519 } 520 // Must be native-compiled frame, i.e. the marshaling code for native 521 // methods that exists in the core system. 522 return frame(sender_sp(), link(), sender_pc()); 523 } 524 525 bool frame::is_interpreted_frame_valid(JavaThread* thread) const { 526 // QQQ 527 #ifdef CC_INTERP 528 #else 529 assert(is_interpreted_frame(), "Not an interpreted frame"); 530 // These are reasonable sanity checks 531 if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) { 532 return false; 533 } 534 if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) { 535 return false; 536 } 537 if (fp() + interpreter_frame_initial_sp_offset < sp()) { 538 return false; 539 } 540 // These are hacks to keep us out of trouble. 541 // The problem with these is that they mask other problems 542 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above 543 return false; 544 } 545 546 // do some validation of frame elements 547 548 // first the method 549 550 Method* m = *interpreter_frame_method_addr(); 551 552 // validate the method we'd find in this potential sender 553 if (!m->is_valid_method()) return false; 554 555 // stack frames shouldn't be much larger than max_stack elements 556 // this test requires the use the unextended_sp which is the sp as seen by 557 // the current frame, and not sp which is the "raw" pc which could point 558 // further because of local variables of the callee method inserted after 559 // method arguments 560 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { 561 return false; 562 } 563 564 // validate bci/bcp 565 566 address bcp = interpreter_frame_bcp(); 567 if (m->validate_bci_from_bcp(bcp) < 0) { 568 return false; 569 } 570 571 // validate ConstantPoolCache* 572 ConstantPoolCache* cp = *interpreter_frame_cache_addr(); 573 if (cp == NULL || !cp->is_metaspace_object()) return false; 574 575 // validate locals 576 577 address locals = (address) *interpreter_frame_locals_addr(); 578 579 if (locals > thread->stack_base() || locals < (address) fp()) return false; 580 581 // We'd have to be pretty unlucky to be mislead at this point 582 583 #endif // CC_INTERP 584 return true; 585 } 586 587 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) { 588 #ifdef CC_INTERP 589 // Needed for JVMTI. The result should always be in the 590 // interpreterState object 591 interpreterState istate = get_interpreterState(); 592 #endif // CC_INTERP 593 assert(is_interpreted_frame(), "interpreted frame expected"); 594 Method* method = interpreter_frame_method(); 595 BasicType type = method->result_type(); 596 597 intptr_t* tos_addr; 598 if (method->is_native()) { 599 // Prior to calling into the runtime to report the method_exit the possible 600 // return value is pushed to the native stack. If the result is a jfloat/jdouble 601 // then ST0 is saved before EAX/EDX. See the note in generate_native_result 602 tos_addr = (intptr_t*)sp(); 603 if (type == T_FLOAT || type == T_DOUBLE) { 604 // QQQ seems like this code is equivalent on the two platforms 605 #ifdef AMD64 606 // This is times two because we do a push(ltos) after pushing XMM0 607 // and that takes two interpreter stack slots. 608 tos_addr += 2 * Interpreter::stackElementWords; 609 #else 610 tos_addr += 2; 611 #endif // AMD64 612 } 613 } else { 614 tos_addr = (intptr_t*)interpreter_frame_tos_address(); 615 } 616 617 switch (type) { 618 case T_OBJECT : 619 case T_ARRAY : { 620 oop obj; 621 if (method->is_native()) { 622 #ifdef CC_INTERP 623 obj = istate->_oop_temp; 624 #else 625 obj = cast_to_oop(at(interpreter_frame_oop_temp_offset)); 626 #endif // CC_INTERP 627 } else { 628 oop* obj_p = (oop*)tos_addr; 629 obj = (obj_p == NULL) ? (oop)NULL : *obj_p; 630 } 631 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check"); 632 *oop_result = obj; 633 break; 634 } 635 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break; 636 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break; 637 case T_CHAR : value_result->c = *(jchar*)tos_addr; break; 638 case T_SHORT : value_result->s = *(jshort*)tos_addr; break; 639 case T_INT : value_result->i = *(jint*)tos_addr; break; 640 case T_LONG : value_result->j = *(jlong*)tos_addr; break; 641 case T_FLOAT : { 642 #ifdef AMD64 643 value_result->f = *(jfloat*)tos_addr; 644 #else 645 if (method->is_native()) { 646 jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat 655 case T_VOID : /* Nothing to do */ break; 656 default : ShouldNotReachHere(); 657 } 658 659 return type; 660 } 661 662 663 intptr_t* frame::interpreter_frame_tos_at(jint offset) const { 664 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); 665 return &interpreter_frame_tos_address()[index]; 666 } 667 668 #ifndef PRODUCT 669 670 #define DESCRIBE_FP_OFFSET(name) \ 671 values.describe(frame_no, fp() + frame::name##_offset, #name) 672 673 void frame::describe_pd(FrameValues& values, int frame_no) { 674 if (is_interpreted_frame()) { 675 #ifndef CC_INTERP 676 DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp); 677 DESCRIBE_FP_OFFSET(interpreter_frame_last_sp); 678 DESCRIBE_FP_OFFSET(interpreter_frame_method); 679 DESCRIBE_FP_OFFSET(interpreter_frame_mdp); 680 DESCRIBE_FP_OFFSET(interpreter_frame_cache); 681 DESCRIBE_FP_OFFSET(interpreter_frame_locals); 682 DESCRIBE_FP_OFFSET(interpreter_frame_bcp); 683 DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp); 684 #ifdef AMD64 685 } else if (is_entry_frame()) { 686 // This could be more descriptive if we use the enum in 687 // stubGenerator to map to real names but it's most important to 688 // claim these frame slots so the error checking works. 689 for (int i = 0; i < entry_frame_after_call_words; i++) { 690 values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i)); 691 } 692 #endif // AMD64 693 } 694 #endif 695 } 696 #endif // !PRODUCT 697 698 intptr_t *frame::initial_deoptimization_info() { 699 // used to reset the saved FP 700 return fp(); 701 } 702 703 intptr_t* frame::real_fp() const { 704 if (_cb != NULL) { 705 // use the frame size if valid 706 int size = _cb->frame_size(); 707 if (size > 0) { 708 return unextended_sp() + size; 709 } 710 } 711 // else rely on fp() 712 assert(! is_compiled_frame(), "unknown compiled frame size"); 713 return fp(); 714 } | 296 } 297 } 298 299 bool frame::is_interpreted_frame() const { 300 return Interpreter::contains(pc()); 301 } 302 303 int frame::frame_size(RegisterMap* map) const { 304 frame sender = this->sender(map); 305 return sender.sp() - sp(); 306 } 307 308 intptr_t* frame::entry_frame_argument_at(int offset) const { 309 // convert offset to index to deal with tsi 310 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); 311 // Entry frame's arguments are always in relation to unextended_sp() 312 return &unextended_sp()[index]; 313 } 314 315 // sender_sp 316 317 intptr_t* frame::interpreter_frame_sender_sp() const { 318 assert(is_interpreted_frame(), "interpreted frame expected"); 319 return (intptr_t*) at(interpreter_frame_sender_sp_offset); 320 } 321 322 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) { 323 assert(is_interpreted_frame(), "interpreted frame expected"); 324 ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp); 325 } 326 327 328 // monitor elements 329 330 BasicObjectLock* frame::interpreter_frame_monitor_begin() const { 331 return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset); 332 } 333 334 BasicObjectLock* frame::interpreter_frame_monitor_end() const { 335 BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset); 336 // make sure the pointer points inside the frame 337 assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer"); 338 assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer"); 339 return result; 340 } 341 342 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) { 343 *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value; 344 } 345 346 // Used by template based interpreter deoptimization 347 void frame::interpreter_frame_set_last_sp(intptr_t* sp) { 348 *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp; 349 } 350 351 frame frame::sender_for_entry_frame(RegisterMap* map) const { 352 assert(map != NULL, "map must be set"); 353 // Java frame called from C; skip all C frames and return top C 354 // frame of that chunk as the sender 355 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); 356 assert(!entry_frame_is_first(), "next Java fp must be non zero"); 357 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); 358 map->clear(); 359 assert(map->include_argument_oops(), "should be set by clear"); 360 if (jfa->last_Java_pc() != NULL ) { 361 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); 362 return fr; 363 } 364 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp()); 365 return fr; 366 } 367 368 //------------------------------------------------------------------------------ 369 // frame::verify_deopt_original_pc 485 //------------------------------------------------------------------------------ 486 // frame::sender 487 frame frame::sender(RegisterMap* map) const { 488 // Default is we done have to follow them. The sender_for_xxx will 489 // update it accordingly 490 map->set_include_argument_oops(false); 491 492 if (is_entry_frame()) return sender_for_entry_frame(map); 493 if (is_interpreted_frame()) return sender_for_interpreter_frame(map); 494 assert(_cb == CodeCache::find_blob(pc()),"Must be the same"); 495 496 if (_cb != NULL) { 497 return sender_for_compiled_frame(map); 498 } 499 // Must be native-compiled frame, i.e. the marshaling code for native 500 // methods that exists in the core system. 501 return frame(sender_sp(), link(), sender_pc()); 502 } 503 504 bool frame::is_interpreted_frame_valid(JavaThread* thread) const { 505 assert(is_interpreted_frame(), "Not an interpreted frame"); 506 // These are reasonable sanity checks 507 if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) { 508 return false; 509 } 510 if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) { 511 return false; 512 } 513 if (fp() + interpreter_frame_initial_sp_offset < sp()) { 514 return false; 515 } 516 // These are hacks to keep us out of trouble. 517 // The problem with these is that they mask other problems 518 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above 519 return false; 520 } 521 522 // do some validation of frame elements 523 // first the method 524 525 Method* m = *interpreter_frame_method_addr(); 526 527 // validate the method we'd find in this potential sender 528 if (!m->is_valid_method()) return false; 529 530 // stack frames shouldn't be much larger than max_stack elements 531 // this test requires the use the unextended_sp which is the sp as seen by 532 // the current frame, and not sp which is the "raw" pc which could point 533 // further because of local variables of the callee method inserted after 534 // method arguments 535 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { 536 return false; 537 } 538 539 // validate bci/bcp 540 541 address bcp = interpreter_frame_bcp(); 542 if (m->validate_bci_from_bcp(bcp) < 0) { 543 return false; 544 } 545 546 // validate ConstantPoolCache* 547 ConstantPoolCache* cp = *interpreter_frame_cache_addr(); 548 if (cp == NULL || !cp->is_metaspace_object()) return false; 549 550 // validate locals 551 552 address locals = (address) *interpreter_frame_locals_addr(); 553 554 if (locals > thread->stack_base() || locals < (address) fp()) return false; 555 556 // We'd have to be pretty unlucky to be mislead at this point 557 return true; 558 } 559 560 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) { 561 assert(is_interpreted_frame(), "interpreted frame expected"); 562 Method* method = interpreter_frame_method(); 563 BasicType type = method->result_type(); 564 565 intptr_t* tos_addr; 566 if (method->is_native()) { 567 // Prior to calling into the runtime to report the method_exit the possible 568 // return value is pushed to the native stack. If the result is a jfloat/jdouble 569 // then ST0 is saved before EAX/EDX. See the note in generate_native_result 570 tos_addr = (intptr_t*)sp(); 571 if (type == T_FLOAT || type == T_DOUBLE) { 572 // QQQ seems like this code is equivalent on the two platforms 573 #ifdef AMD64 574 // This is times two because we do a push(ltos) after pushing XMM0 575 // and that takes two interpreter stack slots. 576 tos_addr += 2 * Interpreter::stackElementWords; 577 #else 578 tos_addr += 2; 579 #endif // AMD64 580 } 581 } else { 582 tos_addr = (intptr_t*)interpreter_frame_tos_address(); 583 } 584 585 switch (type) { 586 case T_OBJECT : 587 case T_ARRAY : { 588 oop obj; 589 if (method->is_native()) { 590 obj = cast_to_oop(at(interpreter_frame_oop_temp_offset)); 591 } else { 592 oop* obj_p = (oop*)tos_addr; 593 obj = (obj_p == NULL) ? (oop)NULL : *obj_p; 594 } 595 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check"); 596 *oop_result = obj; 597 break; 598 } 599 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break; 600 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break; 601 case T_CHAR : value_result->c = *(jchar*)tos_addr; break; 602 case T_SHORT : value_result->s = *(jshort*)tos_addr; break; 603 case T_INT : value_result->i = *(jint*)tos_addr; break; 604 case T_LONG : value_result->j = *(jlong*)tos_addr; break; 605 case T_FLOAT : { 606 #ifdef AMD64 607 value_result->f = *(jfloat*)tos_addr; 608 #else 609 if (method->is_native()) { 610 jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat 619 case T_VOID : /* Nothing to do */ break; 620 default : ShouldNotReachHere(); 621 } 622 623 return type; 624 } 625 626 627 intptr_t* frame::interpreter_frame_tos_at(jint offset) const { 628 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); 629 return &interpreter_frame_tos_address()[index]; 630 } 631 632 #ifndef PRODUCT 633 634 #define DESCRIBE_FP_OFFSET(name) \ 635 values.describe(frame_no, fp() + frame::name##_offset, #name) 636 637 void frame::describe_pd(FrameValues& values, int frame_no) { 638 if (is_interpreted_frame()) { 639 DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp); 640 DESCRIBE_FP_OFFSET(interpreter_frame_last_sp); 641 DESCRIBE_FP_OFFSET(interpreter_frame_method); 642 DESCRIBE_FP_OFFSET(interpreter_frame_mdp); 643 DESCRIBE_FP_OFFSET(interpreter_frame_cache); 644 DESCRIBE_FP_OFFSET(interpreter_frame_locals); 645 DESCRIBE_FP_OFFSET(interpreter_frame_bcp); 646 DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp); 647 #ifdef AMD64 648 } else if (is_entry_frame()) { 649 // This could be more descriptive if we use the enum in 650 // stubGenerator to map to real names but it's most important to 651 // claim these frame slots so the error checking works. 652 for (int i = 0; i < entry_frame_after_call_words; i++) { 653 values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i)); 654 } 655 #endif // AMD64 656 } 657 } 658 #endif // !PRODUCT 659 660 intptr_t *frame::initial_deoptimization_info() { 661 // used to reset the saved FP 662 return fp(); 663 } 664 665 intptr_t* frame::real_fp() const { 666 if (_cb != NULL) { 667 // use the frame size if valid 668 int size = _cb->frame_size(); 669 if (size > 0) { 670 return unextended_sp() + size; 671 } 672 } 673 // else rely on fp() 674 assert(! is_compiled_frame(), "unknown compiled frame size"); 675 return fp(); 676 } |