Skip to content

[F-Req] Java 17/21 support for HarmonyOS NEXT #157

@joaquimbc

Description

@joaquimbc

Describe the bug

Running JRE versions other than 8 on HarmonyOS's Android compatibility layer crashes the game immediately.

The log file and images/videos

latestlog.txt --------- Starting game with Launcher Debug! Info: Launcher version: amethyst-legacy-20251219-603ff97-feat/import-modpack Info: Architecture: arm64 Info: Device model: HUAWEI QXS-W00 Info: API version: 31 Info: Selected Minecraft version: 1.21.10 Info: Custom Java arguments: "-Xint" Info: Graphics device: HUAWEI Maleoon 910 (OpenGL ES 3) Writing MG configs to /data/user/0/org.angelauramc.amethyst.debug/MobileGlues/config.json MG Config is { "enableANGLE": 0, "enableNoError": 0, "fsr1Setting": 0, "enableExtGL43": 0, "enableExtComputeShader": 0, "angleDepthClearFixMode": 0, "enableExtTimerQuery": 0, "enableExtDirectStateAccess": 0, "multidrawMode": 0, "maxGlslCacheSize": 128 } Added custom env: TMPDIR=/data/user/0/org.angelauramc.amethyst.debug/cache Added custom env: AWTSTUB_WIDTH=1716 Added custom env: FORCE_VSYNC=true Added custom env: POJAV_NATIVEDIR=/data/app/~~PrKXXfoYIkOK_tyMkUnO6w==/org.angelauramc.amethyst.debug-qyxrgiOAri4bH4azDqe3nA==/lib/arm64 Added custom env: MG_DIR_PATH=/data/user/0/org.angelauramc.amethyst.debug/MobileGlues Added custom env: LIBGL_MIPMAP=3 Added custom env: allow_higher_compat_version=true Added custom env: MESA_GLSL_CACHE_DIR=/data/user/0/org.angelauramc.amethyst.debug/cache Added custom env: HOME=/storage/emulated/0/Android/data/org.angelauramc.amethyst.debug/files Added custom env: PATH=/data/user/0/org.angelauramc.amethyst.debug/runtimes/Internal-21/bin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin Added custom env: LIBGL_NOINTOVLHACK=1 Added custom env: force_glsl_extensions_warn=true Added custom env: LIBGL_NORMALIZE=1 Added custom env: POJAV_VSYNC_IN_ZINK=1 Added custom env: LD_LIBRARY_PATH=/data/user/0/org.angelauramc.amethyst.debug/runtimes/Internal-21/lib/jli:/data/user/0/org.angelauramc.amethyst.debug/runtimes/Internal-21/lib:/system/lib64:/vendor/lib64:/vendor/lib64/hw:/data/app/~~PrKXXfoYIkOK_tyMkUnO6w==/org.angelauramc.amethyst.debug-qyxrgiOAri4bH4azDqe3nA==/lib/arm64 Added custom env: LIBGL_NOERROR=1 Added custom env: POJAV_RENDERER=opengles_mobileglues Added custom env: LIBGL_ES=2 Added custom env: VTEST_SOCKET_NAME=/data/user/0/org.angelauramc.amethyst.debug/cache/.virgl_test Added custom env: MESA_LOADER_DRIVER_OVERRIDE=zink Added custom env: POJAVEXEC_EGL=libmobileglues.so Added custom env: JAVA_HOME=/data/user/0/org.angelauramc.amethyst.debug/runtimes/Internal-21 Added custom env: allow_glsl_extension_directive_midshader=true Added custom env: AWTSTUB_HEIGHT=1144 Initializing MobileGlues ... The Open Source License of MobileGlues: GNU LGPL-2.1 License MG_DIR_PATH = /data/user/0/org.angelauramc.amethyst.debug/MobileGlues [MobileGlues] Setting: enableAngle = false [MobileGlues] Setting: ignoreError = 0 [MobileGlues] Setting: enableExtComputeShader = false [MobileGlues] Setting: enableExtGL43 = false [MobileGlues] Setting: enableExtTimerQuery = false [MobileGlues] Setting: enableExtDirectStateAccess = false [MobileGlues] Setting: maxGlslCacheSize = 128 [MobileGlues] Setting: angleDepthClearFixMode = 0 [MobileGlues] Setting: bufferCoherentAsFlush = 1 [MobileGlues] Setting: customGLVersion = 4.0.0 [MobileGlues] Setting: fsr1Setting = 0 EGL initialized successfully OpenGL ES Version: OpenGL ES 3.2 (320) Detected GL_EXT_multi_draw_indirect! [MobileGlues] Setting: multidrawMode = Auto multidrawMode = Auto -> MultidrawIndirect (Auto detected)

A fatal error has been detected by the Java Runtime Environment:

SIGILL (0x4) at pc=0x00000065b2013ba8, pid=39180, tid=39245

JRE version: (21.0.1) (build )
Java VM: OpenJDK 64-Bit Server VM (21.0.1-internal-adhoc.runner.openjdk-21, mixed mode, tiered, g1 gc, linux-aarch64)
Problematic frame:
j java.lang.System.registerNatives()V+0 java.base

Core dump will be written. Default location: core.39180 (may not exist)

An error report file with more information is saved as:
/storage/emulated/0/Android/data/org.angelauramc.amethyst.debug/files/.minecraft/hs_err_pid39180.log
[0.043s][warning][os] Loading hsdis library failed

The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.

Steps To Reproduce

1. Start any Minecraft version with JRE>=17
2. Click play
3. Crash

Expected Behavior

Not crash immediately ;p

Platform

- Device model: MatePad Edge
- CPU architecture: AARCH64
- Android version: Android 12
- Amethyst version:

Anything else?

I know this is probably out-of-scope as it's technically not an Android problem... but I would appreciate getting a little insight on it. I've tried debugging it myself but I'm not really familiar with Java, JVM's internals or how it's handled/modified on the launcher

Basically, as the log says it runs into a SIGILL right at the beginning when loading native code. The problem instruction at the crashing address is DCPS1 (C1 D5 BB D4), probably coming from here

void MacroAssembler::stop(const char* msg) {
  // Skip AOT caching C strings in scratch buffer.
  const char* str = (code_section()->scratch_emit()) ? msg : AOTCodeCache::add_C_string(msg);
  BLOCK_COMMENT(str);
  // load msg into r0 so we can access it from the signal handler
  // ExternalAddress enables saving and restoring via the code cache
  lea(c_rarg0, ExternalAddress((address) str));
  dcps1(0xdeae);
}

I'm not sure if stop() is executed because of some failed safety assertion or if it's supposed to self-correct itself, the crash dump has R0 as null so if this didn't crash it wouldn't display a message. Either Kirin chips don't support it or HarmonyOS's emulator doesn't implement it. Older Java versions use BRK instead of DCPS1, which is probably why it won't crash on Java 8

As I said, I don't understand much of Java so I don't know if modifying the JVM to use the old BRK instructions would fix it, or possibly compiling the zero version of hotspot to see if it still fails. I would be willing to fix it myself (if it's something fixable ;p), just a bit unsure on where to start

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions