Skip to content

Commit 02b5484

Browse files
committed
[GR-70018] Record virtual call targets in FactoryMethods
PullRequest: graal/22228
2 parents 596b59b + d2f3b07 commit 02b5484

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/LayeredDispatchTableFeature.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.oracle.svm.core.util.VMError;
6666
import com.oracle.svm.hosted.FeatureImpl;
6767
import com.oracle.svm.hosted.FeatureImpl.BeforeCompilationAccessImpl;
68+
import com.oracle.svm.hosted.code.FactoryMethod;
6869
import com.oracle.svm.hosted.image.NativeImage;
6970
import com.oracle.svm.hosted.image.NativeImageCodeCache;
7071
import com.oracle.svm.hosted.meta.HostedMetaAccess;
@@ -264,11 +265,20 @@ void installBuilderModules(Set<Module> newCoreTypes) {
264265
public void recordVirtualCallTarget(HostedMethod caller, HostedMethod callee) {
265266
Module callerModule = caller.getDeclaringClass().getJavaClass().getModule();
266267
Module calleeModule = callee.getDeclaringClass().getJavaClass().getModule();
267-
if (!(builderModules.contains(callerModule) || builderModules.contains(calleeModule))) {
268+
if (!(builderModules.contains(callerModule) && !isFactoryMethod(caller)) && !builderModules.contains(calleeModule)) {
268269
virtualCallTargets.add(callee);
269270
}
270271
}
271272

273+
/**
274+
* {@link FactoryMethod FactoryMethods} outline the allocation and call to the original
275+
* constructor. Hence, whether the call is included or not should be based exclusively on the
276+
* callee.
277+
*/
278+
private static boolean isFactoryMethod(HostedMethod caller) {
279+
return caller.getWrapped().getWrapped() instanceof FactoryMethod;
280+
}
281+
272282
public void registerDeclaredDispatchInfo(HostedType type, List<HostedMethod> declaredMethods) {
273283
var dispatchTable = new HostedDispatchTable();
274284
dispatchTable.type = type;

0 commit comments

Comments
 (0)