comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/CompilerImpl.java @ 2288:8c426c2891c8

client/server: new interface Remote marks classes that should not be serialized, but called remotely
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 11 Apr 2011 10:37:24 +0200
parents 762de4b26788
children 175e7b4d7322
comparison
equal deleted inserted replaced
2287:66ffa0e99cef 2288:8c426c2891c8
20 */ 20 */
21 package com.sun.hotspot.c1x; 21 package com.sun.hotspot.c1x;
22 22
23 import java.io.*; 23 import java.io.*;
24 import java.lang.management.*; 24 import java.lang.management.*;
25 import java.lang.reflect.Proxy;
26 import java.net.*; 25 import java.net.*;
27 26
28 import com.sun.c1x.*; 27 import com.sun.c1x.*;
29 import com.sun.c1x.target.amd64.*; 28 import com.sun.c1x.target.amd64.*;
30 import com.sun.cri.xir.*; 29 import com.sun.cri.xir.*;
31 import com.sun.hotspot.c1x.logging.*; 30 import com.sun.hotspot.c1x.logging.*;
32 import com.sun.hotspot.c1x.server.*; 31 import com.sun.hotspot.c1x.server.*;
33 import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingInputStream;
34 import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingOutputStream;
35 32
36 /** 33 /**
37 * Singleton class holding the instance of the C1XCompiler. 34 * Singleton class holding the instance of the C1XCompiler.
38 * 35 *
39 * @author Thomas Wuerthinger, Lukas Stadler 36 * @author Thomas Wuerthinger, Lukas Stadler
40 */ 37 */
41 public final class CompilerImpl implements Compiler { 38 public final class CompilerImpl implements Compiler, Remote {
42 39
43 private static Compiler theInstance; 40 private static Compiler theInstance;
44 private static boolean PrintGCStats = false; 41 private static boolean PrintGCStats = false;
45 42
46 private final VMEntries vmEntries; 43 private final VMEntries vmEntries;
48 45
49 private final C1XCompiler compiler; 46 private final C1XCompiler compiler;
50 47
51 public static Compiler getInstance() { 48 public static Compiler getInstance() {
52 if (theInstance == null) { 49 if (theInstance == null) {
53 theInstance = new CompilerImpl(null); 50 // remote compilation (will not create a C1XCompiler)
54 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); 51 String remote = System.getProperty("c1x.remote");
52 if (remote != null) {
53 try {
54 System.out.println("C1X compiler started in client/server mode, server: " + remote);
55 Socket socket = new Socket(remote, 1199);
56 ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream());
57 streams.getInvocation().sendResult(new VMEntriesNative());
58
59 theInstance = (Compiler) streams.getInvocation().waitForResult();
60 } catch (IOException e1) {
61 System.out.println("Connection to compilation server FAILED.");
62 throw new RuntimeException(e1);
63 } catch (ClassNotFoundException e2) {
64 System.out.println("Connection to compilation server FAILED.");
65 throw new RuntimeException(e2);
66 }
67 } else {
68 theInstance = new CompilerImpl(null);
69 Runtime.getRuntime().addShutdownHook(new ShutdownThread());
70 }
55 } 71 }
56 return theInstance; 72 return theInstance;
57 } 73 }
58 74
59 public static class ShutdownThread extends Thread { 75 public static class ShutdownThread extends Thread {
94 } 110 }
95 111
96 public static Compiler initializeServer(VMEntries entries) { 112 public static Compiler initializeServer(VMEntries entries) {
97 assert theInstance == null; 113 assert theInstance == null;
98 theInstance = new CompilerImpl(entries); 114 theInstance = new CompilerImpl(entries);
115 Runtime.getRuntime().addShutdownHook(new ShutdownThread());
99 return theInstance; 116 return theInstance;
100 } 117 }
101 118
102 @Override 119 @Override
103 public VMEntries getVMEntries() { 120 public VMEntries getVMEntries() {
108 public VMExits getVMExits() { 125 public VMExits getVMExits() {
109 return vmExits; 126 return vmExits;
110 } 127 }
111 128
112 private CompilerImpl(VMEntries entries) { 129 private CompilerImpl(VMEntries entries) {
113 // remote compilation (will not create a C1XCompiler)
114 String remote = System.getProperty("c1x.remote");
115 if (remote != null) {
116 try {
117 System.out.println("C1X compiler started in client/server mode, server: " + remote);
118 Socket socket = new Socket(remote, 1199);
119 ReplacingStreams streams = new ReplacingStreams();
120
121 ReplacingOutputStream output = streams.new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream()));
122 // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream
123 output.flush();
124 ReplacingInputStream input = streams.new ReplacingInputStream(new BufferedInputStream(socket.getInputStream()));
125 input.setCompiler(this);
126
127 InvocationSocket invocation = new InvocationSocket(output, input);
128 vmEntries = new VMEntriesNative();
129 vmExits = (VMExits) Proxy.newProxyInstance(VMExits.class.getClassLoader(), new Class<?>[] { VMExits.class}, invocation);
130 invocation.setDelegate(vmEntries);
131 compiler = null;
132 return;
133 } catch (IOException t) {
134 System.out.println("Connection to compilation server FAILED.");
135 throw new RuntimeException(t);
136 }
137 }
138 130
139 // initialize VMEntries 131 // initialize VMEntries
140 if (entries == null) 132 if (entries == null)
141 entries = new VMEntriesNative(); 133 entries = new VMEntriesNative();
142 134