Search in sources :

Example 31 with MetaAccessProvider

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);
    }
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) Providers(org.graalvm.compiler.phases.util.Providers) VerifyPhase(org.graalvm.compiler.phases.VerifyPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 32 with MetaAccessProvider

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;
}
Also used : ClassfileBytecodeProvider(org.graalvm.compiler.replacements.classfile.ClassfileBytecodeProvider) ReplacementsImpl(org.graalvm.compiler.replacements.ReplacementsImpl) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 33 with MetaAccessProvider

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);
            }
        }
    }
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) VerifyBailoutUsage(org.graalvm.compiler.phases.verify.VerifyBailoutUsage) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Providers(org.graalvm.compiler.phases.util.Providers) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 34 with MetaAccessProvider

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;
}
Also used : IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Aggregations

MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)34 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)18 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 DebugContext (org.graalvm.compiler.debug.DebugContext)9 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)9 OptionValues (org.graalvm.compiler.options.OptionValues)9 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)8 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)8 Method (java.lang.reflect.Method)7 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)7 Providers (org.graalvm.compiler.phases.util.Providers)7 RuntimeProvider (org.graalvm.compiler.runtime.RuntimeProvider)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)6 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)6 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)5 PhaseSuite (org.graalvm.compiler.phases.PhaseSuite)5 ArrayList (java.util.ArrayList)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4