Skip to content

Commit f4610bc

Browse files
committed
lang/openjdk11: Workaround for the VM dying on Apple Silicon chips
See the patch for threadWXSetters.inline.hpp for details. I rebuilt the bootkit for aarch64 with new patches applied. This may cause some performance regression on Cortex series, but as I stated in the patch comment, relying on assumptions made on implementation details of chips is fundamentally unsound, and that's why it didn't work on Apple Silicon in the first place. Also backported fixes regarding floating point arithmetics that appeared in OpenJDK 22.
1 parent c9af737 commit f4610bc

28 files changed

Lines changed: 703 additions & 19 deletions

lang/openjdk11/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $NetBSD: Makefile,v 1.74 2025/06/15 13:41:51 ryoon Exp $
1+
# $NetBSD: Makefile,v 1.75 2025/08/04 13:22:05 pho Exp $
22

33
DISTNAME= jdk11u-${GITHUB_TAG:C/\+/-/}
44
PKGNAME= openjdk11-1.${GITHUB_TAG:C/\+/./:C/jdk-([.0-9]+).*/\1/}
@@ -34,6 +34,7 @@ CONFIG_GUESS_OVERRIDE+= make/autoconf/build-aux/config.guess
3434
CONFIG_SUB_OVERRIDE+= make/autoconf/build-aux/autoconf-config.sub
3535
CONFIG_GUESS_OVERRIDE+= make/autoconf/build-aux/autoconf-config.guess
3636
USE_LANGUAGES= c c++
37+
USE_CXX_FEATURES= c++11
3738
USE_TOOLS+= bash gmake pax pkg-config unzip:run zip:run autoconf automake
3839
UNLIMIT_RESOURCES= datasize stacksize virtualsize cputime
3940

@@ -43,7 +44,10 @@ BUILDLINK_PASSTHRU_DIRS+= ${ALT_BOOTDIR}
4344
BOOT_JVMARGS= -XX:+UnlockDiagnosticVMOptions \
4445
-XX:-UseSemaphoreGCThreadsSynchronization
4546

46-
CONFIGURE_ARGS+= --prefix=${PREFIX:Q}
47+
# ${WRKSRC}/doc/building.mk explicitly states that its Makefiles are unsafe
48+
# to use -j.
49+
MAKE_JOBS_SAFE= no
50+
4751
CONFIGURE_ARGS+= --openjdk-target=${MACHINE_GNU_PLATFORM:Q}
4852
CONFIGURE_ARGS+= --with-boot-jdk=${ALT_BOOTDIR}
4953
CONFIGURE_ARGS+= --with-boot-jdk-jvmargs=${BOOT_JVMARGS:Q}

lang/openjdk11/bootstrap.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# $NetBSD: bootstrap.mk,v 1.9 2023/12/12 12:37:44 ryoon Exp $
1+
# $NetBSD: bootstrap.mk,v 1.10 2025/08/04 13:22:05 pho Exp $
22

33
.if ${OPSYS} == "NetBSD" && ${OPSYS_VERSION} < 080000
44
PKG_FAIL_REASON+= "Only supports NetBSD >= 8"
55
.endif
66

7-
.if (!empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) || !empty(MACHINE_PLATFORM:MNetBSD-*-*earm*)) && ${OPSYS_VERSION} < 099983
8-
PKG_FAIL_REASON+= "PR 55248: please update to NetBSD >= 9.99.83 to use this package"
7+
.if !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) && ${OPSYS_VERSION} < 090400
8+
PKG_FAIL_REASON+= "Only supports NetBSD >= 9.4"
99
.endif
1010

1111
ONLY_FOR_PLATFORM+= NetBSD-*-i386
@@ -25,7 +25,7 @@ EXTRACT_ONLY+= ${BOOT.nb7-amd64}
2525
.endif
2626

2727
ONLY_FOR_PLATFORM+= NetBSD-*-aarch64
28-
BOOT.nb9-aarch64= bootstrap-jdk-1.11.0.7.10-netbsd-9-aarch64-20200509.tar.xz
28+
BOOT.nb9-aarch64= bootstrap-jdk-1.11.0.27.6-netbsd-9-aarch64-20250804.tar.xz
2929
SITES.${BOOT.nb9-aarch64}= ${MASTER_SITE_LOCAL:=openjdk11/}
3030
.if !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) || make(distinfo)
3131
DISTFILES+= ${BOOT.nb9-aarch64}

lang/openjdk11/distinfo

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,55 @@
1-
$NetBSD: distinfo,v 1.47 2025/06/15 13:41:51 ryoon Exp $
1+
$NetBSD: distinfo,v 1.48 2025/08/04 13:22:05 pho Exp $
22

33
BLAKE2s (bootstrap-jdk-1.11.0.15.10-netbsd-8-earmv6hf-20220525.tar.xz) = f93572f551f242344e5d6d5e46b9812e5b426772842b5fa06fea4422e327c871
44
SHA512 (bootstrap-jdk-1.11.0.15.10-netbsd-8-earmv6hf-20220525.tar.xz) = c4030c99e4c1bb209f0c1ca6c10665c3f4c906f9d7dc13b912c3fbb8031f3dbb6f8d2e5e966cbbc452c307ba5d6de816c0f000b5b7c5d4e3fe8511baf12aab49
55
Size (bootstrap-jdk-1.11.0.15.10-netbsd-8-earmv6hf-20220525.tar.xz) = 92279544 bytes
6+
BLAKE2s (bootstrap-jdk-1.11.0.27.6-netbsd-9-aarch64-20250804.tar.xz) = 68bd15487eb52b1800fc32fff95625b7bc512c82f0ca7ec7326df237124afa72
7+
SHA512 (bootstrap-jdk-1.11.0.27.6-netbsd-9-aarch64-20250804.tar.xz) = d6800c43357104ab09c7a9fb86443005de7951385a1a1128f1a943445764af9f730ea146cb3194f84a8da6c10d4000ce8675f67ab2142ebab6b68d3f3faaba9a
8+
Size (bootstrap-jdk-1.11.0.27.6-netbsd-9-aarch64-20250804.tar.xz) = 110043364 bytes
69
BLAKE2s (bootstrap-jdk-1.11.0.5.8-netbsd-7-amd64-20190928.tar.xz) = b57b09661581b7dc6e3700a777f030dfa2fef6f953533456686bfd0dde9157d0
710
SHA512 (bootstrap-jdk-1.11.0.5.8-netbsd-7-amd64-20190928.tar.xz) = 6e61996f7e3c3492b0c878644db30d72021dc4096639992e53b4440d4e2e18cd92e5630ecd4600d1917a1e63a7c814b63f74f811a40588febfe19ad8d3208a9d
811
Size (bootstrap-jdk-1.11.0.5.8-netbsd-7-amd64-20190928.tar.xz) = 105760636 bytes
912
BLAKE2s (bootstrap-jdk-1.11.0.5.8-netbsd-7-i386-20190928.tar.xz) = c54603eabe28bae659a2042cb3b69588840a57502e741c3de333ac70ea1dedc2
1013
SHA512 (bootstrap-jdk-1.11.0.5.8-netbsd-7-i386-20190928.tar.xz) = 1bf5336e9bfeea9ecbcd347f2ea8dd3c9633df42cab13a09c7afaae94faa95b92d862dd97caf380a7037825c3324377240d5d0639b2e0b31a2d7a6316ed56359
1114
Size (bootstrap-jdk-1.11.0.5.8-netbsd-7-i386-20190928.tar.xz) = 96662264 bytes
12-
BLAKE2s (bootstrap-jdk-1.11.0.7.10-netbsd-9-aarch64-20200509.tar.xz) = 5aac0ec747ac714032dfcb4cc4f093ee3f9ddeb070301856727a8597cedd65cf
13-
SHA512 (bootstrap-jdk-1.11.0.7.10-netbsd-9-aarch64-20200509.tar.xz) = 735f47d7398a48f0963c5d629c6c319dfe22d84bacd45f84a34f4784433c8cf6bfe6b356363a4591f035bec4a32e2e38d0a9c6be361aa57e5f0170ad4e16a1ad
14-
Size (bootstrap-jdk-1.11.0.7.10-netbsd-9-aarch64-20200509.tar.xz) = 99673444 bytes
1515
BLAKE2s (jdk11u-jdk-11.0.27-6-1.tar.gz) = f6cb29c7378c404ad66e94a323c33781ad38fd5911e9efcb435c4444dc7ad82c
1616
SHA512 (jdk11u-jdk-11.0.27-6-1.tar.gz) = b8b808585a67a8ed09b83b07f4ed8304bb6fd2e89eb729c89c188c94aede655a24e67a1b6803a4d4fba70b91a76daf356ba7b7d4826b858eb598f7dac22de22c
1717
Size (jdk11u-jdk-11.0.27-6-1.tar.gz) = 116708083 bytes
1818
SHA1 (patch-make_autoconf_build-performance.m4) = d52cb5897e9fb6e3b0cdbe34641d8caa218b21b7
1919
SHA1 (patch-make_autoconf_buildjdk-spec.gmk.in) = d0b600237853c17ecc2864604f0bd847ba6b0149
20-
SHA1 (patch-make_autoconf_flags-cflags.m4) = f8ef1f5f62234ff2c7d8d6e44cba85929cc5bd62
20+
SHA1 (patch-make_autoconf_flags-cflags.m4) = 04ef9cbf5e2b192af6e634243d496cfc24d11717
2121
SHA1 (patch-make_autoconf_hotspot.m4) = 437c8b09114933cca22c4a847a90a415cd113e5a
2222
SHA1 (patch-make_autoconf_lib-alsa.m4) = 999fbf951363f6b49b22aad81537728f22d7c381
2323
SHA1 (patch-make_autoconf_lib-bundled.m4) = 35a4cdb3c4c3e4893b583cc73a0a79fda6f487e0
2424
SHA1 (patch-make_autoconf_lib-freetype.m4) = 3dbdfea4011dc69593ab302626b9ec4dfc7a7d54
2525
SHA1 (patch-make_autoconf_lib-x11.m4) = f609a726f2d795f1d05cc933df587d3440c09b9f
2626
SHA1 (patch-make_data_fontconfig_bsd.fontconfig.properties) = 9fd9f6ef4af0eece0b4ca0acbb44331566f17e07
2727
SHA1 (patch-make_launcher_LauncherCommon.gmk) = e306dac42c5bdd908775b78c80128c9a96781b06
28+
SHA1 (patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp) = 263be050505100a9ff37d75e2aa465e0ffb04d68
29+
SHA1 (patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp) = 92026071ff9354dd845ede6aa8f47c12ba883faf
30+
SHA1 (patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp) = 0b720cdfef884368432b818bb56648b462539125
31+
SHA1 (patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp) = 301d16361542eec9123b9a4cf0a64978cc863ed6
32+
SHA1 (patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp) = 248188cc49cfca7fb26b907525f19b9cec5caffd
33+
SHA1 (patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp) = 146a6ab00271395ddfdb42bf50375ec6c1bfd18c
34+
SHA1 (patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp) = 1a017334bdab5717ea2aaf4ae77a1e3974ebee0e
35+
SHA1 (patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp) = 17918e89d4575a3f55c9e163370d7daf95043866
2836
SHA1 (patch-src_hotspot_os__cpu_bsd__arm_bsd__arm__32.s) = 474a66abfb25030d4e32134816c14b157d1ebe6a
2937
SHA1 (patch-src_hotspot_os_bsd_os__bsd.cpp) = 6322cbdda03dee528e89ac8b725f3df5e2165797
3038
SHA1 (patch-src_hotspot_os_bsd_os__perf__bsd.cpp) = 7bb57f82f3a93adc1970ed4215148fc02ecbcd5a
3139
SHA1 (patch-src_hotspot_os_posix_os__posix.cpp) = e70e8c1e59f0be184a7a1d6e9d11ac7b934ce4b2
40+
SHA1 (patch-src_hotspot_share_c1_c1__Runtime1.cpp) = a5e22891f91792e16aced8738c916b7c3e583010
41+
SHA1 (patch-src_hotspot_share_interpreter_interpreterRuntime.cpp) = 50da5fb63869733859bbae7756eef07b4718fd7f
42+
SHA1 (patch-src_hotspot_share_jvmci_jvmciEnv.hpp) = 75c7e29a69c75abc7747a7f1ba792400889f6157
3243
SHA1 (patch-src_hotspot_share_libadt_dict.cpp) = a5c62973f563742d4ccc7db341b33366d14e2a01
44+
SHA1 (patch-src_hotspot_share_opto_runtime.cpp) = 65c60e5ca89be4d7003a4667c43f18a936a9a95d
45+
SHA1 (patch-src_hotspot_share_prims_jniCheck.cpp) = a3e92b764d9b7aef64ed3908435921ba4d7fec1c
46+
SHA1 (patch-src_hotspot_share_prims_jvmtiEnter.xsl) = a29d326249ae0a1fb960c7aa17f5128869869000
47+
SHA1 (patch-src_hotspot_share_prims_jvmtiEnv.cpp) = 475117e9d8578291294b5752029b92fe86fccae6
48+
SHA1 (patch-src_hotspot_share_prims_whitebox.inline.hpp) = 3efde30edae364d19541b9aceb9a2f52edbc364a
49+
SHA1 (patch-src_hotspot_share_runtime_deoptimization.cpp) = d791d59c9491f7bc448c9f7c10afdfa950e0f5b0
50+
SHA1 (patch-src_hotspot_share_runtime_interfaceSupport.inline.hpp) = a4d92a4aab76fcd4754004876dc27753322f3aa7
51+
SHA1 (patch-src_hotspot_share_runtime_safefetch.inline.hpp) = 1dc90818272e04b8b8825e54241c78e233e34593
52+
SHA1 (patch-src_hotspot_share_runtime_safepoint.cpp) = 0c694e52ae6a9e2e893d832e58b555fa9c316e75
53+
SHA1 (patch-src_hotspot_share_runtime_thread.cpp) = 54cbd9300afc23dbd90db4c21eced285cee56e8f
54+
SHA1 (patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp) = f704bb060803e500415b5d300e26857cf7288ca5
3355
SHA1 (patch-src_java.desktop_unix_native_common_awt_fontpath.c) = c27a058dbcc836fa5a9f979f193284a706a7c50b

lang/openjdk11/hacks.mk

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $NetBSD: hacks.mk,v 1.2 2020/05/03 20:07:34 tnn Exp $
1+
# $NetBSD: hacks.mk,v 1.3 2025/08/04 13:22:05 pho Exp $
22

33
.if !defined(OPENJDK11_HACKS_MK)
44
OPENJDK11_HACKS_MK= # empty
@@ -18,9 +18,12 @@ post-wrapper:
1818
# JDK can correctly build itself. Compiling or running programs other than
1919
# openjdk itself on such hardware may still cause unexpected behaviour.
2020
#
21-
22-
.if !empty(MACHINE_PLATFORM:MNetBSD-*-*arm*) || \
23-
!empty(MACHINE_PLATFORM:MNetBSD-*-aarch64)
21+
# The issue has been fixed in OpenJDK 22 for aarch64, and we have
22+
# backported the fix to this package. We aren't sure if it's still an issue
23+
# on 32bit ARM. Probably not? You know when the issue bites you: javac
24+
# enters into an infinite loop while parsing subnormal numeric constants.
25+
#
26+
.if ${MACHINE_PLATFORM:MNetBSD-*-*arm*}
2427
PKG_HACKS+= broken-ieee-floats
2528
SUBST_CLASSES+= fpu
2629
SUBST_STAGE.fpu= pre-build

lang/openjdk11/options.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $NetBSD: options.mk,v 1.8 2022/05/25 06:05:34 tnn Exp $
1+
# $NetBSD: options.mk,v 1.9 2025/08/04 13:22:05 pho Exp $
22

33
PKG_OPTIONS_VAR= PKG_OPTIONS.openjdk11
44
PKG_OPTIONS_OPTIONAL_GROUPS= variant
@@ -45,8 +45,10 @@ BUILDLINK_DEPMETHOD.libXt?= build
4545
.include "../../x11/libXtst/buildlink3.mk"
4646
.include "../../x11/libXrandr/buildlink3.mk"
4747
.else
48+
CONFIGURE_ARGS+= --x-includes=${X11BASE}/include
49+
CONFIGURE_ARGS+= --x-libraries=${X11BASE}/lib
4850
CONFIGURE_ARGS+= --enable-headless-only
49-
# We apparently still need the Xlib headers to build headless. why?
51+
# We apparently still need the Xlib headers and libraries to build headless. why?
5052
BUILDLINK_DEPMETHOD.libX11?= build
5153
.include "../../x11/libX11/buildlink3.mk"
5254
BUILDLINK_DEPMETHOD.libXext?=build

lang/openjdk11/patches/patch-make_autoconf_flags-cflags.m4

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
$NetBSD: patch-make_autoconf_flags-cflags.m4,v 1.4 2024/10/01 14:48:00 ryoon Exp $
1+
$NetBSD: patch-make_autoconf_flags-cflags.m4,v 1.5 2025/08/04 13:22:06 pho Exp $
22

33
We prefer to use explicit run paths.
44
Add lib/jli to link libjli.so dynamically. Fix runtime error of Bazel.
5+
Require c++11 as we have some patches using it.
56

6-
--- make/autoconf/flags-cflags.m4.orig 2024-08-26 15:59:52.654571089 +0000
7+
--- make/autoconf/flags-cflags.m4.orig 2025-04-19 23:57:10.000000000 +0000
78
+++ make/autoconf/flags-cflags.m4
89
@@ -42,8 +42,8 @@ AC_DEFUN([FLAGS_SETUP_SHARED_LIBS],
910
# --disable-new-dtags forces use of RPATH instead of RUNPATH for rpaths.
@@ -39,3 +40,21 @@ Add lib/jli to link libjli.so dynamically. Fix runtime error of Bazel.
3940
fi
4041

4142
elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
43+
@@ -566,7 +559,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
44+
TOOLCHAIN_CFLAGS_JDK="-pipe"
45+
TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing" # technically NOT for CXX
46+
47+
- CXXSTD_CXXFLAG="-std=gnu++98"
48+
+ CXXSTD_CXXFLAG="-std=gnu++11"
49+
FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$CXXSTD_CXXFLAG -Werror],
50+
IF_FALSE: [CXXSTD_CXXFLAG=""])
51+
TOOLCHAIN_CFLAGS_JDK_CXXONLY="$CXXSTD_CXXFLAG"
52+
@@ -817,7 +810,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
53+
$1_CFLAGS_CPU_JDK="${$1_CFLAGS_CPU_JDK} -fno-omit-frame-pointer"
54+
fi
55+
56+
- $1_CXXSTD_CXXFLAG="-std=gnu++98"
57+
+ $1_CXXSTD_CXXFLAG="-std=gnu++11"
58+
FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${$1_CXXSTD_CXXFLAG} -Werror],
59+
PREFIX: $3, IF_FALSE: [$1_CXXSTD_CXXFLAG=""])
60+
$1_TOOLCHAIN_CFLAGS_JDK_CXXONLY="${$1_CXXSTD_CXXFLAG}"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$NetBSD: patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp,v 1.1 2025/08/04 13:22:06 pho Exp $
2+
3+
Backport a bugfix appeared in Java 22:
4+
https://github.com/openjdk/jdk21u-dev/commit/9e582fcbb8ab34b44ff01ac13de5cc4d6487396d
5+
6+
--- src/hotspot/cpu/aarch64/frame_aarch64.hpp.orig 2025-08-01 18:15:42.300499547 +0000
7+
+++ src/hotspot/cpu/aarch64/frame_aarch64.hpp
8+
@@ -95,7 +95,7 @@
9+
// Entry frames
10+
// n.b. these values are determined by the layout defined in
11+
// stubGenerator for the Java call stub
12+
- entry_frame_after_call_words = 27,
13+
+ entry_frame_after_call_words = 29,
14+
entry_frame_call_wrapper_offset = -8,
15+
16+
// we don't need a save area
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$NetBSD: patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp,v 1.1 2025/08/04 13:22:06 pho Exp $
2+
3+
Workaround for the Hotspot VM dying on Apple Silicon chips. See
4+
the patch to threadWXSetters.inline.hpp for details.
5+
6+
--- src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp.orig 2025-04-19 23:57:10.000000000 +0000
7+
+++ src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp
8+
@@ -57,8 +57,6 @@ static const Register result = r7
9+
// (8262896). So each FastGetXXXField is wrapped into a C++ statically
10+
// compiled template function that optionally switches to WXExec if necessary.
11+
12+
-#ifdef __APPLE__
13+
-
14+
static address generated_fast_get_field[T_LONG + 1 - T_BOOLEAN];
15+
16+
template<int BType> struct BasicTypeToJni {};
17+
@@ -85,15 +83,6 @@ address JNI_FastGetField::generate_fast_
18+
return (address)static_fast_get_field_wrapper<BType>;
19+
}
20+
21+
-#else // __APPLE__
22+
-
23+
-template<int BType>
24+
-address JNI_FastGetField::generate_fast_get_int_field1() {
25+
- return generate_fast_get_int_field0((BasicType)BType);
26+
-}
27+
-
28+
-#endif // __APPLE__
29+
-
30+
address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
31+
const char *name;
32+
switch (type) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
$NetBSD: patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp,v 1.1 2025/08/04 13:22:06 pho Exp $
2+
3+
Backport a bugfix appeared in Java 22:
4+
https://github.com/openjdk/jdk/commit/50f31240555888018f0f496ab29c8a5932dce459
5+
6+
--- src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp.orig 2025-08-01 18:07:27.105868141 +0000
7+
+++ src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
8+
@@ -3670,6 +3670,23 @@ void MacroAssembler::load_klass(Register
9+
}
10+
}
11+
12+
+void MacroAssembler::restore_cpu_control_state_after_jni(Register tmp1, Register tmp2) {
13+
+ if (RestoreMXCSROnJNICalls) {
14+
+ Label OK;
15+
+ get_fpcr(tmp1);
16+
+ mov(tmp2, tmp1);
17+
+ // Set FPCR to the state we need. We do want Round to Nearest. We
18+
+ // don't want non-IEEE rounding modes or floating-point traps.
19+
+ bfi(tmp1, zr, 22, 4); // Clear DN, FZ, and Rmode
20+
+ bfi(tmp1, zr, 8, 5); // Clear exception-control bits (8-12)
21+
+ bfi(tmp1, zr, 0, 2); // Clear AH:FIZ
22+
+ eor(tmp2, tmp1, tmp2);
23+
+ cbz(tmp2, OK); // Only reset FPCR if it's wrong
24+
+ set_fpcr(tmp1);
25+
+ bind(OK);
26+
+ }
27+
+}
28+
+
29+
// ((OopHandle)result).resolve();
30+
void MacroAssembler::resolve_oop_handle(Register result, Register tmp) {
31+
// OopHandle::resolve is an indirection.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
$NetBSD: patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp,v 1.1 2025/08/04 13:22:06 pho Exp $
2+
3+
Backport a bugfix appeared in Java 22:
4+
https://github.com/openjdk/jdk/commit/50f31240555888018f0f496ab29c8a5932dce459
5+
https://github.com/openjdk/jdk21u-dev/commit/9e582fcbb8ab34b44ff01ac13de5cc4d6487396d
6+
7+
--- src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp.orig 2025-08-01 18:05:51.700767534 +0000
8+
+++ src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
9+
@@ -559,6 +559,18 @@ public:
10+
msr(0b011, 0b0100, 0b0100, 0b001, zr);
11+
}
12+
13+
+ // FPCR : op1 == 011
14+
+ // CRn == 0100
15+
+ // CRm == 0100
16+
+ // op2 == 000
17+
+ inline void get_fpcr(Register reg) {
18+
+ mrs(0b11, 0b0100, 0b0100, 0b000, reg);
19+
+ }
20+
+
21+
+ inline void set_fpcr(Register reg) {
22+
+ msr(0b011, 0b0100, 0b0100, 0b000, reg);
23+
+ }
24+
+
25+
// DCZID_EL0: op1 == 011
26+
// CRn == 0000
27+
// CRm == 0000
28+
@@ -946,6 +958,9 @@ public:
29+
#define verify_method_ptr(reg) _verify_method_ptr(reg, "broken method " #reg, __FILE__, __LINE__)
30+
#define verify_klass_ptr(reg) _verify_klass_ptr(reg, "broken klass " #reg, __FILE__, __LINE__)
31+
32+
+ // Restore cpu control state after JNI call
33+
+ void restore_cpu_control_state_after_jni(Register tmp1, Register tmp2);
34+
+
35+
// only if +VerifyFPU
36+
void verify_FPU(int stack_depth, const char* s = "illegal FPU state");
37+

0 commit comments

Comments
 (0)