Skip to content

Commit eb0708f

Browse files
author
Vladimir Kempik
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 8262896: [macos_aarch64] Crash in jni_fast_GetLongField Reviewed-by: adinn, burban, aph Backport-of: dbc9e4b
1 parent fe17b44 commit eb0708f

File tree

76 files changed

+3136
-113
lines changed

Some content is hidden

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

76 files changed

+3136
-113
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, 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
@@ -106,6 +107,14 @@ if [ "x$OUT" = x ]; then
106107
fi
107108
fi
108109

110+
# Test and fix cpu on macos-aarch64, uname -p reports arm, buildsys expects aarch64
111+
echo $OUT | grep arm-apple-darwin > /dev/null 2> /dev/null
112+
if test $? = 0; then
113+
if [ `uname -m` = arm64 ]; then
114+
OUT=aarch64`echo $OUT | sed -e 's/[^-]*//'`
115+
fi
116+
fi
117+
109118
# Test and fix cpu on Macosx when C preprocessor is not on the path
110119
echo $OUT | grep i386-apple-darwin > /dev/null 2> /dev/null
111120
if test $? = 0; then

make/autoconf/flags.m4

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,25 @@ AC_DEFUN([FLAGS_SETUP_MACOSX_VERSION],
111111
[
112112
# Additional macosx handling
113113
if test "x$OPENJDK_TARGET_OS" = xmacosx; then
114+
# The expected format for <version> is either nn.n.n or nn.nn.nn. See
115+
# /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/AvailabilityVersions.h
116+
114117
# MACOSX_VERSION_MIN specifies the lowest version of Macosx that the built
115118
# binaries should be compatible with, even if compiled on a newer version
116119
# of the OS. It currently has a hard coded value. Setting this also limits
117120
# exposure to API changes in header files. Bumping this is likely to
118121
# require code changes to build.
119-
MACOSX_VERSION_MIN=10.9.0
122+
if test "x$OPENJDK_TARGET_CPU_ARCH" = xaarch64; then
123+
MACOSX_VERSION_MIN=11.00.00
124+
else
125+
MACOSX_VERSION_MIN=10.9.0
126+
fi
120127
MACOSX_VERSION_MIN_NODOTS=${MACOSX_VERSION_MIN//\./}
121128
122129
AC_SUBST(MACOSX_VERSION_MIN)
123130
124131
# Setting --with-macosx-version-max=<version> makes it an error to build or
125-
# link to macosx APIs that are newer than the given OS version. The expected
126-
# format for <version> is either nn.n.n or nn.nn.nn. See /usr/include/AvailabilityMacros.h.
132+
# link to macosx APIs that are newer than the given OS version.
127133
AC_ARG_WITH([macosx-version-max], [AS_HELP_STRING([--with-macosx-version-max],
128134
[error on use of newer functionality. @<:@macosx@:>@])],
129135
[

make/autoconf/hotspot.m4

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2018, 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
@@ -274,6 +274,14 @@ AC_DEFUN_ONCE([HOTSPOT_ENABLE_DISABLE_CDS],
274274
fi
275275
fi
276276
277+
# Disable CDS on macos-aarch64
278+
if test "x$OPENJDK_TARGET_OS" = "xmacosx" && test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
279+
ENABLE_CDS="false"
280+
if test "x$enable_cds" = "xyes"; then
281+
AC_MSG_ERROR([CDS is currently not supported on macOS/aarch64. Remove --enable-cds.])
282+
fi
283+
fi
284+
277285
AC_SUBST(ENABLE_CDS)
278286
])
279287

make/common/NativeCompilation.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ define SetupNativeCompilationBody
12131213
# This only works if the openjdk_codesign identity is present on the system. Let
12141214
# silently fail otherwise.
12151215
ifneq ($(CODESIGN), )
1216-
$(CODESIGN) -s "$(MACOSX_CODESIGN_IDENTITY)" --timestamp --options runtime \
1216+
$(CODESIGN) -f -s "$(MACOSX_CODESIGN_IDENTITY)" --timestamp --options runtime \
12171217
--entitlements $$(call GetEntitlementsFile, $$@) $$@
12181218
endif
12191219
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, 2018, 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
@@ -99,6 +99,9 @@ ifeq ($(call check-jvm-feature, compiler2), true)
9999
ADLCFLAGS += -DAIX=1
100100
else ifeq ($(OPENJDK_TARGET_OS), macosx)
101101
ADLCFLAGS += -D_ALLBSD_SOURCE=1 -D_GNU_SOURCE=1
102+
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), aarch64)
103+
ADLCFLAGS += -DR18_RESERVED
104+
endif
102105
else ifeq ($(OPENJDK_TARGET_OS), windows)
103106
ifeq ($(call isTargetCpuBits, 64), true)
104107
ADLCFLAGS += -D_WIN64=1

make/lib/Awt2dLibraries.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ else
562562
maybe-uninitialized class-memaccess
563563
HARFBUZZ_DISABLED_WARNINGS_clang := unused-value incompatible-pointer-types \
564564
tautological-constant-out-of-range-compare int-to-pointer-cast \
565-
undef missing-field-initializers
565+
undef missing-field-initializers deprecated-declarations c++11-narrowing
566566
HARFBUZZ_DISABLED_WARNINGS_microsoft := 4267 4244 4090 4146 4334 4819 4101 4068 4805 4138
567567
HARFBUZZ_DISABLED_WARNINGS_C_solstudio := \
568568
E_INTEGER_OVERFLOW_DETECTED \

make/lib/Lib-jdk.hotspot.agent.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ else ifeq ($(OPENJDK_TARGET_OS), solaris)
3636
SA_LDFLAGS := -mt
3737

3838
else ifeq ($(OPENJDK_TARGET_OS), macosx)
39-
SA_CFLAGS := -Damd64 -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \
39+
SA_CFLAGS := -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \
4040
-mstack-alignment=16 -fPIC
4141
LIBSA_EXTRA_SRC := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.hotspot.agent
4242
else ifeq ($(OPENJDK_TARGET_OS), windows)

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, 2015, 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
*
@@ -53,7 +53,7 @@ const bool CCallingConventionRequiresIntsAsLongs = false;
5353

5454
#define THREAD_LOCAL_POLL
5555

56-
#if defined(_WIN64)
56+
#if defined(__APPLE__) || defined(_WIN64)
5757
#define R18_RESERVED
5858
#define R18_RESERVED_ONLY(code) code
5959
#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
@@ -58,9 +59,14 @@ FloatRegister InterpreterRuntime::SignatureHandlerGenerator::next_fpr() {
5859
return fnoreg;
5960
}
6061

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

@@ -72,6 +78,30 @@ InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(
7278
_stack_offset = 0;
7379
}
7480

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

@@ -80,7 +110,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
80110
__ ldr(reg, src);
81111
} else {
82112
__ ldrw(r0, src);
83-
__ strw(r0, Address(to(), next_stack_offset()));
113+
__ strw(r0, Address(to(), next_stack_offset(sizeof(jint))));
84114
}
85115
}
86116

@@ -92,7 +122,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
92122
__ ldr(reg, src);
93123
} else {
94124
__ ldr(r0, src);
95-
__ str(r0, Address(to(), next_stack_offset()));
125+
__ str(r0, Address(to(), next_stack_offset(sizeof(jlong))));
96126
}
97127
}
98128

@@ -104,7 +134,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
104134
__ ldrs(reg, src);
105135
} else {
106136
__ ldrw(r0, src);
107-
__ strw(r0, Address(to(), next_stack_offset()));
137+
__ strw(r0, Address(to(), next_stack_offset(sizeof(jfloat))));
108138
}
109139
}
110140

@@ -116,7 +146,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
116146
__ ldrd(reg, src);
117147
} else {
118148
__ ldr(r0, src);
119-
__ str(r0, Address(to(), next_stack_offset()));
149+
__ str(r0, Address(to(), next_stack_offset(sizeof(jdouble))));
120150
}
121151
}
122152

@@ -140,7 +170,8 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
140170
__ cbnz(temp(), L);
141171
__ mov(r0, zr);
142172
__ bind(L);
143-
__ str(r0, Address(to(), next_stack_offset()));
173+
STATIC_ASSERT(sizeof(jobject) == wordSize);
174+
__ str(r0, Address(to(), next_stack_offset(sizeof(jobject))));
144175
}
145176
}
146177

@@ -165,7 +196,7 @@ class SlowSignatureHandler
165196
: public NativeSignatureIterator {
166197
private:
167198
address _from;
168-
intptr_t* _to;
199+
char* _to;
169200
intptr_t* _int_args;
170201
intptr_t* _fp_args;
171202
intptr_t* _fp_identifiers;
@@ -200,36 +231,53 @@ class SlowSignatureHandler
200231
return -1;
201232
}
202233

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

207255
virtual void pass_int() {
208256
jint value = *(jint*)single_slot_addr();
209257
if (pass_gpr(value) < 0) {
210-
pass_stack(value);
258+
pass_stack<>(value);
211259
}
212260
}
213261

214262
virtual void pass_long() {
215263
intptr_t value = *double_slot_addr();
216264
if (pass_gpr(value) < 0) {
217-
pass_stack(value);
265+
pass_stack<>(value);
218266
}
219267
}
220268

221269
virtual void pass_object() {
222270
intptr_t* addr = single_slot_addr();
223271
intptr_t value = *addr == 0 ? NULL : (intptr_t)addr;
224272
if (pass_gpr(value) < 0) {
225-
pass_stack(value);
273+
pass_stack<>(value);
226274
}
227275
}
228276

229277
virtual void pass_float() {
230278
jint value = *(jint*)single_slot_addr();
231279
if (pass_fpr(value) < 0) {
232-
pass_stack(value);
280+
pass_stack<>(value);
233281
}
234282
}
235283

@@ -239,7 +287,7 @@ class SlowSignatureHandler
239287
if (0 <= arg) {
240288
*_fp_identifiers |= (1ull << arg); // mark as double
241289
} else {
242-
pass_stack(value);
290+
pass_stack<>(value);
243291
}
244292
}
245293

@@ -248,7 +296,7 @@ class SlowSignatureHandler
248296
: NativeSignatureIterator(method)
249297
{
250298
_from = from;
251-
_to = to;
299+
_to = (char *)to;
252300

253301
_int_args = to - (method->is_static() ? 16 : 17);
254302
_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, 2018, 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

0 commit comments

Comments
 (0)