Skip to content

Fix jdk.internal.misc.Unsafe.registerNatives not called in -server17 - #158

Open
luchsh wants to merge 1 commit into
jdk17u-target8from
bugfix/jdk-internal-misc-unsafe-registration
Open

Fix jdk.internal.misc.Unsafe.registerNatives not called in -server17#158
luchsh wants to merge 1 commit into
jdk17u-target8from
bugfix/jdk-internal-misc-unsafe-registration

Conversation

@luchsh

@luchsh luchsh commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

rt17.jar is built from cvm/alt_kernel/src17u/share/classes and ships jdk.internal.misc.Unsafe for the -server17 kernel. The static initializer of this class is expected to call registerNatives() so that JVM_RegisterJDKInternalMiscUnsafeMethods installs the private native implementations (objectFieldOffset0/1, allocateMemory0, staticFieldOffset0, etc.) required by the rest of jdk.internal.*.

The registerNatives() call was commented out in the alt_kernel source, which produced rt17.jar classfiles whose does not invoke registerNatives(). As a consequence, any code path that reaches jdk.internal.misc.Unsafe. followed by a call to a private native (e.g. InnocuousThread. calling objectFieldOffset -> objectFieldOffset1 during Cleaner.start) fails with:

  java.lang.UnsatisfiedLinkError:
    'long jdk.internal.misc.Unsafe.objectFieldOffset1(Class,String)'
    at jdk.internal.misc.InnocuousThread.<clinit>
    at jdk.internal.ref.CleanerImpl$InnocuousThreadFactory.newThread
    at java.lang.ref.Cleaner.create

Fix: re-enable the registerNatives() call in the static initializer of cvm/alt_kernel/src17u/share/classes/jdk/internal/misc/Unsafe.java so rebuilt rt17.jar ships with the correct bytecode.

Add jtreg-style regression test
cvm/test/hotspot/runtime/Unsafe/JDKInternalMiscUnsafeRegisterNatives.java which runs with -server17 and exercises objectFieldOffset1 vs sun.misc.Unsafe.objectFieldOffset, staticFieldOffset0, and the end-to-end Cleaner.create() -> InnocuousThread path that tripped the original UnsatisfiedLinkError.

Co-worked with Doubao

@luchsh
luchsh requested a review from superajun-wsj July 31, 2026 09:02
@luchsh
luchsh force-pushed the bugfix/jdk-internal-misc-unsafe-registration branch 2 times, most recently from 601c8c3 to d0c097b Compare July 31, 2026 09:18
…n -server17

rt17.jar is built from cvm/alt_kernel/src17u/share/classes and ships
jdk.internal.misc.Unsafe for the -server17 kernel.  The static
initializer of this class is expected to call registerNatives() so
that JVM_RegisterJDKInternalMiscUnsafeMethods installs the private
native implementations (objectFieldOffset0/1, allocateMemory0,
staticFieldOffset0, etc.) required by the rest of jdk.internal.*.

The registerNatives() call was commented out in the alt_kernel source,
which produced rt17.jar classfiles whose <clinit> does not invoke
registerNatives().  As a consequence, any code path that reaches
jdk.internal.misc.Unsafe.<clinit> followed by a call to a private
native (e.g. InnocuousThread.<clinit> calling objectFieldOffset ->
objectFieldOffset1 during Cleaner.start) fails with:

  java.lang.UnsatisfiedLinkError:
    'long jdk.internal.misc.Unsafe.objectFieldOffset1(Class,String)'
    at jdk.internal.misc.InnocuousThread.<clinit>
    at jdk.internal.ref.CleanerImpl$InnocuousThreadFactory.newThread
    at java.lang.ref.Cleaner.create

Fix: re-enable the registerNatives() call in the static initializer
of cvm/alt_kernel/src17u/share/classes/jdk/internal/misc/Unsafe.java
so rebuilt rt17.jar ships with the correct <clinit> bytecode.

Add jtreg-style regression test
cvm/test/hotspot/runtime/Unsafe/JDKInternalMiscUnsafeRegisterNatives.java
which runs with -server17 and exercises objectFieldOffset1 vs
sun.misc.Unsafe.objectFieldOffset, staticFieldOffset0, and the
end-to-end Cleaner.create() -> InnocuousThread path that tripped the
original UnsatisfiedLinkError.

Co-authored-by: TRAE CLI <noreply@bytedance.com>
@luchsh
luchsh force-pushed the bugfix/jdk-internal-misc-unsafe-registration branch from d0c097b to aa8f333 Compare July 31, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant