[Web Image] Fix unhandled UNSTRUCTURED_LOCKING and an order-dependent single-abstract-method failure - #14195
Open
amritk wants to merge 1 commit into
Open
Conversation
Both were found compiling ktfmt (the Kotlin formatter, which embeds the Kotlin compiler frontend and IntelliJ's intellij-core) with --tool:svm-wasm. Unhandled UNSTRUCTURED_LOCKING (GR issue: unhandled BytecodeExceptionKind) WebImageImplicitExceptionsFeature.getSupportMethodName maps thirteen BytecodeExceptionKinds to support methods in Web Image's ImplicitExceptions and falls through to shouldNotReachHere for UNSTRUCTURED_LOCKING, so an image whose reachable graph produces such a node cannot be built at all. This adds the missing nullary creator, following the shape of the other kinds that carry a fixed message (createNewNegativeLengthException and createNewArgumentIsNotArrayException), and maps the kind to it. java.lang.Object filter silently disabled by initialization order ReflectUtil.singleAbstractMethodForInterface skips abstract methods that match a public java.lang.Object method, per JLS 9.8, so a @FunctionalInterface may legally redeclare hashCode(). It built that filter set from ResolvedJavaType.getDeclaredMethods(false), which returns an empty array for a type that is not linked yet and is never allowed to force linking. The result is cached in a static field for the rest of the build, so an empty result silently disables the filter for every later query. The symptom is a failed guarantee ("Incorrect single abstract method logic") naming an interface that is a legitimate functional interface - IntelliJ's RefHashMap.Key declares get() and hashCode(). It is order dependent: two identical builds of the same application named two different interfaces, RefHashMap$Key and ConcurrentRefHashMap$KeyReference, because which query happens to populate the cache first depends on the parallel analysis. Building the set by reflecting over the host java.lang.Object removes the linkage dependency entirely, and a guarantee makes an empty set loud rather than silently wrong. Verified by compiling ktfmt 0.64 with --tool:svm-wasm: the build now completes and produces a 33MB WasmGC module, where before it failed at analysis on the second issue and at code generation on the first.
|
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two independent Web Image build failures, both found compiling ktfmt (the Kotlin
formatter, which embeds the Kotlin compiler frontend and IntelliJ's
intellij-core) with
--tool:svm-wasm.Unhandled
UNSTRUCTURED_LOCKING.WebImageImplicitExceptionsFeature.getSupportMethodNamemaps thirteenBytecodeExceptionKinds to support methods in Web Image'sImplicitExceptionsand falls through to
shouldNotReachHereforUNSTRUCTURED_LOCKING, so an imagewhose reachable graph produces such a node cannot be built at all. This adds the
missing nullary creator, following the shape of the other kinds that carry a
fixed message (
createNewNegativeLengthException,createNewArgumentIsNotArrayException), and maps the kind to it.A nullary creator rather than one taking the message: the regular SVM backend
maps this kind to
CREATE_ILLEGAL_MONITOR_STATE_EXCEPTION, which takes aString, andNonSnippetLoweringsappendsgetExceptionMessage()as a constantargument during lowering. Web Image's feature compares
node.getArguments()against the support method's parameter count directly with no such append, so a
one-parameter creator would fail the arity check.
java.lang.Objectfilter silently disabled by initialization order.ReflectUtil.singleAbstractMethodForInterfaceskips abstract methods matching apublic
java.lang.Objectmethod, per JLS 9.8, so a@FunctionalInterfacemaylegally redeclare
hashCode(). It built that filter set fromResolvedJavaType.getDeclaredMethods(false), which returns an empty array for atype that is not linked yet and is never allowed to force linking
(
AnalysisType.getDeclaredMethodsguarantees!forceLink). The result is cachedin a static field for the rest of the build, so an empty result silently disables
the filter for every later query.
The symptom is a failed guarantee ("Incorrect single abstract method logic")
naming an interface that is a legitimate functional interface — IntelliJ's
RefHashMap.Keydeclaresget()andhashCode(). It is order dependent: twoidentical builds of the same application named two different interfaces,
RefHashMap$KeyandConcurrentRefHashMap$KeyReference, because which queryhappens to populate the cache first depends on the parallel analysis.
Building the set by reflecting over the host
java.lang.Objectremoves thelinkage dependency entirely, and a guarantee makes an empty set loud rather than
silently wrong.
Related Issues
UNSTRUCTURED_LOCKING)report is wrong — the
Object-method filter already exists and is correct; itis the cached empty set that disables it. Corrected in a comment on the issue.
Testing
No automated test is included, and I would appreciate direction on where one
belongs.
I did write a unit test against
singleAbstractMethodForInterfaceand thenremoved it: called with host JVMCI types it returns empty for every interface,
because
GuestAnnotationAccesscannot read@FunctionalInterfaceoff them, soit asserted nothing. It also would not have caught the original bug, which
depends on analysis ordering rather than on the shape of the interface. A
meaningful regression test looks like a real image build, and I would rather
follow your lead than guess at the harness.
Verified manually:
mx buildin theweb-imagesuite, against labsjdkce-25.0.4+7-jvmci-25.2-b20(thelabsjdk-ce-latestpin incommon.json),Linux x64.
--tool:svm-wasmthrough the builtnative-image.Before: analysis fails on [Web Image] --tool:svm-wasm: "Incorrect single abstract method logic" for a non-functional interface reaching the JS boundary #14192; with only that fixed, code generation fails
on [Web Image] --tool:svm-wasm: unhandled UNSTRUCTURED_LOCKING in WebImageImplicitExceptionsFeature aborts code generation #14193. After both: the build completes and produces a 33MB WasmGC module
(12,320 types and 57,270 methods reachable).
exported entry point is reachable.
longer appears.
Scope note: the module builds and boots but cannot yet do useful work, because
AtomicReferenceFieldUpdater.newUpdaterthrows at run time under Web Image.That is unrelated to either fix here, reproduces on a released 25.2.4 with a
15-line example, and is filed separately — nothing in this PR is intended to
address it.
Documentation
No documentation updates. Both changes are internal to the Web Image builder and
alter no documented behaviour, option, or API.
Contributor Checklist