8254231: Implementation of Foreign Linker API (Incubator)

Reviewed-by: coleenp, ihse, dholmes, vlivanov
This commit is contained in:
Maurizio Cimadamore 2020-11-23 11:00:38 +00:00
parent 53f38353e0
commit 0fb31dbf3a
212 changed files with 67390 additions and 179 deletions

View file

@ -65,8 +65,10 @@
#include "runtime/sweeper.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/align.hpp"
#include "utilities/copy.hpp"
#include "utilities/dtrace.hpp"
#include "utilities/events.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/resourceHash.hpp"
#include "utilities/xmlstream.hpp"
#if INCLUDE_JVMCI
@ -496,7 +498,8 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
ExceptionHandlerTable* handler_table,
ImplicitExceptionTable* nul_chk_table,
AbstractCompiler* compiler,
int comp_level
int comp_level,
const GrowableArrayView<BufferBlob*>& native_invokers
#if INCLUDE_JVMCI
, char* speculations,
int speculations_len,
@ -518,6 +521,7 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
CodeBlob::allocation_size(code_buffer, sizeof(nmethod))
+ adjust_pcs_size(debug_info->pcs_size())
+ align_up((int)dependencies->size_in_bytes(), oopSize)
+ align_up(checked_cast<int>(native_invokers.data_size_in_bytes()), oopSize)
+ align_up(handler_table->size_in_bytes() , oopSize)
+ align_up(nul_chk_table->size_in_bytes() , oopSize)
#if INCLUDE_JVMCI
@ -533,7 +537,8 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
handler_table,
nul_chk_table,
compiler,
comp_level
comp_level,
native_invokers
#if INCLUDE_JVMCI
, speculations,
speculations_len,
@ -621,7 +626,8 @@ nmethod::nmethod(
scopes_data_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize);
_scopes_pcs_offset = scopes_data_offset;
_dependencies_offset = _scopes_pcs_offset;
_handler_table_offset = _dependencies_offset;
_native_invokers_offset = _dependencies_offset;
_handler_table_offset = _native_invokers_offset;
_nul_chk_table_offset = _handler_table_offset;
#if INCLUDE_JVMCI
_speculations_offset = _nul_chk_table_offset;
@ -717,7 +723,8 @@ nmethod::nmethod(
ExceptionHandlerTable* handler_table,
ImplicitExceptionTable* nul_chk_table,
AbstractCompiler* compiler,
int comp_level
int comp_level,
const GrowableArrayView<BufferBlob*>& native_invokers
#if INCLUDE_JVMCI
, char* speculations,
int speculations_len,
@ -794,7 +801,8 @@ nmethod::nmethod(
_scopes_pcs_offset = scopes_data_offset + align_up(debug_info->data_size (), oopSize);
_dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
_handler_table_offset = _dependencies_offset + align_up((int)dependencies->size_in_bytes (), oopSize);
_native_invokers_offset = _dependencies_offset + align_up((int)dependencies->size_in_bytes(), oopSize);
_handler_table_offset = _native_invokers_offset + align_up(checked_cast<int>(native_invokers.data_size_in_bytes()), oopSize);
_nul_chk_table_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
#if INCLUDE_JVMCI
_speculations_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
@ -816,6 +824,10 @@ nmethod::nmethod(
code_buffer->copy_values_to(this);
debug_info->copy_to(this);
dependencies->copy_to(this);
if (native_invokers.is_nonempty()) { // can not get address of zero-length array
// Copy native stubs
memcpy(native_invokers_begin(), native_invokers.adr_at(0), native_invokers.data_size_in_bytes());
}
clear_unloading_state();
Universe::heap()->register_nmethod(this);
@ -978,6 +990,10 @@ void nmethod::print_nmethod(bool printmethod) {
print_dependencies();
tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
}
if (printmethod && native_invokers_begin() < native_invokers_end()) {
print_native_invokers();
tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
}
if (printmethod || PrintExceptionHandlers) {
print_handler_table();
tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
@ -1038,6 +1054,12 @@ void nmethod::copy_values(GrowableArray<Metadata*>* array) {
}
}
void nmethod::free_native_invokers() {
for (BufferBlob** it = native_invokers_begin(); it < native_invokers_end(); it++) {
CodeCache::free(*it);
}
}
void nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) {
// re-patch all oop-bearing instructions, just in case some oops moved
RelocIterator iter(this, begin, end);
@ -2670,6 +2692,14 @@ void nmethod::print_pcs_on(outputStream* st) {
}
}
void nmethod::print_native_invokers() {
ResourceMark m; // in case methods get printed via debugger
tty->print_cr("Native invokers:");
for (BufferBlob** itt = native_invokers_begin(); itt < native_invokers_end(); itt++) {
(*itt)->print_on(tty);
}
}
void nmethod::print_handler_table() {
ExceptionHandlerTable(this).print();
}