Mercurial > hg > truffle
changeset 14053:a7f26a522439
Direct LIR generation: added alternative compilation path to GraalCompilerTest.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 05 Mar 2014 10:11:34 +0100 |
parents | 361acb279104 |
children | 4c2bfd3e6021 |
files | graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java |
diffstat | 2 files changed, 83 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue Mar 04 22:23:24 2014 -0800 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Wed Mar 05 10:11:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -424,7 +424,12 @@ ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method); checkArgs(javaMethod, executeArgs); - InstalledCode compiledMethod = getCode(javaMethod, parse(method)); + InstalledCode compiledMethod = null; + if (UseLIRBuilder.getValue()) { + compiledMethod = getCodeBaseline(javaMethod, method); + } else { + compiledMethod = getCode(javaMethod, parse(method)); + } try { return new Result(compiledMethod.executeVarargs(executeArgs), null); } catch (Throwable e) { @@ -434,6 +439,79 @@ } } + protected InstalledCode getCodeBaseline(ResolvedJavaMethod javaMethod, Method method) { + return getCodeBaseline(javaMethod, method, false); + } + + protected InstalledCode getCodeBaseline(ResolvedJavaMethod javaMethod, Method method, boolean forceCompile) { + assert method.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + method; + + try (Scope bds = Debug.scope("Baseline")) { + Debug.log("getCodeBaseline()"); + } catch (Throwable e) { + throw Debug.handle(e); + } + + if (!forceCompile) { + InstalledCode cached = cache.get(javaMethod); + if (cached != null) { + if (cached.isValid()) { + return cached; + } + } + } + + final int id = compilationId.incrementAndGet(); + + InstalledCode installedCode = null; + try (Scope ds = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { + final boolean printCompilation = PrintCompilation.getValue() && !TTY.isSuppressed(); + + if (printCompilation) { + TTY.println(String.format("@%-6d Graal %-70s %-45s %-50s ...", id, javaMethod.getDeclaringClass().getName(), javaMethod.getName(), javaMethod.getSignature())); + } + long start = System.currentTimeMillis(); + + CompilationResult compResult = compileBaseline(javaMethod); + + if (printCompilation) { + TTY.println(String.format("@%-6d Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, compResult.getTargetCodeSize())); + } + + try (Scope s = Debug.scope("CodeInstall", getCodeCache(), javaMethod)) { + installedCode = addMethod(javaMethod, compResult); + if (installedCode == null) { + throw new GraalInternalError("Could not install code for " + MetaUtil.format("%H.%n(%p)", javaMethod)); + } + } catch (Throwable e) { + throw Debug.handle(e); + } + } catch (Throwable e) { + throw Debug.handle(e); + } + + if (!forceCompile) { + cache.put(javaMethod, installedCode); + } + return installedCode; + } + + protected CompilationResult compileBaseline(ResolvedJavaMethod javaMethod) { + try (Scope bds = Debug.scope("compileBaseline")) { + StructuredGraph graph = new StructuredGraph(javaMethod); + PhaseSuite<HighTierContext> graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault()); + graphBuilderSuite.apply(graph, new HighTierContext(providers, null, null, graphBuilderSuite, OptimisticOptimizations.ALL)); + + Debug.dump(graph, "after bytecode parsing"); + + CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); + return compileGraph(graph, cc, javaMethod, getProviders(), getBackend(), getCodeCache().getTarget(), null, getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, + getProfilingInfo(graph), getSpeculationLog(), getSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); + } catch (Throwable e) { + throw Debug.handle(e); + } + } + protected void checkArgs(ResolvedJavaMethod method, Object[] args) { JavaType[] sig = MetaUtil.signatureToTypes(method); Assert.assertEquals(sig.length, args.length);
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Tue Mar 04 22:23:24 2014 -0800 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Wed Mar 05 10:11:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,8 @@ // @formatter:off public final class GraalOptions { + @Option(help = "Enable direct LIR generation") + public static final OptionValue<Boolean> UseLIRBuilder = new OptionValue<>(false); @Option(help = "Enable use of compiler intrinsics") public static final OptionValue<Boolean> Intrinsify = new OptionValue<>(true); @Option(help = "Enable inlining of monomorphic calls")