comparison src/share/vm/graal/graalCodeInstaller.cpp @ 3572:076a2c9caf71

Factor out runtime call target address determination to avoid redundancy between CodeInstaller::site_Call() and VMEntries.getMaxCallTargetOffset()
author Peter Hofer <peter.hofer@jku.at>
date Tue, 06 Sep 2011 11:18:53 +0200
parents 409ef3a68dc8
children af1319bc4fd5
comparison
equal deleted inserted replaced
3571:a72615456c50 3572:076a2c9caf71
565 record_scope(pc_offset, code_pos, new GrowableArray<ScopeValue*>()); 565 record_scope(pc_offset, code_pos, new GrowableArray<ScopeValue*>());
566 566
567 _debug_recorder->end_safepoint(pc_offset); 567 _debug_recorder->end_safepoint(pc_offset);
568 } 568 }
569 569
570 address CodeInstaller::runtime_call_target_address(oop runtime_call) {
571 address target_addr = 0x0;
572 if (runtime_call == CiRuntimeCall::Debug()) {
573 TRACE_graal_3("CiRuntimeCall::Debug()");
574 } else if (runtime_call == CiRuntimeCall::UnwindException()) {
575 target_addr = Runtime1::entry_for(Runtime1::graal_unwind_exception_call_id);
576 TRACE_graal_3("CiRuntimeCall::UnwindException()");
577 } else if (runtime_call == CiRuntimeCall::HandleException()) {
578 target_addr = Runtime1::entry_for(Runtime1::graal_handle_exception_id);
579 TRACE_graal_3("CiRuntimeCall::HandleException()");
580 } else if (runtime_call == CiRuntimeCall::SetDeoptInfo()) {
581 target_addr = Runtime1::entry_for(Runtime1::graal_set_deopt_info_id);
582 TRACE_graal_3("CiRuntimeCall::SetDeoptInfo()");
583 } else if (runtime_call == CiRuntimeCall::CreateNullPointerException()) {
584 target_addr = Runtime1::entry_for(Runtime1::graal_create_null_pointer_exception_id);
585 TRACE_graal_3("CiRuntimeCall::CreateNullPointerException()");
586 } else if (runtime_call == CiRuntimeCall::CreateOutOfBoundsException()) {
587 target_addr = Runtime1::entry_for(Runtime1::graal_create_out_of_bounds_exception_id);
588 TRACE_graal_3("CiRuntimeCall::CreateOutOfBoundsException()");
589 } else if (runtime_call == CiRuntimeCall::JavaTimeMillis()) {
590 target_addr = CAST_FROM_FN_PTR(address, os::javaTimeMillis);
591 TRACE_graal_3("CiRuntimeCall::JavaTimeMillis()");
592 } else if (runtime_call == CiRuntimeCall::JavaTimeNanos()) {
593 target_addr = CAST_FROM_FN_PTR(address, os::javaTimeNanos);
594 TRACE_graal_3("CiRuntimeCall::JavaTimeNanos()");
595 } else if (runtime_call == CiRuntimeCall::ArithmeticFrem()) {
596 target_addr = Runtime1::entry_for(Runtime1::graal_arithmetic_frem_id);
597 TRACE_graal_3("CiRuntimeCall::ArithmeticFrem()");
598 } else if (runtime_call == CiRuntimeCall::ArithmeticDrem()) {
599 target_addr = Runtime1::entry_for(Runtime1::graal_arithmetic_drem_id);
600 TRACE_graal_3("CiRuntimeCall::ArithmeticDrem()");
601 } else if (runtime_call == CiRuntimeCall::ArithmeticSin()) {
602 target_addr = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
603 TRACE_graal_3("CiRuntimeCall::ArithmeticSin()");
604 } else if (runtime_call == CiRuntimeCall::ArithmeticCos()) {
605 target_addr = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
606 TRACE_graal_3("CiRuntimeCall::ArithmeticCos()");
607 } else if (runtime_call == CiRuntimeCall::ArithmeticTan()) {
608 target_addr = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
609 TRACE_graal_3("CiRuntimeCall::ArithmeticTan()");
610 } else if (runtime_call == CiRuntimeCall::RegisterFinalizer()) {
611 target_addr = Runtime1::entry_for(Runtime1::register_finalizer_id);
612 } else if (runtime_call == CiRuntimeCall::Deoptimize()) {
613 target_addr = SharedRuntime::deopt_blob()->uncommon_trap();
614 } else {
615 runtime_call->print();
616 fatal("runtime_call not implemented");
617 }
618 return target_addr;
619 }
620
570 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { 621 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) {
571 oop target = CiTargetMethod_Call::target(site); 622 oop target = CiTargetMethod_Call::target(site);
572 instanceKlass* target_klass = instanceKlass::cast(target->klass()); 623 instanceKlass* target_klass = instanceKlass::cast(target->klass());
573 624
574 oop runtime_call = NULL; // CiRuntimeCall 625 oop runtime_call = NULL; // CiRuntimeCall
608 oop code_pos = CiDebugInfo::codePos(debug_info); 659 oop code_pos = CiDebugInfo::codePos(debug_info);
609 record_scope(next_pc_offset, code_pos, new GrowableArray<ScopeValue*>()); 660 record_scope(next_pc_offset, code_pos, new GrowableArray<ScopeValue*>());
610 } 661 }
611 662
612 if (runtime_call != NULL) { 663 if (runtime_call != NULL) {
613 address target_addr = 0x0; 664 if (runtime_call != CiRuntimeCall::Debug()) {
614 if (runtime_call == CiRuntimeCall::Debug()) { 665 address target_addr = runtime_call_target_address(runtime_call);
615 TRACE_graal_3("CiRuntimeCall::Debug()"); 666
616 } else if (runtime_call == CiRuntimeCall::UnwindException()) { 667 if (inst->is_call()) {
617 target_addr = Runtime1::entry_for(Runtime1::graal_unwind_exception_call_id); 668 // NOTE: for call without a mov, the offset must fit a 32-bit immediate
618 TRACE_graal_3("CiRuntimeCall::UnwindException()"); 669 // see also VMEntries.getMaxCallTargetOffset()
619 } else if (runtime_call == CiRuntimeCall::HandleException()) { 670 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
620 target_addr = Runtime1::entry_for(Runtime1::graal_handle_exception_id); 671 call->set_destination(target_addr);
621 TRACE_graal_3("CiRuntimeCall::HandleException()"); 672 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand);
622 } else if (runtime_call == CiRuntimeCall::SetDeoptInfo()) { 673 } else if (inst->is_mov_literal64()) {
623 target_addr = Runtime1::entry_for(Runtime1::graal_set_deopt_info_id); 674 NativeMovConstReg* mov = nativeMovConstReg_at(_instructions->start() + pc_offset);
624 TRACE_graal_3("CiRuntimeCall::SetDeoptInfo()"); 675 mov->set_data((intptr_t) target_addr);
625 } else if (runtime_call == CiRuntimeCall::CreateNullPointerException()) { 676 _instructions->relocate(mov->instruction_address(), runtime_call_Relocation::spec(), Assembler::imm_operand);
626 target_addr = Runtime1::entry_for(Runtime1::graal_create_null_pointer_exception_id); 677 } else {
627 TRACE_graal_3("CiRuntimeCall::CreateNullPointerException()"); 678 runtime_call->print();
628 } else if (runtime_call == CiRuntimeCall::CreateOutOfBoundsException()) { 679 fatal("unknown type of instruction for runtime call");
629 target_addr = Runtime1::entry_for(Runtime1::graal_create_out_of_bounds_exception_id); 680 }
630 TRACE_graal_3("CiRuntimeCall::CreateOutOfBoundsException()");
631 } else if (runtime_call == CiRuntimeCall::JavaTimeMillis()) {
632 target_addr = CAST_FROM_FN_PTR(address, os::javaTimeMillis);
633 TRACE_graal_3("CiRuntimeCall::JavaTimeMillis()");
634 } else if (runtime_call == CiRuntimeCall::JavaTimeNanos()) {
635 target_addr = CAST_FROM_FN_PTR(address, os::javaTimeNanos);
636 TRACE_graal_3("CiRuntimeCall::JavaTimeNanos()");
637 } else if (runtime_call == CiRuntimeCall::ArithmeticFrem()) {
638 target_addr = Runtime1::entry_for(Runtime1::graal_arithmetic_frem_id);
639 TRACE_graal_3("CiRuntimeCall::ArithmeticFrem()");
640 } else if (runtime_call == CiRuntimeCall::ArithmeticDrem()) {
641 target_addr = Runtime1::entry_for(Runtime1::graal_arithmetic_drem_id);
642 TRACE_graal_3("CiRuntimeCall::ArithmeticDrem()");
643 } else if (runtime_call == CiRuntimeCall::ArithmeticSin()) {
644 target_addr = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
645 TRACE_graal_3("CiRuntimeCall::ArithmeticSin()");
646 } else if (runtime_call == CiRuntimeCall::ArithmeticCos()) {
647 target_addr = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
648 TRACE_graal_3("CiRuntimeCall::ArithmeticCos()");
649 } else if (runtime_call == CiRuntimeCall::ArithmeticTan()) {
650 target_addr = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
651 TRACE_graal_3("CiRuntimeCall::ArithmeticTan()");
652 } else if (runtime_call == CiRuntimeCall::RegisterFinalizer()) {
653 target_addr = Runtime1::entry_for(Runtime1::register_finalizer_id);
654 } else if (runtime_call == CiRuntimeCall::Deoptimize()) {
655 target_addr = SharedRuntime::deopt_blob()->uncommon_trap();
656 } else {
657 runtime_call->print();
658 fatal("runtime_call not implemented");
659 }
660
661 if (inst->is_call()) {
662 // NOTE: for call without a mov, the offset must fit a 32-bit immediate
663 // see also VMEntries.getMaxCallTargetOffset()
664 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
665 call->set_destination(target_addr);
666 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand);
667 } else if (inst->is_mov_literal64()) {
668 NativeMovConstReg* mov = nativeMovConstReg_at(_instructions->start() + pc_offset);
669 mov->set_data((intptr_t) target_addr);
670 _instructions->relocate(mov->instruction_address(), runtime_call_Relocation::spec(), Assembler::imm_operand);
671 } else {
672 runtime_call->print();
673 fatal("unknown type of instruction for runtime call");
674 } 681 }
675 } else if (global_stub != NULL) { 682 } else if (global_stub != NULL) {
676 assert(java_lang_boxing_object::is_instance(global_stub, T_LONG), "global_stub needs to be of type Long"); 683 assert(java_lang_boxing_object::is_instance(global_stub, T_LONG), "global_stub needs to be of type Long");
677 684
678 if (inst->is_call()) { 685 if (inst->is_call()) {