@@ -619,8 +619,23 @@ address MacroAssembler::trampoline_call1(Address entry, CodeBuffer* cbuf, bool c
619619 || entry.rspec ().type () == relocInfo::static_call_type
620620 || entry.rspec ().type () == relocInfo::virtual_call_type, " wrong reloc type" );
621621
622+ bool need_trampoline = far_branches ();
623+ if (!need_trampoline && entry.rspec ().type () == relocInfo::runtime_call_type && !CodeCache::contains (entry.target ())) {
624+ // If it is a runtime call of an address outside small CodeCache,
625+ // we need to check whether it is in range.
626+ address target = entry.target ();
627+ assert (target < CodeCache::low_bound () || target >= CodeCache::high_bound (), " target is inside CodeCache" );
628+ // Case 1: -------T-------L====CodeCache====H-------
629+ // ^-------longest branch---|
630+ // Case 2: -------L====CodeCache====H-------T-------
631+ // |-------longest branch ---^
632+ address longest_branch_start = (target < CodeCache::low_bound ()) ? CodeCache::high_bound () - NativeInstruction::instruction_size
633+ : CodeCache::low_bound ();
634+ need_trampoline = !reachable_from_branch_at (longest_branch_start, target);
635+ }
636+
622637 // We need a trampoline if branches are far.
623- if (far_branches () ) {
638+ if (need_trampoline ) {
624639 bool in_scratch_emit_size = false ;
625640#ifdef COMPILER2
626641 if (check_emit_size) {
@@ -643,7 +658,7 @@ address MacroAssembler::trampoline_call1(Address entry, CodeBuffer* cbuf, bool c
643658
644659 if (cbuf) cbuf->set_insts_mark ();
645660 relocate (entry.rspec ());
646- if (!far_branches () ) {
661+ if (!need_trampoline ) {
647662 bl (entry.target ());
648663 } else {
649664 bl (pc ());
0 commit comments