Mercurial > hg > truffle
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/CompilationServer.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 | 52bb06250d35 |
children | 762de4b26788 |
comparison
equal
deleted
inserted
replaced
2282:0309d394eb5f | 2284:569d3fe7d65c |
---|---|
26 import java.rmi.registry.*; | 26 import java.rmi.registry.*; |
27 | 27 |
28 import javax.net.*; | 28 import javax.net.*; |
29 | 29 |
30 import com.sun.cri.ci.*; | 30 import com.sun.cri.ci.*; |
31 import com.sun.cri.ri.*; | |
32 import com.sun.hotspot.c1x.*; | 31 import com.sun.hotspot.c1x.*; |
33 import com.sun.hotspot.c1x.Compiler; | 32 import com.sun.hotspot.c1x.Compiler; |
33 import com.sun.hotspot.c1x.InvocationSocket.DelegateCallback; | |
34 import com.sun.hotspot.c1x.logging.*; | 34 import com.sun.hotspot.c1x.logging.*; |
35 | 35 |
36 /** | 36 /** |
37 * Server side of the client/server compilation model. | 37 * Server side of the client/server compilation model. |
38 * | 38 * |
41 public class CompilationServer { | 41 public class CompilationServer { |
42 | 42 |
43 private Registry registry; | 43 private Registry registry; |
44 private ServerSocket serverSocket; | 44 private ServerSocket serverSocket; |
45 private Socket socket; | 45 private Socket socket; |
46 private ObjectOutputStream output; | 46 |
47 private ObjectInputStream input; | 47 private ReplacingOutputStream output; |
48 private ReplacingInputStream input; | |
49 | |
48 | 50 |
49 public static void main(String[] args) throws Exception { | 51 public static void main(String[] args) throws Exception { |
50 new CompilationServer().run(); | 52 new CompilationServer().run(); |
51 } | 53 } |
52 | 54 |
75 protected Object replaceObject(Object obj) throws IOException { | 77 protected Object replaceObject(Object obj) throws IOException { |
76 Class<? extends Object> clazz = obj.getClass(); | 78 Class<? extends Object> clazz = obj.getClass(); |
77 if (clazz == CiConstant.class) { | 79 if (clazz == CiConstant.class) { |
78 CiConstant o = (CiConstant) obj; | 80 CiConstant o = (CiConstant) obj; |
79 return new Container(clazz, o.kind, o.boxedValue()); | 81 return new Container(clazz, o.kind, o.boxedValue()); |
80 } else if (clazz == CiDebugInfo.class) { | 82 } else if (obj == CiValue.IllegalValue) { |
81 CiDebugInfo o = (CiDebugInfo) obj; | 83 return new Container(CiValue.class); |
82 return new Container(clazz, o.codePos, o.registerRefMap, o.frameRefMap); | 84 } else if (obj instanceof Compiler) { |
83 } else if (clazz == CiCodePos.class) { | 85 return new Container(Compiler.class); |
84 CiCodePos o = (CiCodePos) obj; | |
85 return new Container(clazz, o.caller, o.method, o.bci); | |
86 } | 86 } |
87 return obj; | 87 return obj; |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 /** | 91 /** |
92 * Replaces certain cir objects that cannot easily be made Serializable. | 92 * Replaces certain cir objects that cannot easily be made Serializable. |
93 */ | 93 */ |
94 public static class ReplacingInputStream extends ObjectInputStream { | 94 public static class ReplacingInputStream extends ObjectInputStream { |
95 private Compiler compiler; | |
95 | 96 |
96 public ReplacingInputStream(InputStream in) throws IOException { | 97 public ReplacingInputStream(InputStream in) throws IOException { |
97 super(in); | 98 super(in); |
98 enableResolveObject(true); | 99 enableResolveObject(true); |
100 } | |
101 | |
102 public void setCompiler(Compiler compiler) { | |
103 this.compiler = compiler; | |
99 } | 104 } |
100 | 105 |
101 @Override | 106 @Override |
102 protected Object resolveObject(Object obj) throws IOException { | 107 protected Object resolveObject(Object obj) throws IOException { |
103 if (obj instanceof Container) { | 108 if (obj instanceof Container) { |
104 Container c = (Container) obj; | 109 Container c = (Container) obj; |
105 if (c.clazz == CiConstant.class) { | 110 if (c.clazz == CiConstant.class) { |
106 return CiConstant.forBoxed((CiKind) c.values[0], c.values[1]); | 111 return CiConstant.forBoxed((CiKind) c.values[0], c.values[1]); |
107 } else if (c.clazz == CiDebugInfo.class) { | 112 } else if (c.clazz == CiValue.class) { |
108 return new CiDebugInfo((CiCodePos) c.values[0], (CiBitMap) c.values[2], (CiBitMap) c.values[3]); | 113 return CiValue.IllegalValue; |
109 } else if (c.clazz == CiCodePos.class) { | 114 } else if (c.clazz == Compiler.class) { |
110 return new CiCodePos((CiCodePos) c.values[0], (RiMethod) c.values[1], (Integer) c.values[2]); | 115 assert compiler != null; |
116 return compiler; | |
111 } | 117 } |
112 throw new RuntimeException("unexpected container class"); | 118 throw new RuntimeException("unexpected container class: " + c.clazz); |
113 } | 119 } |
114 return obj; | 120 return obj; |
115 } | 121 } |
116 } | 122 } |
117 | 123 |
118 private void run() throws IOException, ClassNotFoundException { | 124 private void run() throws IOException, ClassNotFoundException { |
119 serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); | 125 serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); |
120 while (true) { | 126 do { |
121 try { | 127 try { |
122 Logger.log("Compilation server ready, waiting for client to connect..."); | 128 Logger.log("Compilation server ready, waiting for client to connect..."); |
123 socket = serverSocket.accept(); | 129 socket = serverSocket.accept(); |
124 Logger.log("Connected to " + socket.getRemoteSocketAddress()); | 130 Logger.log("Connected to " + socket.getRemoteSocketAddress()); |
125 output = new ReplacingOutputStream(socket.getOutputStream()); | |
126 input = new ReplacingInputStream(socket.getInputStream()); | |
127 | 131 |
128 InvocationSocket invocation = new InvocationSocket(output, input); | 132 output = new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream())); |
129 VMEntries entries = (VMEntries) Proxy.newProxyInstance(VMEntries.class.getClassLoader(), new Class<?>[] {VMEntries.class}, invocation); | 133 // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream |
130 VMExits exits = Compiler.initializeServer(entries); | 134 output.flush(); |
131 invocation.setDelegate(exits); | 135 input = new ReplacingInputStream(new BufferedInputStream(socket.getInputStream())); |
136 | |
137 final InvocationSocket invocation = new InvocationSocket(output, input); | |
138 invocation.setDelegateCallback( new DelegateCallback() { | |
139 public Object getDelegate() { | |
140 VMEntries entries = (VMEntries) Proxy.newProxyInstance(VMEntries.class.getClassLoader(), new Class<?>[] {VMEntries.class}, invocation); | |
141 Compiler compiler = Compiler.initializeServer(entries); | |
142 input.setCompiler(compiler); | |
143 return compiler.getVMExits(); | |
144 } | |
145 }); | |
132 | 146 |
133 invocation.waitForResult(); | 147 invocation.waitForResult(); |
134 } catch (IOException e) { | 148 } catch (IOException e) { |
135 e.printStackTrace(); | 149 e.printStackTrace(); |
136 socket.close(); | 150 socket.close(); |
137 } | 151 } |
138 } | 152 } while (false); |
139 } | 153 } |
140 } | 154 } |