43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 2016, 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.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.replacements;
|
|
24 |
|
|
25 |
import static jdk.vm.ci.code.MemoryBarriers.JMM_POST_VOLATILE_READ;
|
|
26 |
import static jdk.vm.ci.code.MemoryBarriers.JMM_POST_VOLATILE_WRITE;
|
|
27 |
import static jdk.vm.ci.code.MemoryBarriers.JMM_PRE_VOLATILE_READ;
|
|
28 |
import static jdk.vm.ci.code.MemoryBarriers.JMM_PRE_VOLATILE_WRITE;
|
|
29 |
import static jdk.vm.ci.code.MemoryBarriers.LOAD_LOAD;
|
|
30 |
import static jdk.vm.ci.code.MemoryBarriers.LOAD_STORE;
|
|
31 |
import static jdk.vm.ci.code.MemoryBarriers.STORE_LOAD;
|
|
32 |
import static jdk.vm.ci.code.MemoryBarriers.STORE_STORE;
|
46344
|
33 |
import static org.graalvm.compiler.core.common.util.Util.Java8OrEarlier;
|
43972
|
34 |
|
|
35 |
import java.lang.reflect.Array;
|
|
36 |
import java.lang.reflect.Field;
|
|
37 |
import java.util.Arrays;
|
|
38 |
|
|
39 |
import org.graalvm.compiler.api.directives.GraalDirectives;
|
|
40 |
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
|
|
41 |
import org.graalvm.compiler.bytecode.BytecodeProvider;
|
|
42 |
import org.graalvm.compiler.core.common.LocationIdentity;
|
|
43 |
import org.graalvm.compiler.core.common.calc.Condition;
|
|
44 |
import org.graalvm.compiler.core.common.calc.UnsignedMath;
|
46371
|
45 |
import org.graalvm.compiler.core.common.type.ObjectStamp;
|
43972
|
46 |
import org.graalvm.compiler.core.common.type.Stamp;
|
|
47 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
|
48 |
import org.graalvm.compiler.core.common.type.TypeReference;
|
|
49 |
import org.graalvm.compiler.debug.GraalError;
|
|
50 |
import org.graalvm.compiler.graph.Edges;
|
|
51 |
import org.graalvm.compiler.graph.Node;
|
|
52 |
import org.graalvm.compiler.graph.NodeList;
|
|
53 |
import org.graalvm.compiler.nodes.ConstantNode;
|
|
54 |
import org.graalvm.compiler.nodes.DeoptimizeNode;
|
|
55 |
import org.graalvm.compiler.nodes.FixedGuardNode;
|
|
56 |
import org.graalvm.compiler.nodes.LogicNode;
|
|
57 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
58 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
59 |
import org.graalvm.compiler.nodes.calc.AbsNode;
|
|
60 |
import org.graalvm.compiler.nodes.calc.CompareNode;
|
|
61 |
import org.graalvm.compiler.nodes.calc.ConditionalNode;
|
|
62 |
import org.graalvm.compiler.nodes.calc.IntegerEqualsNode;
|
|
63 |
import org.graalvm.compiler.nodes.calc.NarrowNode;
|
|
64 |
import org.graalvm.compiler.nodes.calc.ReinterpretNode;
|
|
65 |
import org.graalvm.compiler.nodes.calc.RightShiftNode;
|
|
66 |
import org.graalvm.compiler.nodes.calc.SignExtendNode;
|
|
67 |
import org.graalvm.compiler.nodes.calc.SqrtNode;
|
|
68 |
import org.graalvm.compiler.nodes.calc.UnsignedDivNode;
|
|
69 |
import org.graalvm.compiler.nodes.calc.UnsignedRemNode;
|
|
70 |
import org.graalvm.compiler.nodes.calc.ZeroExtendNode;
|
|
71 |
import org.graalvm.compiler.nodes.debug.BindToRegisterNode;
|
|
72 |
import org.graalvm.compiler.nodes.debug.BlackholeNode;
|
|
73 |
import org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode;
|
|
74 |
import org.graalvm.compiler.nodes.debug.OpaqueNode;
|
|
75 |
import org.graalvm.compiler.nodes.debug.SpillRegistersNode;
|
|
76 |
import org.graalvm.compiler.nodes.extended.BoxNode;
|
|
77 |
import org.graalvm.compiler.nodes.extended.BranchProbabilityNode;
|
|
78 |
import org.graalvm.compiler.nodes.extended.GetClassNode;
|
|
79 |
import org.graalvm.compiler.nodes.extended.MembarNode;
|
46371
|
80 |
import org.graalvm.compiler.nodes.extended.RawLoadNode;
|
|
81 |
import org.graalvm.compiler.nodes.extended.RawStoreNode;
|
43972
|
82 |
import org.graalvm.compiler.nodes.extended.UnboxNode;
|
|
83 |
import org.graalvm.compiler.nodes.extended.UnsafeMemoryLoadNode;
|
|
84 |
import org.graalvm.compiler.nodes.extended.UnsafeMemoryStoreNode;
|
|
85 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
|
86 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
|
|
87 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver;
|
|
88 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
|
89 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
|
|
90 |
import org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode;
|
|
91 |
import org.graalvm.compiler.nodes.java.DynamicNewArrayNode;
|
|
92 |
import org.graalvm.compiler.nodes.java.DynamicNewInstanceNode;
|
|
93 |
import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
|
|
94 |
import org.graalvm.compiler.nodes.java.LoadFieldNode;
|
|
95 |
import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
|
46371
|
96 |
import org.graalvm.compiler.nodes.java.UnsafeCompareAndSwapNode;
|
43972
|
97 |
import org.graalvm.compiler.nodes.util.GraphUtil;
|
|
98 |
import org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode;
|
|
99 |
import org.graalvm.compiler.replacements.nodes.ReverseBytesNode;
|
|
100 |
import org.graalvm.compiler.replacements.nodes.VirtualizableInvokeMacroNode;
|
|
101 |
import org.graalvm.compiler.replacements.nodes.arithmetic.IntegerAddExactNode;
|
|
102 |
import org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulExactNode;
|
|
103 |
import org.graalvm.compiler.replacements.nodes.arithmetic.IntegerSubExactNode;
|
|
104 |
|
|
105 |
import jdk.vm.ci.meta.DeoptimizationAction;
|
|
106 |
import jdk.vm.ci.meta.DeoptimizationReason;
|
|
107 |
import jdk.vm.ci.meta.JavaConstant;
|
|
108 |
import jdk.vm.ci.meta.JavaKind;
|
|
109 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
110 |
import jdk.vm.ci.meta.ResolvedJavaField;
|
|
111 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
112 |
import jdk.vm.ci.meta.ResolvedJavaType;
|
|
113 |
import sun.misc.Unsafe;
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Provides non-runtime specific {@link InvocationPlugin}s.
|
|
117 |
*/
|
|
118 |
public class StandardGraphBuilderPlugins {
|
|
119 |
|
|
120 |
public static void registerInvocationPlugins(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, InvocationPlugins plugins, BytecodeProvider bytecodeProvider,
|
|
121 |
boolean allowDeoptimization) {
|
|
122 |
registerObjectPlugins(plugins);
|
|
123 |
registerClassPlugins(plugins);
|
|
124 |
registerMathPlugins(plugins, allowDeoptimization);
|
|
125 |
registerUnsignedMathPlugins(plugins);
|
|
126 |
registerStringPlugins(plugins, bytecodeProvider, snippetReflection);
|
|
127 |
registerCharacterPlugins(plugins);
|
|
128 |
registerShortPlugins(plugins);
|
|
129 |
registerIntegerLongPlugins(plugins, JavaKind.Int);
|
|
130 |
registerIntegerLongPlugins(plugins, JavaKind.Long);
|
|
131 |
registerFloatPlugins(plugins);
|
|
132 |
registerDoublePlugins(plugins);
|
|
133 |
registerArraysPlugins(plugins, bytecodeProvider);
|
|
134 |
registerArrayPlugins(plugins, bytecodeProvider);
|
|
135 |
registerUnsafePlugins(plugins, bytecodeProvider);
|
|
136 |
registerEdgesPlugins(metaAccess, plugins);
|
|
137 |
registerGraalDirectivesPlugins(plugins);
|
|
138 |
registerBoxingPlugins(plugins);
|
|
139 |
registerJMHBlackholePlugins(plugins, bytecodeProvider);
|
|
140 |
registerJFRThrowablePlugins(plugins, bytecodeProvider);
|
|
141 |
registerMethodHandleImplPlugins(plugins, snippetReflection, bytecodeProvider);
|
|
142 |
}
|
|
143 |
|
|
144 |
private static final Field STRING_VALUE_FIELD;
|
|
145 |
|
|
146 |
static {
|
|
147 |
try {
|
|
148 |
STRING_VALUE_FIELD = String.class.getDeclaredField("value");
|
|
149 |
} catch (NoSuchFieldException e) {
|
|
150 |
throw new GraalError(e);
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) {
|
46344
|
155 |
final Registration r = new Registration(plugins, String.class, bytecodeProvider);
|
43972
|
156 |
r.register1("hashCode", Receiver.class, new InvocationPlugin() {
|
|
157 |
@Override
|
|
158 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
159 |
if (receiver.isConstant()) {
|
|
160 |
String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
|
|
161 |
b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
|
|
162 |
return true;
|
|
163 |
}
|
|
164 |
return false;
|
|
165 |
}
|
|
166 |
});
|
46344
|
167 |
|
43972
|
168 |
if (Java8OrEarlier) {
|
|
169 |
r.registerMethodSubstitution(StringSubstitutions.class, "equals", Receiver.class, Object.class);
|
46344
|
170 |
r.register7("indexOf", char[].class, int.class, int.class, char[].class, int.class, int.class, int.class, new StringIndexOfConstantPlugin());
|
43972
|
171 |
|
46344
|
172 |
Registration sr = new Registration(plugins, StringSubstitutions.class);
|
|
173 |
sr.register1("getValue", String.class, new InvocationPlugin() {
|
43972
|
174 |
@Override
|
|
175 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
|
176 |
ResolvedJavaField field = b.getMetaAccess().lookupJavaField(STRING_VALUE_FIELD);
|
46371
|
177 |
b.addPush(JavaKind.Object, LoadFieldNode.create(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(),
|
|
178 |
b.getOptions(), b.getAssumptions(), value, field, false, false));
|
43972
|
179 |
return true;
|
|
180 |
}
|
|
181 |
});
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
private static void registerArraysPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
|
|
186 |
Registration r = new Registration(plugins, Arrays.class, bytecodeProvider);
|
|
187 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", boolean[].class, boolean[].class);
|
|
188 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", byte[].class, byte[].class);
|
|
189 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", short[].class, short[].class);
|
|
190 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", char[].class, char[].class);
|
|
191 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", int[].class, int[].class);
|
|
192 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", float[].class, float[].class);
|
|
193 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", long[].class, long[].class);
|
|
194 |
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", double[].class, double[].class);
|
|
195 |
}
|
|
196 |
|
|
197 |
private static void registerArrayPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
|
|
198 |
Registration r = new Registration(plugins, Array.class, bytecodeProvider);
|
|
199 |
r.register2("newInstance", Class.class, int.class, new InvocationPlugin() {
|
|
200 |
@Override
|
|
201 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode componentType, ValueNode length) {
|
|
202 |
b.addPush(JavaKind.Object, new DynamicNewArrayNode(componentType, length, true));
|
|
203 |
return true;
|
|
204 |
}
|
|
205 |
});
|
|
206 |
r.registerMethodSubstitution(ArraySubstitutions.class, "getLength", Object.class);
|
|
207 |
}
|
|
208 |
|
|
209 |
private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
|
|
210 |
Registration r;
|
|
211 |
if (Java8OrEarlier) {
|
|
212 |
r = new Registration(plugins, Unsafe.class);
|
|
213 |
} else {
|
|
214 |
r = new Registration(plugins, "jdk.internal.misc.Unsafe", bytecodeProvider);
|
|
215 |
}
|
|
216 |
|
|
217 |
for (JavaKind kind : JavaKind.values()) {
|
|
218 |
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
|
|
219 |
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
|
|
220 |
String kindName = kind.name();
|
|
221 |
String getName = "get" + kindName;
|
|
222 |
String putName = "put" + kindName;
|
|
223 |
// Object-based accesses
|
|
224 |
r.register3(getName, Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, false));
|
|
225 |
r.register4(putName, Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, false));
|
|
226 |
// Volatile object-based accesses
|
|
227 |
r.register3(getName + "Volatile", Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, true));
|
|
228 |
r.register4(putName + "Volatile", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, true));
|
|
229 |
// Ordered object-based accesses
|
|
230 |
if (Java8OrEarlier) {
|
|
231 |
if (kind == JavaKind.Int || kind == JavaKind.Long || kind == JavaKind.Object) {
|
|
232 |
r.register4("putOrdered" + kindName, Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, true));
|
|
233 |
}
|
|
234 |
} else {
|
|
235 |
r.register4("put" + kindName + "Release", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, true));
|
|
236 |
}
|
|
237 |
if (kind != JavaKind.Boolean && kind != JavaKind.Object) {
|
|
238 |
// Raw accesses to memory addresses
|
|
239 |
r.register2(getName, Receiver.class, long.class, new UnsafeGetPlugin(kind, false));
|
|
240 |
r.register3(putName, Receiver.class, long.class, kind.toJavaClass(), new UnsafePutPlugin(kind, false));
|
|
241 |
}
|
|
242 |
}
|
|
243 |
}
|
|
244 |
|
|
245 |
// Accesses to native memory addresses.
|
|
246 |
r.register2("getAddress", Receiver.class, long.class, new UnsafeGetPlugin(JavaKind.Long, false));
|
|
247 |
r.register3("putAddress", Receiver.class, long.class, long.class, new UnsafePutPlugin(JavaKind.Long, false));
|
|
248 |
|
|
249 |
for (JavaKind kind : new JavaKind[]{JavaKind.Int, JavaKind.Long, JavaKind.Object}) {
|
|
250 |
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
|
|
251 |
r.register5("compareAndSwap" + kind.name(), Receiver.class, Object.class, long.class, javaClass, javaClass, new InvocationPlugin() {
|
|
252 |
@Override
|
|
253 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode expected, ValueNode x) {
|
|
254 |
// Emits a null-check for the otherwise unused receiver
|
|
255 |
unsafe.get();
|
46344
|
256 |
b.addPush(JavaKind.Int, new UnsafeCompareAndSwapNode(object, offset, expected, x, kind, LocationIdentity.any()));
|
43972
|
257 |
b.getGraph().markUnsafeAccess();
|
|
258 |
return true;
|
|
259 |
}
|
|
260 |
});
|
|
261 |
}
|
|
262 |
|
|
263 |
r.register2("allocateInstance", Receiver.class, Class.class, new InvocationPlugin() {
|
|
264 |
|
|
265 |
@Override
|
|
266 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode clazz) {
|
|
267 |
// Emits a null-check for the otherwise unused receiver
|
|
268 |
unsafe.get();
|
46344
|
269 |
b.addPush(JavaKind.Object, new DynamicNewInstanceNode(b.nullCheckedValue(clazz, DeoptimizationAction.None), true));
|
43972
|
270 |
return true;
|
|
271 |
}
|
|
272 |
|
|
273 |
});
|
|
274 |
|
|
275 |
r.register1("loadFence", Receiver.class, new UnsafeFencePlugin(LOAD_LOAD | LOAD_STORE));
|
|
276 |
r.register1("storeFence", Receiver.class, new UnsafeFencePlugin(STORE_STORE | LOAD_STORE));
|
|
277 |
r.register1("fullFence", Receiver.class, new UnsafeFencePlugin(LOAD_LOAD | STORE_STORE | LOAD_STORE | STORE_LOAD));
|
|
278 |
}
|
|
279 |
|
|
280 |
private static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind) {
|
|
281 |
Class<?> declaringClass = kind.toBoxedJavaClass();
|
|
282 |
Class<?> type = kind.toJavaClass();
|
|
283 |
Registration r = new Registration(plugins, declaringClass);
|
|
284 |
r.register1("reverseBytes", type, new InvocationPlugin() {
|
|
285 |
@Override
|
|
286 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
287 |
b.push(kind, b.append(new ReverseBytesNode(value).canonical(null)));
|
43972
|
288 |
return true;
|
|
289 |
}
|
|
290 |
});
|
|
291 |
r.register2("divideUnsigned", type, type, new InvocationPlugin() {
|
|
292 |
@Override
|
|
293 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode dividend, ValueNode divisor) {
|
46393
|
294 |
b.push(kind, b.append(new UnsignedDivNode(dividend, divisor).canonical(null)));
|
43972
|
295 |
return true;
|
|
296 |
}
|
|
297 |
});
|
|
298 |
r.register2("remainderUnsigned", type, type, new InvocationPlugin() {
|
|
299 |
@Override
|
|
300 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode dividend, ValueNode divisor) {
|
46393
|
301 |
b.push(kind, b.append(new UnsignedRemNode(dividend, divisor).canonical(null)));
|
43972
|
302 |
return true;
|
|
303 |
}
|
|
304 |
});
|
|
305 |
}
|
|
306 |
|
|
307 |
private static void registerCharacterPlugins(InvocationPlugins plugins) {
|
|
308 |
Registration r = new Registration(plugins, Character.class);
|
|
309 |
r.register1("reverseBytes", char.class, new InvocationPlugin() {
|
|
310 |
@Override
|
|
311 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
|
312 |
// return (char) (Integer.reverse(i) >> 16);
|
|
313 |
ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
|
|
314 |
RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
|
|
315 |
ZeroExtendNode charCast = b.add(new ZeroExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
|
46393
|
316 |
b.push(JavaKind.Char, b.append(charCast.canonical(null)));
|
43972
|
317 |
return true;
|
|
318 |
}
|
|
319 |
});
|
|
320 |
}
|
|
321 |
|
|
322 |
private static void registerShortPlugins(InvocationPlugins plugins) {
|
|
323 |
Registration r = new Registration(plugins, Short.class);
|
|
324 |
r.register1("reverseBytes", short.class, new InvocationPlugin() {
|
|
325 |
@Override
|
|
326 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
|
327 |
// return (short) (Integer.reverse(i) >> 16);
|
|
328 |
ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
|
|
329 |
RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
|
|
330 |
SignExtendNode charCast = b.add(new SignExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
|
46393
|
331 |
b.push(JavaKind.Short, b.append(charCast.canonical(null)));
|
43972
|
332 |
return true;
|
|
333 |
}
|
|
334 |
});
|
|
335 |
}
|
|
336 |
|
|
337 |
private static void registerFloatPlugins(InvocationPlugins plugins) {
|
|
338 |
Registration r = new Registration(plugins, Float.class);
|
|
339 |
r.register1("floatToRawIntBits", float.class, new InvocationPlugin() {
|
|
340 |
@Override
|
|
341 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
342 |
b.push(JavaKind.Int, b.append(new ReinterpretNode(JavaKind.Int, value).canonical(null)));
|
43972
|
343 |
return true;
|
|
344 |
}
|
|
345 |
});
|
|
346 |
r.register1("intBitsToFloat", int.class, new InvocationPlugin() {
|
|
347 |
@Override
|
|
348 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
349 |
b.push(JavaKind.Float, b.append(new ReinterpretNode(JavaKind.Float, value).canonical(null)));
|
43972
|
350 |
return true;
|
|
351 |
}
|
|
352 |
});
|
|
353 |
}
|
|
354 |
|
|
355 |
private static void registerDoublePlugins(InvocationPlugins plugins) {
|
|
356 |
Registration r = new Registration(plugins, Double.class);
|
|
357 |
r.register1("doubleToRawLongBits", double.class, new InvocationPlugin() {
|
|
358 |
@Override
|
|
359 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
360 |
b.push(JavaKind.Long, b.append(new ReinterpretNode(JavaKind.Long, value).canonical(null)));
|
43972
|
361 |
return true;
|
|
362 |
}
|
|
363 |
});
|
|
364 |
r.register1("longBitsToDouble", long.class, new InvocationPlugin() {
|
|
365 |
@Override
|
|
366 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
367 |
b.push(JavaKind.Double, b.append(new ReinterpretNode(JavaKind.Double, value).canonical(null)));
|
43972
|
368 |
return true;
|
|
369 |
}
|
|
370 |
});
|
|
371 |
}
|
|
372 |
|
|
373 |
private static void registerMathPlugins(InvocationPlugins plugins, boolean allowDeoptimization) {
|
|
374 |
Registration r = new Registration(plugins, Math.class);
|
|
375 |
if (allowDeoptimization) {
|
|
376 |
for (JavaKind kind : new JavaKind[]{JavaKind.Int, JavaKind.Long}) {
|
|
377 |
Class<?> type = kind.toJavaClass();
|
|
378 |
r.register2("addExact", type, type, new InvocationPlugin() {
|
|
379 |
@Override
|
|
380 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
|
|
381 |
b.addPush(kind, new IntegerAddExactNode(x, y));
|
|
382 |
return true;
|
|
383 |
}
|
|
384 |
});
|
|
385 |
r.register2("subtractExact", type, type, new InvocationPlugin() {
|
|
386 |
@Override
|
|
387 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
|
|
388 |
b.addPush(kind, new IntegerSubExactNode(x, y));
|
|
389 |
return true;
|
|
390 |
}
|
|
391 |
});
|
|
392 |
r.register2("multiplyExact", type, type, new InvocationPlugin() {
|
|
393 |
@Override
|
|
394 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
|
|
395 |
b.addPush(kind, new IntegerMulExactNode(x, y));
|
|
396 |
return true;
|
|
397 |
}
|
|
398 |
});
|
|
399 |
}
|
|
400 |
}
|
|
401 |
r.register1("abs", Float.TYPE, new InvocationPlugin() {
|
|
402 |
|
|
403 |
@Override
|
|
404 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
405 |
b.push(JavaKind.Float, b.append(new AbsNode(value).canonical(null)));
|
43972
|
406 |
return true;
|
|
407 |
}
|
|
408 |
});
|
|
409 |
r.register1("abs", Double.TYPE, new InvocationPlugin() {
|
|
410 |
@Override
|
|
411 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
412 |
b.push(JavaKind.Double, b.append(new AbsNode(value).canonical(null)));
|
43972
|
413 |
return true;
|
|
414 |
}
|
|
415 |
});
|
|
416 |
r.register1("sqrt", Double.TYPE, new InvocationPlugin() {
|
|
417 |
@Override
|
|
418 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46393
|
419 |
b.push(JavaKind.Double, b.append(new SqrtNode(value).canonical(null)));
|
43972
|
420 |
return true;
|
|
421 |
}
|
|
422 |
});
|
|
423 |
}
|
|
424 |
|
46344
|
425 |
public static final class StringIndexOfConstantPlugin implements InvocationPlugin {
|
|
426 |
@Override
|
|
427 |
public boolean inlineOnly() {
|
|
428 |
return true;
|
|
429 |
}
|
|
430 |
|
|
431 |
@Override
|
|
432 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4,
|
|
433 |
ValueNode arg5, ValueNode arg6, ValueNode arg7) {
|
|
434 |
if (arg3.isConstant()) {
|
|
435 |
b.addPush(JavaKind.Int,
|
|
436 |
new StringIndexOfNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnStamp(b.getAssumptions()), arg1, arg2, arg3, arg4, arg5, arg6, arg7));
|
|
437 |
return true;
|
|
438 |
}
|
|
439 |
return false;
|
|
440 |
}
|
|
441 |
}
|
|
442 |
|
43972
|
443 |
public static class UnsignedMathPlugin implements InvocationPlugin {
|
|
444 |
private final Condition condition;
|
|
445 |
|
|
446 |
public UnsignedMathPlugin(Condition condition) {
|
|
447 |
this.condition = condition;
|
|
448 |
}
|
|
449 |
|
|
450 |
@Override
|
|
451 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
|
|
452 |
// the mirroring and negation operations get the condition into canonical form
|
|
453 |
boolean mirror = condition.canonicalMirror();
|
|
454 |
boolean negate = condition.canonicalNegate();
|
|
455 |
StructuredGraph graph = b.getGraph();
|
|
456 |
|
|
457 |
ValueNode lhs = mirror ? y : x;
|
|
458 |
ValueNode rhs = mirror ? x : y;
|
|
459 |
|
|
460 |
ValueNode trueValue = ConstantNode.forBoolean(!negate, graph);
|
|
461 |
ValueNode falseValue = ConstantNode.forBoolean(negate, graph);
|
|
462 |
|
|
463 |
Condition cond = mirror ? condition.mirror() : condition;
|
|
464 |
if (negate) {
|
|
465 |
cond = cond.negate();
|
|
466 |
}
|
|
467 |
|
46393
|
468 |
LogicNode compare = CompareNode.createCompareNode(graph, b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, cond, lhs, rhs);
|
43972
|
469 |
b.addPush(JavaKind.Boolean, new ConditionalNode(compare, trueValue, falseValue));
|
|
470 |
return true;
|
|
471 |
}
|
|
472 |
}
|
|
473 |
|
|
474 |
private static void registerUnsignedMathPlugins(InvocationPlugins plugins) {
|
|
475 |
Registration r = new Registration(plugins, UnsignedMath.class);
|
|
476 |
r.register2("aboveThan", int.class, int.class, new UnsignedMathPlugin(Condition.AT));
|
|
477 |
r.register2("aboveThan", long.class, long.class, new UnsignedMathPlugin(Condition.AT));
|
|
478 |
r.register2("belowThan", int.class, int.class, new UnsignedMathPlugin(Condition.BT));
|
|
479 |
r.register2("belowThan", long.class, long.class, new UnsignedMathPlugin(Condition.BT));
|
|
480 |
r.register2("aboveOrEqual", int.class, int.class, new UnsignedMathPlugin(Condition.AE));
|
|
481 |
r.register2("aboveOrEqual", long.class, long.class, new UnsignedMathPlugin(Condition.AE));
|
|
482 |
r.register2("belowOrEqual", int.class, int.class, new UnsignedMathPlugin(Condition.BE));
|
|
483 |
r.register2("belowOrEqual", long.class, long.class, new UnsignedMathPlugin(Condition.BE));
|
|
484 |
}
|
|
485 |
|
|
486 |
protected static void registerBoxingPlugins(InvocationPlugins plugins) {
|
|
487 |
for (JavaKind kind : JavaKind.values()) {
|
|
488 |
if (kind.isPrimitive() && kind != JavaKind.Void) {
|
|
489 |
new BoxPlugin(kind).register(plugins);
|
|
490 |
new UnboxPlugin(kind).register(plugins);
|
|
491 |
}
|
|
492 |
}
|
|
493 |
}
|
|
494 |
|
|
495 |
private static void registerObjectPlugins(InvocationPlugins plugins) {
|
|
496 |
Registration r = new Registration(plugins, Object.class);
|
|
497 |
r.register1("<init>", Receiver.class, new InvocationPlugin() {
|
|
498 |
@Override
|
|
499 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
500 |
/*
|
|
501 |
* Object.<init> is a common instrumentation point so only perform this rewrite if
|
|
502 |
* the current definition is the normal empty method with a single return bytecode.
|
|
503 |
* The finalizer registration will instead be performed by the BytecodeParser.
|
|
504 |
*/
|
|
505 |
if (targetMethod.getCodeSize() == 1) {
|
|
506 |
ValueNode object = receiver.get();
|
|
507 |
if (RegisterFinalizerNode.mayHaveFinalizer(object, b.getAssumptions())) {
|
|
508 |
b.add(new RegisterFinalizerNode(object));
|
|
509 |
}
|
|
510 |
return true;
|
|
511 |
}
|
|
512 |
return false;
|
|
513 |
}
|
|
514 |
});
|
|
515 |
r.register1("getClass", Receiver.class, new InvocationPlugin() {
|
|
516 |
@Override
|
|
517 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
518 |
ValueNode object = receiver.get();
|
|
519 |
ValueNode folded = GetClassNode.tryFold(b.getMetaAccess(), b.getConstantReflection(), GraphUtil.originalValue(object));
|
|
520 |
if (folded != null) {
|
|
521 |
b.addPush(JavaKind.Object, folded);
|
|
522 |
} else {
|
|
523 |
Stamp stamp = StampFactory.objectNonNull(TypeReference.createTrusted(b.getAssumptions(), b.getMetaAccess().lookupJavaType(Class.class)));
|
|
524 |
b.addPush(JavaKind.Object, new GetClassNode(stamp, object));
|
|
525 |
}
|
|
526 |
return true;
|
|
527 |
}
|
|
528 |
});
|
|
529 |
}
|
|
530 |
|
|
531 |
private static void registerClassPlugins(InvocationPlugins plugins) {
|
|
532 |
Registration r = new Registration(plugins, Class.class);
|
|
533 |
r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {
|
|
534 |
@Override
|
|
535 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode object) {
|
46393
|
536 |
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), type.get(), object, false));
|
|
537 |
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
|
43972
|
538 |
return true;
|
|
539 |
}
|
|
540 |
});
|
|
541 |
r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {
|
|
542 |
@Override
|
|
543 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
|
46393
|
544 |
ClassIsAssignableFromNode condition = b.append(new ClassIsAssignableFromNode(type.get(), otherType));
|
|
545 |
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
|
43972
|
546 |
return true;
|
|
547 |
}
|
|
548 |
});
|
|
549 |
}
|
|
550 |
|
|
551 |
/**
|
|
552 |
* Substitutions for improving the performance of some critical methods in {@link Edges}. These
|
|
553 |
* substitutions improve the performance by forcing the relevant methods to be inlined
|
|
554 |
* (intrinsification being a special form of inlining) and removing a checked cast.
|
|
555 |
*/
|
|
556 |
private static void registerEdgesPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
|
|
557 |
Registration r = new Registration(plugins, Edges.class);
|
|
558 |
for (Class<?> c : new Class<?>[]{Node.class, NodeList.class}) {
|
|
559 |
r.register2("get" + c.getSimpleName() + "Unsafe", Node.class, long.class, new InvocationPlugin() {
|
|
560 |
@Override
|
|
561 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset) {
|
46371
|
562 |
ObjectStamp stamp = StampFactory.object(TypeReference.createTrusted(b.getAssumptions(), metaAccess.lookupJavaType(c)));
|
|
563 |
RawLoadNode value = b.add(new RawLoadNode(stamp, node, offset, LocationIdentity.any(), JavaKind.Object));
|
43972
|
564 |
b.addPush(JavaKind.Object, value);
|
|
565 |
return true;
|
|
566 |
}
|
|
567 |
});
|
|
568 |
r.register3("put" + c.getSimpleName() + "Unsafe", Node.class, long.class, c, new InvocationPlugin() {
|
|
569 |
@Override
|
|
570 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset, ValueNode value) {
|
46344
|
571 |
b.add(new RawStoreNode(node, offset, value, JavaKind.Object, LocationIdentity.any()));
|
43972
|
572 |
return true;
|
|
573 |
}
|
|
574 |
});
|
|
575 |
}
|
|
576 |
}
|
|
577 |
|
|
578 |
public static class BoxPlugin implements InvocationPlugin {
|
|
579 |
|
|
580 |
private final JavaKind kind;
|
|
581 |
|
|
582 |
BoxPlugin(JavaKind kind) {
|
|
583 |
this.kind = kind;
|
|
584 |
}
|
|
585 |
|
|
586 |
@Override
|
|
587 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
|
588 |
if (b.parsingIntrinsic()) {
|
|
589 |
ResolvedJavaMethod rootMethod = b.getGraph().method();
|
|
590 |
if (b.getMetaAccess().lookupJavaType(BoxingSnippets.class).isAssignableFrom(rootMethod.getDeclaringClass())) {
|
|
591 |
// Disable invocation plugins for boxing snippets so that the
|
|
592 |
// original JDK methods are inlined
|
|
593 |
return false;
|
|
594 |
}
|
|
595 |
}
|
|
596 |
ResolvedJavaType resultType = b.getMetaAccess().lookupJavaType(kind.toBoxedJavaClass());
|
|
597 |
b.addPush(JavaKind.Object, new BoxNode(value, resultType, kind));
|
|
598 |
return true;
|
|
599 |
}
|
|
600 |
|
|
601 |
void register(InvocationPlugins plugins) {
|
|
602 |
plugins.register(this, kind.toBoxedJavaClass(), "valueOf", kind.toJavaClass());
|
|
603 |
}
|
|
604 |
}
|
|
605 |
|
|
606 |
public static class UnboxPlugin implements InvocationPlugin {
|
|
607 |
|
|
608 |
private final JavaKind kind;
|
|
609 |
|
|
610 |
UnboxPlugin(JavaKind kind) {
|
|
611 |
this.kind = kind;
|
|
612 |
}
|
|
613 |
|
|
614 |
@Override
|
|
615 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
616 |
if (b.parsingIntrinsic()) {
|
|
617 |
ResolvedJavaMethod rootMethod = b.getGraph().method();
|
|
618 |
if (b.getMetaAccess().lookupJavaType(BoxingSnippets.class).isAssignableFrom(rootMethod.getDeclaringClass())) {
|
|
619 |
// Disable invocation plugins for unboxing snippets so that the
|
|
620 |
// original JDK methods are inlined
|
|
621 |
return false;
|
|
622 |
}
|
|
623 |
}
|
|
624 |
ValueNode valueNode = UnboxNode.create(b.getMetaAccess(), b.getConstantReflection(), receiver.get(), kind);
|
|
625 |
b.addPush(kind, valueNode);
|
|
626 |
return true;
|
|
627 |
}
|
|
628 |
|
|
629 |
void register(InvocationPlugins plugins) {
|
|
630 |
String name = kind.toJavaClass().getSimpleName() + "Value";
|
|
631 |
plugins.register(this, kind.toBoxedJavaClass(), name, Receiver.class);
|
|
632 |
}
|
|
633 |
}
|
|
634 |
|
|
635 |
public static class UnsafeGetPlugin implements InvocationPlugin {
|
|
636 |
|
|
637 |
private final JavaKind returnKind;
|
|
638 |
private final boolean isVolatile;
|
|
639 |
|
|
640 |
public UnsafeGetPlugin(JavaKind returnKind, boolean isVolatile) {
|
|
641 |
this.returnKind = returnKind;
|
|
642 |
this.isVolatile = isVolatile;
|
|
643 |
}
|
|
644 |
|
|
645 |
@Override
|
|
646 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode address) {
|
|
647 |
// Emits a null-check for the otherwise unused receiver
|
|
648 |
unsafe.get();
|
|
649 |
b.addPush(returnKind, new UnsafeMemoryLoadNode(address, returnKind, LocationIdentity.any()));
|
|
650 |
b.getGraph().markUnsafeAccess();
|
|
651 |
return true;
|
|
652 |
}
|
|
653 |
|
|
654 |
@Override
|
|
655 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset) {
|
|
656 |
// Emits a null-check for the otherwise unused receiver
|
|
657 |
unsafe.get();
|
|
658 |
if (isVolatile) {
|
|
659 |
b.add(new MembarNode(JMM_PRE_VOLATILE_READ));
|
|
660 |
}
|
46344
|
661 |
b.addPush(returnKind, new RawLoadNode(object, offset, returnKind, LocationIdentity.any()));
|
43972
|
662 |
if (isVolatile) {
|
|
663 |
b.add(new MembarNode(JMM_POST_VOLATILE_READ));
|
|
664 |
}
|
|
665 |
b.getGraph().markUnsafeAccess();
|
|
666 |
return true;
|
|
667 |
}
|
|
668 |
}
|
|
669 |
|
|
670 |
public static class UnsafePutPlugin implements InvocationPlugin {
|
|
671 |
|
|
672 |
private final JavaKind kind;
|
|
673 |
private final boolean isVolatile;
|
|
674 |
|
|
675 |
public UnsafePutPlugin(JavaKind kind, boolean isVolatile) {
|
|
676 |
this.kind = kind;
|
|
677 |
this.isVolatile = isVolatile;
|
|
678 |
}
|
|
679 |
|
|
680 |
@Override
|
|
681 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode address, ValueNode value) {
|
|
682 |
// Emits a null-check for the otherwise unused receiver
|
|
683 |
unsafe.get();
|
|
684 |
b.add(new UnsafeMemoryStoreNode(address, value, kind, LocationIdentity.any()));
|
|
685 |
b.getGraph().markUnsafeAccess();
|
|
686 |
return true;
|
|
687 |
}
|
|
688 |
|
|
689 |
@Override
|
|
690 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) {
|
|
691 |
// Emits a null-check for the otherwise unused receiver
|
|
692 |
unsafe.get();
|
|
693 |
if (isVolatile) {
|
|
694 |
b.add(new MembarNode(JMM_PRE_VOLATILE_WRITE));
|
|
695 |
}
|
46344
|
696 |
b.add(new RawStoreNode(object, offset, value, kind, LocationIdentity.any()));
|
43972
|
697 |
if (isVolatile) {
|
|
698 |
b.add(new MembarNode(JMM_POST_VOLATILE_WRITE));
|
|
699 |
}
|
|
700 |
b.getGraph().markUnsafeAccess();
|
|
701 |
return true;
|
|
702 |
}
|
|
703 |
}
|
|
704 |
|
|
705 |
public static class UnsafeFencePlugin implements InvocationPlugin {
|
|
706 |
|
|
707 |
private final int barriers;
|
|
708 |
|
|
709 |
public UnsafeFencePlugin(int barriers) {
|
|
710 |
this.barriers = barriers;
|
|
711 |
}
|
|
712 |
|
|
713 |
@Override
|
|
714 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe) {
|
|
715 |
// Emits a null-check for the otherwise unused receiver
|
|
716 |
unsafe.get();
|
|
717 |
b.add(new MembarNode(barriers));
|
|
718 |
return true;
|
|
719 |
}
|
|
720 |
}
|
|
721 |
|
|
722 |
private static void registerGraalDirectivesPlugins(InvocationPlugins plugins) {
|
|
723 |
Registration r = new Registration(plugins, GraalDirectives.class);
|
|
724 |
r.register0("deoptimize", new InvocationPlugin() {
|
|
725 |
@Override
|
|
726 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
727 |
b.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
|
|
728 |
return true;
|
|
729 |
}
|
|
730 |
});
|
|
731 |
|
|
732 |
r.register0("deoptimizeAndInvalidate", new InvocationPlugin() {
|
|
733 |
@Override
|
|
734 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
735 |
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
|
|
736 |
return true;
|
|
737 |
}
|
|
738 |
});
|
|
739 |
|
|
740 |
r.register0("inCompiledCode", new InvocationPlugin() {
|
|
741 |
@Override
|
|
742 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
743 |
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
|
|
744 |
return true;
|
|
745 |
}
|
|
746 |
});
|
|
747 |
|
|
748 |
r.register0("controlFlowAnchor", new InvocationPlugin() {
|
|
749 |
@Override
|
|
750 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
751 |
b.add(new ControlFlowAnchorNode());
|
|
752 |
return true;
|
|
753 |
}
|
|
754 |
});
|
|
755 |
|
|
756 |
r.register2("injectBranchProbability", double.class, boolean.class, new InvocationPlugin() {
|
|
757 |
@Override
|
|
758 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
|
|
759 |
b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
|
|
760 |
return true;
|
|
761 |
}
|
|
762 |
});
|
|
763 |
|
|
764 |
InvocationPlugin blackholePlugin = new InvocationPlugin() {
|
|
765 |
@Override
|
|
766 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
|
767 |
b.add(new BlackholeNode(value));
|
|
768 |
return true;
|
|
769 |
}
|
|
770 |
};
|
|
771 |
|
|
772 |
InvocationPlugin bindToRegisterPlugin = new InvocationPlugin() {
|
|
773 |
@Override
|
|
774 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
|
775 |
b.add(new BindToRegisterNode(value));
|
|
776 |
return true;
|
|
777 |
}
|
|
778 |
};
|
|
779 |
for (JavaKind kind : JavaKind.values()) {
|
|
780 |
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
|
|
781 |
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
|
|
782 |
r.register1("blackhole", javaClass, blackholePlugin);
|
|
783 |
r.register1("bindToRegister", javaClass, bindToRegisterPlugin);
|
|
784 |
|
|
785 |
r.register1("opaque", javaClass, new InvocationPlugin() {
|
|
786 |
@Override
|
|
787 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
|
788 |
b.addPush(kind, new OpaqueNode(value));
|
|
789 |
return true;
|
|
790 |
}
|
|
791 |
});
|
|
792 |
}
|
|
793 |
}
|
|
794 |
|
|
795 |
InvocationPlugin spillPlugin = new InvocationPlugin() {
|
|
796 |
@Override
|
|
797 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
|
|
798 |
b.add(new SpillRegistersNode());
|
|
799 |
return true;
|
|
800 |
}
|
|
801 |
};
|
|
802 |
r.register0("spillRegisters", spillPlugin);
|
|
803 |
|
|
804 |
r.register1("guardingNonNull", Object.class, new InvocationPlugin() {
|
|
805 |
@Override
|
|
806 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
|
46344
|
807 |
b.addPush(value.getStackKind(), b.nullCheckedValue(value));
|
43972
|
808 |
return true;
|
|
809 |
}
|
|
810 |
});
|
|
811 |
|
|
812 |
r.register1("ensureVirtualized", Object.class, new InvocationPlugin() {
|
|
813 |
@Override
|
|
814 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
|
|
815 |
b.add(new EnsureVirtualizedNode(object, false));
|
|
816 |
return true;
|
|
817 |
}
|
|
818 |
});
|
|
819 |
r.register1("ensureVirtualizedHere", Object.class, new InvocationPlugin() {
|
|
820 |
@Override
|
|
821 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
|
|
822 |
b.add(new EnsureVirtualizedNode(object, true));
|
|
823 |
return true;
|
|
824 |
}
|
|
825 |
});
|
|
826 |
}
|
|
827 |
|
|
828 |
private static void registerJMHBlackholePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
|
|
829 |
InvocationPlugin blackholePlugin = new InvocationPlugin() {
|
|
830 |
@Override
|
|
831 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver blackhole, ValueNode value) {
|
|
832 |
blackhole.get();
|
|
833 |
b.add(new BlackholeNode(value));
|
|
834 |
return true;
|
|
835 |
}
|
|
836 |
};
|
|
837 |
String[] names = {"org.openjdk.jmh.infra.Blackhole", "org.openjdk.jmh.logic.BlackHole"};
|
|
838 |
for (String name : names) {
|
|
839 |
Registration r = new Registration(plugins, name, bytecodeProvider);
|
|
840 |
for (JavaKind kind : JavaKind.values()) {
|
|
841 |
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
|
|
842 |
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
|
46344
|
843 |
r.registerOptional2("consume", Receiver.class, javaClass, blackholePlugin);
|
43972
|
844 |
}
|
|
845 |
}
|
46344
|
846 |
r.registerOptional2("consume", Receiver.class, Object[].class, blackholePlugin);
|
43972
|
847 |
}
|
|
848 |
}
|
|
849 |
|
|
850 |
private static void registerJFRThrowablePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
|
|
851 |
Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer", bytecodeProvider);
|
|
852 |
r.register2("traceThrowable", Throwable.class, String.class, new InvocationPlugin() {
|
|
853 |
@Override
|
|
854 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
|
|
855 |
b.add(new VirtualizableInvokeMacroNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnStamp(b.getAssumptions()), throwable, message));
|
|
856 |
return true;
|
|
857 |
}
|
|
858 |
|
|
859 |
@Override
|
|
860 |
public boolean inlineOnly() {
|
|
861 |
return true;
|
|
862 |
}
|
|
863 |
});
|
|
864 |
}
|
|
865 |
|
|
866 |
private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider) {
|
|
867 |
Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", bytecodeProvider);
|
|
868 |
r.register2("profileBoolean", boolean.class, int[].class, new InvocationPlugin() {
|
|
869 |
@Override
|
|
870 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode counters) {
|
|
871 |
if (result.isConstant()) {
|
|
872 |
b.push(JavaKind.Boolean, result);
|
|
873 |
return true;
|
|
874 |
}
|
|
875 |
if (counters.isConstant()) {
|
|
876 |
ValueNode newResult = result;
|
|
877 |
int[] ctrs = snippetReflection.asObject(int[].class, (JavaConstant) counters.asConstant());
|
|
878 |
if (ctrs != null && ctrs.length == 2) {
|
|
879 |
int falseCount = ctrs[0];
|
|
880 |
int trueCount = ctrs[1];
|
|
881 |
int totalCount = trueCount + falseCount;
|
|
882 |
|
|
883 |
if (totalCount == 0) {
|
|
884 |
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
|
|
885 |
} else if (falseCount == 0 || trueCount == 0) {
|
46371
|
886 |
boolean expected = falseCount == 0;
|
46393
|
887 |
LogicNode condition = b.addWithInputs(
|
|
888 |
IntegerEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, result, b.add(ConstantNode.forBoolean(!expected))));
|
43972
|
889 |
b.append(new FixedGuardNode(condition, DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile, true));
|
|
890 |
newResult = b.add(ConstantNode.forBoolean(expected));
|
|
891 |
} else {
|
|
892 |
// We cannot use BranchProbabilityNode here since there's no guarantee
|
|
893 |
// the result of MethodHandleImpl.profileBoolean() is used as the
|
|
894 |
// test in an `if` statement (as required by BranchProbabilityNode).
|
|
895 |
}
|
|
896 |
}
|
|
897 |
b.addPush(JavaKind.Boolean, newResult);
|
|
898 |
return true;
|
|
899 |
}
|
|
900 |
return false;
|
|
901 |
}
|
|
902 |
});
|
|
903 |
}
|
|
904 |
}
|