Mercurial > hg > truffle
comparison graal/Runtime/src/com/sun/hotspot/c1x/CompilerImpl.java @ 2297:099e697d8934
Renaming c1x4hotspotsrc => graal and HotSpotVM => Runtime
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 22 Apr 2011 15:08:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2296:34354e2e40a3 | 2297:099e697d8934 |
---|---|
1 /* | |
2 * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. | |
3 * | |
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product | |
5 * that is described in this document. In particular, and without limitation, these intellectual property | |
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or | |
7 * more additional patents or pending patent applications in the U.S. and in other countries. | |
8 * | |
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun | |
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its | |
11 * supplements. | |
12 * | |
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or | |
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks | |
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the | |
16 * U.S. and other countries. | |
17 * | |
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open | |
19 * Company, Ltd. | |
20 */ | |
21 package com.sun.hotspot.c1x; | |
22 | |
23 import java.io.*; | |
24 import java.lang.management.*; | |
25 import java.net.*; | |
26 | |
27 import com.sun.c1x.*; | |
28 import com.sun.c1x.target.amd64.*; | |
29 import com.sun.cri.ci.*; | |
30 import com.sun.cri.ri.*; | |
31 import com.sun.cri.xir.*; | |
32 import com.sun.hotspot.c1x.logging.*; | |
33 import com.sun.hotspot.c1x.server.*; | |
34 | |
35 /** | |
36 * Singleton class holding the instance of the C1XCompiler. | |
37 * | |
38 * @author Thomas Wuerthinger, Lukas Stadler | |
39 */ | |
40 public final class CompilerImpl implements Compiler, Remote { | |
41 | |
42 private static Compiler theInstance; | |
43 private static boolean PrintGCStats = false; | |
44 | |
45 public static Compiler getInstance() { | |
46 return theInstance; | |
47 } | |
48 | |
49 public static void initialize() { | |
50 if (theInstance != null) { | |
51 throw new IllegalStateException("Compiler already initialized"); | |
52 } | |
53 | |
54 String remote = System.getProperty("c1x.remote"); | |
55 if (remote != null) { | |
56 // remote compilation (will not create a local Compiler) | |
57 try { | |
58 System.out.println("C1X compiler started in client/server mode, server: " + remote); | |
59 Socket socket = new Socket(remote, 1199); | |
60 ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); | |
61 streams.getInvocation().sendResult(new VMEntriesNative()); | |
62 | |
63 theInstance = (Compiler) streams.getInvocation().waitForResult(false); | |
64 } catch (IOException e1) { | |
65 System.out.println("Connection to compilation server FAILED."); | |
66 throw new RuntimeException(e1); | |
67 } catch (ClassNotFoundException e2) { | |
68 System.out.println("Connection to compilation server FAILED."); | |
69 throw new RuntimeException(e2); | |
70 } | |
71 } else { | |
72 // ordinary local compilation | |
73 theInstance = new CompilerImpl(null); | |
74 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); | |
75 } | |
76 } | |
77 | |
78 public static Compiler initializeServer(VMEntries entries) { | |
79 assert theInstance == null; | |
80 theInstance = new CompilerImpl(entries); | |
81 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); | |
82 return theInstance; | |
83 } | |
84 | |
85 public static class ShutdownThread extends Thread { | |
86 | |
87 @Override | |
88 public void run() { | |
89 VMExitsNative.compileMethods = false; | |
90 if (C1XOptions.PrintMetrics) { | |
91 C1XMetrics.print(); | |
92 } | |
93 if (C1XOptions.PrintTimers) { | |
94 C1XTimers.print(); | |
95 } | |
96 if (PrintGCStats) { | |
97 printGCStats(); | |
98 } | |
99 } | |
100 } | |
101 | |
102 public static void printGCStats() { | |
103 long totalGarbageCollections = 0; | |
104 long garbageCollectionTime = 0; | |
105 | |
106 for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { | |
107 long count = gc.getCollectionCount(); | |
108 if (count >= 0) { | |
109 totalGarbageCollections += count; | |
110 } | |
111 | |
112 long time = gc.getCollectionTime(); | |
113 if (time >= 0) { | |
114 garbageCollectionTime += time; | |
115 } | |
116 } | |
117 | |
118 System.out.println("Total Garbage Collections: " + totalGarbageCollections); | |
119 System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime); | |
120 } | |
121 | |
122 private final VMEntries vmEntries; | |
123 private final VMExits vmExits; | |
124 private C1XCompiler compiler; | |
125 | |
126 private final HotSpotRuntime runtime; | |
127 private final CiTarget target; | |
128 private final RiXirGenerator generator; | |
129 private final RiRegisterConfig registerConfig; | |
130 | |
131 private CompilerImpl(VMEntries entries) { | |
132 | |
133 // initialize VMEntries | |
134 if (entries == null) { | |
135 entries = new VMEntriesNative(); | |
136 } | |
137 | |
138 // initialize VMExits | |
139 VMExits exits = new VMExitsNative(this); | |
140 | |
141 // logging, etc. | |
142 if (CountingProxy.ENABLED) { | |
143 exits = CountingProxy.getProxy(VMExits.class, exits); | |
144 entries = CountingProxy.getProxy(VMEntries.class, entries); | |
145 } | |
146 if (Logger.ENABLED) { | |
147 exits = LoggingProxy.getProxy(VMExits.class, exits); | |
148 entries = LoggingProxy.getProxy(VMEntries.class, entries); | |
149 } | |
150 | |
151 // set the final fields | |
152 vmEntries = entries; | |
153 vmExits = exits; | |
154 | |
155 // initialize compiler and C1XOptions | |
156 HotSpotVMConfig config = vmEntries.getConfiguration(); | |
157 config.check(); | |
158 | |
159 // these options are important - c1x4hotspot will not generate correct code without them | |
160 C1XOptions.GenSpecialDivChecks = true; | |
161 C1XOptions.NullCheckUniquePc = true; | |
162 C1XOptions.InvokeSnippetAfterArguments = true; | |
163 C1XOptions.StackShadowPages = config.stackShadowPages; | |
164 | |
165 runtime = new HotSpotRuntime(config, this); | |
166 registerConfig = runtime.globalStubRegConfig; | |
167 | |
168 final int wordSize = 8; | |
169 final int stackFrameAlignment = 16; | |
170 target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true); | |
171 | |
172 RiXirGenerator generator = new HotSpotXirGenerator(config, target, registerConfig, this); | |
173 if (Logger.ENABLED) { | |
174 this.generator = LoggingProxy.getProxy(RiXirGenerator.class, generator); | |
175 } else { | |
176 this.generator = generator; | |
177 } | |
178 | |
179 } | |
180 | |
181 @Override | |
182 public C1XCompiler getCompiler() { | |
183 if (compiler == null) { | |
184 compiler = new C1XCompiler(runtime, target, generator, registerConfig); | |
185 } | |
186 return compiler; | |
187 } | |
188 | |
189 @Override | |
190 public VMEntries getVMEntries() { | |
191 return vmEntries; | |
192 } | |
193 | |
194 @Override | |
195 public VMExits getVMExits() { | |
196 return vmExits; | |
197 } | |
198 | |
199 } |