-
Bug
-
Resolution: Fixed
-
P3
-
17
-
b26
-
aarch64
-
os_x
Testing https://github.com/openjdk/jdk/pull/2200 reveals this crash in java/foreign/StdLibTest.java
java/foreign/TestVarArgs.java
java/foreign/valist/VaListTest.java
The root cause of all three crashes is the same
snipets of stack traces:
StdLibTest.java
Current thread (0x000000012d009200): JavaThread "MainThread" [_thread_in_native, id=24579, stack(0x000000016e190000,0x000000016e393000)]
Stack: [0x000000016e190000,0x000000016e393000], sp=0x000000016e390480, free space=2049k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libsystem_platform.dylib+0xfa4] _platform_strlen+0x4
C [libsystem_c.dylib+0x6796c] __v2printf+0x194
C [libsystem_c.dylib+0x42c4c] vfprintf_l+0x44
C [libsystem_c.dylib+0x411b8] printf+0x54
C 0x047c80011209f27c
V [libjvm.dylib+0x974590] ProgrammableInvoker::invoke_native(void (*)(unsigned char*), unsigned char*, JavaThread*)+0xb8
V [libjvm.dylib+0x97473c] PI_invokeNative+0x104
printf is va_arg function as we all know.
VaListTest.java
Current thread (0x000000015c04dc00): JavaThread "MainThread" [_thread_in_native, id=39939, stack(0x0000000171644000,0x0000000171847000)]
Stack: [0x0000000171644000,0x0000000171847000], sp=0x0000000171844830, free space=2050k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libVaList.dylib+0x3ac4] sumHugeStruct+0x4
V [libjvm.dylib+0x974590] ProgrammableInvoker::invoke_native(void (*)(unsigned char*), unsigned char*, JavaThread*)+0xb8
V [libjvm.dylib+0x97473c] PI_invokeNative+0x104
j jdk.internal.foreign.abi.ProgrammableInvoker.invokeNative(JJ)V+0 jdk.incubator.foreign@17-internal
where sumHugeStruct is va_arg function:
EXPORT long long sumHugeStruct(va_list list) {
HugePoint point = va_arg(list, HugePoint);
return point.x + point.y + point.z;
}
va_args work diferently on macos_aarch64 then on intel
fixed part is passed in regs/on stack
variable part is passed on stack always
https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code
"On arm64, the compiler always places variadic parameters on the stack, regardless of whether registers are available. If you implement a function with fixed parameters, but redeclare it with variadic parameters, the mismatch causes unexpected behavior at runtime."
java/foreign/TestVarArgs.java
java/foreign/valist/VaListTest.java
The root cause of all three crashes is the same
snipets of stack traces:
StdLibTest.java
Current thread (0x000000012d009200): JavaThread "MainThread" [_thread_in_native, id=24579, stack(0x000000016e190000,0x000000016e393000)]
Stack: [0x000000016e190000,0x000000016e393000], sp=0x000000016e390480, free space=2049k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libsystem_platform.dylib+0xfa4] _platform_strlen+0x4
C [libsystem_c.dylib+0x6796c] __v2printf+0x194
C [libsystem_c.dylib+0x42c4c] vfprintf_l+0x44
C [libsystem_c.dylib+0x411b8] printf+0x54
C 0x047c80011209f27c
V [libjvm.dylib+0x974590] ProgrammableInvoker::invoke_native(void (*)(unsigned char*), unsigned char*, JavaThread*)+0xb8
V [libjvm.dylib+0x97473c] PI_invokeNative+0x104
printf is va_arg function as we all know.
VaListTest.java
Current thread (0x000000015c04dc00): JavaThread "MainThread" [_thread_in_native, id=39939, stack(0x0000000171644000,0x0000000171847000)]
Stack: [0x0000000171644000,0x0000000171847000], sp=0x0000000171844830, free space=2050k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libVaList.dylib+0x3ac4] sumHugeStruct+0x4
V [libjvm.dylib+0x974590] ProgrammableInvoker::invoke_native(void (*)(unsigned char*), unsigned char*, JavaThread*)+0xb8
V [libjvm.dylib+0x97473c] PI_invokeNative+0x104
j jdk.internal.foreign.abi.ProgrammableInvoker.invokeNative(JJ)V+0 jdk.incubator.foreign@17-internal
where sumHugeStruct is va_arg function:
EXPORT long long sumHugeStruct(va_list list) {
HugePoint point = va_arg(list, HugePoint);
return point.x + point.y + point.z;
}
va_args work diferently on macos_aarch64 then on intel
fixed part is passed in regs/on stack
variable part is passed on stack always
https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code
"On arm64, the compiler always places variadic parameters on the stack, regardless of whether registers are available. If you implement a function with fixed parameters, but redeclare it with variadic parameters, the mismatch causes unexpected behavior at runtime."
- relates to
-
JDK-8265182 [macos_aarch64] java/foreign/TestUpcall.java crashes with SIGBUS
-
- Resolved
-
-
JDK-8265183 [macos_aarch64] java/foreign/TestIntrinsics.java crashes with SIGBUS
-
- Resolved
-
-
JDK-8265292 [macos_aarch64] java/foreign/TestDowncall.java crashes with SIGBUS
-
- Resolved
-
-
JDK-8263606 [macos_aarch64] java/foreign/StdLibTest.java crashes
-
- Closed
-
-
JDK-8249755 JEP 389: Foreign Linker API (Incubator)
-
- Closed
-
(2 links to)