Mercurial > hg > graal-compiler
comparison graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompiler.java @ 21780:3d15183f3c93
Introduce Compiler interface in jvmci. Use it from jvmci.hotspot.CompilationTask
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Wed, 03 Jun 2015 15:47:54 +0200 |
parents | |
children | f6fd9fb11816 |
comparison
equal
deleted
inserted
replaced
21779:20ace3139510 | 21780:3d15183f3c93 |
---|---|
1 /* | |
2 * Copyright (c) 2015, 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 com.oracle.graal.hotspot; | |
24 | |
25 import static com.oracle.graal.compiler.common.GraalOptions.*; | |
26 import static com.oracle.jvmci.code.CallingConvention.Type.*; | |
27 import static com.oracle.jvmci.code.CodeUtil.*; | |
28 | |
29 import com.oracle.graal.compiler.*; | |
30 import com.oracle.graal.hotspot.meta.*; | |
31 import com.oracle.graal.hotspot.phases.*; | |
32 import com.oracle.graal.lir.asm.*; | |
33 import com.oracle.graal.lir.phases.*; | |
34 import com.oracle.graal.nodes.*; | |
35 import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; | |
36 import com.oracle.graal.phases.*; | |
37 import com.oracle.graal.phases.OptimisticOptimizations.Optimization; | |
38 import com.oracle.graal.phases.tiers.*; | |
39 import com.oracle.jvmci.code.*; | |
40 import com.oracle.jvmci.code.CallingConvention.Type; | |
41 import com.oracle.jvmci.compiler.Compiler; | |
42 import com.oracle.jvmci.meta.*; | |
43 import com.oracle.jvmci.service.*; | |
44 | |
45 @ServiceProvider(Compiler.class) | |
46 public class HotSpotGraalCompiler implements Compiler { | |
47 | |
48 public CompilationResult compile(ResolvedJavaMethod method, int entryBCI, boolean mustRecordMethodInlining) { | |
49 HotSpotBackend backend = HotSpotGraalRuntime.runtime().getHostBackend(); | |
50 HotSpotProviders providers = HotSpotGraalRuntime.runtime().getHostProviders(); | |
51 final boolean isOSR = entryBCI != INVOCATION_ENTRY_BCI; | |
52 | |
53 StructuredGraph graph = new StructuredGraph(method, entryBCI, AllowAssumptions.from(OptAssumptions.getValue())); | |
54 if (!mustRecordMethodInlining) { | |
55 graph.disableInlinedMethodRecording(); | |
56 } | |
57 | |
58 CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false); | |
59 if (isOSR) { | |
60 // for OSR, only a pointer is passed to the method. | |
61 JavaType[] parameterTypes = new JavaType[]{providers.getMetaAccess().lookupJavaType(long.class)}; | |
62 CallingConvention tmp = providers.getCodeCache().getRegisterConfig().getCallingConvention(JavaCallee, providers.getMetaAccess().lookupJavaType(void.class), parameterTypes, | |
63 backend.getTarget(), false); | |
64 cc = new CallingConvention(cc.getStackSize(), cc.getReturn(), tmp.getArgument(0)); | |
65 } | |
66 Suites suites = getSuites(providers); | |
67 LIRSuites lirSuites = getLIRSuites(providers); | |
68 ProfilingInfo profilingInfo = method.getProfilingInfo(!isOSR, isOSR); | |
69 OptimisticOptimizations optimisticOpts = getOptimisticOpts(profilingInfo); | |
70 if (isOSR) { | |
71 // In OSR compiles, we cannot rely on never executed code profiles, because | |
72 // all code after the OSR loop is never executed. | |
73 optimisticOpts.remove(Optimization.RemoveNeverExecutedCode); | |
74 } | |
75 CompilationResult result = GraalCompiler.compileGraph(graph, cc, method, providers, backend, backend.getTarget(), getGraphBuilderSuite(providers, isOSR), optimisticOpts, profilingInfo, | |
76 method.getSpeculationLog(), suites, lirSuites, new CompilationResult(), CompilationResultBuilderFactory.Default); | |
77 | |
78 result.setEntryBCI(entryBCI); | |
79 | |
80 if (!isOSR) { | |
81 ProfilingInfo profile = method.getProfilingInfo(); | |
82 profile.setCompilerIRSize(StructuredGraph.class, graph.getNodeCount()); | |
83 } | |
84 | |
85 return result; | |
86 } | |
87 | |
88 protected OptimisticOptimizations getOptimisticOpts(ProfilingInfo profilingInfo) { | |
89 return new OptimisticOptimizations(profilingInfo); | |
90 } | |
91 | |
92 protected Suites getSuites(HotSpotProviders providers) { | |
93 return providers.getSuites().getDefaultSuites(); | |
94 } | |
95 | |
96 protected LIRSuites getLIRSuites(HotSpotProviders providers) { | |
97 return providers.getSuites().getDefaultLIRSuites(); | |
98 } | |
99 | |
100 protected PhaseSuite<HighTierContext> getGraphBuilderSuite(HotSpotProviders providers, boolean isOSR) { | |
101 PhaseSuite<HighTierContext> suite = HotSpotSuitesProvider.withSimpleDebugInfoIfRequested(providers.getSuites().getDefaultGraphBuilderSuite()); | |
102 if (isOSR) { | |
103 suite = suite.copy(); | |
104 suite.appendPhase(new OnStackReplacementPhase()); | |
105 } | |
106 return suite; | |
107 } | |
108 } |