Skip to content

Commit

Permalink
Merge remote-tracking branch 'jdk-sandbox/JEP-391-branch' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry committed Oct 9, 2020
2 parents 52e45a3 + 8ab282d commit f69c83a
Show file tree
Hide file tree
Showing 85 changed files with 2,519 additions and 86 deletions.
174 changes: 163 additions & 11 deletions src/hotspot/cpu/aarch64/interpreterRT_aarch64.cpp
Expand Up @@ -38,6 +38,30 @@

#define __ _masm->

//describe amount of space in bytes occupied by type on native stack
#ifdef __APPLE__
const int nativeByteSpace = sizeof(jbyte);
const int nativeShortSpace = sizeof(jshort);
const int nativeIntSpace = sizeof(jint);
const int nativeLongSpace = wordSize;
const int nativeFloatSpace = nativeIntSpace;
const int nativeDoubleSpace = nativeLongSpace;
#else
const int nativeByteSpace = wordSize;
const int nativeShortSpace = wordSize;
const int nativeIntSpace = wordSize;
const int nativeLongSpace = wordSize;
const int nativeFloatSpace = nativeIntSpace;
const int nativeDoubleSpace = nativeLongSpace;
#endif

template <typename T>
static inline void store_and_inc(char* &to, T value, int inc_size) {
to = align_up(to, inc_size);
*(T *)to = value;
to = to + inc_size;
}

// Implementation of SignatureHandlerGenerator
Register InterpreterRuntime::SignatureHandlerGenerator::from() { return rlocals; }
Register InterpreterRuntime::SignatureHandlerGenerator::to() { return sp; }
Expand All @@ -51,6 +75,95 @@ InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(
_stack_offset = 0;
}

// On macos/aarch64 native stack is packed, int/float are using only 4 bytes
// on stack. Natural alignment for types are still in place,
// for example double/long should be 8 bytes alligned

void InterpreterRuntime::SignatureHandlerGenerator::pass_byte() {
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));

switch (_num_int_args) {
case 0:
__ ldr(c_rarg1, src);
_num_int_args++;
break;
case 1:
__ ldr(c_rarg2, src);
_num_int_args++;
break;
case 2:
__ ldr(c_rarg3, src);
_num_int_args++;
break;
case 3:
__ ldr(c_rarg4, src);
_num_int_args++;
break;
case 4:
__ ldr(c_rarg5, src);
_num_int_args++;
break;
case 5:
__ ldr(c_rarg6, src);
_num_int_args++;
break;
case 6:
__ ldr(c_rarg7, src);
_num_int_args++;
break;
default:
__ ldrb(r0, src);
__ strb(r0, Address(to(), _stack_offset));
_stack_offset += nativeByteSpace;

_num_int_args++;
break;
}
}

void InterpreterRuntime::SignatureHandlerGenerator::pass_short() {
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));

switch (_num_int_args) {
case 0:
__ ldr(c_rarg1, src);
_num_int_args++;
break;
case 1:
__ ldr(c_rarg2, src);
_num_int_args++;
break;
case 2:
__ ldr(c_rarg3, src);
_num_int_args++;
break;
case 3:
__ ldr(c_rarg4, src);
_num_int_args++;
break;
case 4:
__ ldr(c_rarg5, src);
_num_int_args++;
break;
case 5:
__ ldr(c_rarg6, src);
_num_int_args++;
break;
case 6:
__ ldr(c_rarg7, src);
_num_int_args++;
break;
default:
_stack_offset = align_up(_stack_offset, nativeShortSpace);
__ ldrh(r0, src);
__ strh(r0, Address(to(), _stack_offset));
_stack_offset += nativeShortSpace;

_num_int_args++;
break;
}
}

void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));

Expand Down Expand Up @@ -84,9 +197,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
_num_int_args++;
break;
default:
_stack_offset = align_up(_stack_offset, nativeIntSpace);
__ ldr(r0, src);
__ str(r0, Address(to(), _stack_offset));
_stack_offset += wordSize;
_stack_offset += nativeIntSpace;
_num_int_args++;
break;
}
Expand Down Expand Up @@ -125,9 +239,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
_num_int_args++;
break;
default:
_stack_offset = align_up(_stack_offset, nativeLongSpace);
__ ldr(r0, src);
__ str(r0, Address(to(), _stack_offset));
_stack_offset += wordSize;
_stack_offset += nativeLongSpace;
_num_int_args++;
break;
}
Expand All @@ -139,9 +254,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
if (_num_fp_args < Argument::n_float_register_parameters_c) {
__ ldrs(as_FloatRegister(_num_fp_args++), src);
} else {
_stack_offset = align_up(_stack_offset, nativeFloatSpace);
__ ldrw(r0, src);
__ strw(r0, Address(to(), _stack_offset));
_stack_offset += wordSize;
_stack_offset += nativeFloatSpace;
_num_fp_args++;
}
}
Expand All @@ -152,9 +268,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
if (_num_fp_args < Argument::n_float_register_parameters_c) {
__ ldrd(as_FloatRegister(_num_fp_args++), src);
} else {
_stack_offset = align_up(_stack_offset, nativeDoubleSpace);
__ ldr(r0, src);
__ str(r0, Address(to(), _stack_offset));
_stack_offset += wordSize;
_stack_offset += nativeDoubleSpace;
_num_fp_args++;
}
}
Expand Down Expand Up @@ -247,6 +364,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
__ cbnz(temp(), L);
__ mov(r0, zr);
__ bind(L);
_stack_offset = align_up(_stack_offset, wordSize);
__ str(r0, Address(to(), _stack_offset));
_stack_offset += wordSize;
_num_int_args++;
Expand Down Expand Up @@ -276,13 +394,45 @@ class SlowSignatureHandler
: public NativeSignatureIterator {
private:
address _from;
intptr_t* _to;
char* _to;
intptr_t* _int_args;
intptr_t* _fp_args;
intptr_t* _fp_identifiers;
unsigned int _num_int_args;
unsigned int _num_fp_args;


virtual void pass_byte()
{
NOT_MACOS(return pass_int();)
jbyte from_obj = *(jbyte *)(_from+Interpreter::local_offset_in_bytes(0));
_from -= Interpreter::stackElementSize;

if (_num_int_args < Argument::n_int_register_parameters_c-1) {
*_int_args++ = from_obj;
_num_int_args++;
} else {
store_and_inc(_to, from_obj, nativeByteSpace);

_num_int_args++;
}
}

virtual void pass_short()
{
NOT_MACOS(return pass_int();)
jshort from_obj = *(jshort *)(_from+Interpreter::local_offset_in_bytes(0));
_from -= Interpreter::stackElementSize;

if (_num_int_args < Argument::n_int_register_parameters_c-1) {
*_int_args++ = from_obj;
_num_int_args++;
} else {
store_and_inc(_to, from_obj, nativeShortSpace);

_num_int_args++;
}
}
virtual void pass_int()
{
jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
Expand All @@ -292,7 +442,8 @@ class SlowSignatureHandler
*_int_args++ = from_obj;
_num_int_args++;
} else {
*_to++ = from_obj;
store_and_inc(_to, from_obj, nativeIntSpace);

_num_int_args++;
}
}
Expand All @@ -306,7 +457,7 @@ class SlowSignatureHandler
*_int_args++ = from_obj;
_num_int_args++;
} else {
*_to++ = from_obj;
store_and_inc(_to, from_obj, nativeLongSpace);
_num_int_args++;
}
}
Expand All @@ -320,7 +471,7 @@ class SlowSignatureHandler
*_int_args++ = (*from_addr == 0) ? NULL : (intptr_t)from_addr;
_num_int_args++;
} else {
*_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr;
store_and_inc(_to, (*from_addr == 0) ? (intptr_t)NULL : (intptr_t) from_addr, wordSize);
_num_int_args++;
}
}
Expand All @@ -334,7 +485,8 @@ class SlowSignatureHandler
*_fp_args++ = from_obj;
_num_fp_args++;
} else {
*_to++ = from_obj;
store_and_inc(_to, from_obj, nativeFloatSpace);

_num_fp_args++;
}
}
Expand All @@ -349,7 +501,7 @@ class SlowSignatureHandler
*_fp_identifiers |= (1ull << _num_fp_args); // mark as double
_num_fp_args++;
} else {
*_to++ = from_obj;
store_and_inc(_to, from_obj, nativeDoubleSpace);
_num_fp_args++;
}
}
Expand All @@ -359,7 +511,7 @@ class SlowSignatureHandler
: NativeSignatureIterator(method)
{
_from = from;
_to = to;
_to = (char *)to;

_int_args = to - (method->is_static() ? 16 : 17);
_fp_args = to - 8;
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/aarch64/interpreterRT_aarch64.hpp
Expand Up @@ -38,6 +38,8 @@ class SignatureHandlerGenerator: public NativeSignatureIterator {
unsigned int _num_int_args;
int _stack_offset;

void pass_byte();
void pass_short();
void pass_int();
void pass_long();
void pass_float();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
Expand Up @@ -5243,7 +5243,7 @@ void MacroAssembler::char_array_compress(Register src, Register dst, Register le
// aarch64_get_thread_helper() clobbers only r0, r1, and flags.
//
void MacroAssembler::get_thread(Register dst) {
RegSet saved_regs = RegSet::range(r0, r1) + lr - dst;
RegSet saved_regs = RegSet::range(r0, r1) + BSD_ONLY(RegSet::range(r2, r17)) + lr - dst;
push(saved_regs, sp);

mov(lr, CAST_FROM_FN_PTR(address, JavaThread::aarch64_get_thread_helper));
Expand Down
14 changes: 14 additions & 0 deletions src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp
Expand Up @@ -801,6 +801,11 @@ int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
if (int_args < Argument::n_int_register_parameters_c) {
regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
} else {
#ifdef __APPLE__
// Less-than word types are stored one after another.
// The code unable to handle this, bailout.
return -1;
#endif
regs[i].set1(VMRegImpl::stack2reg(stk_args));
stk_args += 2;
}
Expand All @@ -823,6 +828,11 @@ int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
if (fp_args < Argument::n_float_register_parameters_c) {
regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
} else {
#ifdef __APPLE__
// Less-than word types are stored one after another.
// The code unable to handle this, bailout.
return -1;
#endif
regs[i].set1(VMRegImpl::stack2reg(stk_args));
stk_args += 2;
}
Expand Down Expand Up @@ -1384,6 +1394,10 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
int out_arg_slots;
out_arg_slots = c_calling_convention(out_sig_bt, out_regs, NULL, total_c_args);

if (out_arg_slots < 0) {
return NULL;
}

// Compute framesize for the wrapper. We need to handlize all oops in
// incoming registers

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os/aix/os_aix.cpp
Expand Up @@ -1976,7 +1976,7 @@ void os::pd_commit_memory_or_exit(char* addr, size_t size,
pd_commit_memory_or_exit(addr, size, exec, mesg);
}

bool os::pd_uncommit_memory(char* addr, size_t size) {
bool os::pd_uncommit_memory(char* addr, size_t size, bool exec) {
assert(is_aligned_to(addr, os::vm_page_size()),
"addr " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
p2i(addr), os::vm_page_size());
Expand Down Expand Up @@ -2053,7 +2053,7 @@ char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info
}

// Reserves and attaches a shared memory segment.
char* os::pd_reserve_memory(size_t bytes) {
char* os::pd_reserve_memory(size_t bytes, bool executable) {
// Always round to os::vm_page_size(), which may be larger than 4K.
bytes = align_up(bytes, os::vm_page_size());

Expand Down

0 comments on commit f69c83a

Please sign in to comment.