use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class StaticInterfaceFieldTest method eagerlyParseMethod.
@SuppressWarnings("try")
private void eagerlyParseMethod(Class<C> clazz, String methodName) {
RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
Providers providers = rt.getHostBackend().getProviders();
MetaAccessProvider metaAccess = providers.getMetaAccess();
PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
Plugins plugins = new Plugins(new InvocationPlugins());
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
final Method m = getMethod(clazz, methodName);
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
try (DebugCloseable s = debug.disableIntercept();
DebugContext.Scope ds = debug.scope("GraphBuilding", graph, method)) {
graphBuilderSuite.apply(graph, context);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class ReplacementsTest method getSystemClassLoaderBytecodeProvider.
/**
* Gets a {@link ClassfileBytecodeProvider} that enables snippets and intrinsics to be loaded
* from the system class path (instead of from the JVMCI class path or Graal module).
*/
protected final ClassfileBytecodeProvider getSystemClassLoaderBytecodeProvider() {
ReplacementsImpl d = (ReplacementsImpl) getReplacements();
MetaAccessProvider metaAccess = d.providers.getMetaAccess();
ClassfileBytecodeProvider bytecodeProvider = new ClassfileBytecodeProvider(metaAccess, d.snippetReflection, ClassLoader.getSystemClassLoader());
return bytecodeProvider;
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class VerifyBailoutUsageTest method testBailoutUsage.
@SuppressWarnings("try")
private static void testBailoutUsage(Class<?> c) {
RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
Providers providers = rt.getHostBackend().getProviders();
MetaAccessProvider metaAccess = providers.getMetaAccess();
PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
Plugins plugins = new Plugins(new InvocationPlugins());
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
for (Method m : c.getDeclaredMethods()) {
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
graphBuilderSuite.apply(graph, context);
try (DebugCloseable s = debug.disableIntercept()) {
new VerifyBailoutUsage().apply(graph, context);
}
}
}
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class IfNode method tryEliminateBoxedReferenceEquals.
/**
* Attempts to replace the following pattern:
*
* <pre>
* Integer x = ...;
* Integer y = ...;
* if ((x == y) || x.equals(y)) { ... }
* </pre>
*
* with:
*
* <pre>
* Integer x = ...;
* Integer y = ...;
* if (x.equals(y)) { ... }
* </pre>
*
* whenever the probability that the reference check will pass is relatively small.
*
* See GR-1315 for more information.
*/
private boolean tryEliminateBoxedReferenceEquals(SimplifierTool tool) {
if (!(condition instanceof ObjectEqualsNode)) {
return false;
}
MetaAccessProvider meta = tool.getMetaAccess();
ObjectEqualsNode equalsCondition = (ObjectEqualsNode) condition;
ValueNode x = equalsCondition.getX();
ValueNode y = equalsCondition.getY();
ResolvedJavaType integerType = meta.lookupJavaType(Integer.class);
// At least one argument for reference equal must be a boxed primitive.
NodeView view = NodeView.from(tool);
if (!x.stamp(view).javaType(meta).equals(integerType) && !y.stamp(view).javaType(meta).equals(integerType)) {
return false;
}
// no sense to eliminate it.
if (getTrueSuccessorProbability() > 0.4) {
return false;
}
// True branch must be empty.
if (trueSuccessor instanceof BeginNode || trueSuccessor instanceof LoopExitNode) {
if (trueSuccessor.next() instanceof EndNode) {
// Empty true branch.
} else {
return false;
}
} else {
return false;
}
// False branch must only check the unboxed values.
UnboxNode unbox = null;
FixedGuardNode unboxCheck = null;
for (FixedNode node : falseSuccessor.getBlockNodes()) {
if (!(node instanceof BeginNode || node instanceof UnboxNode || node instanceof FixedGuardNode || node instanceof EndNode || node instanceof LoadFieldNode || node instanceof LoopExitNode)) {
return false;
}
if (node instanceof UnboxNode) {
if (unbox == null) {
unbox = (UnboxNode) node;
} else {
return false;
}
}
if (!(node instanceof FixedGuardNode)) {
continue;
}
FixedGuardNode fixed = (FixedGuardNode) node;
if (!(fixed.condition() instanceof IntegerEqualsNode)) {
continue;
}
IntegerEqualsNode equals = (IntegerEqualsNode) fixed.condition();
if ((isUnboxedFrom(meta, view, equals.getX(), x) && isUnboxedFrom(meta, view, equals.getY(), y)) || (isUnboxedFrom(meta, view, equals.getX(), y) && isUnboxedFrom(meta, view, equals.getY(), x))) {
unboxCheck = fixed;
}
}
if (unbox == null || unboxCheck == null) {
return false;
}
// Falsify the reference check.
setCondition(graph().addOrUniqueWithInputs(LogicConstantNode.contradiction()));
return true;
}
Aggregations