Skip to content

Commit a5b439f

Browse files
committed
Fixed SetIdentityForValueTypesPhase on native-image.
1 parent a94c18b commit a5b439f

File tree

9 files changed

+110
-6
lines changed

9 files changed

+110
-6
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/PartialEvaluator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ private static InlineKind getInlineKind(TruffleCompilerRuntime runtime, Annotati
295295

296296
public abstract ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field);
297297

298+
public abstract boolean isValueType(ResolvedJavaType type);
299+
298300
public EconomicMap<ResolvedJavaMethod, EncodedGraph> getOrCreateEncodedGraphCache() {
299301
return EconomicMap.create();
300302
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/HotSpotPartialEvaluator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
100100
return constantInfoCache.get(field);
101101
}
102102

103+
@Override
104+
public boolean isValueType(ResolvedJavaType type) {
105+
return AnnotationValueSupport.getDeclaredAnnotationValue(types.CompilerDirectives_ValueType, type) != null;
106+
}
107+
103108
@Override
104109
public PartialEvaluationMethodInfo getMethodInfo(ResolvedJavaMethod method) {
105110
return methodInfoCache.get(method);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/phases/SetIdentityForValueTypesPhase.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@
2424
*/
2525
package jdk.graal.compiler.truffle.phases;
2626

27-
import jdk.graal.compiler.annotation.AnnotationValueSupport;
2827
import jdk.graal.compiler.nodes.StructuredGraph;
2928
import jdk.graal.compiler.nodes.virtual.VirtualInstanceNode;
3029
import jdk.graal.compiler.nodes.virtual.VirtualObjectNode;
3130
import jdk.graal.compiler.phases.BasePhase;
32-
import jdk.graal.compiler.truffle.KnownTruffleTypes;
3331
import jdk.graal.compiler.truffle.TruffleTierContext;
3432

3533
import jdk.vm.ci.meta.ResolvedJavaType;
@@ -38,12 +36,11 @@ public final class SetIdentityForValueTypesPhase extends BasePhase<TruffleTierCo
3836
@Override
3937
protected void run(StructuredGraph graph, TruffleTierContext context) {
4038
graph.checkCancellation();
41-
KnownTruffleTypes types = context.types();
4239
for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.TYPE)) {
4340
if (virtualObjectNode instanceof VirtualInstanceNode) {
4441
VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
4542
ResolvedJavaType type = virtualInstanceNode.type();
46-
if (AnnotationValueSupport.getDeclaredAnnotationValue(types.CompilerDirectives_ValueType, type) != null) {
43+
if (context.getPartialEvaluator().isValueType(type)) {
4744
virtualInstanceNode.setIdentity(false);
4845
}
4946
}

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/runtimecompilation/GraalGraphObjectReplacer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public synchronized SubstrateType createType(JavaType original) {
367367
VMError.guarantee(!(forbidNewTypes || (original instanceof HostedType)), "Too late to create a new type: %s", aType);
368368
aType.registerAsReachable("type reachable from Graal graphs");
369369
DynamicHub hub = ((SVMHost) aUniverse.hostVM()).dynamicHub(aType);
370-
SubstrateType newType = new SubstrateType(aType.getJavaKind(), hub);
370+
SubstrateType newType = universeFactory.createType(aType, hub);
371371
sType = types.putIfAbsent(aType, newType);
372372
if (sType == null) {
373373
sType = newType;

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/meta/SubstrateUniverseFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package com.oracle.svm.graal.meta;
2626

27+
import com.oracle.graal.pointsto.meta.AnalysisType;
28+
import com.oracle.svm.core.hub.DynamicHub;
2729
import org.graalvm.nativeimage.Platform;
2830
import org.graalvm.nativeimage.Platforms;
2931

@@ -42,6 +44,10 @@
4244
@Platforms(Platform.HOSTED_ONLY.class)
4345
public class SubstrateUniverseFactory {
4446

47+
public SubstrateType createType(AnalysisType analysisType, DynamicHub hub) {
48+
return new SubstrateType(analysisType.getJavaKind(), hub);
49+
}
50+
4551
public SubstrateMethod createMethod(AnalysisMethod aMethod, ImageCodeInfo imageCodeInfo, HostedStringDeduplication stringTable) {
4652
return new SubstrateMethod(aMethod, imageCodeInfo, stringTable);
4753
}

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.concurrent.ConcurrentHashMap;
2828
import java.util.function.Supplier;
2929

30+
import jdk.vm.ci.meta.ResolvedJavaType;
3031
import org.graalvm.collections.EconomicMap;
3132
import org.graalvm.nativeimage.Platform;
3233
import org.graalvm.nativeimage.Platforms;
@@ -98,10 +99,15 @@ public final PartialEvaluationMethodInfo getMethodInfo(ResolvedJavaMethod method
9899
}
99100

100101
@Override
101-
public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
102+
public final ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
102103
return ((TruffleField) field).getConstantFieldInfo();
103104
}
104105

106+
@Override
107+
public final boolean isValueType(ResolvedJavaType type) {
108+
return ((TruffleType) type).isValueType();
109+
}
110+
105111
@Override
106112
protected void registerGraphBuilderInvocationPlugins(InvocationPlugins invocationPlugins, boolean canDelayIntrinsification) {
107113
super.registerGraphBuilderInvocationPlugins(invocationPlugins, canDelayIntrinsification);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2025, 2025, 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.truffle.api;
26+
27+
import com.oracle.svm.core.hub.DynamicHub;
28+
import com.oracle.svm.graal.meta.SubstrateType;
29+
import jdk.vm.ci.meta.JavaKind;
30+
import org.graalvm.nativeimage.Platform;
31+
import org.graalvm.nativeimage.Platforms;
32+
33+
public class SubstrateTruffleType extends SubstrateType implements TruffleType {
34+
35+
private final boolean valueType;
36+
37+
@Platforms(Platform.HOSTED_ONLY.class)
38+
public SubstrateTruffleType(JavaKind kind, DynamicHub hub, boolean valueType) {
39+
super(kind, hub);
40+
this.valueType = valueType;
41+
}
42+
43+
@Override
44+
public boolean isValueType() {
45+
return valueType;
46+
}
47+
}

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleUniverseFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import java.util.concurrent.ConcurrentHashMap;
2929
import java.util.concurrent.ConcurrentMap;
3030

31+
import com.oracle.graal.pointsto.meta.AnalysisType;
32+
import com.oracle.svm.core.hub.DynamicHub;
33+
import com.oracle.svm.graal.meta.SubstrateType;
3134
import com.oracle.svm.truffle.TruffleFeature;
3235
import com.oracle.svm.util.OriginalClassProvider;
3336
import org.graalvm.nativeimage.ImageSingletons;
@@ -88,6 +91,14 @@ public SubstrateField createField(AnalysisField aField, HostedStringDeduplicatio
8891
return new SubstrateTruffleField(aField, stringTable, canonicalFieldInfo);
8992
}
9093

94+
@Override
95+
public SubstrateType createType(AnalysisType analysisType, DynamicHub hub) {
96+
SubstrateAnnotationExtractor extractor = (SubstrateAnnotationExtractor) ImageSingletons.lookup(AnnotationExtractor.class);
97+
Map<ResolvedJavaType, AnnotationValue> annotations = extractor.getDeclaredAnnotationValues(analysisType);
98+
boolean valueType = annotations.containsKey(OriginalClassProvider.getOriginalType(truffleFeature.getTypes().CompilerDirectives_ValueType));
99+
return new SubstrateTruffleType(analysisType.getJavaKind(), hub, valueType);
100+
}
101+
91102
@Platforms(Platform.HOSTED_ONLY.class)
92103
static PartialEvaluationMethodInfo createPartialEvaluationMethodInfo(TruffleCompilerRuntime runtime, ResolvedJavaMethod method,
93104
KnownTruffleTypes types) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2025, 2025, 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.truffle.api;
26+
27+
public interface TruffleType {
28+
29+
boolean isValueType();
30+
}

0 commit comments

Comments
 (0)