pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/lang/openjdk17



Module Name:    pkgsrc
Committed By:   pho
Date:           Wed Aug  6 08:47:16 UTC 2025

Modified Files:
        pkgsrc/lang/openjdk17: Makefile bootstrap.mk distinfo hacks.mk
            options.mk
Added Files:
        pkgsrc/lang/openjdk17/patches:
            patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp
            patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp
            patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp
            patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp
            patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp
            patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp
            patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp
            patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp
            patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp

Log Message:
lang/openjdk17: 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 implementation details of a particular chip is
fundamentally unsound, and that's why it didn't work on Apple Silicon in
the first place.

But since the upstream has stated they are knowingly doing this, the chance
of these patches getting accepted is slim, if not zero.

Also backported fixes regarding floating point arithmetics that appeared in
OpenJDK 22.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 pkgsrc/lang/openjdk17/Makefile
cvs rdiff -u -r1.7 -r1.8 pkgsrc/lang/openjdk17/bootstrap.mk
cvs rdiff -u -r1.22 -r1.23 pkgsrc/lang/openjdk17/distinfo
cvs rdiff -u -r1.1 -r1.2 pkgsrc/lang/openjdk17/hacks.mk
cvs rdiff -u -r1.3 -r1.4 pkgsrc/lang/openjdk17/options.mk
cvs rdiff -u -r0 -r1.1 \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp
cvs rdiff -u -r0 -r1.5 \
    pkgsrc/lang/openjdk17/patches/patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/lang/openjdk17/Makefile
diff -u pkgsrc/lang/openjdk17/Makefile:1.34 pkgsrc/lang/openjdk17/Makefile:1.35
--- pkgsrc/lang/openjdk17/Makefile:1.34 Sun Jun 15 13:43:21 2025
+++ pkgsrc/lang/openjdk17/Makefile      Wed Aug  6 08:47:15 2025
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.34 2025/06/15 13:43:21 ryoon Exp $
+# $NetBSD: Makefile,v 1.35 2025/08/06 08:47:15 pho Exp $
 
 DISTNAME=      jdk17u-${GITHUB_TAG:C/\+/-/}
 PKGNAME=       openjdk17-1.${GITHUB_TAG:C/\+/./:C/jdk-([.0-9]+).*/\1/}
@@ -49,6 +49,7 @@ CONFIG_GUESS_OVERRIDE+=       make/autoconf/bu
 CONFIG_SUB_OVERRIDE+=  make/autoconf/build-aux/autoconf-config.sub
 CONFIG_GUESS_OVERRIDE+=        make/autoconf/build-aux/autoconf-config.guess
 USE_LANGUAGES=         c c++
+USE_CXX_FEATURES=      c++14
 USE_TOOLS+=            bash gmake pax pkg-config unzip:run zip:run autoconf automake
 UNLIMIT_RESOURCES=     datasize stacksize virtualsize cputime
 
@@ -57,7 +58,10 @@ BUILDLINK_PASSTHRU_DIRS+=    ${ALT_BOOTDIR}
 # Try to use less POSIX semaphores (large MAKE_JOBS can consume them all)
 BOOT_JVMARGS=  -XX:+UnlockDiagnosticVMOptions
 
-CONFIGURE_ARGS+=       --prefix=${PREFIX}
+# ${WRKSRC}/doc/building.mk explicitly states that its Makefiles are unsafe
+# to use -j.
+MAKE_JOBS_SAFE=        no
+
 CONFIGURE_ARGS+=       --openjdk-target=${MACHINE_GNU_PLATFORM}
 CONFIGURE_ARGS+=       --with-boot-jdk=${ALT_BOOTDIR}
 CONFIGURE_ARGS+=       --with-boot-jdk-jvmargs=${BOOT_JVMARGS:Q}
@@ -135,6 +139,33 @@ SUBST_FILES.fontpaths=             make/data/fontco
 SUBST_FILES.fontpaths+=                src/java.desktop/unix/native/common/awt/fontpath.c
 SUBST_VARS.fontpaths=          PREFIX BUILDLINK_PREFIX.fontconfig
 
+.if ${MACHINE_ARCH} == "aarch64"
+# See patches/patch-*threadWXSetters* for details.
+SUBST_CLASSES+=                        aa64-membar
+SUBST_STAGE.aa64-membar=       pre-build
+SUBST_MESSAGE.aa64-membar=     Fixing cache coherency issues
+SUBST_SED.aa64-membar=         -e 's/MACOS_AARCH64_ONLY(ThreadWXEnable /AARCH64_ONLY(ThreadWXEnable /'
+SUBST_FILES.aa64-membar+=      src/hotspot/share/c1/c1_Runtime1.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/code/nmethod.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/gc/shared/barrierSetNMethod.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/gc/z/zBarrierSetNMethod.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/interpreter/interpreterRuntime.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/prims/jniCheck.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/prims/jvmtiEnter.xsl
+SUBST_FILES.aa64-membar+=      src/hotspot/share/prims/jvmtiEnv.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/prims/universalNativeInvoker.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/prims/universalUpcallHandler.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/prims/unsafe.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/prims/whitebox.inline.hpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/runtime/deoptimization.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/runtime/interfaceSupport.inline.hpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/runtime/safepoint.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/runtime/sharedRuntime.cpp
+SUBST_FILES.aa64-membar+=      src/hotspot/share/runtime/thread.cpp
+.endif
+
 .if ${OPSYS} == "NetBSD"
 # NetBSD's EVFILT_* EV_* are different from FreeBSD/OpenBSD's values.
 SUBST_CLASSES+=                        kqueue

Index: pkgsrc/lang/openjdk17/bootstrap.mk
diff -u pkgsrc/lang/openjdk17/bootstrap.mk:1.7 pkgsrc/lang/openjdk17/bootstrap.mk:1.8
--- pkgsrc/lang/openjdk17/bootstrap.mk:1.7      Wed May 25 20:00:56 2022
+++ pkgsrc/lang/openjdk17/bootstrap.mk  Wed Aug  6 08:47:15 2025
@@ -1,11 +1,11 @@
-# $NetBSD: bootstrap.mk,v 1.7 2022/05/25 20:00:56 tnn Exp $
+# $NetBSD: bootstrap.mk,v 1.8 2025/08/06 08:47:15 pho Exp $
 
 .if ${OPSYS} == "NetBSD" && ${OPSYS_VERSION} < 090000
 PKG_FAIL_REASON+=              "Only supports NetBSD >= 9"
 .endif
 
-.if (!empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) ||!empty(MACHINE_PLATFORM:MNetBSD-*-*earm*)) && ${OPSYS_VERSION} < 099983
-PKG_FAIL_REASON+=              "PR 55248: please update to NetBSD >= 9.99.83 to use this package"
+.if !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) && ${OPSYS_VERSION} < 090400
+PKG_FAIL_REASON+=              "Only supports NetBSD >= 9.4"
 .endif
 
 ONLY_FOR_PLATFORM+=            NetBSD-*-i386
@@ -25,7 +25,7 @@ EXTRACT_ONLY+=                        ${BOOT.nb9-amd64}
 .endif
 
 ONLY_FOR_PLATFORM+=            NetBSD-*-aarch64
-BOOT.nb9-aarch64=              bootstrap-jdk-1.17.0.3.7-netbsd-9-aarch64-20220516.tar.xz
+BOOT.nb9-aarch64=              bootstrap-jdk-1.17.0.15.6-netbsd-9-aarch64-20250806.tar.xz
 SITES.${BOOT.nb9-aarch64}=     ${MASTER_SITE_LOCAL:=openjdk17/}
 .if !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) || make(distinfo)
 DISTFILES+=                    ${BOOT.nb9-aarch64}

Index: pkgsrc/lang/openjdk17/distinfo
diff -u pkgsrc/lang/openjdk17/distinfo:1.22 pkgsrc/lang/openjdk17/distinfo:1.23
--- pkgsrc/lang/openjdk17/distinfo:1.22 Sun Jun 15 13:43:21 2025
+++ pkgsrc/lang/openjdk17/distinfo      Wed Aug  6 08:47:15 2025
@@ -1,8 +1,8 @@
-$NetBSD: distinfo,v 1.22 2025/06/15 13:43:21 ryoon Exp $
+$NetBSD: distinfo,v 1.23 2025/08/06 08:47:15 pho Exp $
 
-BLAKE2s (bootstrap-jdk-1.17.0.3.7-netbsd-9-aarch64-20220516.tar.xz) = b632092d25292e795a2d7567ec55d03f21021dbba27eab3e81a48aed5e5bdd68
-SHA512 (bootstrap-jdk-1.17.0.3.7-netbsd-9-aarch64-20220516.tar.xz) = fb86749d56be94cc1509f92d8fbdec481b0c7f6fdd5e731826098e6eaa668539052571ffd09125346c1920262b07857ea675799ab8476fcff53c03e158536c1d
-Size (bootstrap-jdk-1.17.0.3.7-netbsd-9-aarch64-20220516.tar.xz) = 105121752 bytes
+BLAKE2s (bootstrap-jdk-1.17.0.15.6-netbsd-9-aarch64-20250806.tar.xz) = cd7cd0c0acc259f55291932fc679388003c3c108257f08f660d328974b764ee5
+SHA512 (bootstrap-jdk-1.17.0.15.6-netbsd-9-aarch64-20250806.tar.xz) = 26003c0ace59f41b03584ae0bbe79b15041d4c3537d5d4227a3396276943ff95d687de0aa5025b5dddb1d91cf33ffbc7fd57d7cc8de70aef53907fa2c2652811
+Size (bootstrap-jdk-1.17.0.15.6-netbsd-9-aarch64-20250806.tar.xz) = 104813852 bytes
 BLAKE2s (bootstrap-jdk-1.17.0.3.7-netbsd-9-amd64-20220515.tar.xz) = 5da928c9ad945b0be6eebdada9788fe0f837a52d1e50ffa3535ef4115700f20a
 SHA512 (bootstrap-jdk-1.17.0.3.7-netbsd-9-amd64-20220515.tar.xz) = 785a6f203e7e5a31f48c708e6a33aa28f00b742226248e2757564d521c580f78070145e4a5dedf3eac1801531781143550c1c127ef6f8d310b88e864d42f4279
 Size (bootstrap-jdk-1.17.0.3.7-netbsd-9-amd64-20220515.tar.xz) = 105391720 bytes
@@ -25,6 +25,15 @@ SHA1 (patch-make_autoconf_lib-freetype.m
 SHA1 (patch-make_autoconf_lib-x11.m4) = 38038e6d7cfc2d15fb3537a52f11d2961cc2ec99
 SHA1 (patch-make_data_fontconfig_bsd.fontconfig.properties) = 3172d8d76e0e79b127605429fb70dccd164b33c8
 SHA1 (patch-make_lib_Awt2dLibraries.gmk) = d69fa8c5cab173be2f41cfbd6479dad60a6337db
+SHA1 (patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp) = 263be050505100a9ff37d75e2aa465e0ffb04d68
+SHA1 (patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp) = 8e9bcae8bf94e316618b4086590e2a9fa99a5ed9
+SHA1 (patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp) = 0b720cdfef884368432b818bb56648b462539125
+SHA1 (patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp) = 301d16361542eec9123b9a4cf0a64978cc863ed6
+SHA1 (patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp) = 248188cc49cfca7fb26b907525f19b9cec5caffd
+SHA1 (patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp) = 146a6ab00271395ddfdb42bf50375ec6c1bfd18c
+SHA1 (patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp) = 1a017334bdab5717ea2aaf4ae77a1e3974ebee0e
+SHA1 (patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp) = 86d793892426979625437ffe7634ce4b4ea93e4b
 SHA1 (patch-src_hotspot_os__cpu_bsd__x86_os__bsd__x86.cpp) = 7cdc5a746ab26df5b2be98b0d254e6018dc96fda
 SHA1 (patch-src_hotspot_os_bsd_os__bsd.cpp) = 5561ed502aa925cd3d0514c7ec298e0491d14ffc
+SHA1 (patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp) = f704bb060803e500415b5d300e26857cf7288ca5
 SHA1 (patch-src_java.desktop_unix_native_common_awt_fontpath.c) = d7bd8839ecd84459fbd3e7d14ac0e2f48b8b4032

Index: pkgsrc/lang/openjdk17/hacks.mk
diff -u pkgsrc/lang/openjdk17/hacks.mk:1.1 pkgsrc/lang/openjdk17/hacks.mk:1.2
--- pkgsrc/lang/openjdk17/hacks.mk:1.1  Fri May 13 14:24:19 2022
+++ pkgsrc/lang/openjdk17/hacks.mk      Wed Aug  6 08:47:15 2025
@@ -1,4 +1,4 @@
-# $NetBSD: hacks.mk,v 1.1 2022/05/13 14:24:19 ryoon Exp $
+# $NetBSD: hacks.mk,v 1.2 2025/08/06 08:47:15 pho Exp $
 
 .if !defined(OPENJDK17_HACKS_MK)
 OPENJDK17_HACKS_MK=    # empty
@@ -18,9 +18,12 @@ post-wrapper:
 # JDK can correctly build itself. Compiling or running programs other than
 # openjdk itself on such hardware may still cause unexpected behaviour.
 #
-
-.if !empty(MACHINE_PLATFORM:MNetBSD-*-*arm*)   || \
-       !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64)
+# The issue has been fixed in OpenJDK 22 for aarch64, and we have
+# backported the fix to this package. We aren't sure if it's still an issue
+# on 32bit ARM. Probably not? You know when the issue bites you: javac
+# enters into an infinite loop while parsing subnormal numeric constants.
+#
+.if ${MACHINE_PLATFORM:MNetBSD-*-*arm*}
 PKG_HACKS+=            broken-ieee-floats
 SUBST_CLASSES+=                fpu
 SUBST_STAGE.fpu=       pre-build

Index: pkgsrc/lang/openjdk17/options.mk
diff -u pkgsrc/lang/openjdk17/options.mk:1.3 pkgsrc/lang/openjdk17/options.mk:1.4
--- pkgsrc/lang/openjdk17/options.mk:1.3        Wed May 25 06:05:34 2022
+++ pkgsrc/lang/openjdk17/options.mk    Wed Aug  6 08:47:15 2025
@@ -1,4 +1,4 @@
-# $NetBSD: options.mk,v 1.3 2022/05/25 06:05:34 tnn Exp $
+# $NetBSD: options.mk,v 1.4 2025/08/06 08:47:15 pho Exp $
 
 PKG_OPTIONS_VAR=               PKG_OPTIONS.openjdk17
 PKG_OPTIONS_OPTIONAL_GROUPS=   variant
@@ -45,8 +45,10 @@ BUILDLINK_DEPMETHOD.libXt?=  build
 .include "../../x11/libXtst/buildlink3.mk"
 .include "../../x11/libXrandr/buildlink3.mk"
 .else
+CONFIGURE_ARGS+=       --x-includes=${X11BASE}/include
+CONFIGURE_ARGS+=       --x-libraries=${X11BASE}/lib
 CONFIGURE_ARGS+=       --enable-headless-only
-# We apparently still need the Xlib headers to build headless. why?
+# We apparently still need the Xlib headers and libraries to build headless. why?
 BUILDLINK_DEPMETHOD.libX11?=   build
 .include "../../x11/libX11/buildlink3.mk"
 BUILDLINK_DEPMETHOD.libXext?=build

Added files:

Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp      Wed Aug  6 08:47:15 2025
@@ -0,0 +1,16 @@
+$NetBSD: patch-src_hotspot_cpu_aarch64_frame__aarch64.hpp,v 1.1 2025/08/06 08:47:15 pho Exp $
+
+Backport a bugfix appeared in Java 22:
+https://github.com/openjdk/jdk21u-dev/commit/9e582fcbb8ab34b44ff01ac13de5cc4d6487396d
+
+--- src/hotspot/cpu/aarch64/frame_aarch64.hpp.orig     2025-08-01 18:15:42.300499547 +0000
++++ src/hotspot/cpu/aarch64/frame_aarch64.hpp
+@@ -95,7 +95,7 @@
+     // Entry frames
+     // n.b. these values are determined by the layout defined in
+     // stubGenerator for the Java call stub
+-    entry_frame_after_call_words                     = 27,
++    entry_frame_after_call_words                     = 29,
+     entry_frame_call_wrapper_offset                  = -8,
+ 
+     // we don't need a save area
Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp    Wed Aug  6 08:47:15 2025
@@ -0,0 +1,40 @@
+$NetBSD: patch-src_hotspot_cpu_aarch64_jniFastGetField__aarch64.cpp,v 1.1 2025/08/06 08:47:15 pho Exp $
+
+Workaround for the Hotspot VM dying on Apple Silicon chips. See
+the patch to threadWXSetters.inline.hpp for details.
+
+--- src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp.orig   2025-04-19 18:17:03.000000000 +0000
++++ src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp
+@@ -32,6 +32,7 @@
+ #include "prims/jvm_misc.hpp"
+ #include "prims/jvmtiExport.hpp"
+ #include "runtime/safepoint.hpp"
++#include "runtime/thread.inline.hpp"
+ #include "runtime/threadWXSetters.inline.hpp"
+ 
+ #define __ masm->
+@@ -58,8 +59,6 @@ static const Register result        = r7
+ // (8262896).  So each FastGetXXXField is wrapped into a C++ statically
+ // compiled template function that optionally switches to WXExec if necessary.
+ 
+-#ifdef __APPLE__
+-
+ static address generated_fast_get_field[T_LONG + 1 - T_BOOLEAN];
+ 
+ template<int BType> struct BasicTypeToJni {};
+@@ -86,15 +85,6 @@ address JNI_FastGetField::generate_fast_
+   return (address)static_fast_get_field_wrapper<BType>;
+ }
+ 
+-#else // __APPLE__
+-
+-template<int BType>
+-address JNI_FastGetField::generate_fast_get_int_field1() {
+-  return generate_fast_get_int_field0((BasicType)BType);
+-}
+-
+-#endif // __APPLE__
+-
+ address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
+   const char *name;
+   switch (type) {
Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp     Wed Aug  6 08:47:15 2025
@@ -0,0 +1,31 @@
+$NetBSD: patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.cpp,v 1.1 2025/08/06 08:47:15 pho Exp $
+
+Backport a bugfix appeared in Java 22:
+https://github.com/openjdk/jdk/commit/50f31240555888018f0f496ab29c8a5932dce459
+
+--- src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp.orig    2025-08-01 18:07:27.105868141 +0000
++++ src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
+@@ -3670,6 +3670,23 @@ void MacroAssembler::load_klass(Register
+   }
+ }
+ 
++void MacroAssembler::restore_cpu_control_state_after_jni(Register tmp1, Register tmp2) {
++  if (RestoreMXCSROnJNICalls) {
++    Label OK;
++    get_fpcr(tmp1);
++    mov(tmp2, tmp1);
++    // Set FPCR to the state we need. We do want Round to Nearest. We
++    // don't want non-IEEE rounding modes or floating-point traps.
++    bfi(tmp1, zr, 22, 4); // Clear DN, FZ, and Rmode
++    bfi(tmp1, zr, 8, 5);  // Clear exception-control bits (8-12)
++    bfi(tmp1, zr, 0, 2);  // Clear AH:FIZ
++    eor(tmp2, tmp1, tmp2);
++    cbz(tmp2, OK);        // Only reset FPCR if it's wrong
++    set_fpcr(tmp1);
++    bind(OK);
++  }
++}
++
+ // ((OopHandle)result).resolve();
+ void MacroAssembler::resolve_oop_handle(Register result, Register tmp) {
+   // OopHandle::resolve is an indirection.
Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp     Wed Aug  6 08:47:15 2025
@@ -0,0 +1,37 @@
+$NetBSD: patch-src_hotspot_cpu_aarch64_macroAssembler__aarch64.hpp,v 1.1 2025/08/06 08:47:15 pho Exp $
+
+Backport a bugfix appeared in Java 22:
+https://github.com/openjdk/jdk/commit/50f31240555888018f0f496ab29c8a5932dce459
+https://github.com/openjdk/jdk21u-dev/commit/9e582fcbb8ab34b44ff01ac13de5cc4d6487396d
+
+--- src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp.orig    2025-08-01 18:05:51.700767534 +0000
++++ src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
+@@ -559,6 +559,18 @@ public:
+     msr(0b011, 0b0100, 0b0100, 0b001, zr);
+   }
+ 
++  // FPCR : op1 == 011
++  //        CRn == 0100
++  //        CRm == 0100
++  //        op2 == 000
++  inline void get_fpcr(Register reg) {
++    mrs(0b11, 0b0100, 0b0100, 0b000, reg);
++  }
++
++  inline void set_fpcr(Register reg) {
++    msr(0b011, 0b0100, 0b0100, 0b000, reg);
++  }
++
+   // DCZID_EL0: op1 == 011
+   //            CRn == 0000
+   //            CRm == 0000
+@@ -946,6 +958,9 @@ public:
+ #define verify_method_ptr(reg) _verify_method_ptr(reg, "broken method " #reg, __FILE__, __LINE__)
+ #define verify_klass_ptr(reg) _verify_klass_ptr(reg, "broken klass " #reg, __FILE__, __LINE__)
+ 
++  // Restore cpu control state after JNI call
++  void restore_cpu_control_state_after_jni(Register tmp1, Register tmp2);
++
+   // only if +VerifyFPU
+   void verify_FPU(int stack_depth, const char* s = "illegal FPU state");
+ 
Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp      Wed Aug  6 08:47:16 2025
@@ -0,0 +1,17 @@
+$NetBSD: patch-src_hotspot_cpu_aarch64_sharedRuntime__aarch64.cpp,v 1.1 2025/08/06 08:47:16 pho Exp $
+
+Backport a bugfix appeared in Java 22:
+https://github.com/openjdk/jdk/commit/50f31240555888018f0f496ab29c8a5932dce459
+
+--- src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp.orig     2025-08-01 17:56:57.114189168 +0000
++++ src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp
+@@ -1806,6 +1806,9 @@ nmethod* SharedRuntime::generate_native_
+   intptr_t return_pc = (intptr_t) __ pc();
+   oop_maps->add_gc_map(return_pc - start, map);
+ 
++  // Restore cpu control state after JNI call
++  __ restore_cpu_control_state_after_jni(rscratch1, rscratch2);
++
+   // Unpack native results.
+   switch (ret_type) {
+   case T_BOOLEAN: __ c2bool(r0);                     break;
Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp      Wed Aug  6 08:47:16 2025
@@ -0,0 +1,55 @@
+$NetBSD: patch-src_hotspot_cpu_aarch64_stubGenerator__aarch64.cpp,v 1.1 2025/08/06 08:47:16 pho Exp $
+
+Backport a bugfix appeared in Java 22:
+https://github.com/openjdk/jdk21u-dev/commit/9e582fcbb8ab34b44ff01ac13de5cc4d6487396d
+
+--- src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp.orig     2025-08-01 18:21:30.132638820 +0000
++++ src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
+@@ -160,8 +160,9 @@ class StubGenerator: public StubCodeGene
+ 
+   // Call stub stack layout word offsets from fp
+   enum call_stub_layout {
+-    sp_after_call_off = -26,
++    sp_after_call_off = -28,
+ 
++    fpcr_off           = sp_after_call_off,
+     d15_off            = -26,
+     d13_off            = -24,
+     d11_off            = -22,
+@@ -191,8 +192,9 @@ class StubGenerator: public StubCodeGene
+     StubCodeMark mark(this, "StubRoutines", "call_stub");
+     address start = __ pc();
+ 
+-    const Address sp_after_call(rfp, sp_after_call_off * wordSize);
++    const Address sp_after_call (rfp, sp_after_call_off * wordSize);
+ 
++    const Address fpcr_save     (rfp, fpcr_off           * wordSize);
+     const Address call_wrapper  (rfp, call_wrapper_off   * wordSize);
+     const Address result        (rfp, result_off         * wordSize);
+     const Address result_type   (rfp, result_type_off    * wordSize);
+@@ -241,6 +243,14 @@ class StubGenerator: public StubCodeGene
+     __ stpd(v13, v12,  d13_save);
+     __ stpd(v15, v14,  d15_save);
+ 
++    __ get_fpcr(rscratch1);
++    __ str(rscratch1, fpcr_save);
++    // Set FPCR to the state we need. We do want Round to Nearest. We
++    // don't want non-IEEE rounding modes or floating-point traps.
++    __ bfi(rscratch1, zr, 22, 4); // Clear DN, FZ, and Rmode
++    __ bfi(rscratch1, zr, 8, 5);  // Clear exception-control bits (8-12)
++    __ set_fpcr(rscratch1);
++
+     // install Java thread in global register now we have saved
+     // whatever value it held
+     __ mov(rthread, c_rarg7);
+@@ -352,6 +362,10 @@ class StubGenerator: public StubCodeGene
+     __ ldp(r22, r21,   r22_save);
+     __ ldp(r20, r19,   r20_save);
+ 
++    // restore fpcr
++    __ ldr(rscratch1,  fpcr_save);
++    __ set_fpcr(rscratch1);
++
+     __ ldp(c_rarg0, c_rarg1,  call_wrapper);
+     __ ldrw(c_rarg2, result_type);
+     __ ldr(c_rarg3,  method);
Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp       Wed Aug  6 08:47:16 2025
@@ -0,0 +1,17 @@
+$NetBSD: patch-src_hotspot_cpu_aarch64_templateInterpreterGenerator__aarch64.cpp,v 1.1 2025/08/06 08:47:16 pho Exp $
+
+Backport a bugfix appeared in Java 22:
+https://github.com/openjdk/jdk/commit/50f31240555888018f0f496ab29c8a5932dce459
+
+--- src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp.orig      2025-08-01 18:02:38.517120527 +0000
++++ src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp
+@@ -1365,6 +1365,9 @@ address TemplateInterpreterGenerator::ge
+   __ get_method(rmethod);
+   // result potentially in r0 or v0
+ 
++  // Restore cpu control state after JNI call
++  __ restore_cpu_control_state_after_jni(rscratch1, rscratch2);
++
+   // make room for the pushes we're about to do
+   __ sub(rscratch1, esp, 4 * wordSize);
+   __ andr(sp, rscratch1, -16);
Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp:1.1
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp    Wed Aug  6 08:47:16 2025
@@ -0,0 +1,63 @@
+$NetBSD: patch-src_hotspot_share_runtime_threadWXSetters.inline.hpp,v 1.1 2025/08/06 08:47:16 pho Exp $
+
+Workaround for the Hotspot VM dying on Apple Silicon chips:
+https://mail-index.netbsd.org/tech-pkg/2025/07/12/msg031385.html
+
+The problem is basically that Hotspot outrightly violates the architecture
+spec, and then it does all kinds of weird workarounds to compensate,
+assuming their workarounds happen to work on some implementations of actual
+chips. It essentially relies on implementation details of chips:
+https://cr.openjdk.org/~jrose/jvm/hotspot-cmc.html
+
+However, their workaround does not work on Apple Silicon. It's not Apple's
+fault, because Hotspot knowingly violates the spec. The problem does not
+come to the surface on Darwin/aarch64 but it's only by an accident:
+Darwin/aarch64 strictly forbids executing code in writable pages, and
+provides a non-portable function pthread_jit_write_protect_np(), which
+Hotspot uses every time it needs to modify code in memory.
+
+The function temporarily write-protects every executable page in the entire
+process space but only for the calling thread, so that the thread can
+execute code in pages that are otherwise writable. The important fact is
+that the function happens to issue data and instruction memory barriers
+(i.e. DSB and ISB) in its implementation. It turned out these barriers were
+what made Hotspot work on Apple Silicon.
+
+So, in order to make it work on non-Darwin OSes on Apple Silicon, and
+possibly on other non-Cortex aarch64 chips, we must issue memory barriers
+every time it would call pthread_jit_write_protect_np() on
+Darwin/aarch64. FreeBSD suffers from the same problem:
+https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=265284
+
+--- src/hotspot/share/runtime/threadWXSetters.inline.hpp.orig  2025-08-01 07:55:07.225394550 +0000
++++ src/hotspot/share/runtime/threadWXSetters.inline.hpp
+@@ -43,6 +43,29 @@ public:
+     }
+   }
+ };
++#elif defined(AARCH64)
++class ThreadWXEnable  {
++  WXMode _new_mode;
++public:
++  ThreadWXEnable(WXMode new_mode, Thread*) :
++    _new_mode(new_mode)
++  {
++    if (_new_mode == WXExec) {
++      // We are going to execute some code that has been potentially
++      // modified.
++      __asm__ __volatile__ ("dsb\tsy\n"
++                            "isb\tsy" : : : "memory");
++    }
++  }
++  ~ThreadWXEnable() {
++    if (_new_mode == WXWrite) {
++      // We may have modified some code that is going to be executed
++      // outside of this block.
++      __asm__ __volatile__ ("dsb\tsy\n"
++                            "isb\tsy" : : : "memory");
++    }
++  }
++};
+ #endif // __APPLE__ && AARCH64
+ 
+ #endif // SHARE_RUNTIME_THREADWXSETTERS_INLINE_HPP

Index: pkgsrc/lang/openjdk17/patches/patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp
diff -u /dev/null pkgsrc/lang/openjdk17/patches/patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp:1.5
--- /dev/null   Wed Aug  6 08:47:16 2025
+++ pkgsrc/lang/openjdk17/patches/patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp   Wed Aug  6 08:47:16 2025
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_hotspot_os__cpu_bsd__aarch64_os__bsd__aarch64.cpp,v 1.5 2025/08/06 08:47:16 pho Exp $
+
+Workaround for the Hotspot VM dying on Apple Silicon chips. See
+the patch to threadWXSetters.inline.hpp for details.
+
+--- src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp.orig     2025-08-05 06:55:35.035540383 +0000
++++ src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp
+@@ -765,6 +765,11 @@ bool PosixSignals::pd_hotspot_signal_han
+     assert(sig == info->si_signo, "bad siginfo");
+   }
+ */
++
++  // Enable WXWrite: this function is called by the signal handler at arbitrary
++  // point of execution.
++  ThreadWXEnable wx(WXWrite, thread);
++
+   // decide if this trap can be handled by a stub
+   address stub = NULL;
+ 



Home | Main Index | Thread Index | Old Index