Skip to content

Commit aae2bb6

Browse files
Vladimir KozlovAshutosh Mehra
andcommitted
8350209: Preserve adapters in AOT cache
Co-authored-by: Ashutosh Mehra <[email protected]> Reviewed-by: vlivanov, asmehra, ihse, iklam
1 parent c116b18 commit aae2bb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3100
-470
lines changed

make/hotspot/lib/JvmFeatures.gmk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ endif
125125
ifneq ($(call check-jvm-feature, cds), true)
126126
JVM_CFLAGS_FEATURES += -DINCLUDE_CDS=0
127127
JVM_EXCLUDE_FILES += \
128+
aotCodeCache.cpp \
128129
classLoaderDataShared.cpp \
129130
classLoaderExt.cpp \
130131
systemDictionaryShared.cpp

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ void MacroAssembler::set_last_Java_frame(Register last_java_sp,
675675
}
676676

677677
static inline bool target_needs_far_branch(address addr) {
678+
if (AOTCodeCache::is_on_for_dump()) {
679+
return true;
680+
}
678681
// codecache size <= 128M
679682
if (!MacroAssembler::far_branches()) {
680683
return false;
@@ -859,6 +862,9 @@ void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, in
859862

860863
// Check the entry target is always reachable from any branch.
861864
static bool is_always_within_branch_range(Address entry) {
865+
if (AOTCodeCache::is_on_for_dump()) {
866+
return false;
867+
}
862868
const address target = entry.target();
863869

864870
if (!CodeCache::contains(target)) {
@@ -2154,7 +2160,7 @@ void MacroAssembler::call_VM_leaf_base(address entry_point,
21542160

21552161
stp(rscratch1, rmethod, Address(pre(sp, -2 * wordSize)));
21562162

2157-
mov(rscratch1, entry_point);
2163+
mov(rscratch1, RuntimeAddress(entry_point));
21582164
blr(rscratch1);
21592165
if (retaddr)
21602166
bind(*retaddr);
@@ -3231,9 +3237,13 @@ void MacroAssembler::resolve_global_jobject(Register value, Register tmp1, Regis
32313237
}
32323238

32333239
void MacroAssembler::stop(const char* msg) {
3234-
BLOCK_COMMENT(msg);
3240+
// Skip AOT caching C strings in scratch buffer.
3241+
const char* str = (code_section()->scratch_emit()) ? msg : AOTCodeCache::add_C_string(msg);
3242+
BLOCK_COMMENT(str);
3243+
// load msg into r0 so we can access it from the signal handler
3244+
// ExternalAddress enables saving and restoring via the code cache
3245+
lea(c_rarg0, ExternalAddress((address) str));
32353246
dcps1(0xdeae);
3236-
emit_int64((uintptr_t)msg);
32373247
}
32383248

32393249
void MacroAssembler::unimplemented(const char* what) {

src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define CPU_AARCH64_MACROASSEMBLER_AARCH64_HPP
2828

2929
#include "asm/assembler.inline.hpp"
30+
#include "code/aotCodeCache.hpp"
3031
#include "code/vmreg.hpp"
3132
#include "metaprogramming/enableIf.hpp"
3233
#include "oops/compressedOops.hpp"
@@ -1315,6 +1316,10 @@ class MacroAssembler: public Assembler {
13151316

13161317
// Check if branches to the non nmethod section require a far jump
13171318
static bool codestub_branch_needs_far_jump() {
1319+
if (AOTCodeCache::is_on_for_dump()) {
1320+
// To calculate far_codestub_branch_size correctly.
1321+
return true;
1322+
}
13181323
return CodeCache::max_distance_to_non_nmethod() > branch_range;
13191324
}
13201325

src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -557,40 +557,6 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
557557
// If this happens, control eventually transfers back to the compiled
558558
// caller, but with an uncorrected stack, causing delayed havoc.
559559

560-
if (VerifyAdapterCalls &&
561-
(Interpreter::code() != nullptr || StubRoutines::final_stubs_code() != nullptr)) {
562-
#if 0
563-
// So, let's test for cascading c2i/i2c adapters right now.
564-
// assert(Interpreter::contains($return_addr) ||
565-
// StubRoutines::contains($return_addr),
566-
// "i2c adapter must return to an interpreter frame");
567-
__ block_comment("verify_i2c { ");
568-
Label L_ok;
569-
if (Interpreter::code() != nullptr) {
570-
range_check(masm, rax, r11,
571-
Interpreter::code()->code_start(), Interpreter::code()->code_end(),
572-
L_ok);
573-
}
574-
if (StubRoutines::initial_stubs_code() != nullptr) {
575-
range_check(masm, rax, r11,
576-
StubRoutines::initial_stubs_code()->code_begin(),
577-
StubRoutines::initial_stubs_code()->code_end(),
578-
L_ok);
579-
}
580-
if (StubRoutines::final_stubs_code() != nullptr) {
581-
range_check(masm, rax, r11,
582-
StubRoutines::final_stubs_code()->code_begin(),
583-
StubRoutines::final_stubs_code()->code_end(),
584-
L_ok);
585-
}
586-
const char* msg = "i2c adapter must return to an interpreter frame";
587-
__ block_comment(msg);
588-
__ stop(msg);
589-
__ bind(L_ok);
590-
__ block_comment("} verify_i2ce ");
591-
#endif
592-
}
593-
594560
// Cut-out for having no stack args.
595561
int comp_words_on_stack = align_up(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord;
596562
if (comp_args_on_stack) {
@@ -711,12 +677,12 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
711677
}
712678

713679
// ---------------------------------------------------------------
714-
AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
715-
int total_args_passed,
716-
int comp_args_on_stack,
717-
const BasicType *sig_bt,
718-
const VMRegPair *regs,
719-
AdapterFingerPrint* fingerprint) {
680+
void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
681+
int total_args_passed,
682+
int comp_args_on_stack,
683+
const BasicType *sig_bt,
684+
const VMRegPair *regs,
685+
AdapterHandlerEntry* handler) {
720686
address i2c_entry = __ pc();
721687

722688
gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
@@ -777,7 +743,8 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
777743

778744
gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
779745

780-
return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
746+
handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
747+
return;
781748
}
782749

783750
static int c_calling_convention_priv(const BasicType *sig_bt,

src/hotspot/cpu/arm/sharedRuntime_arm.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,12 @@ static void gen_c2i_adapter(MacroAssembler *masm,
612612

613613
}
614614

615-
AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
616-
int total_args_passed,
617-
int comp_args_on_stack,
618-
const BasicType *sig_bt,
619-
const VMRegPair *regs,
620-
AdapterFingerPrint* fingerprint) {
615+
void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
616+
int total_args_passed,
617+
int comp_args_on_stack,
618+
const BasicType *sig_bt,
619+
const VMRegPair *regs,
620+
AdapterHandlerEntry* handler) {
621621
address i2c_entry = __ pc();
622622
gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
623623

@@ -637,7 +637,8 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
637637
address c2i_entry = __ pc();
638638
gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
639639

640-
return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
640+
handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, nullptr);
641+
return;
641642
}
642643

643644

src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,12 +1143,12 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
11431143
__ bctr();
11441144
}
11451145

1146-
AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1147-
int total_args_passed,
1148-
int comp_args_on_stack,
1149-
const BasicType *sig_bt,
1150-
const VMRegPair *regs,
1151-
AdapterFingerPrint* fingerprint) {
1146+
void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1147+
int total_args_passed,
1148+
int comp_args_on_stack,
1149+
const BasicType *sig_bt,
1150+
const VMRegPair *regs,
1151+
AdapterHandlerEntry* handler) {
11521152
address i2c_entry;
11531153
address c2i_unverified_entry;
11541154
address c2i_entry;
@@ -1223,8 +1223,8 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
12231223

12241224
gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, call_interpreter, ientry);
12251225

1226-
return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry,
1227-
c2i_no_clinit_check_entry);
1226+
handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
1227+
return;
12281228
}
12291229

12301230
// An oop arg. Must pass a handle not the oop itself.

src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,13 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
596596
}
597597

598598
// ---------------------------------------------------------------
599-
AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
600-
int total_args_passed,
601-
int comp_args_on_stack,
602-
const BasicType *sig_bt,
603-
const VMRegPair *regs,
604-
AdapterFingerPrint* fingerprint) {
599+
600+
void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
601+
int total_args_passed,
602+
int comp_args_on_stack,
603+
const BasicType *sig_bt,
604+
const VMRegPair *regs,
605+
AdapterHandlerEntry* handler) {
605606
address i2c_entry = __ pc();
606607
gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
607608

@@ -658,7 +659,8 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
658659

659660
gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
660661

661-
return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
662+
handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
663+
return;
662664
}
663665

664666
int SharedRuntime::vector_calling_convention(VMRegPair *regs,

src/hotspot/cpu/s390/sharedRuntime_s390.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,12 +2352,12 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
23522352
__ z_br(Z_R1_scratch);
23532353
}
23542354

2355-
AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
2356-
int total_args_passed,
2357-
int comp_args_on_stack,
2358-
const BasicType *sig_bt,
2359-
const VMRegPair *regs,
2360-
AdapterFingerPrint* fingerprint) {
2355+
void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
2356+
int total_args_passed,
2357+
int comp_args_on_stack,
2358+
const BasicType *sig_bt,
2359+
const VMRegPair *regs,
2360+
AdapterHandlerEntry* handler) {
23612361
__ align(CodeEntryAlignment);
23622362
address i2c_entry = __ pc();
23632363
gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
@@ -2411,7 +2411,8 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
24112411

24122412
gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
24132413

2414-
return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
2414+
handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
2415+
return;
24152416
}
24162417

24172418
// This function returns the adjust size (in number of words) to a c2i adapter

src/hotspot/cpu/x86/macroAssembler_x86.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "asm/assembler.hpp"
2626
#include "asm/assembler.inline.hpp"
27+
#include "code/aotCodeCache.hpp"
2728
#include "code/compiledIC.hpp"
2829
#include "compiler/compiler_globals.hpp"
2930
#include "compiler/disassembler.hpp"
@@ -366,7 +367,9 @@ void MacroAssembler::stop(const char* msg) {
366367
lea(c_rarg1, InternalAddress(rip));
367368
movq(c_rarg2, rsp); // pass pointer to regs array
368369
}
369-
lea(c_rarg0, ExternalAddress((address) msg));
370+
// Skip AOT caching C strings in scratch buffer.
371+
const char* str = (code_section()->scratch_emit()) ? msg : AOTCodeCache::add_C_string(msg);
372+
lea(c_rarg0, ExternalAddress((address) str));
370373
andq(rsp, -16); // align stack as required by ABI
371374
call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64)));
372375
hlt();

src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ static void patch_callers_callsite(MacroAssembler *masm) {
675675
__ bind(L);
676676
}
677677

678-
679678
static void gen_c2i_adapter(MacroAssembler *masm,
680679
int total_args_passed,
681680
int comp_args_on_stack,
@@ -826,19 +825,6 @@ static void gen_c2i_adapter(MacroAssembler *masm,
826825
__ jmp(rcx);
827826
}
828827

829-
static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
830-
address code_start, address code_end,
831-
Label& L_ok) {
832-
Label L_fail;
833-
__ lea(temp_reg, AddressLiteral(code_start, relocInfo::none));
834-
__ cmpptr(pc_reg, temp_reg);
835-
__ jcc(Assembler::belowEqual, L_fail);
836-
__ lea(temp_reg, AddressLiteral(code_end, relocInfo::none));
837-
__ cmpptr(pc_reg, temp_reg);
838-
__ jcc(Assembler::below, L_ok);
839-
__ bind(L_fail);
840-
}
841-
842828
void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
843829
int total_args_passed,
844830
int comp_args_on_stack,
@@ -871,41 +857,6 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
871857
// If this happens, control eventually transfers back to the compiled
872858
// caller, but with an uncorrected stack, causing delayed havoc.
873859

874-
if (VerifyAdapterCalls &&
875-
(Interpreter::code() != nullptr || StubRoutines::final_stubs_code() != nullptr)) {
876-
// So, let's test for cascading c2i/i2c adapters right now.
877-
// assert(Interpreter::contains($return_addr) ||
878-
// StubRoutines::contains($return_addr),
879-
// "i2c adapter must return to an interpreter frame");
880-
__ block_comment("verify_i2c { ");
881-
// Pick up the return address
882-
__ movptr(rax, Address(rsp, 0));
883-
Label L_ok;
884-
if (Interpreter::code() != nullptr) {
885-
range_check(masm, rax, r11,
886-
Interpreter::code()->code_start(),
887-
Interpreter::code()->code_end(),
888-
L_ok);
889-
}
890-
if (StubRoutines::initial_stubs_code() != nullptr) {
891-
range_check(masm, rax, r11,
892-
StubRoutines::initial_stubs_code()->code_begin(),
893-
StubRoutines::initial_stubs_code()->code_end(),
894-
L_ok);
895-
}
896-
if (StubRoutines::final_stubs_code() != nullptr) {
897-
range_check(masm, rax, r11,
898-
StubRoutines::final_stubs_code()->code_begin(),
899-
StubRoutines::final_stubs_code()->code_end(),
900-
L_ok);
901-
}
902-
const char* msg = "i2c adapter must return to an interpreter frame";
903-
__ block_comment(msg);
904-
__ stop(msg);
905-
__ bind(L_ok);
906-
__ block_comment("} verify_i2ce ");
907-
}
908-
909860
// Must preserve original SP for loading incoming arguments because
910861
// we need to align the outgoing SP for compiled code.
911862
__ movptr(r11, rsp);
@@ -1050,12 +1001,12 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
10501001
}
10511002

10521003
// ---------------------------------------------------------------
1053-
AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1054-
int total_args_passed,
1055-
int comp_args_on_stack,
1056-
const BasicType *sig_bt,
1057-
const VMRegPair *regs,
1058-
AdapterFingerPrint* fingerprint) {
1004+
void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1005+
int total_args_passed,
1006+
int comp_args_on_stack,
1007+
const BasicType *sig_bt,
1008+
const VMRegPair *regs,
1009+
AdapterHandlerEntry* handler) {
10591010
address i2c_entry = __ pc();
10601011

10611012
gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
@@ -1117,7 +1068,8 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
11171068

11181069
gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
11191070

1120-
return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
1071+
handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
1072+
return;
11211073
}
11221074

11231075
int SharedRuntime::c_calling_convention(const BasicType *sig_bt,

0 commit comments

Comments
 (0)