Mercurial > hg > truffle
comparison graal/Runtime/src/com/sun/hotspot/c1x/server/CompilationServer.java @ 2297:099e697d8934
Renaming c1x4hotspotsrc => graal and HotSpotVM => Runtime
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 22 Apr 2011 15:08:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2296:34354e2e40a3 | 2297:099e697d8934 |
---|---|
1 /* | |
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. | |
3 * | |
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 | |
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. | |
8 * | |
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun | |
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its | |
11 * supplements. | |
12 * | |
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or | |
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks | |
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the | |
16 * U.S. and other countries. | |
17 * | |
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open | |
19 * Company, Ltd. | |
20 */ | |
21 package com.sun.hotspot.c1x.server; | |
22 | |
23 import java.io.*; | |
24 import java.net.*; | |
25 import java.util.*; | |
26 | |
27 import javax.net.*; | |
28 | |
29 import com.sun.hotspot.c1x.*; | |
30 import com.sun.hotspot.c1x.Compiler; | |
31 import com.sun.hotspot.c1x.logging.*; | |
32 | |
33 /** | |
34 * Server side of the client/server compilation model. The server listens for connections on the hardcoded port 1199. | |
35 * | |
36 * @author Lukas Stadler | |
37 */ | |
38 public class CompilationServer implements Runnable { | |
39 | |
40 public static void main(String[] args) throws Exception { | |
41 new CompilationServer(false).run(); | |
42 } | |
43 | |
44 public static interface ConnectionObserver { | |
45 | |
46 public void connectionStarted(Compiler compiler); | |
47 | |
48 public void connectionFinished(Compiler compiler); | |
49 } | |
50 | |
51 private final boolean multiple; | |
52 private final ArrayList<ConnectionObserver> observers = new ArrayList<ConnectionObserver>(); | |
53 | |
54 /** | |
55 * Creates a new Compilation server. The server is activated by calling {@link #run()} directly or via a new | |
56 * {@link Thread}. | |
57 * | |
58 * @param multiple true if the server should server should serve an infinite amount of consecutive connections, | |
59 * false if it should terminate after the first connection ends. | |
60 */ | |
61 public CompilationServer(boolean multiple) { | |
62 this.multiple = multiple; | |
63 HotSpotOptions.setDefaultOptions(); | |
64 } | |
65 | |
66 public void addConnectionObserver(ConnectionObserver observer) { | |
67 observers.add(observer); | |
68 } | |
69 | |
70 public void removeConnectionObserver(ConnectionObserver observer) { | |
71 observers.remove(observer); | |
72 } | |
73 | |
74 public void run() { | |
75 final ServerSocket serverSocket; | |
76 try { | |
77 serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); | |
78 } catch (IOException e) { | |
79 throw new RuntimeException("Couldn't create compilation server", e); | |
80 } | |
81 do { | |
82 Socket socket = null; | |
83 try { | |
84 Logger.log("Compilation server ready, waiting for client to connect..."); | |
85 socket = serverSocket.accept(); | |
86 Logger.log("Connected to " + socket.getRemoteSocketAddress()); | |
87 | |
88 ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); | |
89 | |
90 // get the VMEntries proxy from the client | |
91 VMEntries entries = (VMEntries) streams.getInvocation().waitForResult(false); | |
92 | |
93 // return the initialized compiler to the client | |
94 Compiler compiler = CompilerImpl.initializeServer(entries); | |
95 compiler.getCompiler(); | |
96 streams.getInvocation().sendResult(compiler); | |
97 | |
98 for (ConnectionObserver observer : observers) { | |
99 observer.connectionStarted(compiler); | |
100 } | |
101 | |
102 streams.getInvocation().waitForResult(true); | |
103 | |
104 for (ConnectionObserver observer : observers) { | |
105 observer.connectionFinished(compiler); | |
106 } | |
107 } catch (IOException e) { | |
108 e.printStackTrace(); | |
109 } catch (ClassNotFoundException e) { | |
110 throw new RuntimeException(e); | |
111 } finally { | |
112 if (socket != null) { | |
113 try { | |
114 socket.close(); | |
115 } catch (IOException e) { | |
116 } | |
117 } | |
118 } | |
119 } while (multiple); | |
120 } | |
121 } |