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

Implementation of JEP 391: macOS/AArch64 Port #29

Open
wants to merge 28 commits into
base: macos-aarch64
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b58c2b8
8253015: Aarch64: Move linux code out from generic CPU feature detection
GlebSolovev Nov 28, 2021
f96bf9f
fixup! 8253015: Aarch64: Move linux code out from generic CPU feature…
GlebSolovev Nov 28, 2021
113106c
8255716: AArch64: Regression: JVM crashes if manually offline a core
GlebSolovev Nov 28, 2021
dfce581
8255799: AArch64: CPU_A53MAC feature may be set incorrectly
GlebSolovev Nov 28, 2021
904b9d4
JDK-8253819: Copy files from linux_aarch64
KaperD Dec 10, 2021
bd0fa05
JDK-8253819: Change names in defines
KaperD Dec 1, 2021
f2e78c1
JDK-8253819: pick 5e4dae92d17
KaperD Dec 10, 2021
7ec9fd6
JDK-8253819: remove functions for sve
KaperD Dec 8, 2021
3f46bc5
JDK-8253819: return removed fuctions
KaperD Dec 8, 2021
897c0e4
JDK-8253819: change address to ExtendedPC
KaperD Dec 8, 2021
5295934
JDK-8253819: change address to ExtendPC and change stackoverflow
KaperD Dec 8, 2021
df1d239
JDK-8253819: add is_cpu_emulated method
AntonKozlov Mar 25, 2021
bedc1be
JDK-8253819: Add cast to long
KaperD Dec 8, 2021
2eca5b4
JDK-8253819: Suppress deprecated-declarations
KaperD Dec 8, 2021
56bfb49
JDK-8253817: Support macOS Aarch64 ABI in Interpreter
AntonKozlov Mar 25, 2021
aa22394
JDK-8253817: fixup! Support macOS Aarch64 ABI in Interpreter
KaperD Dec 9, 2021
3bde285
JDK-8253817: take change from Pull/2020 (#5)
VladimirKempik Feb 15, 2021
d799fb8
JDK-8254941: Implement Serviceability Agent for macOS/AArch64
AntonKozlov Mar 25, 2021
2319f63
JDK-8254941: fixup! Implement Serviceability Agent for macOS/AArch64
KaperD Dec 9, 2021
5a6ba22
JDK-8253839: Update tests and JDK code for macOS/Aarch64
AntonKozlov Mar 25, 2021
d5ee91d
JDK-8253839: fixup! Update tests and JDK code for macOS/Aarch64
KaperD Dec 9, 2021
fb5d431
JDK-8253839: Disable aot on macarm until it's ready
KaperD Dec 9, 2021
33d2ca4
JDK-8253839: Fix NativeCallStack for aarch64
KaperD Dec 9, 2021
ec56a5d
JDK-8253816: Support macOS W^X
AntonKozlov Mar 25, 2021
05d37e5
JDK-8253816: fixup! Support macOS W^X
KaperD Dec 9, 2021
ef9e10d
Backport 283d64f81531ec3edc156f13278a9a284445b61d
KaperD Dec 9, 2021
3a42fed
Quick fix backport
KaperD Dec 9, 2021
cfe786d
Change static_assert to STATIC_ASSERT, remove MACOS_AARCH64_ONLY and …
KaperD Jan 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions make/autoconf/jvm-features.m4
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ AC_DEFUN_ONCE([JVM_FEATURES_CHECK_AOT],
JVM_FEATURES_CHECK_AVAILABILITY(aot, [
AC_MSG_CHECKING([if platform is supported by AOT])
# AOT is only available where JVMCI is available since it requires JVMCI.
if test "x$OPENJDK_TARGET_CPU" = "xx86_64" || \
test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
if test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
AC_MSG_RESULT([yes])
elif test "x$OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU" = "xlinux-aarch64"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
Expand Down
3 changes: 2 additions & 1 deletion make/modules/java.desktop/lib/Awt2dLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
DISABLED_WARNINGS_gcc := sign-compare type-limits unused-result \
maybe-uninitialized shift-negative-value implicit-fallthrough \
unused-function, \
DISABLED_WARNINGS_clang := incompatible-pointer-types sign-compare, \
DISABLED_WARNINGS_clang := incompatible-pointer-types sign-compare \
deprecated-declarations, \
DISABLED_WARNINGS_microsoft := 4018 4244 4267, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/assembler_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class Address {
static bool offset_ok_for_immed(int64_t offset, int shift) {
unsigned mask = (1 << shift) - 1;
if (offset < 0 || offset & mask) {
return (uabs(offset) < (1 << (20 - 12))); // Unscaled offset
return (uabs((long)offset) < (1 << (20 - 12))); // Unscaled offset
} else {
return ((offset >> shift) < (1 << (21 - 10 + 1))); // Scaled, unsigned offset
}
Expand Down
82 changes: 65 additions & 17 deletions src/hotspot/cpu/aarch64/interpreterRT_aarch64.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
* Copyright (c) 2021, Azul Systems, Inc. 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
Expand Down Expand Up @@ -57,9 +58,14 @@ FloatRegister InterpreterRuntime::SignatureHandlerGenerator::next_fpr() {
return fnoreg;
}

int InterpreterRuntime::SignatureHandlerGenerator::next_stack_offset() {
// 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 aligned.

int InterpreterRuntime::SignatureHandlerGenerator::next_stack_offset(unsigned elem_size) {
MACOS_ONLY(_stack_offset = align_up(_stack_offset, elem_size));
int ret = _stack_offset;
_stack_offset += wordSize;
_stack_offset += NOT_MACOS(wordSize) MACOS_ONLY(elem_size);
return ret;
}

Expand All @@ -71,6 +77,30 @@ InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(
_stack_offset = 0;
}

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

Register reg = next_gpr();
if (reg != noreg) {
__ ldr(reg, src);
} else {
__ ldrb(r0, src);
__ strb(r0, Address(to(), next_stack_offset(sizeof(jbyte))));
}
}

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

Register reg = next_gpr();
if (reg != noreg) {
__ ldr(reg, src);
} else {
__ ldrh(r0, src);
__ strh(r0, Address(to(), next_stack_offset(sizeof(jshort))));
}
}

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

Expand All @@ -79,7 +109,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
__ ldr(reg, src);
} else {
__ ldrw(r0, src);
__ strw(r0, Address(to(), next_stack_offset()));
__ strw(r0, Address(to(), next_stack_offset(sizeof(jint))));
}
}

Expand All @@ -91,7 +121,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
__ ldr(reg, src);
} else {
__ ldr(r0, src);
__ str(r0, Address(to(), next_stack_offset()));
__ str(r0, Address(to(), next_stack_offset(sizeof(jlong))));
}
}

Expand All @@ -103,7 +133,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
__ ldrs(reg, src);
} else {
__ ldrw(r0, src);
__ strw(r0, Address(to(), next_stack_offset()));
__ strw(r0, Address(to(), next_stack_offset(sizeof(jfloat))));
}
}

Expand All @@ -115,7 +145,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
__ ldrd(reg, src);
} else {
__ ldr(r0, src);
__ str(r0, Address(to(), next_stack_offset()));
__ str(r0, Address(to(), next_stack_offset(sizeof(jdouble))));
}
}

Expand All @@ -139,7 +169,8 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
__ cbnz(temp(), L);
__ mov(r0, zr);
__ bind(L);
__ str(r0, Address(to(), next_stack_offset()));
static_assert(sizeof(jobject) == wordSize, "");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ой, вот тут нужно изменить на STATIC_ASSERT

__ str(r0, Address(to(), next_stack_offset(sizeof(jobject))));
}
}

Expand All @@ -164,7 +195,7 @@ class SlowSignatureHandler
: public NativeSignatureIterator {
private:
address _from;
intptr_t* _to;
char* _to;
intptr_t* _int_args;
intptr_t* _fp_args;
intptr_t* _fp_identifiers;
Expand Down Expand Up @@ -199,36 +230,53 @@ class SlowSignatureHandler
return -1;
}

void pass_stack(intptr_t value) {
*_to++ = value;
template<typename T>
void pass_stack(T value) {
MACOS_ONLY(_to = align_up(_to, sizeof(value)));
*(T *)_to = value;
_to += NOT_MACOS(wordSize) MACOS_ONLY(sizeof(value));
}

virtual void pass_byte() {
jbyte value = *(jbyte*)single_slot_addr();
if (pass_gpr(value) < 0) {
pass_stack<>(value);
}
}

virtual void pass_short() {
jshort value = *(jshort*)single_slot_addr();
if (pass_gpr(value) < 0) {
pass_stack<>(value);
}
}

virtual void pass_int() {
jint value = *(jint*)single_slot_addr();
if (pass_gpr(value) < 0) {
pass_stack(value);
pass_stack<>(value);
}
}

virtual void pass_long() {
intptr_t value = *double_slot_addr();
if (pass_gpr(value) < 0) {
pass_stack(value);
pass_stack<>(value);
}
}

virtual void pass_object() {
intptr_t* addr = single_slot_addr();
intptr_t value = *addr == 0 ? NULL : (intptr_t)addr;
if (pass_gpr(value) < 0) {
pass_stack(value);
pass_stack<>(value);
}
}

virtual void pass_float() {
jint value = *(jint*)single_slot_addr();
if (pass_fpr(value) < 0) {
pass_stack(value);
pass_stack<>(value);
}
}

Expand All @@ -238,7 +286,7 @@ class SlowSignatureHandler
if (0 <= arg) {
*_fp_identifiers |= (1ull << arg); // mark as double
} else {
pass_stack(value);
pass_stack<>(value);
}
}

Expand All @@ -247,7 +295,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
7 changes: 5 additions & 2 deletions src/hotspot/cpu/aarch64/interpreterRT_aarch64.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* Copyright (c) 2021, Azul Systems, Inc. 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
Expand Down Expand Up @@ -38,6 +39,8 @@ class SignatureHandlerGenerator: public NativeSignatureIterator {
unsigned int _num_reg_int_args;
int _stack_offset;

void pass_byte();
void pass_short();
void pass_int();
void pass_long();
void pass_float();
Expand All @@ -46,7 +49,7 @@ class SignatureHandlerGenerator: public NativeSignatureIterator {

Register next_gpr();
FloatRegister next_fpr();
int next_stack_offset();
int next_stack_offset(unsigned elem_size);

public:
// Creation
Expand Down
59 changes: 51 additions & 8 deletions src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "prims/jniFastGetField.hpp"
#include "prims/jvm_misc.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/threadWXSetters.inline.hpp"

#define __ masm->

Expand All @@ -51,6 +52,48 @@ static const Register roffset = r5;
static const Register rcounter_addr = r6;
static const Register result = r7;

// On macos/aarch64 we need to ensure WXExec mode when running generated
// FastGetXXXField, as these functions can be called from WXWrite context
// (8262896). So each FastGetXXXField is wrapped into a C++ statically
// compiled template function that optionally switches to WXExec if necessary.

#ifdef __APPLE__

static address generated_fast_get_field[T_LONG + 1 - T_BOOLEAN];

template<int BType> struct BasicTypeToJni {};
template<> struct BasicTypeToJni<T_BOOLEAN> { static const jboolean jni_type; };
template<> struct BasicTypeToJni<T_BYTE> { static const jbyte jni_type; };
template<> struct BasicTypeToJni<T_CHAR> { static const jchar jni_type; };
template<> struct BasicTypeToJni<T_SHORT> { static const jshort jni_type; };
template<> struct BasicTypeToJni<T_INT> { static const jint jni_type; };
template<> struct BasicTypeToJni<T_LONG> { static const jlong jni_type; };
template<> struct BasicTypeToJni<T_FLOAT> { static const jfloat jni_type; };
template<> struct BasicTypeToJni<T_DOUBLE> { static const jdouble jni_type; };

template<int BType>
decltype(BasicTypeToJni<BType>::jni_type) static_fast_get_field_wrapper(JNIEnv *env, jobject obj, jfieldID fieldID) {
JavaThread* thread = JavaThread::thread_from_jni_environment(env);
ThreadWXEnable wx(WXExec, thread);
address get_field_addr = generated_fast_get_field[BType - T_BOOLEAN];
return ((decltype(BasicTypeToJni<BType>::jni_type)(*)(JNIEnv *env, jobject obj, jfieldID fieldID))get_field_addr)(env, obj, fieldID);
}

template<int BType>
address JNI_FastGetField::generate_fast_get_int_field1() {
generated_fast_get_field[BType - T_BOOLEAN] = generate_fast_get_int_field0((BasicType)BType);
return (address)static_fast_get_field_wrapper<BType>;
}

#else // __APPLE__

template<int BType>
address JNI_FastGetField::generate_fast_get_int_field1() {
return generate_fast_get_int_field0((BasicType)BType);
}

#endif // __APPLE__

address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
const char *name;
switch (type) {
Expand Down Expand Up @@ -168,33 +211,33 @@ address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
}

address JNI_FastGetField::generate_fast_get_boolean_field() {
return generate_fast_get_int_field0(T_BOOLEAN);
return generate_fast_get_int_field1<T_BOOLEAN>();
}

address JNI_FastGetField::generate_fast_get_byte_field() {
return generate_fast_get_int_field0(T_BYTE);
return generate_fast_get_int_field1<T_BYTE>();
}

address JNI_FastGetField::generate_fast_get_char_field() {
return generate_fast_get_int_field0(T_CHAR);
return generate_fast_get_int_field1<T_CHAR>();
}

address JNI_FastGetField::generate_fast_get_short_field() {
return generate_fast_get_int_field0(T_SHORT);
return generate_fast_get_int_field1<T_SHORT>();
}

address JNI_FastGetField::generate_fast_get_int_field() {
return generate_fast_get_int_field0(T_INT);
return generate_fast_get_int_field1<T_INT>();
}

address JNI_FastGetField::generate_fast_get_long_field() {
return generate_fast_get_int_field0(T_LONG);
return generate_fast_get_int_field1<T_LONG>();
}

address JNI_FastGetField::generate_fast_get_float_field() {
return generate_fast_get_int_field0(T_FLOAT);
return generate_fast_get_int_field1<T_FLOAT>();
}

address JNI_FastGetField::generate_fast_get_double_field() {
return generate_fast_get_int_field0(T_DOUBLE);
return generate_fast_get_int_field1<T_DOUBLE>();
}
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5258,7 +5258,7 @@ void MacroAssembler::cache_wb(Address line) {
assert(line.offset() == 0, "offset should be 0");
// would like to assert this
// assert(line._ext.shift == 0, "shift should be zero");
if (VM_Version::supports_dcpop()) {
if (VM_Version::features() & VM_Version::CPU_DCPOP) {
// writeback using clear virtual address to point of persistence
dc(Assembler::CVAP, line.base());
} else {
Expand Down
Loading