-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8254231: Implementation of Foreign Linker API (Incubator) #634
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
Closed
Closed
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
dc186e3
RFR 8254162: Implementation of Foreign-Memory Access API (Third Incub…
mcimadamore e4eb2c7
Add modified files
mcimadamore fa051ab
Address review comments
mcimadamore b941c4a
Fix indent in GensrcScopedMemoryAccess.gmk
mcimadamore d96c32a
Address review comments
mcimadamore 9b3fc22
Fix performance issue with "small" segment mismatch
mcimadamore 770b1e9
Tweak referenced to MemoryAddressProxy in Utils.java
mcimadamore 75e406c
Tweak support for mapped memory segments
mcimadamore d14d06a
Simplify example in the toplevel javadoc
mcimadamore 8815d94
Merge branch 'master' into 8254162
mcimadamore 8fb8ff2
Remove spurious check on MemoryScope::confineTo
mcimadamore e866bb2
Merge branch 'master' into 8254162
mcimadamore 4506d75
Merge with master
mcimadamore adcef6a
Add new files
mcimadamore 4f2ed7c
More updates
mcimadamore 8ce0357
Remove rejected file
mcimadamore 7cc344c
Fix whitespaces
mcimadamore 7cf0ef0
Fix more whitespaces
mcimadamore ad8bee1
Merge branch 'master' into 8254231_linker
JornVernee 2184831
Re-add erroneously removed files
JornVernee 830c5ce
Re-add file erroneously deleted (detected as rename)
JornVernee 6c7fef0
Merge branch 'master' into 8254162
JornVernee 28b3e3a
Merge branch 'master' into 8254162
JornVernee 6091ed0
Back-port of TestByteBuffer fix
JornVernee 3167431
Address CSR comments
mcimadamore c595a8d
Use separate constants for native invoker code size
JornVernee aee2245
Update copyright years, and add classpath exception to files that wer…
JornVernee 7d6eadc
Fix incorrect capitalization in one copyright header
JornVernee 502bd98
Merge branch 'master' into 8254231_linker
JornVernee 7cef16f
Don't use JNI when generating native wrappers
JornVernee 8c7b75d
Merge branch 'master' into 8254231_linker
JornVernee e543231
Review comments:
JornVernee 87a55e2
Fix build issues caused by recent refactorings
mcimadamore 8cfd401
Merge branch 'master' into 8254231_linker
mcimadamore dd20288
Remove spurious include
mcimadamore 03dbb52
Fix aarch issues
mcimadamore 9ec4c0e
Fix copyright of AbstractNativeScope
mcimadamore 6aec407
Fix more copyright headers
mcimadamore 3df6cee
And more copyright fixes
mcimadamore 003614a
Fix most review comments
mcimadamore d1c1309
Add missing resource marks before parsing descriptors
JornVernee 33f4143
Simplify AbstractNativeScope::allocate
mcimadamore 7675bbc
Fix CLinker javadoc
mcimadamore 21f5087
Merge pull request #4 from JornVernee/Missing_ResourceMarks
mcimadamore fb355ad
Merge branch '8254231_linker' into No_JNI_Comments_v2
JornVernee 0c89229
Merge pull request #2 from JornVernee/No_JNI_Comments_v2
mcimadamore 2c2d2a7
Fix whitespaces
mcimadamore 5d4c8af
Address review comment for scoped memory access makefile
mcimadamore 697c7ca
Merge branch 'master' into 8254162
mcimadamore dd8896a
Tweak javadoc for MemorySegment::mapFromPath
mcimadamore 41544e3
Merge branch 'master' into 8254162
mcimadamore f844f54
Remove TestMismatch from 32-bit problem list
mcimadamore e43f5d7
* Add final to MappedByteBuffer::SCOPED_MEMORY_ACCESS field
mcimadamore b01af09
More 32-bit fixes for TestLayouts
mcimadamore e3ec6b4
Fix issues with derived buffers and IO operations
mcimadamore 059d3ab
Address CSR feedback
mcimadamore bd40061
Merge branch 'master' into 8254162
mcimadamore 4a2c224
Merge branch '8254162' into 8254231_linker
mcimadamore 9871886
Fix typo in upcall helper for aarch64
mcimadamore 8225bf2
Address comments from @AlanBateman
mcimadamore e2f69ec
Addess remaining feedback from @AlanBateman and @mrserb
mcimadamore 258b400
Merge branch 'master' into 8254162
mcimadamore 02f9e25
Fix post-merge issues caused by 8219014
mcimadamore b38afb3
Merge branch '8254162' into 8254231_linker
mcimadamore 719224c
- Use lazy constant for upcall_info
JornVernee e9606ed
Merge pull request #6 from JornVernee/MoveUpcallInfo
mcimadamore 9960b3d
Address more CSR feedback
mcimadamore bd932cd
remove blank line in thread.hpp
JornVernee 28e7a83
Remove os::is_MP() check
JornVernee 969fb3d
remove excessive asserts in ProgrammableInvoker::invoke_native
JornVernee 033a7c8
Extra space after if
JornVernee 39a040a
Relax ret_addr_offset() assert
JornVernee 1d3a5ca
Sort includes alphabetically
JornVernee bb75026
Check result of AttachCurrentThread
JornVernee 18f0e2d
Set copyright year for added files to 2020
JornVernee 64c3a16
Revert System.java changes
JornVernee efc969d
Merge pull request #7 from JornVernee/Additional_Review_Comments
mcimadamore 2ed0f17
Add ResourceMark to ProgrammableUpcallHandler constructor
JornVernee 56099da
Merge branch 'master' into 8254231_linker
mcimadamore e3d62ee
Fix whitespaces
mcimadamore 0ab509e
Address Vlad's review comments
JornVernee a9384a0
Fix build failure with disabled precompiled headers
mcimadamore cd7d3f7
Fix high arity test for aarch64
mcimadamore 15ab364
Fix crashes on aarch64 due to lack of intrinsics support
mcimadamore 4976e3e
Merge branch '8254231_linker' into Vlad_Comments
JornVernee 9b7cd25
Merge branch 'master' into 8254231_linker
mcimadamore 0f0b972
Simplify print code
JornVernee c8dafc6
- Don't print anything in nmehtod debug output for native invoker if …
JornVernee 739c792
Merge pull request #8 from JornVernee/Vlad_Comments
mcimadamore 7407874
Fix warnings on MSVC
JornVernee 000f75d
Merge pull request #9 from JornVernee/Windows_Warnings
mcimadamore 3999a18
Fix signature mismatch on aarch64
mcimadamore a836cc3
Fix aarch64 test failure
mcimadamore a71d51a
Add `final` modifier on NativeLibraries.defaultLookup
mcimadamore 40bd5df
Merge branch 'master' into 8254231_linker
mcimadamore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2019, Arm Limited. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include "runtime/jniHandles.hpp" | ||
#include "runtime/jniHandles.inline.hpp" | ||
#include "oops/typeArrayOop.inline.hpp" | ||
#include "prims/foreign_globals.hpp" | ||
#include "prims/foreign_globals.inline.hpp" | ||
|
||
bool ABIDescriptor::is_volatile_reg(Register reg) const { | ||
return _integer_argument_registers.contains(reg) | ||
|| _integer_additional_volatile_registers.contains(reg); | ||
} | ||
|
||
bool ABIDescriptor::is_volatile_reg(FloatRegister reg) const { | ||
return _vector_argument_registers.contains(reg) | ||
|| _vector_additional_volatile_registers.contains(reg); | ||
} | ||
|
||
#define INTEGER_TYPE 0 | ||
#define VECTOR_TYPE 1 | ||
|
||
const ABIDescriptor ForeignGlobals::parse_abi_descriptor_impl(jobject jabi) const { | ||
oop abi_oop = JNIHandles::resolve_non_null(jabi); | ||
ABIDescriptor abi; | ||
|
||
objArrayOop inputStorage = cast<objArrayOop>(abi_oop->obj_field(ABI.inputStorage_offset)); | ||
loadArray(inputStorage, INTEGER_TYPE, abi._integer_argument_registers, as_Register); | ||
loadArray(inputStorage, VECTOR_TYPE, abi._vector_argument_registers, as_FloatRegister); | ||
|
||
objArrayOop outputStorage = cast<objArrayOop>(abi_oop->obj_field(ABI.outputStorage_offset)); | ||
loadArray(outputStorage, INTEGER_TYPE, abi._integer_return_registers, as_Register); | ||
loadArray(outputStorage, VECTOR_TYPE, abi._vector_return_registers, as_FloatRegister); | ||
|
||
objArrayOop volatileStorage = cast<objArrayOop>(abi_oop->obj_field(ABI.volatileStorage_offset)); | ||
loadArray(volatileStorage, INTEGER_TYPE, abi._integer_additional_volatile_registers, as_Register); | ||
loadArray(volatileStorage, VECTOR_TYPE, abi._vector_additional_volatile_registers, as_FloatRegister); | ||
|
||
abi._stack_alignment_bytes = abi_oop->int_field(ABI.stackAlignment_offset); | ||
abi._shadow_space_bytes = abi_oop->int_field(ABI.shadowSpace_offset); | ||
|
||
return abi; | ||
} | ||
|
||
const BufferLayout ForeignGlobals::parse_buffer_layout_impl(jobject jlayout) const { | ||
oop layout_oop = JNIHandles::resolve_non_null(jlayout); | ||
BufferLayout layout; | ||
|
||
layout.stack_args_bytes = layout_oop->long_field(BL.stack_args_bytes_offset); | ||
layout.stack_args = layout_oop->long_field(BL.stack_args_offset); | ||
layout.arguments_next_pc = layout_oop->long_field(BL.arguments_next_pc_offset); | ||
|
||
typeArrayOop input_offsets = cast<typeArrayOop>(layout_oop->obj_field(BL.input_type_offsets_offset)); | ||
layout.arguments_integer = (size_t) input_offsets->long_at(INTEGER_TYPE); | ||
layout.arguments_vector = (size_t) input_offsets->long_at(VECTOR_TYPE); | ||
|
||
typeArrayOop output_offsets = cast<typeArrayOop>(layout_oop->obj_field(BL.output_type_offsets_offset)); | ||
layout.returns_integer = (size_t) output_offsets->long_at(INTEGER_TYPE); | ||
layout.returns_vector = (size_t) output_offsets->long_at(VECTOR_TYPE); | ||
|
||
layout.buffer_size = layout_oop->long_field(BL.size_offset); | ||
|
||
return layout; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2019, Arm Limited. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
#ifndef CPU_AARCH64_VM_FOREIGN_GLOBALS_AARCH64_HPP | ||
#define CPU_AARCH64_VM_FOREIGN_GLOBALS_AARCH64_HPP | ||
|
||
#include "asm/macroAssembler.hpp" | ||
#include "utilities/growableArray.hpp" | ||
|
||
constexpr size_t float_reg_size = 16; // bytes | ||
|
||
struct ABIDescriptor { | ||
GrowableArray<Register> _integer_argument_registers; | ||
GrowableArray<Register> _integer_return_registers; | ||
GrowableArray<FloatRegister> _vector_argument_registers; | ||
GrowableArray<FloatRegister> _vector_return_registers; | ||
|
||
GrowableArray<Register> _integer_additional_volatile_registers; | ||
GrowableArray<FloatRegister> _vector_additional_volatile_registers; | ||
|
||
int32_t _stack_alignment_bytes; | ||
int32_t _shadow_space_bytes; | ||
|
||
bool is_volatile_reg(Register reg) const; | ||
bool is_volatile_reg(FloatRegister reg) const; | ||
}; | ||
|
||
struct BufferLayout { | ||
size_t stack_args_bytes; | ||
size_t stack_args; | ||
size_t arguments_vector; | ||
size_t arguments_integer; | ||
size_t arguments_next_pc; | ||
size_t returns_vector; | ||
size_t returns_integer; | ||
size_t buffer_size; | ||
}; | ||
|
||
#endif // CPU_AARCH64_VM_FOREIGN_GLOBALS_AARCH64_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/hotspot/cpu/aarch64/universalNativeInvoker_aarch64.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2019, Arm Limited. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include "asm/macroAssembler.hpp" | ||
#include "code/codeBlob.hpp" | ||
#include "memory/resourceArea.hpp" | ||
#include "prims/universalNativeInvoker.hpp" | ||
|
||
#define __ _masm-> | ||
|
||
void ProgrammableInvoker::Generator::generate() { | ||
__ enter(); | ||
|
||
// Name registers used in the stub code. These are all caller-save so | ||
// may be clobbered by the call to the native function. Avoid using | ||
// rscratch1 here as it's r8 which is the indirect result register in | ||
// the standard ABI. | ||
Register Rctx = r10, Rstack_size = r11; | ||
Register Rwords = r12, Rtmp = r13; | ||
Register Rsrc_ptr = r14, Rdst_ptr = r15; | ||
|
||
assert_different_registers(Rctx, Rstack_size, rscratch1, rscratch2); | ||
|
||
// TODO: if the callee is not using the standard C ABI then we need to | ||
// preserve more registers here. | ||
|
||
__ block_comment("init_and_alloc_stack"); | ||
|
||
__ mov(Rctx, c_rarg0); | ||
__ str(Rctx, Address(__ pre(sp, -2 * wordSize))); | ||
|
||
assert(_abi->_stack_alignment_bytes % 16 == 0, "stack must be 16 byte aligned"); | ||
|
||
__ block_comment("allocate_stack"); | ||
__ ldr(Rstack_size, Address(Rctx, (int) _layout->stack_args_bytes)); | ||
__ add(rscratch2, Rstack_size, _abi->_stack_alignment_bytes - 1); | ||
__ andr(rscratch2, rscratch2, -_abi->_stack_alignment_bytes); | ||
__ sub(sp, sp, rscratch2); | ||
|
||
__ block_comment("load_arguments"); | ||
|
||
__ ldr(Rsrc_ptr, Address(Rctx, (int) _layout->stack_args)); | ||
__ lsr(Rwords, Rstack_size, LogBytesPerWord); | ||
__ mov(Rdst_ptr, sp); | ||
|
||
Label Ldone, Lnext; | ||
__ bind(Lnext); | ||
__ cbz(Rwords, Ldone); | ||
__ ldr(Rtmp, __ post(Rsrc_ptr, wordSize)); | ||
__ str(Rtmp, __ post(Rdst_ptr, wordSize)); | ||
__ sub(Rwords, Rwords, 1); | ||
__ b(Lnext); | ||
__ bind(Ldone); | ||
|
||
for (int i = 0; i < _abi->_vector_argument_registers.length(); i++) { | ||
ssize_t offs = _layout->arguments_vector + i * float_reg_size; | ||
__ ldrq(_abi->_vector_argument_registers.at(i), Address(Rctx, offs)); | ||
} | ||
|
||
for (int i = 0; i < _abi->_integer_argument_registers.length(); i++) { | ||
ssize_t offs = _layout->arguments_integer + i * sizeof(uintptr_t); | ||
__ ldr(_abi->_integer_argument_registers.at(i), Address(Rctx, offs)); | ||
} | ||
|
||
assert(_abi->_shadow_space_bytes == 0, "shadow space not supported on AArch64"); | ||
|
||
// call target function | ||
__ block_comment("call target function"); | ||
__ ldr(rscratch2, Address(Rctx, (int) _layout->arguments_next_pc)); | ||
__ blr(rscratch2); | ||
|
||
__ ldr(Rctx, Address(rfp, -2 * wordSize)); // Might have clobbered Rctx | ||
|
||
__ block_comment("store_registers"); | ||
|
||
for (int i = 0; i < _abi->_integer_return_registers.length(); i++) { | ||
ssize_t offs = _layout->returns_integer + i * sizeof(uintptr_t); | ||
__ str(_abi->_integer_return_registers.at(i), Address(Rctx, offs)); | ||
} | ||
|
||
for (int i = 0; i < _abi->_vector_return_registers.length(); i++) { | ||
ssize_t offs = _layout->returns_vector + i * float_reg_size; | ||
__ strq(_abi->_vector_return_registers.at(i), Address(Rctx, offs)); | ||
} | ||
|
||
__ leave(); | ||
__ ret(lr); | ||
|
||
__ flush(); | ||
} | ||
|
||
address ProgrammableInvoker::generate_adapter(jobject jabi, jobject jlayout) { | ||
ResourceMark rm; | ||
const ABIDescriptor abi = ForeignGlobals::parse_abi_descriptor(jabi); | ||
const BufferLayout layout = ForeignGlobals::parse_buffer_layout(jlayout); | ||
|
||
BufferBlob* _invoke_native_blob = BufferBlob::create("invoke_native_blob", native_invoker_size); | ||
|
||
CodeBuffer code2(_invoke_native_blob); | ||
ProgrammableInvoker::Generator g2(&code2, &abi, &layout); | ||
g2.generate(); | ||
code2.log_section_sizes("InvokeNativeBlob"); | ||
|
||
return _invoke_native_blob->code_begin(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: includes should be in alphabetical order