Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8296477: Foreign linker implementation update following JEP 434 #11019

Closed
wants to merge 99 commits into from
Closed
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
7d8f4bd
Initial push
mcimadamore Oct 11, 2022
4f3767d
Add missing layout classes
mcimadamore Oct 11, 2022
c207b8e
Drop memory inspection utils
mcimadamore Oct 11, 2022
2bfb7d4
Add missing preview annotation on Linker.Option
mcimadamore Oct 11, 2022
688c9d3
Add preview annotation to Struct/UnionLayout
mcimadamore Oct 11, 2022
7299827
Fix call to SymbolLookup::find
minborg Oct 12, 2022
f54bfe3
Merge pull request #12 from minborg/fix-lookup-find
mcimadamore Oct 12, 2022
ebb5b30
Revert MemorySegment factories
minborg Oct 17, 2022
c7d09ad
Update javadocs after comments
minborg Oct 19, 2022
4fa32dd
Merge pull request #13 from minborg/revert-factories
mcimadamore Oct 19, 2022
341281d
Fix benchmark and test failure
mcimadamore Oct 19, 2022
5143d1d
Merge branch 'master' into PR_20
mcimadamore Oct 19, 2022
0d256f3
Revert some javadoc changes
mcimadamore Oct 19, 2022
83a86be
Update some javadocs
minborg Oct 26, 2022
34122b2
Merge pull request #14 from minborg/small-javadoc
mcimadamore Oct 26, 2022
ac7733d
Merge branch 'master' into PR_20
mcimadamore Oct 26, 2022
3d93302
Merge branch 'master' into PR_20
mcimadamore Nov 4, 2022
89f03a6
Remove VM dead code after implementation of Binding.Cast
mcimadamore Nov 7, 2022
76e9f01
Fix MemorySegment.ofBuffer when applied to StringCharBuffer
mcimadamore Nov 7, 2022
e8b95f8
Fix mismmatched acquire/release in BindingSpecializer
mcimadamore Nov 7, 2022
0c70da2
Add missing tests
mcimadamore Nov 7, 2022
b98febf
Bring windows CallArranger in sync with panama repo
mcimadamore Nov 7, 2022
f04be0d
Make memory session a pure lifetime abstraction
mcimadamore Nov 7, 2022
f73effc
Bring windows CallArranger in sync with panama repo (again)
mcimadamore Nov 8, 2022
2ac0cc1
Update src/java.base/share/classes/java/lang/foreign/Arena.java
mcimadamore Nov 8, 2022
f8858af
Update src/java.base/share/classes/java/lang/foreign/Arena.java
mcimadamore Nov 8, 2022
87d94f3
Update src/java.base/share/classes/java/lang/foreign/MemoryLayout.java
mcimadamore Nov 8, 2022
6b35c69
Update src/java.base/share/classes/java/lang/foreign/MemorySegment.java
mcimadamore Nov 8, 2022
441b4a0
Update src/java.base/share/classes/java/lang/foreign/MemorySegment.java
mcimadamore Nov 8, 2022
cc4ff58
Update src/java.base/share/classes/java/lang/foreign/MemorySession.java
mcimadamore Nov 8, 2022
0f8ca36
Update src/java.base/share/classes/java/lang/foreign/ValueLayout.java
mcimadamore Nov 8, 2022
3ff8210
Update src/java.base/share/classes/java/lang/foreign/package-info.java
mcimadamore Nov 8, 2022
afb36a9
Fix bad indent on ModuleLayer.Controller
mcimadamore Nov 8, 2022
e284023
Rework package-level javadoc for restricted methods
mcimadamore Nov 8, 2022
39099f4
Javadoc tweaks in MemorySession/Arena
mcimadamore Nov 8, 2022
fd36710
Revamp javadoc of Arena/MemorySession
mcimadamore Nov 8, 2022
7abcb28
8291913: Remove the TraceOptimizedUpcallStubs flag
JornVernee Aug 5, 2022
eecd852
8275644: Replace VMReg in shuffling code with something more fine gra…
JornVernee Sep 7, 2022
f8c3442
VMStorage to record
JornVernee Nov 5, 2022
0c810a9
8295265: Refactor handling of special values passed to stubs
JornVernee Oct 14, 2022
8fbc651
8275584: Incorrect stack spilling in CallArranger on MacOS/AArch64
nick-arm Oct 26, 2022
36eba4b
8294970: Add linker option for saving thread-locals that the VM can o…
JornVernee Oct 26, 2022
80339f7
8295353: Mark Register v24 as Volatile in Foreign Function & Memory C…
swesonga Nov 1, 2022
c852298
add stubs
JornVernee Nov 8, 2022
d7bb061
fix TestCaptureCallState
JornVernee Nov 8, 2022
01b0973
More javadoc tweaks
mcimadamore Nov 8, 2022
bb39bef
Address review comments
mcimadamore Nov 8, 2022
a40080e
Rename CAPTURED_STATE_MASK stub location to CAPTURED_STATE_BUFFER
JornVernee Nov 8, 2022
fff83ca
Update src/java.base/share/classes/java/lang/foreign/MemorySession.java
mcimadamore Nov 8, 2022
9be0c97
More javadoc fixes
mcimadamore Nov 8, 2022
df29e6a
Fix typo
mcimadamore Nov 8, 2022
64f4d55
Add @apiNote to package-info
minborg Nov 9, 2022
d7a1c7e
Fix failing tests
minborg Nov 9, 2022
2d75f95
Rename isOwnedBy -> isCloseableBy
mcimadamore Nov 9, 2022
c6cd176
Merge pull request #16 from minborg/fix-tests2
mcimadamore Nov 9, 2022
3952134
Merge pull request #15 from minborg/test
mcimadamore Nov 9, 2022
cd3fbe7
Tweak Arena::close javadoc
mcimadamore Nov 9, 2022
cef1205
Review comments
JornVernee Nov 9, 2022
9e13922
Work around x86 failures
JornVernee Nov 9, 2022
9b97bad
Tweak preview feature description for JEP 434
mcimadamore Nov 10, 2022
eb38b59
Javadoc nits
JornVernee Nov 10, 2022
202f61a
Use AssertionError for internal exceptions
JornVernee Nov 10, 2022
b805dd5
Use @requires to disable some tests on x86
JornVernee Nov 10, 2022
7b1b95f
Tweak copyright headers
JornVernee Nov 10, 2022
20ee6e8
Merge branch 'master' into PR_20
mcimadamore Nov 15, 2022
5ae5864
Rename MemorySession -> SegmentScope
mcimadamore Nov 15, 2022
3d9cebd
Fix whitespace
mcimadamore Nov 15, 2022
b2dd892
Add `since` tag in Module/ModuleLayer preview methods
mcimadamore Nov 15, 2022
19e0f6d
Address review comments
mcimadamore Nov 15, 2022
54fb485
Fix tests broken by MemorySession rename
mcimadamore Nov 15, 2022
b331a4f
Fix MapToMemorySegmentTest
mcimadamore Nov 15, 2022
5f60d05
Fix @since tag in SegmentScope
mcimadamore Nov 15, 2022
876587c
Fix typo in SegmentScope javadoc
mcimadamore Nov 15, 2022
5bff30f
Review pt1
JornVernee Nov 16, 2022
3f375cf
constexpr some functions
JornVernee Nov 16, 2022
4d44044
fix stubs
JornVernee Nov 16, 2022
15f86b5
Address review comments
mcimadamore Nov 17, 2022
ce41598
Fix bad @throws in MemorySegment::copy methods
mcimadamore Nov 17, 2022
0fa0e8c
8296973: saving errno on a value-returning function crashes the JVM
JornVernee Nov 18, 2022
a0cee7b
Address more review comments
mcimadamore Nov 21, 2022
03be64c
drop .inline from vmstorage header names
JornVernee Nov 22, 2022
dd16b99
Merge branch 'PR_20' into VM_Changes
JornVernee Nov 22, 2022
7591721
use Arena in example
JornVernee Nov 22, 2022
66dd888
Fix wrong check in MemorySegment::spliterator/elements
mcimadamore Nov 22, 2022
3c75e09
Fix bit vs. byte mismatch in test
mcimadamore Nov 23, 2022
9716815
* remove unused Scoped interface
mcimadamore Nov 23, 2022
6699ad9
Address review comments
mcimadamore Nov 28, 2022
5a75118
Polish javadoc:
mcimadamore Nov 30, 2022
ce85d18
Address review comment
mcimadamore Nov 30, 2022
8668fb3
Merge branch 'master' into PR_20
mcimadamore Nov 30, 2022
9e7ca30
Merge branch 'PR_20' into VM_Changes
JornVernee Nov 30, 2022
df8a4a6
Address review comments
mcimadamore Nov 30, 2022
198f30c
Address review comments
mcimadamore Nov 30, 2022
8b5dc0f
Merge branch 'master' into PR_20
mcimadamore Nov 30, 2022
6e94e45
Merge branch 'PR_20' into VM_Changes
JornVernee Dec 2, 2022
33b834c
Fix Preview annotation for JEP 434
mcimadamore Dec 5, 2022
2949f99
Merge branch 'PR_20' into VM_Changes
JornVernee Dec 5, 2022
c153fff
Merge master
JornVernee Dec 5, 2022
754faca
Remove spurious imports
JornVernee Dec 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
133 changes: 71 additions & 62 deletions src/hotspot/cpu/aarch64/downcallLinker_aarch64.cpp
Expand Up @@ -42,23 +42,25 @@ class DowncallStubGenerator : public StubCodeGenerator {
BasicType _ret_bt;
const ABIDescriptor& _abi;

const GrowableArray<VMReg>& _input_registers;
const GrowableArray<VMReg>& _output_registers;
const GrowableArray<VMStorage>& _input_registers;
const GrowableArray<VMStorage>& _output_registers;

bool _needs_return_buffer;
int _captured_state_mask;

int _frame_complete;
int _framesize;
int _frame_size_slots;
OopMapSet* _oop_maps;
public:
DowncallStubGenerator(CodeBuffer* buffer,
BasicType* signature,
int num_args,
BasicType ret_bt,
const ABIDescriptor& abi,
const GrowableArray<VMReg>& input_registers,
const GrowableArray<VMReg>& output_registers,
bool needs_return_buffer)
const GrowableArray<VMStorage>& input_registers,
const GrowableArray<VMStorage>& output_registers,
bool needs_return_buffer,
int captured_state_mask)
: StubCodeGenerator(buffer, PrintMethodHandleStubs),
_signature(signature),
_num_args(num_args),
Expand All @@ -67,8 +69,9 @@ class DowncallStubGenerator : public StubCodeGenerator {
_input_registers(input_registers),
_output_registers(output_registers),
_needs_return_buffer(needs_return_buffer),
_captured_state_mask(captured_state_mask),
_frame_complete(0),
_framesize(0),
_frame_size_slots(0),
_oop_maps(NULL) {
}

Expand All @@ -79,7 +82,7 @@ class DowncallStubGenerator : public StubCodeGenerator {
}

int framesize() const {
return (_framesize >> (LogBytesPerWord - LogBytesPerInt));
return (_frame_size_slots >> (LogBytesPerWord - LogBytesPerInt));
}

OopMapSet* oop_maps() const {
Expand All @@ -93,12 +96,15 @@ RuntimeStub* DowncallLinker::make_downcall_stub(BasicType* signature,
int num_args,
BasicType ret_bt,
const ABIDescriptor& abi,
const GrowableArray<VMReg>& input_registers,
const GrowableArray<VMReg>& output_registers,
bool needs_return_buffer) {
int locs_size = 64;
const GrowableArray<VMStorage>& input_registers,
const GrowableArray<VMStorage>& output_registers,
bool needs_return_buffer,
int captured_state_mask) {
int locs_size = 64;
CodeBuffer code("nep_invoker_blob", native_invoker_code_size, locs_size);
DowncallStubGenerator g(&code, signature, num_args, ret_bt, abi, input_registers, output_registers, needs_return_buffer);
DowncallStubGenerator g(&code, signature, num_args, ret_bt, abi,
input_registers, output_registers,
needs_return_buffer, captured_state_mask);
g.generate();
code.log_section_sizes("nep_invoker_blob");

Expand Down Expand Up @@ -137,10 +143,10 @@ void DowncallStubGenerator::generate() {
Register tmp1 = r9;
Register tmp2 = r10;

Register shuffle_reg = r19;
VMStorage shuffle_reg = as_VMStorage(r19);
JavaCallingConvention in_conv;
NativeCallingConvention out_conv(_input_registers);
ArgumentShuffle arg_shuffle(_signature, _num_args, _signature, _num_args, &in_conv, &out_conv, shuffle_reg->as_VMReg());
ArgumentShuffle arg_shuffle(_signature, _num_args, _signature, _num_args, &in_conv, &out_conv, shuffle_reg);

#ifndef PRODUCT
LogTarget(Trace, foreign, downcall) lt;
Expand All @@ -152,46 +158,48 @@ void DowncallStubGenerator::generate() {
#endif

int allocated_frame_size = 0;
if (_needs_return_buffer) {
allocated_frame_size += 8; // for address spill
}
allocated_frame_size += arg_shuffle.out_arg_stack_slots() <<LogBytesPerInt;
assert(_abi._shadow_space_bytes == 0, "not expecting shadow space on AArch64");
allocated_frame_size += arg_shuffle.out_arg_bytes();

int ret_buf_addr_sp_offset = -1;
StubLocations locs;
locs.set(StubLocations::TARGET_ADDRESS, _abi._scratch1);
if (_needs_return_buffer) {
// in sync with the above
ret_buf_addr_sp_offset = allocated_frame_size - 8;
locs.set_frame_data(StubLocations::RETURN_BUFFER, allocated_frame_size);
allocated_frame_size += BytesPerWord; // for address spill
}
if (_captured_state_mask != 0) {
locs.set_frame_data(StubLocations::CAPTURED_STATE_BUFFER, allocated_frame_size);
allocated_frame_size += BytesPerWord;
}

bool should_save_return_value = !_needs_return_buffer;
RegSpiller out_reg_spiller(_output_registers);
int spill_offset = -1;

if (!_needs_return_buffer) {
if (should_save_return_value) {
spill_offset = 0;
// spill area can be shared with the above, so we take the max of the 2
allocated_frame_size = out_reg_spiller.spill_size_bytes() > allocated_frame_size
? out_reg_spiller.spill_size_bytes()
: allocated_frame_size;
}

_framesize = align_up(framesize
+ (allocated_frame_size >> LogBytesPerInt), 4);
assert(is_even(_framesize/2), "sp not 16-byte aligned");
_frame_size_slots = align_up(framesize + (allocated_frame_size >> LogBytesPerInt), 4);
assert(is_even(_frame_size_slots/2), "sp not 16-byte aligned");

_oop_maps = new OopMapSet();
address start = __ pc();

__ enter();

// lr and fp are already in place
__ sub(sp, rfp, ((unsigned)_framesize-4) << LogBytesPerInt); // prolog
__ sub(sp, rfp, ((unsigned)_frame_size_slots-4) << LogBytesPerInt); // prolog

_frame_complete = __ pc() - start;

address the_pc = __ pc();
__ set_last_Java_frame(sp, rfp, the_pc, tmp1);
OopMap* map = new OopMap(_framesize, 0);
OopMap* map = new OopMap(_frame_size_slots, 0);
_oop_maps->add_gc_map(the_pc - start, map);

// State transition
Expand All @@ -200,50 +208,51 @@ void DowncallStubGenerator::generate() {
__ stlrw(tmp1, tmp2);

__ block_comment("{ argument shuffle");
arg_shuffle.generate(_masm, shuffle_reg->as_VMReg(), 0, _abi._shadow_space_bytes);
if (_needs_return_buffer) {
assert(ret_buf_addr_sp_offset != -1, "no return buffer addr spill");
__ str(_abi._ret_buf_addr_reg, Address(sp, ret_buf_addr_sp_offset));
}
arg_shuffle.generate(_masm, shuffle_reg, 0, _abi._shadow_space_bytes, locs);
__ block_comment("} argument shuffle");

__ blr(_abi._target_addr_reg);
__ blr(as_Register(locs.get(StubLocations::TARGET_ADDRESS)));
// this call is assumed not to have killed rthread

if (!_needs_return_buffer) {
// Unpack native results.
switch (_ret_bt) {
case T_BOOLEAN: __ c2bool(r0); break;
case T_CHAR : __ ubfx(r0, r0, 0, 16); break;
case T_BYTE : __ sbfx(r0, r0, 0, 8); break;
case T_SHORT : __ sbfx(r0, r0, 0, 16); break;
case T_INT : __ sbfx(r0, r0, 0, 32); break;
case T_DOUBLE :
case T_FLOAT :
// Result is in v0 we'll save as needed
break;
case T_VOID: break;
case T_LONG: break;
default : ShouldNotReachHere();
}
} else {
assert(ret_buf_addr_sp_offset != -1, "no return buffer addr spill");
__ ldr(tmp1, Address(sp, ret_buf_addr_sp_offset));
if (_needs_return_buffer) {
__ ldr(tmp1, Address(sp, locs.data_offset(StubLocations::RETURN_BUFFER)));
int offset = 0;
for (int i = 0; i < _output_registers.length(); i++) {
VMReg reg = _output_registers.at(i);
if (reg->is_Register()) {
__ str(reg->as_Register(), Address(tmp1, offset));
VMStorage reg = _output_registers.at(i);
if (reg.type() == StorageType::INTEGER) {
__ str(as_Register(reg), Address(tmp1, offset));
offset += 8;
} else if(reg->is_FloatRegister()) {
__ strd(reg->as_FloatRegister(), Address(tmp1, offset));
} else if (reg.type() == StorageType::VECTOR) {
__ strd(as_FloatRegister(reg), Address(tmp1, offset));
offset += 16;
} else {
ShouldNotReachHere();
}
}
}

//////////////////////////////////////////////////////////////////////////////

if (_captured_state_mask != 0) {
__ block_comment("{ save thread local");

if (should_save_return_value) {
out_reg_spiller.generate_spill(_masm, spill_offset);
}

__ ldr(c_rarg0, Address(sp, locs.data_offset(StubLocations::CAPTURED_STATE_BUFFER)));
__ movw(c_rarg1, _captured_state_mask);
__ rt_call(CAST_FROM_FN_PTR(address, DowncallLinker::capture_state), tmp1);

if (should_save_return_value) {
out_reg_spiller.generate_fill(_masm, spill_offset);
}

__ block_comment("} save thread local");
}

//////////////////////////////////////////////////////////////////////////////

__ mov(tmp1, _thread_in_native_trans);
__ strw(tmp1, Address(rthread, JavaThread::thread_state_offset()));

Expand Down Expand Up @@ -288,7 +297,7 @@ void DowncallStubGenerator::generate() {
__ block_comment("{ L_safepoint_poll_slow_path");
__ bind(L_safepoint_poll_slow_path);

if (!_needs_return_buffer) {
if (should_save_return_value) {
// Need to save the native result registers around any runtime calls.
out_reg_spiller.generate_spill(_masm, spill_offset);
}
Expand All @@ -298,7 +307,7 @@ void DowncallStubGenerator::generate() {
__ lea(tmp1, RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
__ blr(tmp1);

if (!_needs_return_buffer) {
if (should_save_return_value) {
out_reg_spiller.generate_fill(_masm, spill_offset);
}

Expand All @@ -310,13 +319,13 @@ void DowncallStubGenerator::generate() {
__ block_comment("{ L_reguard");
__ bind(L_reguard);

if (!_needs_return_buffer) {
if (should_save_return_value) {
out_reg_spiller.generate_spill(_masm, spill_offset);
}

__ rt_call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), tmp1);

if (!_needs_return_buffer) {
if (should_save_return_value) {
out_reg_spiller.generate_fill(_masm, spill_offset);
}

Expand Down