Postpone registering for exception events #22886
Draft
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
In Java 25+,
jdk.internal.misc.Unsafe.INVALID_FIELD_OFFSEThas typelong, notint, so aNoSuchFieldErroris thrown byGetStaticFieldID()called withinsun.misc.Unsafe.registerNatives(). Normally that error is just ignored, but if a user supplies an-Xdumpoption which requires checking the call stack, that check fails because the offset ofThrowable.walkbackhas not been captured for use byJ9VMJAVALANGTHROWABLE_WALKBACK(), etc. The result is that the lock word (at offset zero after the header) is read and interpreted as a heap reference. On must platforms, the initial lock word is zero which behaves likenullwhichiterateStackTraceImpl()handles as an unavailablewalkbackobject. On POWER, however, the initial lock is normally non-zero (but not a valid heap reference), resulting in a crash.This change avoids problems like this early in the lifetime of a JVM by not registering dump hooks for exception events until after all the known classes, fields and methods have been resolved (including the offset of
Throwable.walkback).The change is organized into three commits:
trigger.c, but no functional changestrigger.cto delay installing hooks for exception-related eventssun.misc.Unsafe.registerNatives()