Skip to content

Commit 0129b47

Browse files
committed
[GR-57248] Delay resolution of vtable slots until final layer.
PullRequest: graal/18893
2 parents c6e76a5 + 99a2146 commit 0129b47

File tree

15 files changed

+747
-439
lines changed

15 files changed

+747
-439
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/HostVM.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.Comparator;
3434
import java.util.List;
3535
import java.util.Optional;
36-
import java.util.Set;
3736
import java.util.concurrent.CopyOnWriteArrayList;
3837
import java.util.function.BiConsumer;
3938
import java.util.function.Function;
@@ -441,8 +440,4 @@ public boolean allowConstantFolding(AnalysisMethod method) {
441440
*/
442441
return method.isOriginalMethod();
443442
}
444-
445-
public Set<AnalysisMethod> loadOpenTypeWorldDispatchTableMethods(@SuppressWarnings("unused") AnalysisType type) {
446-
return Set.of();
447-
}
448443
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageLayerWriter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ protected void persistMethod(AnalysisMethod method, EconomicMap<String, Object>
430430
imageLayerWriterHelper.persistMethod(method, methodMap);
431431
}
432432

433+
public boolean isMethodPersisted(AnalysisMethod method) {
434+
String name = imageLayerSnapshotUtil.getMethodIdentifier(method);
435+
return methodsMap.containsKey(name);
436+
}
437+
433438
public void persistMethodGraphs() {
434439
for (AnalysisMethod method : aUniverse.getMethods()) {
435440
if (method.isReachable()) {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,8 @@ public Set<AnalysisMethod> getOrCalculateOpenTypeWorldDispatchTableMethods() {
13211321
return dispatchTableMethods;
13221322
}
13231323
if (getWrapped() instanceof BaseLayerType) {
1324-
var result = universe.hostVM.loadOpenTypeWorldDispatchTableMethods(this);
1325-
1326-
// ensure result is fully visible across threads
1327-
VarHandle.storeStoreFence();
1328-
dispatchTableMethods = result;
1324+
// GR-58587 implement proper support.
1325+
dispatchTableMethods = Set.of();
13291326
return dispatchTableMethods;
13301327
}
13311328

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/InvalidMethodPointerHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030

3131
import org.graalvm.nativeimage.ImageSingletons;
3232
import org.graalvm.nativeimage.LogHandler;
33+
import org.graalvm.nativeimage.Platform;
34+
import org.graalvm.nativeimage.Platforms;
3335
import org.graalvm.nativeimage.c.function.CodePointer;
3436
import org.graalvm.word.Pointer;
3537
import org.graalvm.word.WordFactory;
3638

37-
import com.oracle.svm.core.heap.RestrictHeapAccess;
3839
import com.oracle.svm.core.graal.code.StubCallingConvention;
40+
import com.oracle.svm.core.heap.RestrictHeapAccess;
3941
import com.oracle.svm.core.log.Log;
4042
import com.oracle.svm.core.snippets.KnownIntrinsics;
4143
import com.oracle.svm.core.stack.StackOverflowCheck;
@@ -47,9 +49,11 @@
4749
* the stubs provide full diagnostic output with a stack trace.
4850
*/
4951
public final class InvalidMethodPointerHandler {
52+
@Platforms(Platform.HOSTED_ONLY.class) //
5053
public static final Method INVALID_VTABLE_ENTRY_HANDLER_METHOD = ReflectionUtil.lookupMethod(InvalidMethodPointerHandler.class, "invalidVTableEntryHandler");
5154
public static final String INVALID_VTABLE_ENTRY_MSG = "Fatal error: Virtual method call used an illegal vtable entry that was seen as unused by the static analysis";
5255

56+
@Platforms(Platform.HOSTED_ONLY.class) //
5357
public static final Method METHOD_POINTER_NOT_COMPILED_HANDLER_METHOD = ReflectionUtil.lookupMethod(InvalidMethodPointerHandler.class, "methodPointerNotCompiledHandler");
5458
public static final String METHOD_POINTER_NOT_COMPILED_MSG = "Fatal error: Method pointer invoked on a method that was not compiled because it was not seen as invoked by the static analysis nor was it directly registered for compilation";
5559

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/OpenTypeWorldFeature.java

Lines changed: 19 additions & 369 deletions
Large diffs are not rendered by default.

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,13 +1078,4 @@ public boolean allowConstantFolding(AnalysisMethod method) {
10781078
public SimulateClassInitializerSupport createSimulateClassInitializerSupport(AnalysisMetaAccess aMetaAccess) {
10791079
return new SimulateClassInitializerSupport(aMetaAccess, this);
10801080
}
1081-
1082-
@Override
1083-
public Set<AnalysisMethod> loadOpenTypeWorldDispatchTableMethods(AnalysisType type) {
1084-
/*
1085-
* Will be enabled as part of GR-57248
1086-
*/
1087-
// return OpenTypeWorldFeature.loadDispatchTable(type);
1088-
return Set.of();
1089-
}
10901081
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageLayerWriter.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -194,27 +194,6 @@ private static void handleNameConflict(String message) {
194194
}
195195
}
196196

197-
@Override
198-
protected boolean shouldPersistMethod(AnalysisMethod method) {
199-
if (super.shouldPersistMethod(method)) {
200-
return true;
201-
}
202-
203-
/*
204-
* If the method is present in a dispatch table of a persisted type, then it also should be
205-
* persisted.
206-
*
207-
* Will be enabled as part of GR-57248
208-
*/
209-
/*-
210-
AnalysisType type = method.getDeclaringClass();
211-
if (type.isReachable()) {
212-
return type.getOpenTypeWorldDispatchTableMethods().contains(method);
213-
}
214-
*/
215-
return false;
216-
}
217-
218197
@Override
219198
public void persistMethod(AnalysisMethod method, EconomicMap<String, Object> methodMap) {
220199
super.persistMethod(method, methodMap);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/MethodPointerRelocationProvider.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,33 @@
2424
*/
2525
package com.oracle.svm.hosted.image;
2626

27-
import static com.oracle.svm.hosted.image.NativeImage.localSymbolNameForMethod;
27+
import org.graalvm.nativeimage.ImageSingletons;
2828

2929
import com.oracle.objectfile.ObjectFile;
3030
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3131
import com.oracle.svm.core.feature.InternalFeature;
32+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
33+
import com.oracle.svm.core.meta.MethodPointer;
34+
import com.oracle.svm.hosted.imagelayer.LayeredDispatchTableSupport;
3235
import com.oracle.svm.hosted.meta.HostedMethod;
33-
import org.graalvm.nativeimage.ImageSingletons;
3436

3537
public class MethodPointerRelocationProvider {
3638

39+
private final boolean imageLayer = ImageLayerBuildingSupport.buildingImageLayer();
40+
3741
public static MethodPointerRelocationProvider singleton() {
3842
return ImageSingletons.lookup(MethodPointerRelocationProvider.class);
3943
}
4044

4145
public void markMethodPointerRelocation(ObjectFile.ProgbitsSectionImpl section, int offset, ObjectFile.RelocationKind relocationKind, HostedMethod target,
42-
long addend, @SuppressWarnings("unused") boolean isStaticallyResolved) {
43-
section.markRelocationSite(offset, relocationKind, localSymbolNameForMethod(target), addend);
46+
long addend, MethodPointer methodPointer, boolean isInjectedNotCompiled) {
47+
String symbolName;
48+
if (imageLayer) {
49+
symbolName = LayeredDispatchTableSupport.singleton().getSymbolName(methodPointer, target, isInjectedNotCompiled);
50+
} else {
51+
symbolName = NativeImage.localSymbolNameForMethod(target);
52+
}
53+
section.markRelocationSite(offset, relocationKind, symbolName, addend);
4454
}
4555
}
4656

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
import com.oracle.svm.hosted.image.RelocatableBuffer.Info;
110110
import com.oracle.svm.hosted.imagelayer.HostedDynamicLayerInfo;
111111
import com.oracle.svm.hosted.imagelayer.HostedImageLayerBuildingSupport;
112+
import com.oracle.svm.hosted.imagelayer.LayeredDispatchTableSupport;
112113
import com.oracle.svm.hosted.meta.HostedMetaAccess;
113114
import com.oracle.svm.hosted.meta.HostedMethod;
114115
import com.oracle.svm.hosted.meta.HostedType;
@@ -512,6 +513,9 @@ public void build(String imageName, DebugContext debug) {
512513
if (ImageLayerBuildingSupport.buildingExtensionLayer()) {
513514
HostedDynamicLayerInfo.singleton().defineSymbolsForPriorLayerMethods(objectFile);
514515
}
516+
if (ImageLayerBuildingSupport.buildingImageLayer()) {
517+
LayeredDispatchTableSupport.singleton().defineDispatchTableSlotSymbols(objectFile, textSection, codeCache, metaAccess);
518+
}
515519

516520
// Mark the sections with the relocations from the maps.
517521
markRelocationSitesFromBuffer(textBuffer, textImpl);
@@ -627,13 +631,15 @@ private void markFunctionRelocationSite(final ProgbitsSectionImpl sectionImpl, f
627631
MethodPointer methodPointer = (MethodPointer) info.getTargetObject();
628632
ResolvedJavaMethod method = methodPointer.getMethod();
629633
HostedMethod target = (method instanceof HostedMethod) ? (HostedMethod) method : heap.hUniverse.lookup(method);
634+
boolean injectedNotCompiled = false;
630635
if (!target.isCompiled() && !target.isCompiledInPriorLayer()) {
631636
target = metaAccess.lookupJavaMethod(InvalidMethodPointerHandler.METHOD_POINTER_NOT_COMPILED_HANDLER_METHOD);
637+
injectedNotCompiled = true;
632638
}
633639

634640
assert checkMethodPointerRelocationKind(info);
635641
// A reference to a method. Mark the relocation site using the symbol name.
636-
relocationProvider.markMethodPointerRelocation(sectionImpl, offset, info.getRelocationKind(), target, info.getAddend(), methodPointer.isAbsolute());
642+
relocationProvider.markMethodPointerRelocation(sectionImpl, offset, info.getRelocationKind(), target, info.getAddend(), methodPointer, injectedNotCompiled);
637643
}
638644

639645
private static boolean isAddendAligned(Architecture arch, long addend, RelocationKind kind) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageCodeCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public List<Pair<HostedMethod, CompilationResult>> getOrderedCompilations() {
199199

200200
public abstract int codeSizeFor(HostedMethod method);
201201

202-
protected CompilationResult compilationResultFor(HostedMethod method) {
202+
public CompilationResult compilationResultFor(HostedMethod method) {
203203
return compilations.get(method);
204204
}
205205

0 commit comments

Comments
 (0)