Skip to content

Commit dbc9e4b

Browse files
AntonKozlovVladimir KempiklewurmluhenryMonica Beckwith
committed
8253795: Implementation of JEP 391: macOS/AArch64 Port
8253816: Support macOS W^X 8253817: Support macOS Aarch64 ABI in Interpreter 8253818: Support macOS Aarch64 ABI for compiled wrappers 8253819: Implement os/cpu for macOS/AArch64 8253839: Update tests and JDK code for macOS/Aarch64 8254941: Implement Serviceability Agent for macOS/AArch64 8255776: Change build system for macOS/AArch64 8262903: [macos_aarch64] Thread::current() called on detached thread Co-authored-by: Vladimir Kempik <[email protected]> Co-authored-by: Bernhard Urban-Forster <[email protected]> Co-authored-by: Ludovic Henry <[email protected]> Co-authored-by: Monica Beckwith <[email protected]> Reviewed-by: erikj, ihse, prr, cjplummer, stefank, gziemski, aph, mbeckwit, luhenry
1 parent b006f22 commit dbc9e4b

File tree

75 files changed

+2933
-109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2933
-109
lines changed

make/autoconf/build-aux/config.guess

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22
#
3-
# Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
45
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56
#
67
# This code is free software; you can redistribute it and/or modify it
@@ -101,6 +102,14 @@ if [ "x$OUT" = x ]; then
101102
fi
102103
fi
103104

105+
# Test and fix cpu on macos-aarch64, uname -p reports arm, buildsys expects aarch64
106+
echo $OUT | grep arm-apple-darwin > /dev/null 2> /dev/null
107+
if test $? = 0; then
108+
if [ `uname -m` = arm64 ]; then
109+
OUT=aarch64`echo $OUT | sed -e 's/[^-]*//'`
110+
fi
111+
fi
112+
104113
# Test and fix cpu on Macosx when C preprocessor is not on the path
105114
echo $OUT | grep i386-apple-darwin > /dev/null 2> /dev/null
106115
if test $? = 0; then

make/autoconf/flags.m4

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,25 @@ AC_DEFUN([FLAGS_SETUP_MACOSX_VERSION],
125125
[
126126
# Additional macosx handling
127127
if test "x$OPENJDK_TARGET_OS" = xmacosx; then
128+
# The expected format for <version> is either nn.n.n or nn.nn.nn. See
129+
# /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/AvailabilityVersions.h
130+
128131
# MACOSX_VERSION_MIN specifies the lowest version of Macosx that the built
129132
# binaries should be compatible with, even if compiled on a newer version
130133
# of the OS. It currently has a hard coded value. Setting this also limits
131134
# exposure to API changes in header files. Bumping this is likely to
132135
# require code changes to build.
133-
MACOSX_VERSION_MIN=10.12.0
136+
if test "x$OPENJDK_TARGET_CPU_ARCH" = xaarch64; then
137+
MACOSX_VERSION_MIN=11.00.00
138+
else
139+
MACOSX_VERSION_MIN=10.12.0
140+
fi
134141
MACOSX_VERSION_MIN_NODOTS=${MACOSX_VERSION_MIN//\./}
135142
136143
AC_SUBST(MACOSX_VERSION_MIN)
137144
138145
# Setting --with-macosx-version-max=<version> makes it an error to build or
139-
# link to macosx APIs that are newer than the given OS version. The expected
140-
# format for <version> is either nn.n.n or nn.nn.nn. See /usr/include/AvailabilityMacros.h.
146+
# link to macosx APIs that are newer than the given OS version.
141147
AC_ARG_WITH([macosx-version-max], [AS_HELP_STRING([--with-macosx-version-max],
142148
[error on use of newer functionality. @<:@macosx@:>@])],
143149
[

make/autoconf/jvm-features.m4

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -242,7 +242,7 @@ AC_DEFUN_ONCE([JVM_FEATURES_CHECK_AOT],
242242
elif test "x$OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU" = "xlinux-aarch64"; then
243243
AC_MSG_RESULT([yes])
244244
else
245-
AC_MSG_RESULT([no, $OPENJDK_TARGET_CPU])
245+
AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
246246
AVAILABLE=false
247247
fi
248248
@@ -264,11 +264,13 @@ AC_DEFUN_ONCE([JVM_FEATURES_CHECK_CDS],
264264
[
265265
JVM_FEATURES_CHECK_AVAILABILITY(cds, [
266266
AC_MSG_CHECKING([if platform is supported by CDS])
267-
if test "x$OPENJDK_TARGET_OS" != xaix; then
268-
AC_MSG_RESULT([yes])
269-
else
270-
AC_MSG_RESULT([no, $OPENJDK_TARGET_OS])
267+
if test "x$OPENJDK_TARGET_OS" = xaix || \
268+
( test "x$OPENJDK_TARGET_OS" = "xmacosx" && \
269+
test "x$OPENJDK_TARGET_CPU" = "xaarch64" ) ; then
270+
AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
271271
AVAILABLE=false
272+
else
273+
AC_MSG_RESULT([yes])
272274
fi
273275
])
274276
])

make/common/NativeCompilation.gmk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -1177,7 +1177,7 @@ define SetupNativeCompilationBody
11771177
# This only works if the openjdk_codesign identity is present on the system. Let
11781178
# silently fail otherwise.
11791179
ifneq ($(CODESIGN), )
1180-
$(CODESIGN) -s "$(MACOSX_CODESIGN_IDENTITY)" --timestamp --options runtime \
1180+
$(CODESIGN) -f -s "$(MACOSX_CODESIGN_IDENTITY)" --timestamp --options runtime \
11811181
--entitlements $$(call GetEntitlementsFile, $$@) $$@
11821182
endif
11831183
endif

make/hotspot/gensrc/GensrcAdlc.gmk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -88,6 +88,9 @@ ifeq ($(call check-jvm-feature, compiler2), true)
8888
ADLCFLAGS += -DAIX=1
8989
else ifeq ($(call isTargetOs, macosx), true)
9090
ADLCFLAGS += -D_ALLBSD_SOURCE=1 -D_GNU_SOURCE=1
91+
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), aarch64)
92+
ADLCFLAGS += -DR18_RESERVED
93+
endif
9194
else ifeq ($(call isTargetOs, windows), true)
9295
ifeq ($(call isTargetCpuBits, 64), true)
9396
ADLCFLAGS += -D_WIN64=1

make/modules/java.desktop/lib/Awt2dLibraries.gmk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ else
468468
maybe-uninitialized class-memaccess
469469
HARFBUZZ_DISABLED_WARNINGS_clang := unused-value incompatible-pointer-types \
470470
tautological-constant-out-of-range-compare int-to-pointer-cast \
471-
undef missing-field-initializers range-loop-analysis
471+
undef missing-field-initializers range-loop-analysis \
472+
deprecated-declarations c++11-narrowing
472473
HARFBUZZ_DISABLED_WARNINGS_microsoft := 4267 4244 4090 4146 4334 4819 4101 4068 4805 4138
473474

474475
LIBFONTMANAGER_CFLAGS += $(HARFBUZZ_CFLAGS)

make/modules/jdk.hotspot.agent/Lib.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ifeq ($(call isTargetOs, linux), true)
3131
SA_CFLAGS := -D_FILE_OFFSET_BITS=64
3232

3333
else ifeq ($(call isTargetOs, macosx), true)
34-
SA_CFLAGS := -Damd64 -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \
34+
SA_CFLAGS := -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \
3535
-mstack-alignment=16 -fPIC
3636
LIBSA_EXTRA_SRC := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.hotspot.agent
3737
else ifeq ($(call isTargetOs, windows), true)

src/hotspot/cpu/aarch64/globalDefinitions_aarch64.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -58,7 +58,7 @@ const bool CCallingConventionRequiresIntsAsLongs = false;
5858

5959
#define COMPRESSED_CLASS_POINTERS_DEPENDS_ON_COMPRESSED_OOPS false
6060

61-
#if defined(_WIN64)
61+
#if defined(__APPLE__) || defined(_WIN64)
6262
#define R18_RESERVED
6363
#define R18_RESERVED_ONLY(code) code
6464
#define NOT_R18_RESERVED(code)

src/hotspot/cpu/aarch64/interpreterRT_aarch64.cpp

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
2-
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
4+
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
45
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56
*
67
* This code is free software; you can redistribute it and/or modify it
@@ -57,9 +58,14 @@ FloatRegister InterpreterRuntime::SignatureHandlerGenerator::next_fpr() {
5758
return fnoreg;
5859
}
5960

60-
int InterpreterRuntime::SignatureHandlerGenerator::next_stack_offset() {
61+
// On macos/aarch64 native stack is packed, int/float are using only 4 bytes
62+
// on stack. Natural alignment for types are still in place,
63+
// for example double/long should be 8 bytes aligned.
64+
65+
int InterpreterRuntime::SignatureHandlerGenerator::next_stack_offset(unsigned elem_size) {
66+
MACOS_ONLY(_stack_offset = align_up(_stack_offset, elem_size));
6167
int ret = _stack_offset;
62-
_stack_offset += wordSize;
68+
_stack_offset += NOT_MACOS(wordSize) MACOS_ONLY(elem_size);
6369
return ret;
6470
}
6571

@@ -71,6 +77,30 @@ InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(
7177
_stack_offset = 0;
7278
}
7379

80+
void InterpreterRuntime::SignatureHandlerGenerator::pass_byte() {
81+
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));
82+
83+
Register reg = next_gpr();
84+
if (reg != noreg) {
85+
__ ldr(reg, src);
86+
} else {
87+
__ ldrb(r0, src);
88+
__ strb(r0, Address(to(), next_stack_offset(sizeof(jbyte))));
89+
}
90+
}
91+
92+
void InterpreterRuntime::SignatureHandlerGenerator::pass_short() {
93+
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));
94+
95+
Register reg = next_gpr();
96+
if (reg != noreg) {
97+
__ ldr(reg, src);
98+
} else {
99+
__ ldrh(r0, src);
100+
__ strh(r0, Address(to(), next_stack_offset(sizeof(jshort))));
101+
}
102+
}
103+
74104
void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
75105
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));
76106

@@ -79,7 +109,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
79109
__ ldr(reg, src);
80110
} else {
81111
__ ldrw(r0, src);
82-
__ strw(r0, Address(to(), next_stack_offset()));
112+
__ strw(r0, Address(to(), next_stack_offset(sizeof(jint))));
83113
}
84114
}
85115

@@ -91,7 +121,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
91121
__ ldr(reg, src);
92122
} else {
93123
__ ldr(r0, src);
94-
__ str(r0, Address(to(), next_stack_offset()));
124+
__ str(r0, Address(to(), next_stack_offset(sizeof(jlong))));
95125
}
96126
}
97127

@@ -103,7 +133,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
103133
__ ldrs(reg, src);
104134
} else {
105135
__ ldrw(r0, src);
106-
__ strw(r0, Address(to(), next_stack_offset()));
136+
__ strw(r0, Address(to(), next_stack_offset(sizeof(jfloat))));
107137
}
108138
}
109139

@@ -115,7 +145,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
115145
__ ldrd(reg, src);
116146
} else {
117147
__ ldr(r0, src);
118-
__ str(r0, Address(to(), next_stack_offset()));
148+
__ str(r0, Address(to(), next_stack_offset(sizeof(jdouble))));
119149
}
120150
}
121151

@@ -139,7 +169,8 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
139169
__ cbnz(temp(), L);
140170
__ mov(r0, zr);
141171
__ bind(L);
142-
__ str(r0, Address(to(), next_stack_offset()));
172+
static_assert(sizeof(jobject) == wordSize, "");
173+
__ str(r0, Address(to(), next_stack_offset(sizeof(jobject))));
143174
}
144175
}
145176

@@ -164,7 +195,7 @@ class SlowSignatureHandler
164195
: public NativeSignatureIterator {
165196
private:
166197
address _from;
167-
intptr_t* _to;
198+
char* _to;
168199
intptr_t* _int_args;
169200
intptr_t* _fp_args;
170201
intptr_t* _fp_identifiers;
@@ -199,36 +230,53 @@ class SlowSignatureHandler
199230
return -1;
200231
}
201232

202-
void pass_stack(intptr_t value) {
203-
*_to++ = value;
233+
template<typename T>
234+
void pass_stack(T value) {
235+
MACOS_ONLY(_to = align_up(_to, sizeof(value)));
236+
*(T *)_to = value;
237+
_to += NOT_MACOS(wordSize) MACOS_ONLY(sizeof(value));
238+
}
239+
240+
virtual void pass_byte() {
241+
jbyte value = *(jbyte*)single_slot_addr();
242+
if (pass_gpr(value) < 0) {
243+
pass_stack<>(value);
244+
}
245+
}
246+
247+
virtual void pass_short() {
248+
jshort value = *(jshort*)single_slot_addr();
249+
if (pass_gpr(value) < 0) {
250+
pass_stack<>(value);
251+
}
204252
}
205253

206254
virtual void pass_int() {
207255
jint value = *(jint*)single_slot_addr();
208256
if (pass_gpr(value) < 0) {
209-
pass_stack(value);
257+
pass_stack<>(value);
210258
}
211259
}
212260

213261
virtual void pass_long() {
214262
intptr_t value = *double_slot_addr();
215263
if (pass_gpr(value) < 0) {
216-
pass_stack(value);
264+
pass_stack<>(value);
217265
}
218266
}
219267

220268
virtual void pass_object() {
221269
intptr_t* addr = single_slot_addr();
222270
intptr_t value = *addr == 0 ? NULL : (intptr_t)addr;
223271
if (pass_gpr(value) < 0) {
224-
pass_stack(value);
272+
pass_stack<>(value);
225273
}
226274
}
227275

228276
virtual void pass_float() {
229277
jint value = *(jint*)single_slot_addr();
230278
if (pass_fpr(value) < 0) {
231-
pass_stack(value);
279+
pass_stack<>(value);
232280
}
233281
}
234282

@@ -238,7 +286,7 @@ class SlowSignatureHandler
238286
if (0 <= arg) {
239287
*_fp_identifiers |= (1ull << arg); // mark as double
240288
} else {
241-
pass_stack(value);
289+
pass_stack<>(value);
242290
}
243291
}
244292

@@ -247,7 +295,7 @@ class SlowSignatureHandler
247295
: NativeSignatureIterator(method)
248296
{
249297
_from = from;
250-
_to = to;
298+
_to = (char *)to;
251299

252300
_int_args = to - (method->is_static() ? 16 : 17);
253301
_fp_args = to - 8;

src/hotspot/cpu/aarch64/interpreterRT_aarch64.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
2-
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
4+
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
45
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56
*
67
* This code is free software; you can redistribute it and/or modify it
@@ -38,6 +39,8 @@ class SignatureHandlerGenerator: public NativeSignatureIterator {
3839
unsigned int _num_reg_int_args;
3940
int _stack_offset;
4041

42+
void pass_byte();
43+
void pass_short();
4144
void pass_int();
4245
void pass_long();
4346
void pass_float();
@@ -46,7 +49,7 @@ class SignatureHandlerGenerator: public NativeSignatureIterator {
4649

4750
Register next_gpr();
4851
FloatRegister next_fpr();
49-
int next_stack_offset();
52+
int next_stack_offset(unsigned elem_size);
5053

5154
public:
5255
// Creation

src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "asm/assembler.inline.hpp"
3030
#include "oops/compressedOops.hpp"
31+
#include "runtime/vm_version.hpp"
3132
#include "utilities/powerOfTwo.hpp"
3233

3334
// MacroAssembler extends Assembler by frequently used macros.

0 commit comments

Comments
 (0)