Mercurial > hg > truffle
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/Compiler.java @ 2284:569d3fe7d65c
non-static VMEntries and VMExits, CompilationServer simplifications
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Thu, 07 Apr 2011 15:32:25 +0200 |
parents | 76607939e139 |
children | 762de4b26788 |
comparison
equal
deleted
inserted
replaced
2282:0309d394eb5f | 2284:569d3fe7d65c |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. | 2 * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. |
3 * | 3 * |
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product | 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 | 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 | 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. | 7 * more additional patents or pending patent applications in the U.S. and in other countries. |
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open | 18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open |
19 * Company, Ltd. | 19 * Company, Ltd. |
20 */ | 20 */ |
21 package com.sun.hotspot.c1x; | 21 package com.sun.hotspot.c1x; |
22 | 22 |
23 import java.io.*; | |
23 import java.lang.management.*; | 24 import java.lang.management.*; |
24 import java.lang.reflect.Proxy; | 25 import java.lang.reflect.Proxy; |
25 import java.net.*; | 26 import java.net.*; |
26 | 27 |
27 import com.sun.c1x.*; | 28 import com.sun.c1x.*; |
28 import com.sun.c1x.target.amd64.*; | 29 import com.sun.c1x.target.amd64.*; |
29 import com.sun.cri.ci.*; | |
30 import com.sun.cri.ri.*; | |
31 import com.sun.cri.xir.*; | 30 import com.sun.cri.xir.*; |
32 import com.sun.hotspot.c1x.logging.*; | 31 import com.sun.hotspot.c1x.logging.*; |
33 import com.sun.hotspot.c1x.server.CompilationServer.ReplacingInputStream; | 32 import com.sun.hotspot.c1x.server.CompilationServer.ReplacingInputStream; |
34 import com.sun.hotspot.c1x.server.CompilationServer.ReplacingOutputStream; | 33 import com.sun.hotspot.c1x.server.CompilationServer.ReplacingOutputStream; |
35 | 34 |
41 public final class Compiler { | 40 public final class Compiler { |
42 | 41 |
43 private static Compiler theInstance; | 42 private static Compiler theInstance; |
44 private static boolean PrintGCStats = false; | 43 private static boolean PrintGCStats = false; |
45 | 44 |
45 private final VMEntries vmEntries; | |
46 private final VMExits vmExits; | |
47 | |
46 public static Compiler getInstance() { | 48 public static Compiler getInstance() { |
47 if (theInstance == null) { | 49 if (theInstance == null) { |
48 theInstance = new Compiler(); | 50 theInstance = new Compiler(null); |
49 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); | 51 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); |
50 } | 52 } |
51 return theInstance; | 53 return theInstance; |
52 } | 54 } |
53 | 55 |
54 private static VMEntries vmEntries; | 56 public static class ShutdownThread extends Thread { |
55 | 57 |
56 | |
57 public static class ShutdownThread extends Thread { | |
58 @Override | 58 @Override |
59 public void run() { | 59 public void run() { |
60 VMExitsNative.compileMethods = false; | 60 VMExitsNative.compileMethods = false; |
61 if (C1XOptions.PrintMetrics) { | 61 if (C1XOptions.PrintMetrics) { |
62 C1XMetrics.print(); | 62 C1XMetrics.print(); |
63 } | 63 } |
64 if (C1XOptions.PrintTimers) { | 64 if (C1XOptions.PrintTimers) { |
65 C1XTimers.print(); | 65 C1XTimers.print(); |
66 } | 66 } |
67 | |
68 if (PrintGCStats) { | 67 if (PrintGCStats) { |
69 printGCStats(); | 68 printGCStats(); |
70 } | 69 } |
71 } | 70 } |
72 } | 71 } |
89 | 88 |
90 System.out.println("Total Garbage Collections: " + totalGarbageCollections); | 89 System.out.println("Total Garbage Collections: " + totalGarbageCollections); |
91 System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime); | 90 System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime); |
92 } | 91 } |
93 | 92 |
94 public static VMExits initializeServer(VMEntries entries) { | 93 public static Compiler initializeServer(VMEntries entries) { |
95 if (Logger.ENABLED) { | 94 assert theInstance == null; |
96 vmEntries = LoggingProxy.getProxy(VMEntries.class, entries); | 95 theInstance = new Compiler(entries); |
97 vmExits = LoggingProxy.getProxy(VMExits.class, new VMExitsNative()); | 96 return theInstance; |
98 } else { | |
99 vmEntries = entries; | |
100 vmExits = new VMExitsNative(); | |
101 } | |
102 return vmExits; | |
103 } | 97 } |
104 | 98 |
105 private static VMEntries initializeClient(VMExits exits) { | 99 public VMEntries getVMEntries() { |
106 vmEntries = new VMEntriesNative(); | |
107 vmExits = exits; | |
108 return vmEntries; | 100 return vmEntries; |
109 } | 101 } |
110 | 102 |
111 public static VMEntries getVMEntries() { | 103 public VMExits getVMExits() { |
112 if (vmEntries == null) { | |
113 try { | |
114 vmEntries = new VMEntriesNative(); | |
115 if (CountingProxy.ENABLED) { | |
116 vmEntries = CountingProxy.getProxy(VMEntries.class, vmEntries); | |
117 } | |
118 if (Logger.ENABLED) { | |
119 vmEntries = LoggingProxy.getProxy(VMEntries.class, vmEntries); | |
120 } | |
121 } catch (Throwable t) { | |
122 t.printStackTrace(); | |
123 } | |
124 } | |
125 return vmEntries; | |
126 } | |
127 | |
128 private static VMExits vmExits; | |
129 | |
130 public static VMExits getVMExits() { | |
131 if (vmExits == null) { | |
132 String remote = System.getProperty("c1x.remote"); | |
133 assert theInstance == null; | |
134 assert vmEntries == null; | |
135 try { | |
136 if (remote != null) { | |
137 System.out.println("C1X compiler started in client/server mode, connection to server " + remote); | |
138 Socket socket = new Socket(remote, 1199); | |
139 ReplacingOutputStream output = new ReplacingOutputStream(socket.getOutputStream()); | |
140 ReplacingInputStream input = new ReplacingInputStream(socket.getInputStream()); | |
141 | |
142 InvocationSocket invocation = new InvocationSocket(output, input); | |
143 VMExits exits = (VMExits) Proxy.newProxyInstance(VMExits.class.getClassLoader(), new Class<?>[] {VMExits.class}, invocation); | |
144 VMEntries entries = Compiler.initializeClient(exits); | |
145 invocation.setDelegate(entries); | |
146 } else { | |
147 vmExits = new VMExitsNative(); | |
148 if (CountingProxy.ENABLED) { | |
149 vmExits = CountingProxy.getProxy(VMExits.class, vmExits); | |
150 } | |
151 if (Logger.ENABLED) { | |
152 vmExits = LoggingProxy.getProxy(VMExits.class, vmExits); | |
153 } | |
154 } | |
155 } catch (Throwable t) { | |
156 t.printStackTrace(); | |
157 } | |
158 } | |
159 return vmExits; | 104 return vmExits; |
160 } | 105 } |
161 | 106 |
162 private final C1XCompiler compiler; | 107 private final C1XCompiler compiler; |
163 private final HotSpotVMConfig config; | |
164 private final HotSpotRuntime runtime; | |
165 private final HotSpotRegisterConfig registerConfig; | |
166 private final CiTarget target; | |
167 private final RiXirGenerator generator; | |
168 | 108 |
169 private Compiler() { | 109 private Compiler(VMEntries entries) { |
170 config = getVMEntries().getConfiguration(); | 110 // remote compilation (will not create a C1XCompiler) |
111 String remote = System.getProperty("c1x.remote"); | |
112 if (remote != null) { | |
113 try { | |
114 System.out.println("C1X compiler started in client/server mode, server: " + remote); | |
115 Socket socket = new Socket(remote, 1199); | |
116 | |
117 ReplacingOutputStream output = new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream())); | |
118 // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream | |
119 output.flush(); | |
120 ReplacingInputStream input = new ReplacingInputStream(new BufferedInputStream(socket.getInputStream())); | |
121 input.setCompiler(this); | |
122 | |
123 InvocationSocket invocation = new InvocationSocket(output, input); | |
124 vmEntries = new VMEntriesNative(); | |
125 vmExits = (VMExits) Proxy.newProxyInstance(VMExits.class.getClassLoader(), new Class<?>[] { VMExits.class}, invocation); | |
126 invocation.setDelegate(vmEntries); | |
127 compiler = null; | |
128 return; | |
129 } catch (IOException t) { | |
130 System.out.println("Connection to compilation server FAILED."); | |
131 throw new RuntimeException(t); | |
132 } | |
133 } | |
134 | |
135 // initialize VMEntries | |
136 if (entries == null) | |
137 entries = new VMEntriesNative(); | |
138 | |
139 // initialize VMExits | |
140 VMExits exits = new VMExitsNative(this); | |
141 | |
142 // logging, etc. | |
143 if (CountingProxy.ENABLED) { | |
144 exits = CountingProxy.getProxy(VMExits.class, exits); | |
145 entries = CountingProxy.getProxy(VMEntries.class, entries); | |
146 } | |
147 if (Logger.ENABLED) { | |
148 exits = LoggingProxy.getProxy(VMExits.class, exits); | |
149 entries = LoggingProxy.getProxy(VMEntries.class, entries); | |
150 } | |
151 | |
152 // set the final fields | |
153 vmEntries = entries; | |
154 vmExits = exits; | |
155 | |
156 // initialize compiler and C1XOptions | |
157 HotSpotVMConfig config = vmEntries.getConfiguration(); | |
171 config.check(); | 158 config.check(); |
172 | |
173 runtime = new HotSpotRuntime(config); | |
174 final int wordSize = 8; | |
175 final int stackFrameAlignment = 16; | |
176 registerConfig = runtime.globalStubRegConfig; | |
177 target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true); | |
178 | |
179 if (Logger.ENABLED) { | |
180 generator = LoggingProxy.getProxy(RiXirGenerator.class, new HotSpotXirGenerator(config, target, registerConfig)); | |
181 } else { | |
182 generator = new HotSpotXirGenerator(config, target, registerConfig); | |
183 } | |
184 compiler = new C1XCompiler(runtime, target, generator, registerConfig); | |
185 | 159 |
186 // these options are important - c1x4hotspot will not generate correct code without them | 160 // these options are important - c1x4hotspot will not generate correct code without them |
187 C1XOptions.GenSpecialDivChecks = true; | 161 C1XOptions.GenSpecialDivChecks = true; |
188 C1XOptions.NullCheckUniquePc = true; | 162 C1XOptions.NullCheckUniquePc = true; |
189 C1XOptions.InvokeSnippetAfterArguments = true; | 163 C1XOptions.InvokeSnippetAfterArguments = true; |
190 C1XOptions.StackShadowPages = config.stackShadowPages; | 164 C1XOptions.StackShadowPages = config.stackShadowPages; |
165 | |
166 HotSpotRuntime runtime = new HotSpotRuntime(config, this); | |
167 HotSpotRegisterConfig registerConfig = runtime.globalStubRegConfig; | |
168 | |
169 final int wordSize = 8; | |
170 final int stackFrameAlignment = 16; | |
171 HotSpotTarget target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true); | |
172 | |
173 RiXirGenerator generator = new HotSpotXirGenerator(config, target, registerConfig, this); | |
174 if (Logger.ENABLED) { | |
175 generator = LoggingProxy.getProxy(RiXirGenerator.class, generator); | |
176 } | |
177 compiler = new C1XCompiler(runtime, target, generator, registerConfig); | |
191 } | 178 } |
192 | 179 |
193 public C1XCompiler getCompiler() { | 180 public C1XCompiler getCompiler() { |
194 return compiler; | 181 return compiler; |
195 } | 182 } |
196 | 183 |
197 public HotSpotVMConfig getConfig() { | |
198 return config; | |
199 } | |
200 | |
201 public HotSpotRuntime getRuntime() { | |
202 return runtime; | |
203 } | |
204 | |
205 public RiRegisterConfig getRegisterConfig() { | |
206 return registerConfig; | |
207 } | |
208 | |
209 public CiTarget getTarget() { | |
210 return target; | |
211 } | |
212 | |
213 public RiXirGenerator getGenerator() { | |
214 return generator; | |
215 } | |
216 | |
217 } | 184 } |