Skip to content

Commit 6f8a213

Browse files
committed
GR-74455: restore error message for not-compiled method of AoT class.
1 parent 6bd2a16 commit 6f8a213

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

substratevm/src/com.oracle.svm.interpreter/src/com/oracle/svm/interpreter/InterpreterFeature.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
4747
import com.oracle.graal.pointsto.meta.AnalysisMethod;
48+
import com.oracle.svm.core.InvalidMethodPointerHandler;
4849
import com.oracle.svm.core.ParsingReason;
4950
import com.oracle.svm.core.UninterruptibleAnnotationUtils;
5051
import com.oracle.svm.core.feature.InternalFeature;
@@ -256,6 +257,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
256257

257258
ImageSingletons.add(InterpreterSupport.class, new InterpreterSupportImpl(bciSlot, interpreterMethodSlot, interpreterFrameSlot, intrinsicMethodSlot, intrinsicFrameSlot));
258259
ImageSingletons.add(InterpreterDirectivesSupport.class, new InterpreterDirectivesSupportImpl());
260+
ImageSingletons.add(InterpreterNotCompiledMethodPointerHolder.class, new InterpreterNotCompiledMethodPointerHolder());
259261

260262
// Locals must be available at runtime to retrieve BCI, interpreted method and interpreter
261263
// frame.
@@ -273,7 +275,12 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
273275
public void beforeCompilation(BeforeCompilationAccess access) {
274276
FeatureImpl.BeforeCompilationAccessImpl accessImpl = (FeatureImpl.BeforeCompilationAccessImpl) access;
275277

278+
/* required so that it can hold a relocatable pointer */
279+
accessImpl.registerAsImmutable(InterpreterNotCompiledMethodPointerHolder.singleton());
276280
accessImpl.registerAsImmutable(InterpreterSupport.singleton());
281+
282+
HostedMethod methodNotCompiledHandler = accessImpl.getMetaAccess().lookupJavaMethod(InvalidMethodPointerHandler.METHOD_POINTER_NOT_COMPILED_HANDLER_METHOD);
283+
InterpreterNotCompiledMethodPointerHolder.setMethodNotCompiledHandler(InterpreterResolvedJavaMethod.createMethodRef(methodNotCompiledHandler));
277284
}
278285

279286
/**
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.interpreter;
26+
27+
import org.graalvm.nativeimage.ImageSingletons;
28+
import org.graalvm.nativeimage.Platform;
29+
import org.graalvm.nativeimage.Platforms;
30+
import org.graalvm.nativeimage.c.function.CFunctionPointer;
31+
32+
import com.oracle.svm.core.BuildPhaseProvider;
33+
import com.oracle.svm.core.MethodRefHolder;
34+
import com.oracle.svm.core.heap.UnknownObjectField;
35+
import com.oracle.svm.core.meta.MethodRef;
36+
import com.oracle.svm.shared.singletons.traits.BuiltinTraits.AllAccess;
37+
import com.oracle.svm.shared.singletons.traits.BuiltinTraits.Disallowed;
38+
import com.oracle.svm.shared.singletons.traits.BuiltinTraits.NoLayeredCallbacks;
39+
import com.oracle.svm.shared.singletons.traits.SingletonTraits;
40+
41+
import jdk.graal.compiler.api.replacements.Fold;
42+
43+
@SingletonTraits(access = AllAccess.class, layeredCallbacks = NoLayeredCallbacks.class, other = Disallowed.class)
44+
public class InterpreterNotCompiledMethodPointerHolder {
45+
@Fold
46+
public static InterpreterNotCompiledMethodPointerHolder singleton() {
47+
return ImageSingletons.lookup(InterpreterNotCompiledMethodPointerHolder.class);
48+
}
49+
50+
@UnknownObjectField(availability = BuildPhaseProvider.AfterCompilation.class) //
51+
private MethodRefHolder methodNotCompiledFtnPtr;
52+
53+
public static <T extends CFunctionPointer> T getMethodNotCompiledHandler() {
54+
T ptr = singleton().methodNotCompiledFtnPtr.getFunctionPointer();
55+
assert ptr.rawValue() != 0;
56+
return ptr;
57+
}
58+
59+
@Platforms(Platform.HOSTED_ONLY.class)
60+
public static void setMethodNotCompiledHandler(MethodRef ftnptr) {
61+
assert singleton().methodNotCompiledFtnPtr == null;
62+
singleton().methodNotCompiledFtnPtr = new MethodRefHolder(ftnptr);
63+
}
64+
}

substratevm/src/com.oracle.svm.interpreter/src/com/oracle/svm/interpreter/InterpreterToVM.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,11 @@ private static InterpreterResolvedJavaMethod resolveCallSiteTarget(InterpreterRe
850850
}
851851

852852
private static boolean shouldCallAOTEntryPoint(boolean forceStayInInterpreter, boolean preferStayInInterpreter, InterpreterResolvedJavaMethod target, boolean quiet) {
853-
boolean canBeInterpreterInvoked = target.hasBytecodes() || (RuntimeClassLoading.isSupported() && target.isSignaturePolymorphicIntrinsic());
854-
boolean canBeAOTCalled = target.hasNativeEntryPoint() && target.getNativeEntryPoint().isNonNull();
853+
boolean canBeInterpreterInvoked = target.hasBytecodes() ||
854+
(RuntimeClassLoading.isSupported() && target.isSignaturePolymorphicIntrinsic());
855+
boolean canBeAOTCalled = target.hasNativeEntryPoint() &&
856+
target.getNativeEntryPoint().isNonNull() &&
857+
!target.getNativeEntryPoint().equal(InterpreterNotCompiledMethodPointerHolder.getMethodNotCompiledHandler());
855858

856859
if (!canBeInterpreterInvoked && !canBeAOTCalled) {
857860
String source;
@@ -864,9 +867,14 @@ private static boolean shouldCallAOTEntryPoint(boolean forceStayInInterpreter, b
864867
}
865868
} else {
866869
source = "AOT";
870+
String dotPkg = target.getDeclaringClass().getSymbolicRuntimePackage().toString().replace('/', '.');
867871
if (!DynamicHub.fromClass(target.getDeclaringClass().getJavaClass()).isPreserved()) {
868-
String dotPkg = target.getDeclaringClass().getSymbolicRuntimePackage().toString().replace('/', '.');
869-
reason = MetadataUtil.fmt("Class was not preserved during image build. Consider using '-H:Preserve=package=%s'.", dotPkg);
872+
reason = MetadataUtil.fmt("Class %s was not preserved during image build.%nConsider using '-H:Preserve=package=%s'.", target.getDeclaringClass().toClassName(), dotPkg);
873+
}
874+
if (target.getNativeEntryPoint().equal(InterpreterNotCompiledMethodPointerHolder.getMethodNotCompiledHandler())) {
875+
reason = MetadataUtil.fmt(
876+
"Trying to dispatch to compiled code for AOT method %s but it was not compiled because it was not seen as reachable by analysis.%nConsider using '-H:Preserve=package=%s'",
877+
target, dotPkg);
870878
}
871879
}
872880
InterpreterUtil.guarantee(false, "Unable to call %s method: %s%n%s", source, target, reason);

0 commit comments

Comments
 (0)