Skip to content

Commit

Permalink
Add macOS-AArch64 build and platform support code (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernhard Urban-Forster <[email protected]>
Co-authored-by: Mat Carter <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2020
1 parent f69c83a commit 82895a8
Show file tree
Hide file tree
Showing 42 changed files with 698 additions and 160 deletions.
2 changes: 1 addition & 1 deletion make/autoconf/flags-cflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ AC_DEFUN([FLAGS_SETUP_WARNINGS],
-Wunused-function -Wundef -Wunused-value -Woverloaded-virtual"
WARNINGS_ENABLE_ALL="-Wall -Wextra -Wformat=2 $WARNINGS_ENABLE_ADDITIONAL"
DISABLED_WARNINGS="unknown-warning-option unused-parameter unused"
DISABLED_WARNINGS="unknown-warning-option unused-parameter unused format-nonliteral"
if test "x$OPENJDK_TARGET_OS" = xmacosx; then
# missing-method-return-type triggers in JavaNativeFoundation framework
Expand Down
12 changes: 9 additions & 3 deletions make/autoconf/flags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,25 @@ AC_DEFUN([FLAGS_SETUP_MACOSX_VERSION],
[
# Additional macosx handling
if test "x$OPENJDK_TARGET_OS" = xmacosx; then
# The expected format for <version> is either nn.n.n or nn.nn.nn. See
# /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/AvailabilityVersions.h
# MACOSX_VERSION_MIN specifies the lowest version of Macosx that the built
# binaries should be compatible with, even if compiled on a newer version
# of the OS. It currently has a hard coded value. Setting this also limits
# exposure to API changes in header files. Bumping this is likely to
# require code changes to build.
MACOSX_VERSION_MIN=10.9.0
if test "x$OPENJDK_TARGET_CPU_ARCH" = xaarch64; then
MACOSX_VERSION_MIN=11.00.00
else
MACOSX_VERSION_MIN=10.9.0
fi
MACOSX_VERSION_MIN_NODOTS=${MACOSX_VERSION_MIN//\./}
AC_SUBST(MACOSX_VERSION_MIN)
# Setting --with-macosx-version-max=<version> makes it an error to build or
# link to macosx APIs that are newer than the given OS version. The expected
# format for <version> is either nn.n.n or nn.nn.nn. See /usr/include/AvailabilityMacros.h.
# link to macosx APIs that are newer than the given OS version.
AC_ARG_WITH([macosx-version-max], [AS_HELP_STRING([--with-macosx-version-max],
[error on use of newer functionality. @<:@macosx@:>@])],
[
Expand Down
11 changes: 8 additions & 3 deletions make/hotspot/gensrc/GensrcAdlc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ ifeq ($(call check-jvm-feature, compiler2), true)
ifeq ($(call isTargetCpuBits, 64), true)
ADLCFLAGS += -D_WIN64=1
endif
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), aarch64)
ADLCFLAGS += -DR18_RESERVED
endif
endif

ifeq ($(call isTargetOs, windows), false)
Expand All @@ -119,6 +116,14 @@ ifeq ($(call check-jvm-feature, compiler2), true)
ADLCFLAGS += -DARM=1
endif

ifeq ($(HOTSPOT_TARGET_CPU_ARCH), aarch64)
ifeq ($(call isTargetOs, windows), true)
ADLCFLAGS += -DR18_RESERVED
else ifeq ($(call isTargetOs, macosx), true)
ADLCFLAGS += -DR18_RESERVED
endif
endif

##############################################################################
# Concatenate all ad source files into a single file, which will be fed to
# adlc. Also include a #line directive at the start of every included file
Expand Down
4 changes: 3 additions & 1 deletion make/modules/java.desktop/lib/Awt2dLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBFONTMANAGER, \
CFLAGS_windows = -DCC_NOEX, \
EXTRA_HEADER_DIRS := $(LIBFONTMANAGER_EXTRA_HEADER_DIRS), \
WARNINGS_AS_ERRORS_xlc := false, \
DISABLED_WARNINGS_clang := deprecated-declarations, \
LDFLAGS := $(subst -Xlinker -z -Xlinker defs,, \
$(subst -Wl$(COMMA)-z$(COMMA)defs,,$(LDFLAGS_JDKLIB))) $(LDFLAGS_CXX_JDK) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
Expand Down Expand Up @@ -790,7 +791,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 make/modules/jdk.hotspot.agent/Lib.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ifeq ($(call isTargetOs, linux), true)
SA_CFLAGS := -D_FILE_OFFSET_BITS=64

else ifeq ($(call isTargetOs, macosx), true)
SA_CFLAGS := -Damd64 -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \
SA_CFLAGS := -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \
-mstack-alignment=16 -fPIC
LIBSA_EXTRA_SRC := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.hotspot.agent
else ifeq ($(call isTargetOs, windows), true)
Expand Down
2 changes: 1 addition & 1 deletion make/test/JtregNativeJdk.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ endif
ifeq ($(call isTargetOs, macosx), true)
BUILD_JDK_JTREG_EXCLUDE += exelauncher.c
BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libTestMainKeyWindow := -ObjC
BUILD_JDK_JTREG_LIBRARIES_LIBS_libTestMainKeyWindow := -framework JavaVM \
BUILD_JDK_JTREG_LIBRARIES_LIBS_libTestMainKeyWindow := \
-framework Cocoa -framework JavaNativeFoundation
BUILD_JDK_JTREG_EXECUTABLES_LIBS_exeJniInvocationTest := -ljli
else
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/aarch64/aarch64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ reg_def R16 ( SOC, SOC, Op_RegI, 16, r16->as_VMReg() );
reg_def R16_H ( SOC, SOC, Op_RegI, 16, r16->as_VMReg()->next());
reg_def R17 ( SOC, SOC, Op_RegI, 17, r17->as_VMReg() );
reg_def R17_H ( SOC, SOC, Op_RegI, 17, r17->as_VMReg()->next());
reg_def R18 ( SOC, SOC, Op_RegI, 18, r18_tls->as_VMReg() );
reg_def R18_H ( SOC, SOC, Op_RegI, 18, r18_tls->as_VMReg()->next());
reg_def R18 ( SOC, SOC, Op_RegI, 18, r18_reserved->as_VMReg() );
reg_def R18_H ( SOC, SOC, Op_RegI, 18, r18_reserved->as_VMReg()->next());
reg_def R19 ( SOC, SOE, Op_RegI, 19, r19->as_VMReg() );
reg_def R19_H ( SOC, SOE, Op_RegI, 19, r19->as_VMReg()->next());
reg_def R20 ( SOC, SOE, Op_RegI, 20, r20->as_VMReg() ); // caller esp
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/cpu/aarch64/c1_FrameMap_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void FrameMap::initialize() {
map_register(i, r17); r17_opr = LIR_OprFact::single_cpu(i); i++;
#ifndef R18_RESERVED
// See comment in register_aarch64.hpp
map_register(i, r18_tls); r18_opr = LIR_OprFact::single_cpu(i); i++;
map_register(i, r18_reserved); r18_opr = LIR_OprFact::single_cpu(i); i++;
#endif
map_register(i, r19); r19_opr = LIR_OprFact::single_cpu(i); i++;
map_register(i, r20); r20_opr = LIR_OprFact::single_cpu(i); i++;
Expand All @@ -204,7 +204,7 @@ void FrameMap::initialize() {

#ifdef R18_RESERVED
// See comment in register_aarch64.hpp
map_register(i, r18_tls); r18_opr = LIR_OprFact::single_cpu(i); i++;
map_register(i, r18_reserved); r18_opr = LIR_OprFact::single_cpu(i); i++;
#endif

rscratch1_opr = r8_opr;
Expand Down Expand Up @@ -264,7 +264,7 @@ void FrameMap::initialize() {
r15_oop_opr = as_oop_opr(r15);
r16_oop_opr = as_oop_opr(r16);
r17_oop_opr = as_oop_opr(r17);
r18_oop_opr = as_oop_opr(r18_tls);
r18_oop_opr = as_oop_opr(r18_reserved);
r19_oop_opr = as_oop_opr(r19);
r20_oop_opr = as_oop_opr(r20);
r21_oop_opr = as_oop_opr(r21);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/globalDefinitions_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const bool CCallingConventionRequiresIntsAsLongs = false;

#define COMPRESSED_CLASS_POINTERS_DEPENDS_ON_COMPRESSED_OOPS false

#if defined(_WIN64)
#if defined(__APPLE__) || defined(_WIN64)
#define R18_RESERVED
#define R18_RESERVED_ONLY(code) code
#define NOT_R18_RESERVED(code)
Expand Down
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 @@ -2648,7 +2648,7 @@ void MacroAssembler::debug64(char* msg, int64_t pc, int64_t regs[])
RegSet MacroAssembler::call_clobbered_registers() {
RegSet regs = RegSet::range(r0, r17) - RegSet::of(rscratch1, rscratch2);
#ifndef R18_RESERVED
regs += r18_tls;
regs += r18_reserved;
#endif
return regs;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/register_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const char* RegisterImpl::name() const {
"c_rarg0", "c_rarg1", "c_rarg2", "c_rarg3", "c_rarg4", "c_rarg5", "c_rarg6", "c_rarg7",
"rscratch1", "rscratch2",
"r10", "r11", "r12", "r13", "r14", "r15", "r16",
"r17", "r18_tls", "r19",
"r17", "r18_reserved", "r19",
"resp", "rdispatch", "rbcp", "r23", "rlocals", "rmonitors", "rcpool", "rheapbase",
"rthread", "rfp", "lr", "sp"
};
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/register_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CONSTANT_REGISTER_DECLARATION(Register, r17, (17));
// It's easier to avoid allocating r18 altogether.
//
// See https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=vs-2019#integer-registers
CONSTANT_REGISTER_DECLARATION(Register, r18_tls, (18));
CONSTANT_REGISTER_DECLARATION(Register, r18_reserved, (18));
CONSTANT_REGISTER_DECLARATION(Register, r19, (19));
CONSTANT_REGISTER_DECLARATION(Register, r20, (20));
CONSTANT_REGISTER_DECLARATION(Register, r21, (21));
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/register_definitions_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ REGISTER_DEFINITION(Register, r14);
REGISTER_DEFINITION(Register, r15);
REGISTER_DEFINITION(Register, r16);
REGISTER_DEFINITION(Register, r17);
REGISTER_DEFINITION(Register, r18_tls); // see comment in register_aarch64.hpp
REGISTER_DEFINITION(Register, r18_reserved); // see comment in register_aarch64.hpp
REGISTER_DEFINITION(Register, r19);
REGISTER_DEFINITION(Register, r20);
REGISTER_DEFINITION(Register, r21);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5069,7 +5069,7 @@ class StubGenerator: public StubCodeGenerator {

// Register allocation

RegSetIterator regs = (RegSet::range(r0, r26) - r18_tls).begin();
RegSetIterator regs = (RegSet::range(r0, r26) - r18_reserved).begin();
Pa_base = *regs; // Argument registers
if (squaring)
Pb_base = Pa_base;
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/aarch64/vm_version_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class VM_Version : public Abstract_VM_Version {
CPU_QUALCOM = 'Q',
CPU_MARVELL = 'V',
CPU_INTEL = 'i',
CPU_APPLE = 'a',
};

enum Feature_Flag {
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ static char cpu_arch[] = "arm";
static char cpu_arch[] = "aarch64";
#elif defined(PPC32)
static char cpu_arch[] = "ppc";
#elif defined(AARCH64)
static char cpu_arch[] = "aarch64";
#else
#error Add appropriate cpu_arch setting
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/posix/signals_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ void PosixSignals::install_signal_handlers() {
// exception handling, while leaving the standard BSD signal handlers functional.
kern_return_t kr;
kr = task_set_exception_ports(mach_task_self(),
EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC,
EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC,
MACH_PORT_NULL,
EXCEPTION_STATE_IDENTITY,
MACHINE_THREAD_STATE);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os_cpu/bsd_aarch64/icache_bsd_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ class ICache : public AbstractICache {
}
};

#endif // OS_CPU_BSD_AARCH64_ICACHE_AARCH64_HPP
#endif // OS_CPU_BSD_AARCH64_ICACHE_AARCH64_HPP
49 changes: 49 additions & 0 deletions src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#define context_sp uc_mcontext->DU3_PREFIX(ss,sp)
#define context_pc uc_mcontext->DU3_PREFIX(ss,pc)
#define context_cpsr uc_mcontext->DU3_PREFIX(ss,cpsr)
#define context_esr uc_mcontext->DU3_PREFIX(es,esr)

address os::current_stack_pointer() {
#if defined(__clang__) || defined(__llvm__)
Expand Down Expand Up @@ -463,6 +464,50 @@ PRAGMA_DIAG_POP
}
}

#if defined(ASSERT) && defined(__APPLE__)
// Execution protection violation
//
// This should be kept as the last step in the triage. We don't
// have a dedicated trap number for a no-execute fault, so be
// conservative and allow other handlers the first shot.
if (UnguardOnExecutionViolation > 0 &&
(sig == SIGBUS)) {
static __thread address last_addr = (address) -1;

address addr = (address) info->si_addr;
address pc = os::Bsd::ucontext_get_pc(uc);

if (pc != addr && uc->context_esr == 0x9200004F) { //TODO: figure out what this value means
// We are faulting trying to write a R-X page
pthread_jit_write_protect_np(false);

log_debug(os)("Writing protection violation "
"at " INTPTR_FORMAT
", unprotecting", p2i(addr));

stub = pc;

last_addr = (address) -1;
} else if (pc == addr && uc->context_esr == 0x8200000f) { //TODO: figure out what this value means
// We are faulting trying to execute a RW- page

if (addr != last_addr) {
pthread_jit_write_protect_np(true);

log_debug(os)("Execution protection violation "
"at " INTPTR_FORMAT
", protecting", p2i(addr));

stub = pc;

// Set last_addr so if we fault again at the same address, we don't end
// up in an endless loop.
last_addr = addr;
}
}
}
#endif

if (stub != NULL) {
// save all thread context in case we need to restore it
if (thread != NULL) thread->set_saved_exception_pc(pc);
Expand Down Expand Up @@ -756,6 +801,10 @@ int os::extra_bang_size_in_bytes() {
return 0;
}

void os::current_thread_enable_wx_impl(WXMode mode) {
pthread_jit_write_protect_np(mode == WXExec);
}

extern "C" {
int SpinPause() {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

private:

static void current_thread_enable_wx_impl(WXMode mode) { }
static void current_thread_enable_wx_impl(WXMode mode);

public:

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/os_cpu/bsd_aarch64/thread_bsd_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ frame JavaThread::pd_last_frame() {
// currently interrupted by SIGPROF
bool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr,
void* ucontext, bool isInJava) {

assert(Thread::current() == this, "caller must be current thread");
return pd_get_top_frame(fr_addr, ucontext, isInJava);
}
Expand Down Expand Up @@ -80,7 +79,8 @@ bool JavaThread::pd_get_top_frame(frame* fr_addr, void* ucontext, bool isInJava)

frame ret_frame(ret_sp, ret_fp, addr);
if (!ret_frame.safe_for_sender(jt)) {
#ifdef COMPILER2
#if COMPILER2_OR_JVMCI
// C2 and JVMCI use ebp as a general register see if NULL fp helps
frame ret_frame2(ret_sp, NULL, addr);
if (!ret_frame2.safe_for_sender(jt)) {
// nothing else to try if the frame isn't good
Expand All @@ -90,7 +90,7 @@ bool JavaThread::pd_get_top_frame(frame* fr_addr, void* ucontext, bool isInJava)
#else
// nothing else to try if the frame isn't good
return false;
#endif /* COMPILER2 */
#endif // COMPILER2_OR_JVMCI
}
*fr_addr = ret_frame;
return true;
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/os_cpu/bsd_aarch64/thread_bsd_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
bool isInJava);

bool pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, bool isInJava);

private:
bool pd_get_top_frame(frame* fr_addr, void* ucontext, bool isInJava);
public:
Expand Down
5 changes: 4 additions & 1 deletion src/hotspot/os_cpu/bsd_aarch64/vm_version_bsd_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "runtime/os.hpp"
#include "runtime/vm_version.hpp"


int VM_Version::get_current_sve_vector_length() {
ShouldNotReachHere();
return -1;
Expand All @@ -39,4 +38,8 @@ int VM_Version::set_and_get_current_sve_vector_lenght(int length) {
}

void VM_Version::get_os_cpu_info() {
_icache_line_size = _dcache_line_size = 64;

// Disable DC ZVA
_zva_length = -1;
}
2 changes: 2 additions & 0 deletions src/hotspot/share/c1/c1_Runtime1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,8 @@ JRT_END
void Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id) {
NOT_PRODUCT(_patch_code_slowcase_cnt++);

Thread::WXWriteFromExecSetter wx_write;

if (TracePatching) {
tty->print_cr("Deoptimizing because patch is needed");
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ const intx ObjectAlignmentInBytes = 8;
"Bypass Win32 file system criteria checks (Windows Only)") \
\
product(intx, UnguardOnExecutionViolation, 0, \
"Unguard page and retry on no-execute fault (Win32 only) " \
"Unguard page and retry on no-execute fault " \
"0=off, 1=conservative, 2=aggressive") \
range(0, 2) \
\
Expand Down
Loading

0 comments on commit 82895a8

Please sign in to comment.