Skip to content

Commit 4b51d69

Browse files
committed
[GR-71291] Deprecate ConstantFieldInfo, PartialEvaluationMethodInfo, HostMethodInfo in the com.oracle.truffle.compiler module.
PullRequest: graal/22590
2 parents df4cf9b + b138281 commit 4b51d69

27 files changed

+330
-50
lines changed

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/truffle/HSTruffleCompilerRuntime.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ public final class HSTruffleCompilerRuntime extends HSObject implements TruffleC
9494

9595
@TruffleFromLibGraal(GetPartialEvaluationMethodInfo)
9696
@Override
97+
@SuppressWarnings("deprecation")
9798
public PartialEvaluationMethodInfo getPartialEvaluationMethodInfo(ResolvedJavaMethod method) {
9899
throw new UnsupportedOperationException("Use HotSpotPartialEvaluator#getMethodInfo()");
99100
}
100101

101102
@Override
103+
@SuppressWarnings("deprecation")
102104
public HostMethodInfo getHostMethodInfo(ResolvedJavaMethod method) {
103105
throw new UnsupportedOperationException("Use TruffleHostEnvironment#getHostMethodInfo()");
104106
}
@@ -141,6 +143,7 @@ public boolean isValueType(ResolvedJavaType type) {
141143
}
142144

143145
@Override
146+
@SuppressWarnings("deprecation")
144147
public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
145148
throw new UnsupportedOperationException("Use HotSpotPartialEvaluator#getConstantFieldInfo()");
146149
}

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/truffle/LibGraalTruffleHostEnvironment.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import java.lang.invoke.MethodHandles;
2929
import java.lang.invoke.MethodType;
3030
import java.util.Map;
31+
import java.util.function.Function;
3132

32-
import com.oracle.truffle.compiler.HostMethodInfo;
3333
import com.oracle.truffle.compiler.TruffleCompilable;
3434
import com.oracle.truffle.compiler.TruffleCompilerRuntime;
3535

@@ -38,10 +38,10 @@
3838
import jdk.graal.compiler.core.common.util.MethodKey;
3939
import jdk.graal.compiler.hotspot.CompilationContext;
4040
import jdk.graal.compiler.hotspot.HotSpotGraalServices;
41+
import jdk.graal.compiler.truffle.HostMethodInfo;
4142
import jdk.graal.compiler.truffle.TruffleCompilerImpl;
4243
import jdk.graal.compiler.truffle.TruffleElementCache;
4344
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
44-
import jdk.graal.compiler.truffle.host.TruffleKnownHostTypes;
4545
import jdk.graal.compiler.truffle.hotspot.HotSpotTruffleCompilerImpl;
4646
import jdk.vm.ci.meta.MetaAccessProvider;
4747
import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -101,14 +101,8 @@ protected Object createKey(ResolvedJavaMethod method) {
101101

102102
@Override
103103
protected HostMethodInfo computeValue(ResolvedJavaMethod method) {
104-
TruffleKnownHostTypes hostTypes = types();
105104
Map<ResolvedJavaType, AnnotationValue> annotations = AnnotationValueSupport.getDeclaredAnnotationValues(method);
106-
boolean isTruffleBoundary = annotations.containsKey(hostTypes.TruffleBoundary);
107-
boolean isBytecodeInterpreterSwitch = annotations.containsKey(hostTypes.BytecodeInterpreterSwitch);
108-
boolean isBytecodeInterpreterSwitchBoundary = annotations.containsKey(hostTypes.BytecodeInterpreterSwitchBoundary);
109-
boolean isInliningCutoff = annotations.containsKey(hostTypes.InliningCutoff);
110-
boolean isInliningRoot = annotations.containsKey(hostTypes.InliningRoot);
111-
return new HostMethodInfo(isTruffleBoundary, isBytecodeInterpreterSwitch, isBytecodeInterpreterSwitchBoundary, isInliningCutoff, isInliningRoot);
105+
return computeHostMethodInfo(annotations, Function.identity());
112106
}
113107

114108
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright (c) 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 jdk.graal.compiler.truffle;
26+
27+
import jdk.vm.ci.meta.ResolvedJavaField;
28+
29+
/**
30+
* Value returned by {@link PartialEvaluator#getConstantFieldInfo(ResolvedJavaField)} describing how
31+
* a field read can be constant folded based on Truffle annotations.
32+
*
33+
*/
34+
public final class ConstantFieldInfo {
35+
36+
private final int rawValue;
37+
38+
/**
39+
* Denotes a field is annotated by {@code com.oracle.truffle.api.nodes.Node.Child}.
40+
*/
41+
public static final ConstantFieldInfo CHILD = new ConstantFieldInfo(-1);
42+
43+
/**
44+
* Denotes a field is annotated by {@code com.oracle.truffle.api.nodes.Node.Children}.
45+
*/
46+
public static final ConstantFieldInfo CHILDREN = new ConstantFieldInfo(-2);
47+
48+
private static final ConstantFieldInfo FINAL_DIMENSIONS_ZERO = new ConstantFieldInfo(0);
49+
private static final ConstantFieldInfo FINAL_DIMENSIONS_ONE = new ConstantFieldInfo(1);
50+
private static final ConstantFieldInfo FINAL_DIMENSIONS_TWO = new ConstantFieldInfo(2);
51+
52+
private ConstantFieldInfo(int rawValue) {
53+
this.rawValue = rawValue;
54+
}
55+
56+
/**
57+
* Determines if this object is {@link #CHILD}.
58+
*/
59+
public boolean isChild() {
60+
return this == CHILD;
61+
}
62+
63+
/**
64+
* Determines if this object is {@link #CHILDREN}.
65+
*/
66+
public boolean isChildren() {
67+
return this == CHILDREN;
68+
}
69+
70+
/**
71+
* Gets the number of array dimensions to be marked as compilation final. This value is only
72+
* non-zero for array type fields.
73+
*
74+
* @return a value between 0 and the number of declared array dimensions (inclusive)
75+
*/
76+
public int getDimensions() {
77+
return Math.max(0, rawValue);
78+
}
79+
80+
/**
81+
* Gets a {@link ConstantFieldInfo} object for a field.
82+
*
83+
* @param dimensions the number of array dimensions to be marked as compilation final
84+
*/
85+
public static ConstantFieldInfo forDimensions(int dimensions) {
86+
if (dimensions < 0) {
87+
throw new IllegalArgumentException("Negative dimensions not allowed");
88+
}
89+
switch (dimensions) {
90+
case 0:
91+
return FINAL_DIMENSIONS_ZERO;
92+
case 1:
93+
return FINAL_DIMENSIONS_ONE;
94+
case 2:
95+
return FINAL_DIMENSIONS_TWO;
96+
default:
97+
// should be extremely rare
98+
return new ConstantFieldInfo(dimensions);
99+
}
100+
}
101+
102+
@Override
103+
public boolean equals(Object obj) {
104+
if (obj instanceof ConstantFieldInfo o) {
105+
return this.rawValue == o.rawValue;
106+
}
107+
return false;
108+
}
109+
110+
@Override
111+
public int hashCode() {
112+
return Integer.hashCode(rawValue);
113+
}
114+
115+
@Override
116+
public String toString() {
117+
String simpleName = getClass().getSimpleName();
118+
if (isChild()) {
119+
return simpleName + "[@Child]";
120+
} else if (isChildren()) {
121+
return simpleName + "[@Children]";
122+
} else {
123+
return simpleName + "[@CompilationFinal(dimensions=" + getDimensions() + ")]";
124+
}
125+
}
126+
127+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 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 jdk.graal.compiler.truffle;
26+
27+
/**
28+
*
29+
* @param isTruffleBoundary specifies if the method is annotated by {@code TruffleBoundary}
30+
* @param isBytecodeInterpreterSwitch specifies if the method is annotated by
31+
* {@code BytecodeInterpreterSwitch}.
32+
* @param isBytecodeInterpreterSwitchBoundary specifies if the method is annotated by
33+
* {@code BytecodeInterpreterSwitchBoundary}
34+
* @param isInliningCutoff specifies if the method is annotated by {@code InliningCutoff}
35+
*
36+
*/
37+
public record HostMethodInfo(
38+
boolean isTruffleBoundary,
39+
boolean isBytecodeInterpreterSwitch,
40+
boolean isBytecodeInterpreterSwitchBoundary,
41+
boolean isInliningCutoff,
42+
boolean isInliningRoot) {
43+
44+
// for compatibility
45+
public HostMethodInfo(
46+
boolean isTruffleBoundary,
47+
boolean isBytecodeInterpreterSwitch,
48+
boolean isBytecodeInterpreterSwitchBoundary,
49+
boolean isInliningCutoff) {
50+
this(isTruffleBoundary, isBytecodeInterpreterSwitch, isBytecodeInterpreterSwitchBoundary, isInliningCutoff, false);
51+
}
52+
53+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 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 jdk.graal.compiler.truffle;
26+
27+
import com.oracle.truffle.compiler.TruffleCompilerRuntime.InlineKind;
28+
import com.oracle.truffle.compiler.TruffleCompilerRuntime.LoopExplosionKind;
29+
30+
/**
31+
*
32+
* @param loopExplosion Queries how loops in {@code method} with constant number of invocations
33+
* should be unrolled.
34+
* @param inlineForPartialEvaluation Gets an object describing whether and how a method can be
35+
* inlined based on Truffle directives during partial evaluation
36+
* @param inlineForTruffleBoundary Gets an object describing whether and how a method can be inlined
37+
* based on Truffle directives after partial evaluation e.g. during later inlining
38+
* phases.
39+
* @param isInlineable Determines if {@code method} can be inlined by the runtime (independently
40+
* from Truffle).
41+
* @param isSpecializationMethod Determines if {@code method} is annotated by
42+
* {@code Specialization}.
43+
*/
44+
public record PartialEvaluationMethodInfo(
45+
LoopExplosionKind loopExplosion,
46+
InlineKind inlineForPartialEvaluation,
47+
InlineKind inlineForTruffleBoundary,
48+
boolean isInlineable,
49+
boolean isSpecializationMethod) {
50+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import jdk.graal.compiler.annotation.EnumElement;
3333
import org.graalvm.collections.EconomicMap;
3434

35-
import com.oracle.truffle.compiler.ConstantFieldInfo;
36-
import com.oracle.truffle.compiler.PartialEvaluationMethodInfo;
3735
import com.oracle.truffle.compiler.TruffleCompilable;
3836
import com.oracle.truffle.compiler.TruffleCompilationTask;
3937
import com.oracle.truffle.compiler.TruffleCompilerRuntime;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package jdk.graal.compiler.truffle;
2626

27-
import com.oracle.truffle.compiler.ConstantFieldInfo;
28-
2927
import jdk.graal.compiler.core.common.spi.ConstantFieldProvider;
3028
import jdk.graal.compiler.nodes.spi.CanonicalizerTool;
3129
import jdk.vm.ci.meta.ResolvedJavaField;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package jdk.graal.compiler.truffle;
2626

27-
import com.oracle.truffle.compiler.ConstantFieldInfo;
28-
2927
import jdk.graal.compiler.core.common.spi.ConstantFieldProvider;
3028
import jdk.graal.compiler.nodes.spi.CanonicalizerTool;
3129
import jdk.vm.ci.meta.JavaConstant;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import jdk.graal.compiler.graphio.GraphBlocks;
4242
import jdk.graal.compiler.graphio.GraphStructure;
4343

44-
import com.oracle.truffle.compiler.ConstantFieldInfo;
4544
import com.oracle.truffle.compiler.TruffleCompilable;
4645
import com.oracle.truffle.compiler.TruffleCompilationTask;
4746
import com.oracle.truffle.compiler.TruffleSourceLanguagePosition;

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/host/HostInliningPhase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import org.graalvm.collections.Equivalence;
4343
import org.graalvm.collections.UnmodifiableEconomicMap;
4444

45-
import com.oracle.truffle.compiler.HostMethodInfo;
46-
4745
import jdk.graal.compiler.core.common.type.Stamp;
4846
import jdk.graal.compiler.core.phases.HighTier;
4947
import jdk.graal.compiler.debug.Assertions;
@@ -82,6 +80,7 @@
8280
import jdk.graal.compiler.phases.common.inlining.InliningUtil;
8381
import jdk.graal.compiler.phases.contract.NodeCostUtil;
8482
import jdk.graal.compiler.phases.tiers.HighTierContext;
83+
import jdk.graal.compiler.truffle.HostMethodInfo;
8584
import jdk.graal.compiler.truffle.KnownTruffleTypes;
8685
import jdk.graal.compiler.truffle.PartialEvaluator;
8786
import jdk.vm.ci.meta.JavaTypeProfile;

0 commit comments

Comments
 (0)