Skip to content

Commit 3fbbfd1

Browse files
Matias Saavedra SilvareinrichDingliZhangzifeihanoffamitkumar
committed
8301995: Move invokedynamic resolution information out of ConstantPoolCacheEntry
Co-authored-by: Richard Reingruber <rrich@openjdk.org> Co-authored-by: Dingli Zhang <dzhang@openjdk.org> Co-authored-by: Gui Cao <gcao@openjdk.org> Co-authored-by: Amit Kumar <amitkumar@openjdk.org> Reviewed-by: coleenp, dnsimon, fparain, gcao, aph, fyang, amitkumar, lucy
1 parent 50a995f commit 3fbbfd1

File tree

58 files changed

+1343
-407
lines changed

Some content is hidden

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

58 files changed

+1343
-407
lines changed

src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,3 +1833,14 @@ void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register t
18331833
bind(profile_continue);
18341834
}
18351835
}
1836+
1837+
void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) {
1838+
// Get index out of bytecode pointer, get_cache_entry_pointer_at_bcp
1839+
get_cache_index_at_bcp(index, 1, sizeof(u4));
1840+
// Get address of invokedynamic array
1841+
ldr(cache, Address(rcpool, in_bytes(ConstantPoolCache::invokedynamic_entries_offset())));
1842+
// Scale the index to be the entry index * sizeof(ResolvedInvokeDynamicInfo)
1843+
lsl(index, index, log2i_exact(sizeof(ResolvedIndyEntry)));
1844+
add(cache, cache, Array<ResolvedIndyEntry>::base_offset_in_bytes());
1845+
lea(cache, Address(cache, index));
1846+
}

src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ class InterpreterMacroAssembler: public MacroAssembler {
319319
set_last_Java_frame(esp, rfp, (address) pc(), rscratch1);
320320
MacroAssembler::_call_Unimplemented(call_site);
321321
}
322+
323+
void load_resolved_indy_entry(Register cache, Register index);
322324
};
323325

324326
#endif // CPU_AARCH64_INTERP_MASM_AARCH64_HPP

src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,21 @@ address TemplateInterpreterGenerator::generate_return_entry_for(TosState state,
479479
__ profile_return_type(mdp, obj, tmp);
480480
}
481481

482-
// Pop N words from the stack
483-
__ get_cache_and_index_at_bcp(r1, r2, 1, index_size);
484-
__ ldr(r1, Address(r1, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
485-
__ andr(r1, r1, ConstantPoolCacheEntry::parameter_size_mask);
482+
const Register cache = r1;
483+
const Register index = r2;
486484

487-
__ add(esp, esp, r1, Assembler::LSL, 3);
485+
if (index_size == sizeof(u4)) {
486+
__ load_resolved_indy_entry(cache, index);
487+
__ load_unsigned_short(cache, Address(cache, in_bytes(ResolvedIndyEntry::num_parameters_offset())));
488+
__ add(esp, esp, cache, Assembler::LSL, 3);
489+
} else {
490+
// Pop N words from the stack
491+
__ get_cache_and_index_at_bcp(cache, index, 1, index_size);
492+
__ ldr(cache, Address(cache, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
493+
__ andr(cache, cache, ConstantPoolCacheEntry::parameter_size_mask);
494+
495+
__ add(esp, esp, cache, Assembler::LSL, 3);
496+
}
488497

489498
// Restore machine SP
490499
__ restore_sp_after_call();

src/hotspot/cpu/aarch64/templateTable_aarch64.cpp

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -2320,13 +2320,82 @@ void TemplateTable::load_field_cp_cache_entry(Register obj,
23202320
}
23212321
}
23222322

2323+
// The rmethod register is input and overwritten to be the adapter method for the
2324+
// indy call. Link Register (lr) is set to the return address for the adapter and
2325+
// an appendix may be pushed to the stack. Registers r0-r3 are clobbered
2326+
void TemplateTable::load_invokedynamic_entry(Register method) {
2327+
// setup registers
2328+
const Register appendix = r0;
2329+
const Register cache = r2;
2330+
const Register index = r3;
2331+
assert_different_registers(method, appendix, cache, index, rcpool);
2332+
2333+
__ save_bcp();
2334+
2335+
Label resolved;
2336+
2337+
__ load_resolved_indy_entry(cache, index);
2338+
// Load-acquire the adapter method to match store-release in ResolvedIndyEntry::fill_in()
2339+
__ lea(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset())));
2340+
__ ldar(method, method);
2341+
2342+
// Compare the method to zero
2343+
__ cbnz(method, resolved);
2344+
2345+
Bytecodes::Code code = bytecode();
2346+
2347+
// Call to the interpreter runtime to resolve invokedynamic
2348+
address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2349+
__ mov(method, code); // this is essentially Bytecodes::_invokedynamic
2350+
__ call_VM(noreg, entry, method);
2351+
// Update registers with resolved info
2352+
__ load_resolved_indy_entry(cache, index);
2353+
// Load-acquire the adapter method to match store-release in ResolvedIndyEntry::fill_in()
2354+
__ lea(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset())));
2355+
__ ldar(method, method);
2356+
2357+
#ifdef ASSERT
2358+
__ cbnz(method, resolved);
2359+
__ stop("Should be resolved by now");
2360+
#endif // ASSERT
2361+
__ bind(resolved);
2362+
2363+
Label L_no_push;
2364+
// Check if there is an appendix
2365+
__ load_unsigned_byte(index, Address(cache, in_bytes(ResolvedIndyEntry::flags_offset())));
2366+
__ tbz(index, ResolvedIndyEntry::has_appendix_shift, L_no_push);
2367+
2368+
// Get appendix
2369+
__ load_unsigned_short(index, Address(cache, in_bytes(ResolvedIndyEntry::resolved_references_index_offset())));
2370+
// Push the appendix as a trailing parameter
2371+
// since the parameter_size includes it.
2372+
__ push(method);
2373+
__ mov(method, index);
2374+
__ load_resolved_reference_at_index(appendix, method);
2375+
__ verify_oop(appendix);
2376+
__ pop(method);
2377+
__ push(appendix); // push appendix (MethodType, CallSite, etc.)
2378+
__ bind(L_no_push);
2379+
2380+
// compute return type
2381+
__ load_unsigned_byte(index, Address(cache, in_bytes(ResolvedIndyEntry::result_type_offset())));
2382+
// load return address
2383+
// Return address is loaded into link register(lr) and not pushed to the stack
2384+
// like x86
2385+
{
2386+
const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
2387+
__ mov(rscratch1, table_addr);
2388+
__ ldr(lr, Address(rscratch1, index, Address::lsl(3)));
2389+
}
2390+
}
2391+
23232392
void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
23242393
Register method,
23252394
Register itable_index,
23262395
Register flags,
23272396
bool is_invokevirtual,
23282397
bool is_invokevfinal, /*unused*/
2329-
bool is_invokedynamic) {
2398+
bool is_invokedynamic /*unused*/) {
23302399
// setup registers
23312400
const Register cache = rscratch2;
23322401
const Register index = r4;
@@ -2347,7 +2416,7 @@ void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
23472416
const int index_offset = in_bytes(ConstantPoolCache::base_offset() +
23482417
ConstantPoolCacheEntry::f2_offset());
23492418

2350-
size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2));
2419+
size_t index_size = sizeof(u2);
23512420
resolve_cache_and_index(byte_no, cache, index, index_size);
23522421
__ ldr(method, Address(cache, method_offset));
23532422

@@ -3167,7 +3236,7 @@ void TemplateTable::prepare_invoke(int byte_no,
31673236
load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
31683237

31693238
// maybe push appendix to arguments (just before return address)
3170-
if (is_invokedynamic || is_invokehandle) {
3239+
if (is_invokehandle) {
31713240
Label L_no_push;
31723241
__ tbz(flags, ConstantPoolCacheEntry::has_appendix_shift, L_no_push);
31733242
// Push the appendix as a trailing parameter.
@@ -3438,7 +3507,7 @@ void TemplateTable::invokedynamic(int byte_no) {
34383507
transition(vtos, vtos);
34393508
assert(byte_no == f1_byte, "use this argument");
34403509

3441-
prepare_invoke(byte_no, rmethod, r0);
3510+
load_invokedynamic_entry(rmethod);
34423511

34433512
// r0: CallSite object (from cpool->resolved_references[])
34443513
// rmethod: MH.linkToCallSite method (from f2)

src/hotspot/cpu/ppc/interp_masm_ppc.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
2+
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -127,6 +127,7 @@ class InterpreterMacroAssembler: public MacroAssembler {
127127
void get_cache_index_at_bcp(Register Rdst, int bcp_offset, size_t index_size);
128128

129129
void get_cache_and_index_at_bcp(Register cache, int bcp_offset, size_t index_size = sizeof(u2));
130+
void load_resolved_indy_entry(Register cache, Register index);
130131

131132
void get_u4(Register Rdst, Register Rsrc, int offset, signedOrNot is_signed);
132133

src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2012, 2022 SAP SE. All rights reserved.
3+
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -480,6 +480,18 @@ void InterpreterMacroAssembler::get_u4(Register Rdst, Register Rsrc, int offset,
480480
#endif
481481
}
482482

483+
void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) {
484+
// Get index out of bytecode pointer, get_cache_entry_pointer_at_bcp
485+
get_cache_index_at_bcp(index, 1, sizeof(u4));
486+
487+
// Get address of invokedynamic array
488+
ld_ptr(cache, in_bytes(ConstantPoolCache::invokedynamic_entries_offset()), R27_constPoolCache);
489+
// Scale the index to be the entry index * sizeof(ResolvedInvokeDynamicInfo)
490+
sldi(index, index, log2i_exact(sizeof(ResolvedIndyEntry)));
491+
addi(index, index, Array<ResolvedIndyEntry>::base_offset_in_bytes());
492+
add(cache, cache, index);
493+
}
494+
483495
// Load object from cpool->resolved_references(index).
484496
// Kills:
485497
// - index

src/hotspot/cpu/ppc/templateInterpreterGenerator_ppc.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2015, 2022 SAP SE. All rights reserved.
3+
* Copyright (c) 2015, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
#include "precompiled.hpp"
2727
#include "asm/macroAssembler.inline.hpp"
2828
#include "classfile/javaClasses.hpp"
29+
#include "compiler/disassembler.hpp"
2930
#include "gc/shared/barrierSetAssembler.hpp"
3031
#include "interpreter/bytecodeHistogram.hpp"
3132
#include "interpreter/interpreter.hpp"
@@ -53,7 +54,7 @@
5354
#include "utilities/macros.hpp"
5455

5556
#undef __
56-
#define __ _masm->
57+
#define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
5758

5859
// Size of interpreter code. Increase if too small. Interpreter will
5960
// fail with a guarantee ("not enough space for interpreter generation");
@@ -642,14 +643,24 @@ address TemplateInterpreterGenerator::generate_return_entry_for(TosState state,
642643

643644
const Register cache = R11_scratch1;
644645
const Register size = R12_scratch2;
645-
__ get_cache_and_index_at_bcp(cache, 1, index_size);
646+
if (index_size == sizeof(u4)) {
647+
__ get_cache_index_at_bcp(size, 1, index_size); // Load index.
648+
// Get address of invokedynamic array
649+
__ ld_ptr(cache, in_bytes(ConstantPoolCache::invokedynamic_entries_offset()), R27_constPoolCache);
650+
// Scale the index to be the entry index * sizeof(ResolvedInvokeDynamicInfo)
651+
__ sldi(size, size, log2i_exact(sizeof(ResolvedIndyEntry)));
652+
__ add(cache, cache, size);
653+
__ lhz(size, Array<ResolvedIndyEntry>::base_offset_in_bytes() + in_bytes(ResolvedIndyEntry::num_parameters_offset()), cache);
654+
} else {
655+
__ get_cache_and_index_at_bcp(cache, 1, index_size);
646656

647-
// Get least significant byte of 64 bit value:
657+
// Get least significant byte of 64 bit value:
648658
#if defined(VM_LITTLE_ENDIAN)
649-
__ lbz(size, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()), cache);
659+
__ lbz(size, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()), cache);
650660
#else
651-
__ lbz(size, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()) + 7, cache);
661+
__ lbz(size, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()) + 7, cache);
652662
#endif
663+
}
653664
__ sldi(size, size, Interpreter::logStackElementSize);
654665
__ add(R15_esp, R15_esp, size);
655666

0 commit comments

Comments
 (0)