Mercurial > hg > graal-compiler
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/CompilationServer.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 | 34354e2e40a3 |
comparison
equal
deleted
inserted
replaced
2287:66ffa0e99cef | 2288:8c426c2891c8 |
---|---|
19 * Company, Ltd. | 19 * Company, Ltd. |
20 */ | 20 */ |
21 package com.sun.hotspot.c1x.server; | 21 package com.sun.hotspot.c1x.server; |
22 | 22 |
23 import java.io.*; | 23 import java.io.*; |
24 import java.lang.reflect.Proxy; | |
25 import java.net.*; | 24 import java.net.*; |
26 import java.rmi.registry.*; | |
27 | 25 |
28 import javax.net.*; | 26 import javax.net.*; |
29 | 27 |
30 import com.sun.hotspot.c1x.*; | 28 import com.sun.hotspot.c1x.*; |
31 import com.sun.hotspot.c1x.Compiler; | 29 import com.sun.hotspot.c1x.Compiler; |
32 import com.sun.hotspot.c1x.InvocationSocket.DelegateCallback; | |
33 import com.sun.hotspot.c1x.logging.*; | 30 import com.sun.hotspot.c1x.logging.*; |
34 import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingInputStream; | |
35 import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingOutputStream; | |
36 | 31 |
37 /** | 32 /** |
38 * Server side of the client/server compilation model. | 33 * Server side of the client/server compilation model. |
39 * | 34 * |
40 * @author Lukas Stadler | 35 * @author Lukas Stadler |
41 */ | 36 */ |
42 public class CompilationServer { | 37 public class CompilationServer { |
43 | |
44 private ReplacingOutputStream output; | |
45 private ReplacingInputStream input; | |
46 | 38 |
47 public static void main(String[] args) throws Exception { | 39 public static void main(String[] args) throws Exception { |
48 new CompilationServer().run(); | 40 new CompilationServer().run(); |
49 } | 41 } |
50 | 42 |
51 private void run() throws IOException, ClassNotFoundException { | 43 private void run() throws IOException, ClassNotFoundException { |
52 ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); | 44 ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); |
53 do { | 45 do { |
54 Socket socket = null; | 46 Socket socket = null; |
55 ReplacingStreams streams = new ReplacingStreams(); | |
56 try { | 47 try { |
57 Logger.log("Compilation server ready, waiting for client to connect..."); | 48 Logger.log("Compilation server ready, waiting for client to connect..."); |
58 socket = serverSocket.accept(); | 49 socket = serverSocket.accept(); |
59 Logger.log("Connected to " + socket.getRemoteSocketAddress()); | 50 Logger.log("Connected to " + socket.getRemoteSocketAddress()); |
60 | 51 |
61 output = streams.new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream())); | 52 ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); |
62 // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream | |
63 output.flush(); | |
64 input = streams.new ReplacingInputStream(new BufferedInputStream(socket.getInputStream())); | |
65 | 53 |
66 final InvocationSocket invocation = new InvocationSocket(output, input); | 54 VMEntries entries = (VMEntries) streams.getInvocation().waitForResult(); |
67 invocation.setDelegateCallback(new DelegateCallback() { | 55 Compiler compiler = CompilerImpl.initializeServer(entries); |
68 public Object getDelegate() { | |
69 VMEntries entries = (VMEntries) Proxy.newProxyInstance(VMEntries.class.getClassLoader(), new Class<?>[] { VMEntries.class}, invocation); | |
70 Compiler compiler = CompilerImpl.initializeServer(entries); | |
71 input.setCompiler(compiler); | |
72 return compiler.getVMExits(); | |
73 } | |
74 }); | |
75 | 56 |
76 invocation.waitForResult(); | 57 streams.getInvocation().sendResult(compiler); |
58 | |
59 streams.getInvocation().waitForResult(); | |
77 } catch (IOException e) { | 60 } catch (IOException e) { |
78 e.printStackTrace(); | 61 e.printStackTrace(); |
79 if (socket != null) { | 62 if (socket != null) { |
80 socket.close(); | 63 socket.close(); |
81 } | 64 } |