Skip to content

Commit 0b88d34

Browse files
committed
aarch64: basic support for aarch64
Also fix Unsafe.putOrdered{} intrinsic memory ordering issue, see #45
1 parent 2d06c76 commit 0b88d34

8 files changed

Lines changed: 108 additions & 27 deletions

File tree

.github/workflows/build-linux.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ on:
3333
platform:
3434
required: true
3535
type: string
36-
extra-conf-options:
37-
required: false
36+
runs-on:
37+
required: true
3838
type: string
3939
make-target:
4040
required: false
@@ -57,7 +57,7 @@ on:
5757
jobs:
5858
build-linux:
5959
name: build
60-
runs-on: ubuntu-22.04
60+
runs-on: ${{ inputs.runs-on }}
6161

6262
strategy:
6363
fail-fast: false

.github/workflows/main.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ on:
3737
platforms:
3838
description: 'Platform(s) to execute on (comma separated, e.g. "linux-x64, macos, aarch64")'
3939
required: true
40-
default: 'linux-x64'
40+
default: 'linux-x64, linux-aarch64'
4141

4242
concurrency:
4343
group: ${{ github.workflow }}-${{ github.ref }}
@@ -54,6 +54,7 @@ jobs:
5454
runs-on: ubuntu-22.04
5555
outputs:
5656
linux-x64: ${{ steps.include.outputs.linux-x64 }}
57+
linux-aarch64: ${{ steps.include.outputs.linux-aarch64 }}
5758

5859
steps:
5960
# This function must be inlined in main.yml, or we'd be forced to checkout the repo
@@ -100,7 +101,7 @@ jobs:
100101
}
101102
102103
echo "linux-x64=$(check_platform linux-x64 linux x64)" >> $GITHUB_OUTPUT
103-
104+
echo "linux-aarch64=$(check_platform linux-aarch64 linux aarch64)" >> $GITHUB_OUTPUT
104105
###
105106
### Build jobs
106107
###
@@ -112,9 +113,21 @@ jobs:
112113
with:
113114
platform: linux_x64
114115
apt-gcc-version: '9'
116+
runs-on: ubuntu-22.04
115117
# The linux-x64 jdk bundle is used as buildjdk for the cross-compile job
116118
if: needs.select.outputs.linux-x64 == 'true' || needs.select.outputs.linux-cross-compile == 'true'
117119

120+
build-linux-aarch64:
121+
name: linux-aarch64
122+
needs: select
123+
uses: ./.github/workflows/build-linux.yml
124+
with:
125+
platform: linux_aarch64
126+
apt-gcc-version: '9'
127+
runs-on: ubuntu-22.04-arm
128+
# The linux-aarch64 jdk bundle is used as buildjdk for the cross-compile job
129+
if: needs.select.outputs.linux-aarch64 == 'true' || needs.select.outputs.linux-cross-compile == 'true'
130+
118131
###
119132
### Test jobs
120133
###
@@ -126,9 +139,21 @@ jobs:
126139
uses: ./.github/workflows/test-cvm8+17.yml
127140
with:
128141
platform: linux_x64
142+
arch: x64
129143
runs-on: ubuntu-22.04
130144
debug-level: release
131145

146+
test-linux-aarch64:
147+
name: linux-aarch64
148+
needs:
149+
- build-linux-aarch64
150+
uses: ./.github/workflows/test-cvm8+17.yml
151+
with:
152+
platform: linux_aarch64
153+
arch: aarch64
154+
runs-on: ubuntu-22.04-arm
155+
debug-level: release
156+
132157
# Remove bundles so they are not misconstrued as binary distributions from the JDK project
133158
remove-bundles:
134159
name: 'Remove bundle artifacts'
@@ -137,6 +162,8 @@ jobs:
137162
needs:
138163
- build-linux-x64
139164
- test-linux-x64
165+
- build-linux-aarch64
166+
- test-linux-aarch64
140167

141168
steps:
142169
# Hack to get hold of the api environment variables that are only defined for actions

.github/workflows/test-cvm8+17.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ on:
2525
platform:
2626
required: true
2727
type: string
28+
arch:
29+
required: true
30+
type: string
2831
runs-on:
2932
required: true
3033
type: string
@@ -94,8 +97,8 @@ jobs:
9497

9598
- name: 'Run sanity test jvm patch'
9699
run: |
97-
wget -nc https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u372-b07/OpenJDK8U-jdk_x64_linux_hotspot_8u372b07.tar.gz
98-
tar xzf OpenJDK8U-jdk_x64_linux_hotspot_8u372b07.tar.gz
100+
wget -nc https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u372-b07/OpenJDK8U-jdk_${{ inputs.arch }}_linux_hotspot_8u372b07.tar.gz
101+
tar xzf OpenJDK8U-jdk_${{ inputs.arch }}_linux_hotspot_8u372b07.tar.gz
99102
tar xzf CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}.tar.gz -C jdk8u372-b07/
100103
jdk8u372-b07/bin/java -version 2>&1 | grep "CompoundVM"
101104
shell: bash

cvm.mk

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,34 @@
1717
# 2 along with this work; if not, write to the Free Software Foundation,
1818
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1919

20+
CVM_ARCH := $(shell uname -m)
2021
WORKSPACE := $(shell pwd)
2122
SHELL := /bin/bash
2223
BOOTJDK17 := $(WORKSPACE)/.bootjdks/jdk-17.0.7+7
2324
BOOTJDK8 := $(WORKSPACE)/.bootjdks/jdk8u372-b07
25+
# Variable ARCH conflicts with jdk8's build variable
26+
ifeq ($(CVM_ARCH),x86_64)
27+
BOOTJDK17_URL := https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.7_7.tar.gz
28+
BOOTJDK8_URL := https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u372-b07/OpenJDK8U-jdk_x64_linux_hotspot_8u372b07.tar.gz
29+
ARCH_DIR := amd64
30+
ARCH_DIR1 := x64
31+
else ifeq ($(CVM_ARCH),aarch64)
32+
BOOTJDK17_URL := https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/OpenJDK17U-jdk_aarch64_linux_hotspot_17.0.7_7.tar.gz
33+
BOOTJDK8_URL := https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u372-b07/OpenJDK8U-jdk_aarch64_linux_hotspot_8u372b07.tar.gz
34+
ARCH_DIR := aarch64
35+
ARCH_DIR1 := aarch64
36+
else
37+
ARCH_ERROR := 1
38+
endif
39+
CVM8_LIBDIR := $(WORKSPACE)/build/jdk8/jre/lib/$(ARCH_DIR)
2440
BUILDDIR := $(WORKSPACE)/cvm/build
2541
VERSION := $(shell cat $(WORKSPACE)/cvm/conf/version)
2642
OUTPUTDIR := $(WORKSPACE)/output
27-
DISTRO_NAME := CompoundVM_$(VERSION)_linux_x64
28-
DISTRO_JVM_PATCH_NAME := CompoundVM_$(VERSION)_jvm_patch_linux_x64
43+
DISTRO_NAME := CompoundVM_$(VERSION)_linux_$(ARCH_DIR1)
44+
DISTRO_JVM_PATCH_NAME := CompoundVM_$(VERSION)_jvm_patch_linux_$(ARCH_DIR1)
2945
CVM8DIR := $(BUILDDIR)/jdk8
3046
CVM8_JARDIR := $(CVM8DIR)/jre/lib
31-
CVM8_LIBDIR := $(CVM8DIR)/jre/lib/amd64
47+
CVM8_LIBDIR := $(CVM8DIR)/jre/lib/$(ARCH_DIR)
3248
MODE ?= release
3349
JAR ?= $(BOOTJDK17)/bin/jar
3450
JDK17_SRCROOT := $(WORKSPACE)
@@ -87,12 +103,18 @@ define compile_tools17_bin
87103
-DAPP_CLASSPATH='{ "/lib/tools17.jar", "/lib/tools.jar", }' \
88104
-o $(BUILDDIR)/bin/$(TOOL_NAME) \
89105
$(CVM8_SRCROOT)/alt_app/tools17/src/share/bin/tool.c \
90-
-L$(JDK8_LIB_DIR)/amd64/jli \
91-
-Wl,-rpath,'$$ORIGIN/../lib/amd64/jli' \
106+
-L$(JDK8_LIB_DIR)/$(ARCH_DIR)/jli \
107+
-Wl,-rpath,'$$ORIGIN/../lib/$(ARCH_DIR)/jli' \
92108
-ljli
93109
endef
94110

95-
-bootstrap: -init-dirs $(BOOTJDK17)/ $(BOOTJDK8)/
111+
-bootstrap: -check-arch -init-dirs $(BOOTJDK17)/ $(BOOTJDK8)/
112+
113+
-check-arch:
114+
if [ "$(ARCH_ERROR)" = "1" ]; then \
115+
echo "Unsupported architecture! only x86_64 and aarch64 are supported."; \
116+
exit 1; \
117+
fi
96118

97119
-init-dirs:
98120
[[ -d $(BUILDDIR) ]] || mkdir -p $(BUILDDIR)
@@ -117,12 +139,12 @@ endef
117139

118140
# '/' is indispensable otherwise target name will be treated as a file
119141
$(BOOTJDK17)/:
120-
$(call setup_boot_jdk,https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.7_7.tar.gz,$@)
121-
#cp -f $(WORKSPACE)/bin/linux-x86_64/hsdis-amd64.so $$(dirname $$(find $@ -name libjava.so))
142+
$(call setup_boot_jdk,$(BOOTJDK17_URL),$@)
143+
#cp -f $(WORKSPACE)/bin/linux-$(CVM_ARCH)/hsdis-$(ARCH_DIR).so $$(dirname $$(find $@ -name libjava.so))
122144

123145
$(BOOTJDK8)/:
124-
$(call setup_boot_jdk,https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u372-b07/OpenJDK8U-jdk_x64_linux_hotspot_8u372b07.tar.gz,$@)
125-
#cp -f $(WORKSPACE)/bin/linux-x86_64/hsdis-amd64.so $$(dirname $$(find $@ -name libjava.so))
146+
$(call setup_boot_jdk,$(BOOTJDK8_URL),$@)
147+
#cp -f $(WORKSPACE)/bin/linux-$(CVM_ARCH)/hsdis-$(ARCH_DIR).so $$(dirname $$(find $@ -name libjava.so))
126148

127149
jdk8u/jdk/src:
128150
wget -nc https://github.com/openjdk/jdk8u/archive/refs/tags/jdk8u382-b03.tar.gz
@@ -134,11 +156,11 @@ cvm8default17: jdk8vm17
134156
echo "-server17 KNOWN" > $(CVM8_LIBDIR)/jvm.cfg
135157
echo "-server KNOWN" >> $(CVM8_LIBDIR)/jvm.cfg
136158
echo "-client IGNORE" >> $(CVM8_LIBDIR)/jvm.cfg
137-
echo "-server17 KNOWN" > $(OUTPUTDIR)/$(DISTRO_NAME)/jre/lib/amd64/jvm.cfg
138-
echo "-server KNOWN" >> $(OUTPUTDIR)/$(DISTRO_NAME)/jre/lib/amd64/jvm.cfg
139-
echo "-client IGNORE" >> $(OUTPUTDIR)/$(DISTRO_NAME)/jre/lib/amd64/jvm.cfg
159+
echo "-server17 KNOWN" > $(OUTPUTDIR)/$(DISTRO_NAME)/jre/lib/$(ARCH_DIR)/jvm.cfg
160+
echo "-server KNOWN" >> $(OUTPUTDIR)/$(DISTRO_NAME)/jre/lib/$(ARCH_DIR)/jvm.cfg
161+
echo "-client IGNORE" >> $(OUTPUTDIR)/$(DISTRO_NAME)/jre/lib/$(ARCH_DIR)/jvm.cfg
140162

141-
JVM_PATCH_ARTIFACTS := jre/lib/rt17.jar jre/lib/rt8.jar jre/lib/amd64/libjava17.so jre/lib/amd64/libjimage17.so jre/lib/amd64/libjdwp17.so jre/lib/amd64/server17 jre/lib/amd64/jvm.cfg
163+
JVM_PATCH_ARTIFACTS := jre/lib/rt17.jar jre/lib/rt8.jar jre/lib/$(ARCH_DIR)/libjava17.so jre/lib/$(ARCH_DIR)/libjimage17.so jre/lib/$(ARCH_DIR)/libjdwp17.so jre/lib/$(ARCH_DIR)/server17 jre/lib/$(ARCH_DIR)/jvm.cfg
142164

143165
jvm-patch: cvm8default17
144166
@echo "###### Composing CVM8 jvm patch ######"
@@ -205,7 +227,7 @@ build_jdk8u: -bootstrap jdk8u/jdk/src
205227
--with-vendor-vm-bug-url="https://github.com/bytedance/CompoundVM/issues" \
206228
;\
207229
fi; \
208-
make $(JDK_MAKE_OPTS) CONF=linux-x86_64-normal-server-$(MODE) images; \
230+
make $(JDK_MAKE_OPTS) CONF=linux-$(CVM_ARCH)-normal-server-$(MODE) images; \
209231
[[ $$? -eq 0 ]] || exit 127; \
210232
}
211233

@@ -227,7 +249,7 @@ build_jdk17u: -bootstrap
227249
; \
228250
fi; \
229251
}
230-
make $(JDK_MAKE_OPTS) CONF=linux-x86_64-server-$(MODE) hotspot jdk.jdwp.agent
252+
make $(JDK_MAKE_OPTS) CONF=linux-$(CVM_ARCH)-server-$(MODE) hotspot jdk.jdwp.agent
231253

232254
################ alternative kernel classes ########
233255
# here we copy the JDK17 kernel classes to separate diretory,

cvm/conf/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.0.1
1+
8.0.2

src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,13 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2,
640640

641641
BLOCK_COMMENT("string_compare {");
642642

643+
// LibraryCallKit::inline_string_compareTo() already generated char[] length in cvm8
644+
#if HOTSPOT_TARGET_CLASSLIB != 8
643645
// Bizzarely, the counts are passed in bytes, regardless of whether they
644646
// are L or U strings, however the result is always in characters.
645647
if (!str1_isL) asrw(cnt1, cnt1, 1);
646648
if (!str2_isL) asrw(cnt2, cnt2, 1);
649+
#endif
647650

648651
// Compute the minimum of the string lengths and save the difference.
649652
subsw(result, cnt1, cnt2);

src/hotspot/cpu/aarch64/methodHandles_aarch64.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm,
134134
assert(recv != noreg, "required register");
135135
assert(method_temp == rmethod, "required register for loading method");
136136

137+
#if HOTSPOT_TARGET_CLASSLIB == 8
138+
// Load the invoker, as MH -> MH.form -> LF.vmentry
139+
__ verify_oop(recv);
140+
__ load_heap_oop(method_temp, Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset())));
141+
__ verify_oop(method_temp);
142+
__ load_heap_oop(method_temp, Address(method_temp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset())));
143+
__ verify_oop(method_temp);
144+
// the following assumes that a Method* is normally compressed in the vmtarget field:
145+
//__ movptr(method_temp, Address(method_temp, NONZERO(java_lang_invoke_MemberName::vmtarget_offset())));
146+
__ access_load_at(T_ADDRESS, IN_HEAP, method_temp,
147+
Address(method_temp, NONZERO(java_lang_invoke_MemberName::vmtarget_offset())),
148+
noreg, noreg);
149+
#else
137150
// Load the invoker, as MH -> MH.form -> LF.vmentry
138151
__ verify_oop(recv);
139152
__ load_heap_oop(method_temp, Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset())), temp2);
@@ -143,6 +156,7 @@ void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm,
143156
__ load_heap_oop(method_temp, Address(method_temp, NONZERO(java_lang_invoke_MemberName::method_offset())), temp2);
144157
__ verify_oop(method_temp);
145158
__ access_load_at(T_ADDRESS, IN_HEAP, method_temp, Address(method_temp, NONZERO(java_lang_invoke_ResolvedMethodName::vmtarget_offset())), noreg, noreg);
159+
#endif
146160

147161
if (VerifyMethodHandles && !for_compiler_entry) {
148162
// make sure recv is already on stack
@@ -296,8 +310,12 @@ void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm,
296310

297311
Address member_clazz( member_reg, NONZERO(java_lang_invoke_MemberName::clazz_offset()));
298312
Address member_vmindex( member_reg, NONZERO(java_lang_invoke_MemberName::vmindex_offset()));
313+
#if HOTSPOT_TARGET_CLASSLIB == 8
314+
Address member_vmtarget( member_reg, NONZERO(java_lang_invoke_MemberName::vmtarget_offset()));
315+
#else
299316
Address member_vmtarget( member_reg, NONZERO(java_lang_invoke_MemberName::method_offset()));
300317
Address vmtarget_method( rmethod, NONZERO(java_lang_invoke_ResolvedMethodName::vmtarget_offset()));
318+
#endif
301319

302320
Register temp1_recv_klass = temp1;
303321
if (iid != vmIntrinsics::_linkToStatic) {
@@ -350,16 +368,24 @@ void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm,
350368
if (VerifyMethodHandles) {
351369
verify_ref_kind(_masm, JVM_REF_invokeSpecial, member_reg, temp3);
352370
}
371+
#if HOTSPOT_TARGET_CLASSLIB == 8
372+
__ access_load_at(T_ADDRESS, IN_HEAP, rmethod, member_vmtarget, noreg, noreg);
373+
#else
353374
__ load_heap_oop(rmethod, member_vmtarget);
354375
__ access_load_at(T_ADDRESS, IN_HEAP, rmethod, vmtarget_method, noreg, noreg);
376+
#endif
355377
break;
356378

357379
case vmIntrinsics::_linkToStatic:
358380
if (VerifyMethodHandles) {
359381
verify_ref_kind(_masm, JVM_REF_invokeStatic, member_reg, temp3);
360382
}
383+
#if HOTSPOT_TARGET_CLASSLIB == 8
384+
__ access_load_at(T_ADDRESS, IN_HEAP, rmethod, member_vmtarget, noreg, noreg);
385+
#else
361386
__ load_heap_oop(rmethod, member_vmtarget);
362387
__ access_load_at(T_ADDRESS, IN_HEAP, rmethod, vmtarget_method, noreg, noreg);
388+
#endif
363389
break;
364390

365391
case vmIntrinsics::_linkToVirtual:

src/hotspot/share/c1/c1_GraphBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,9 +3507,9 @@ void GraphBuilder::build_graph_for_intrinsic(ciMethod* callee, bool ignore_retur
35073507
case vmIntrinsics::_putFloat : append_unsafe_put_obj(callee, T_FLOAT, false); return;
35083508
case vmIntrinsics::_putDouble : append_unsafe_put_obj(callee, T_DOUBLE, false); return;
35093509
#if HOTSPOT_TARGET_CLASSLIB == 8
3510-
case vmIntrinsics::_putOrderedObject : append_unsafe_put_obj(callee, T_OBJECT, false); return;
3511-
case vmIntrinsics::_putOrderedInt : append_unsafe_put_obj(callee, T_INT, false); return;
3512-
case vmIntrinsics::_putOrderedLong : append_unsafe_put_obj(callee, T_LONG, false); return;
3510+
case vmIntrinsics::_putOrderedObject : append_unsafe_put_obj(callee, T_OBJECT, true); return;
3511+
case vmIntrinsics::_putOrderedInt : append_unsafe_put_obj(callee, T_INT, true); return;
3512+
case vmIntrinsics::_putOrderedLong : append_unsafe_put_obj(callee, T_LONG, true); return;
35133513
case vmIntrinsics::_getObject2 : append_unsafe_get_obj(callee, T_OBJECT, false); return;
35143514
case vmIntrinsics::_getBoolean2 : append_unsafe_get_obj(callee, T_BOOLEAN, false); return;
35153515
case vmIntrinsics::_getByte2 : append_unsafe_get_obj(callee, T_BYTE, false); return;

0 commit comments

Comments
 (0)