Skip to content

Commit 5322cc4

Browse files
patrick96peter-hofer
authored andcommitted
Lower LoadMethodByIndexNode in Web Image
The default lowering in NonSnippetLowerings is used
1 parent f704127 commit 5322cc4

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageFeature.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.nio.file.Path;
3434
import java.util.ArrayList;
3535
import java.util.List;
36+
import java.util.Map;
37+
import java.util.function.Predicate;
3638
import java.util.function.Supplier;
3739

3840
import org.graalvm.nativeimage.AnnotationAccess;
@@ -61,7 +63,10 @@
6163
import com.oracle.svm.core.code.ImageCodeInfo;
6264
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
6365
import com.oracle.svm.core.feature.InternalFeature;
66+
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
6467
import com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider;
68+
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
69+
import com.oracle.svm.core.heap.RestrictHeapAccessCallees;
6570
import com.oracle.svm.core.hub.DynamicHub;
6671
import com.oracle.svm.core.hub.DynamicHubCompanion;
6772
import com.oracle.svm.core.jdk.FileSystemProviderSupport;
@@ -83,6 +88,7 @@
8388
import com.oracle.svm.hosted.webimage.codegen.WebImageProviders;
8489
import com.oracle.svm.hosted.webimage.name.WebImageNamingConvention;
8590
import com.oracle.svm.hosted.webimage.options.WebImageOptions;
91+
import com.oracle.svm.hosted.webimage.snippets.WebImageNonSnippetLowerings;
8692
import com.oracle.svm.hosted.webimage.wasm.WasmLogHandler;
8793
import com.oracle.svm.util.ReflectionUtil;
8894
import com.oracle.svm.webimage.WebImageJSLog;
@@ -103,8 +109,11 @@
103109
import com.oracle.svm.webimage.substitute.system.WebImageTempFileHelperSupportWithoutSecureRandom;
104110

105111
import jdk.graal.compiler.debug.DebugContext;
112+
import jdk.graal.compiler.graph.Node;
106113
import jdk.graal.compiler.options.OptionValues;
114+
import jdk.graal.compiler.phases.util.Providers;
107115
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
116+
import jdk.vm.ci.meta.ResolvedJavaMethod;
108117

109118
@AutomaticallyRegisteredFeature
110119
@Platforms(WebImagePlatform.class)
@@ -123,6 +132,16 @@ public void registerForeignCalls(SubstrateForeignCallsProvider foreignCalls) {
123132
ImplicitExceptions.registerForeignCalls(foreignCalls);
124133
}
125134

135+
@Override
136+
public void registerLowerings(RuntimeConfiguration runtimeConfig, OptionValues options, Providers providers, Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings, boolean hosted) {
137+
Predicate<ResolvedJavaMethod> mustNotAllocatePredicate = null;
138+
if (hosted) {
139+
mustNotAllocatePredicate = method -> ImageSingletons.lookup(RestrictHeapAccessCallees.class).mustNotAllocate(method);
140+
}
141+
142+
WebImageNonSnippetLowerings.registerLowerings(runtimeConfig, mustNotAllocatePredicate, options, providers, lowerings, hosted);
143+
}
144+
126145
@Override
127146
public void beforeAnalysis(BeforeAnalysisAccess access) {
128147
FeatureImpl.BeforeAnalysisAccessImpl accessImpl = (FeatureImpl.BeforeAnalysisAccessImpl) access;

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/js/WebImageJSLoweringProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.oracle.svm.hosted.webimage.js;
2727

2828
import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode;
29+
import com.oracle.svm.core.graal.nodes.LoadMethodByIndexNode;
2930
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
3031
import com.oracle.svm.hosted.webimage.WebImageLoweringProvider;
3132
import com.oracle.svm.hosted.webimage.snippets.WebImageIdentityHashCodeSnippets;
@@ -61,7 +62,7 @@ protected IdentityHashCodeSnippets.Templates createIdentityHashCodeSnippets(Opti
6162
@SuppressWarnings("unchecked")
6263
@Override
6364
public void lower(Node n, LoweringTool tool) {
64-
if (n instanceof EnsureClassInitializedNode || n instanceof ValidateNewInstanceClassNode) {
65+
if (n instanceof EnsureClassInitializedNode || n instanceof ValidateNewInstanceClassNode || n instanceof LoadMethodByIndexNode) {
6566
@SuppressWarnings("rawtypes")
6667
NodeLoweringProvider nodeLoweringProvider = getLowerings().get(n.getClass());
6768

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* questions.
2424
*/
2525

26-
package com.oracle.svm.hosted.webimage.wasm.snippets;
26+
package com.oracle.svm.hosted.webimage.snippets;
2727

2828
import java.util.Map;
2929
import java.util.function.Predicate;
@@ -37,16 +37,16 @@
3737
import jdk.graal.compiler.phases.util.Providers;
3838
import jdk.vm.ci.meta.ResolvedJavaMethod;
3939

40-
public class WebImageWasmNonSnippetLowerings extends NonSnippetLowerings {
40+
public class WebImageNonSnippetLowerings extends NonSnippetLowerings {
4141

4242
@SuppressWarnings("unused")
4343
public static void registerLowerings(RuntimeConfiguration runtimeConfig, Predicate<ResolvedJavaMethod> mustNotAllocatePredicate, OptionValues options,
4444
Providers providers, Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings, boolean hosted) {
4545

46-
new WebImageWasmNonSnippetLowerings(runtimeConfig, mustNotAllocatePredicate, options, providers, lowerings, hosted);
46+
new WebImageNonSnippetLowerings(runtimeConfig, mustNotAllocatePredicate, options, providers, lowerings, hosted);
4747
}
4848

49-
protected WebImageWasmNonSnippetLowerings(RuntimeConfiguration runtimeConfig, Predicate<ResolvedJavaMethod> mustNotAllocatePredicate, OptionValues options, Providers providers,
49+
protected WebImageNonSnippetLowerings(RuntimeConfiguration runtimeConfig, Predicate<ResolvedJavaMethod> mustNotAllocatePredicate, OptionValues options, Providers providers,
5050
Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings, boolean hosted) {
5151
super(runtimeConfig, mustNotAllocatePredicate, options, providers, lowerings, hosted);
5252
}

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/codegen/WebImageWasmLMNodeLowerer.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import static com.oracle.svm.webimage.functionintrinsics.JSCallNode.MEM_FREE;
4242
import static com.oracle.svm.webimage.functionintrinsics.JSCallNode.MEM_MALLOC;
4343
import static com.oracle.svm.webimage.functionintrinsics.JSCallNode.MEM_REALLOC;
44+
import static com.oracle.svm.webimage.wasm.types.WasmPrimitiveType.i64;
4445

4546
import java.util.Set;
4647

@@ -394,10 +395,17 @@ protected <T extends FixedNode & Invoke> Instruction lowerInvoke(T node) {
394395
callTarget.arguments().forEach(param -> params.add(lowerExpression(param)));
395396

396397
if (callTarget instanceof IndirectCallTargetNode indirectCallTarget) {
398+
WasmPrimitiveType addressType = util.typeForNode(indirectCallTarget.computedAddress()).asPrimitive();
399+
Instruction index = lowerExpression(indirectCallTarget.computedAddress());
397400
/*
398-
* TODO GR-42105 stop using wrap
401+
* The computed address can have different kind of stamps that are represented as either
402+
* i32 or i64 in wasm. For example the stamp could be an i64 integer stamp (represented
403+
* as i64) or a method pointer stamp (represented as i32). If the computed address is
404+
* represented as an i64, it has to first be truncated to i32.
399405
*/
400-
Instruction index = Unary.Op.I32Wrap64.create(lowerExpression(indirectCallTarget.computedAddress()));
406+
if (addressType == i64) {
407+
index = Unary.Op.I32Wrap64.create(index);
408+
}
401409
TypeUse typeUse;
402410

403411
if (targetMethod == null) {

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/snippets/WasmLMSnippetsFeature.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,24 @@
2626
package com.oracle.svm.hosted.webimage.wasm.snippets;
2727

2828
import java.util.Map;
29-
import java.util.function.Predicate;
3029

31-
import org.graalvm.nativeimage.ImageSingletons;
3230
import org.graalvm.nativeimage.Platforms;
3331

3432
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3533
import com.oracle.svm.core.feature.InternalFeature;
3634
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
3735
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
38-
import com.oracle.svm.core.heap.RestrictHeapAccessCallees;
3936
import com.oracle.svm.webimage.platform.WebImageWasmLMPlatform;
4037

4138
import jdk.graal.compiler.graph.Node;
4239
import jdk.graal.compiler.options.OptionValues;
4340
import jdk.graal.compiler.phases.util.Providers;
44-
import jdk.vm.ci.meta.ResolvedJavaMethod;
4541

4642
@AutomaticallyRegisteredFeature
4743
@Platforms(WebImageWasmLMPlatform.class)
4844
class WasmLMSnippetsFeature implements InternalFeature {
49-
5045
@Override
5146
public void registerLowerings(RuntimeConfiguration runtimeConfig, OptionValues options, Providers providers, Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings, boolean hosted) {
52-
Predicate<ResolvedJavaMethod> mustNotAllocatePredicate = null;
53-
if (hosted) {
54-
mustNotAllocatePredicate = method -> ImageSingletons.lookup(RestrictHeapAccessCallees.class).mustNotAllocate(method);
55-
}
56-
5747
WebImageWasmArithmeticSnippets.registerLowerings(options, providers, lowerings);
58-
WebImageWasmNonSnippetLowerings.registerLowerings(runtimeConfig, mustNotAllocatePredicate, options, providers, lowerings, hosted);
5948
}
6049
}

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WebImageWasmGCLoweringProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode;
3333
import com.oracle.svm.core.graal.jdk.SubstrateObjectCloneNode;
3434
import com.oracle.svm.core.graal.jdk.SubstrateObjectCloneWithExceptionNode;
35+
import com.oracle.svm.core.graal.nodes.LoadMethodByIndexNode;
3536
import com.oracle.svm.core.graal.nodes.ThrowBytecodeExceptionNode;
3637
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
3738
import com.oracle.svm.core.hub.DynamicHub;
@@ -112,7 +113,8 @@ public WebImageWasmGCLoweringProvider(MetaAccessProvider metaAccess, ForeignCall
112113
SubstrateObjectCloneNode.class,
113114
SubstrateObjectCloneWithExceptionNode.class,
114115
IntegerDivRemNode.class,
115-
DeoptimizeNode.class));
116+
DeoptimizeNode.class,
117+
LoadMethodByIndexNode.class));
116118

117119
@Override
118120
public void initialize(OptionValues options, SnippetCounter.Group.Factory factory, Providers providers) {

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/snippets/WasmGCSnippetsFeature.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,25 @@
2626
package com.oracle.svm.hosted.webimage.wasmgc.snippets;
2727

2828
import java.util.Map;
29-
import java.util.function.Predicate;
3029

31-
import org.graalvm.nativeimage.ImageSingletons;
3230
import org.graalvm.nativeimage.Platforms;
3331

3432
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3533
import com.oracle.svm.core.feature.InternalFeature;
3634
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
3735
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
38-
import com.oracle.svm.core.heap.RestrictHeapAccessCallees;
3936
import com.oracle.svm.hosted.webimage.wasm.snippets.WebImageWasmArithmeticSnippets;
40-
import com.oracle.svm.hosted.webimage.wasm.snippets.WebImageWasmNonSnippetLowerings;
4137
import com.oracle.svm.webimage.platform.WebImageWasmGCPlatform;
4238

4339
import jdk.graal.compiler.graph.Node;
4440
import jdk.graal.compiler.options.OptionValues;
4541
import jdk.graal.compiler.phases.util.Providers;
46-
import jdk.vm.ci.meta.ResolvedJavaMethod;
4742

4843
@AutomaticallyRegisteredFeature
4944
@Platforms(WebImageWasmGCPlatform.class)
5045
public class WasmGCSnippetsFeature implements InternalFeature {
5146
@Override
5247
public void registerLowerings(RuntimeConfiguration runtimeConfig, OptionValues options, Providers providers, Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings, boolean hosted) {
53-
Predicate<ResolvedJavaMethod> mustNotAllocatePredicate = null;
54-
if (hosted) {
55-
mustNotAllocatePredicate = method -> ImageSingletons.lookup(RestrictHeapAccessCallees.class).mustNotAllocate(method);
56-
}
57-
5848
WebImageWasmArithmeticSnippets.registerLowerings(options, providers, lowerings);
59-
WebImageWasmNonSnippetLowerings.registerLowerings(runtimeConfig, mustNotAllocatePredicate, options, providers, lowerings, hosted);
6049
}
6150
}

0 commit comments

Comments
 (0)