|
37 | 37 |
|
38 | 38 | import jdk.graal.compiler.core.common.Stride; |
39 | 39 | import jdk.graal.compiler.core.common.StrideUtil; |
40 | | -import jdk.graal.compiler.core.common.calc.CanonicalCondition; |
41 | 40 | import jdk.graal.compiler.core.common.calc.FloatConvert; |
42 | 41 | import jdk.graal.compiler.core.common.spi.ConstantFieldProvider; |
43 | 42 | import jdk.graal.compiler.core.common.type.Stamp; |
|
48 | 47 | import jdk.graal.compiler.nodes.ComputeObjectAddressNode; |
49 | 48 | import jdk.graal.compiler.nodes.ConditionAnchorNode; |
50 | 49 | import jdk.graal.compiler.nodes.ConstantNode; |
51 | | -import jdk.graal.compiler.nodes.LogicConstantNode; |
52 | | -import jdk.graal.compiler.nodes.LogicNode; |
53 | 50 | import jdk.graal.compiler.nodes.NamedLocationIdentity; |
54 | 51 | import jdk.graal.compiler.nodes.NodeView; |
55 | 52 | import jdk.graal.compiler.nodes.PiNode; |
56 | 53 | import jdk.graal.compiler.nodes.ValueNode; |
57 | 54 | import jdk.graal.compiler.nodes.calc.AddNode; |
58 | | -import jdk.graal.compiler.nodes.calc.CompareNode; |
59 | 55 | import jdk.graal.compiler.nodes.calc.FloatConvertNode; |
60 | 56 | import jdk.graal.compiler.nodes.calc.LeftShiftNode; |
61 | 57 | import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
@@ -116,58 +112,55 @@ public static void register(Architecture architecture, InvocationPlugins plugins |
116 | 112 | private static void registerFramePlugins(InvocationPlugins plugins) { |
117 | 113 | plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/impl/FrameWithoutBoxing;")); |
118 | 114 | InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.impl.FrameWithoutBoxing"); |
119 | | - r.register(new OptionalInlineOnlyInvocationPlugin("unsafeCast", Object.class, Class.class, boolean.class, boolean.class, boolean.class) { |
120 | | - @Override |
121 | | - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode clazz, ValueNode condition, ValueNode nonNull, |
122 | | - ValueNode isExactType) { |
123 | | - if (!clazz.isConstant() || !nonNull.isConstant() || !isExactType.isConstant()) { |
124 | | - b.push(JavaKind.Object, object); |
125 | | - return true; |
126 | | - } |
127 | | - if (!Options.TruffleTrustedTypeCast.getValue(b.getOptions())) { |
128 | | - b.push(JavaKind.Object, object); |
129 | | - return true; |
130 | | - } |
131 | | - ConstantReflectionProvider constantReflection = b.getConstantReflection(); |
132 | | - ResolvedJavaType javaType = constantReflection.asJavaType(clazz.asConstant()); |
133 | | - if (javaType == null) { |
134 | | - b.push(JavaKind.Object, object); |
135 | | - return true; |
136 | | - } |
137 | | - |
138 | | - TypeReference type; |
139 | | - if (isExactType.asJavaConstant().asInt() != 0) { |
140 | | - assert javaType.isConcrete() || javaType.isArray() : "exact type is not a concrete class: " + javaType; |
141 | | - type = TypeReference.createExactTrusted(javaType); |
142 | | - } else { |
143 | | - type = TypeReference.createTrusted(b.getAssumptions(), javaType); |
144 | | - } |
| 115 | + r.register(new UnsafeCastPlugin("unsafeCast", true)); |
| 116 | + } |
145 | 117 |
|
146 | | - boolean trustedNonNull = nonNull.asJavaConstant().asInt() != 0 && Options.TruffleTrustedNonNullCast.getValue(b.getOptions()); |
147 | | - Stamp piStamp = StampFactory.object(type, trustedNonNull); |
| 118 | + private static final class UnsafeCastPlugin extends OptionalInlineOnlyInvocationPlugin { |
| 119 | + private final boolean injectTrustedFinal; |
148 | 120 |
|
149 | | - ConditionAnchorNode valueAnchorNode = null; |
150 | | - if (condition.isConstant() && condition.asJavaConstant().asInt() == 1) { |
151 | | - // Nothing to do. |
152 | | - } else { |
153 | | - boolean skipAnchor = false; |
154 | | - LogicNode compareNode = CompareNode.createCompareNode(object.graph(), CanonicalCondition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection, |
155 | | - NodeView.DEFAULT); |
156 | | - if (compareNode instanceof LogicConstantNode) { |
157 | | - LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode; |
158 | | - if (logicConstantNode.getValue()) { |
159 | | - skipAnchor = true; |
160 | | - } |
161 | | - } |
162 | | - if (!skipAnchor) { |
163 | | - valueAnchorNode = b.add(new ConditionAnchorNode(compareNode)); |
164 | | - } |
165 | | - } |
| 121 | + UnsafeCastPlugin(String name, boolean injectTrustedFinal) { |
| 122 | + super(name, Object.class, Class.class, boolean.class, boolean.class, boolean.class); |
| 123 | + this.injectTrustedFinal = injectTrustedFinal; |
| 124 | + } |
166 | 125 |
|
167 | | - b.addPush(JavaKind.Object, PiNode.create(castTrustedFinalFrameField(b, object), piStamp, valueAnchorNode)); |
| 126 | + @Override |
| 127 | + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode clazz, ValueNode condition, ValueNode nonNull, |
| 128 | + ValueNode isExactType) { |
| 129 | + if (!clazz.isConstant() || !nonNull.isConstant() || !isExactType.isConstant()) { |
| 130 | + b.push(JavaKind.Object, object); |
168 | 131 | return true; |
169 | 132 | } |
170 | | - }); |
| 133 | + if (!Options.TruffleTrustedTypeCast.getValue(b.getOptions())) { |
| 134 | + b.push(JavaKind.Object, object); |
| 135 | + return true; |
| 136 | + } |
| 137 | + ConstantReflectionProvider constantReflection = b.getConstantReflection(); |
| 138 | + ResolvedJavaType javaType = constantReflection.asJavaType(clazz.asConstant()); |
| 139 | + if (javaType == null) { |
| 140 | + b.push(JavaKind.Object, object); |
| 141 | + return true; |
| 142 | + } |
| 143 | + |
| 144 | + TypeReference type; |
| 145 | + if (isExactType.asJavaConstant().asInt() != 0) { |
| 146 | + assert javaType.isConcrete() || javaType.isArray() : "exact type is not a concrete class: " + javaType; |
| 147 | + type = TypeReference.createExactTrusted(javaType); |
| 148 | + } else { |
| 149 | + type = TypeReference.createTrusted(b.getAssumptions(), javaType); |
| 150 | + } |
| 151 | + |
| 152 | + boolean trustedNonNull = nonNull.asJavaConstant().asInt() != 0 && Options.TruffleTrustedNonNullCast.getValue(b.getOptions()); |
| 153 | + Stamp piStamp = StampFactory.object(type, trustedNonNull); |
| 154 | + |
| 155 | + ValueNode guard = null; |
| 156 | + // If the condition is the constant true then no guard is needed |
| 157 | + if (!condition.isConstant() || condition.asJavaConstant().asInt() == 0) { |
| 158 | + guard = b.add(ConditionAnchorNode.create(condition, b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), NodeView.DEFAULT)); |
| 159 | + } |
| 160 | + ValueNode trustedObject = injectTrustedFinal ? castTrustedFinalFrameField(b, object) : object; |
| 161 | + b.addPush(JavaKind.Object, PiNode.create(trustedObject, piStamp, guard)); |
| 162 | + return true; |
| 163 | + } |
171 | 164 | } |
172 | 165 |
|
173 | 166 | /** |
|
0 commit comments