Mercurial > hg > truffle
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/CompilerImpl.java @ 2296:34354e2e40a3
cleanups and client/server fixes:
* explicit init of CompilerImpl
* CompilationServer terminates without EOFException
* moved C1XOptions initialization code into separate class (static initializer changed to static method)
* added ConnectionObserver to CompilationServer
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 13 Apr 2011 14:40:13 +0200 |
parents | e3c42b8de67e |
children |
comparison
equal
deleted
inserted
replaced
2295:160aacf936ad | 2296:34354e2e40a3 |
---|---|
24 import java.lang.management.*; | 24 import java.lang.management.*; |
25 import java.net.*; | 25 import java.net.*; |
26 | 26 |
27 import com.sun.c1x.*; | 27 import com.sun.c1x.*; |
28 import com.sun.c1x.target.amd64.*; | 28 import com.sun.c1x.target.amd64.*; |
29 import com.sun.cri.ci.*; | |
30 import com.sun.cri.ri.*; | |
29 import com.sun.cri.xir.*; | 31 import com.sun.cri.xir.*; |
30 import com.sun.hotspot.c1x.logging.*; | 32 import com.sun.hotspot.c1x.logging.*; |
31 import com.sun.hotspot.c1x.server.*; | 33 import com.sun.hotspot.c1x.server.*; |
32 | 34 |
33 /** | 35 /** |
38 public final class CompilerImpl implements Compiler, Remote { | 40 public final class CompilerImpl implements Compiler, Remote { |
39 | 41 |
40 private static Compiler theInstance; | 42 private static Compiler theInstance; |
41 private static boolean PrintGCStats = false; | 43 private static boolean PrintGCStats = false; |
42 | 44 |
43 private final VMEntries vmEntries; | 45 public static Compiler getInstance() { |
44 private final VMExits vmExits; | 46 return theInstance; |
47 } | |
45 | 48 |
46 private C1XCompiler compiler; | 49 public static void initialize() { |
47 private final HotSpotRuntime runtime; | 50 if (theInstance != null) { |
48 private final RiXirGenerator generator; | 51 throw new IllegalStateException("Compiler already initialized"); |
49 private final HotSpotTarget target; | 52 } |
50 private final HotSpotRegisterConfig registerConfig; | |
51 | 53 |
52 public static Compiler getInstance() { | 54 String remote = System.getProperty("c1x.remote"); |
53 if (theInstance == null) { | 55 if (remote != null) { |
54 // remote compilation (will not create a C1XCompiler) | 56 // remote compilation (will not create a local Compiler) |
55 String remote = System.getProperty("c1x.remote"); | 57 try { |
56 if (remote != null) { | 58 System.out.println("C1X compiler started in client/server mode, server: " + remote); |
57 try { | 59 Socket socket = new Socket(remote, 1199); |
58 System.out.println("C1X compiler started in client/server mode, server: " + remote); | 60 ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); |
59 Socket socket = new Socket(remote, 1199); | 61 streams.getInvocation().sendResult(new VMEntriesNative()); |
60 ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); | |
61 streams.getInvocation().sendResult(new VMEntriesNative()); | |
62 | 62 |
63 theInstance = (Compiler) streams.getInvocation().waitForResult(); | 63 theInstance = (Compiler) streams.getInvocation().waitForResult(false); |
64 } catch (IOException e1) { | 64 } catch (IOException e1) { |
65 System.out.println("Connection to compilation server FAILED."); | 65 System.out.println("Connection to compilation server FAILED."); |
66 throw new RuntimeException(e1); | 66 throw new RuntimeException(e1); |
67 } catch (ClassNotFoundException e2) { | 67 } catch (ClassNotFoundException e2) { |
68 System.out.println("Connection to compilation server FAILED."); | 68 System.out.println("Connection to compilation server FAILED."); |
69 throw new RuntimeException(e2); | 69 throw new RuntimeException(e2); |
70 } | |
71 } else { | |
72 theInstance = new CompilerImpl(null); | |
73 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); | |
74 } | 70 } |
71 } else { | |
72 // ordinary local compilation | |
73 theInstance = new CompilerImpl(null); | |
74 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); | |
75 } | 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()); | |
76 return theInstance; | 82 return theInstance; |
77 } | 83 } |
78 | 84 |
79 public static class ShutdownThread extends Thread { | 85 public static class ShutdownThread extends Thread { |
80 | 86 |
111 | 117 |
112 System.out.println("Total Garbage Collections: " + totalGarbageCollections); | 118 System.out.println("Total Garbage Collections: " + totalGarbageCollections); |
113 System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime); | 119 System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime); |
114 } | 120 } |
115 | 121 |
116 public static Compiler initializeServer(VMEntries entries) { | 122 private final VMEntries vmEntries; |
117 assert theInstance == null; | 123 private final VMExits vmExits; |
118 theInstance = new CompilerImpl(entries); | 124 private C1XCompiler compiler; |
119 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); | |
120 return theInstance; | |
121 } | |
122 | 125 |
123 @Override | 126 private final HotSpotRuntime runtime; |
124 public VMEntries getVMEntries() { | 127 private final CiTarget target; |
125 return vmEntries; | 128 private final RiXirGenerator generator; |
126 } | 129 private final RiRegisterConfig registerConfig; |
127 | |
128 @Override | |
129 public VMExits getVMExits() { | |
130 return vmExits; | |
131 } | |
132 | 130 |
133 private CompilerImpl(VMEntries entries) { | 131 private CompilerImpl(VMEntries entries) { |
134 | 132 |
135 // initialize VMEntries | 133 // initialize VMEntries |
136 if (entries == null) { | 134 if (entries == null) { |
171 final int stackFrameAlignment = 16; | 169 final int stackFrameAlignment = 16; |
172 target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true); | 170 target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true); |
173 | 171 |
174 RiXirGenerator generator = new HotSpotXirGenerator(config, target, registerConfig, this); | 172 RiXirGenerator generator = new HotSpotXirGenerator(config, target, registerConfig, this); |
175 if (Logger.ENABLED) { | 173 if (Logger.ENABLED) { |
176 generator = LoggingProxy.getProxy(RiXirGenerator.class, generator); | 174 this.generator = LoggingProxy.getProxy(RiXirGenerator.class, generator); |
175 } else { | |
176 this.generator = generator; | |
177 } | 177 } |
178 this.generator = generator; | 178 |
179 } | 179 } |
180 | 180 |
181 @Override | 181 @Override |
182 public C1XCompiler getCompiler() { | 182 public C1XCompiler getCompiler() { |
183 if (compiler == null) { | 183 if (compiler == null) { |
184 compiler = new C1XCompiler(runtime, target, generator, registerConfig); | 184 compiler = new C1XCompiler(runtime, target, generator, registerConfig); |
185 } | 185 } |
186 return compiler; | 186 return compiler; |
187 } | 187 } |
188 | 188 |
189 @Override | |
190 public VMEntries getVMEntries() { | |
191 return vmEntries; | |
192 } | |
193 | |
194 @Override | |
195 public VMExits getVMExits() { | |
196 return vmExits; | |
197 } | |
198 | |
189 } | 199 } |