annotate c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/CompilationServer.java @ 1423:760213a60e8b

* rewrite of the code installation * partial support for safepoints * macro-based CiTargetMethod interface * code stub support
author Lukas Stadler <lukas.stadler@oracle.com>
date Mon, 16 Aug 2010 18:59:36 -0700
parents
children 9e5e83ca2259
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1423
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
1 /*
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
3 *
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
5 * described in this document. In particular, and without limitation, these intellectual property rights may include one
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
6 * or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents or pending patent
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
7 * applications in the U.S. and in other countries.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
8 *
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
10 * license agreement and applicable provisions of the FAR and its supplements.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
11 *
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
12 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or registered
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
13 * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
14 * are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
15 *
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
16 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
17 */
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
18 package com.sun.hotspot.c1x.server;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
19
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
20 import java.io.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
21 import java.lang.reflect.Proxy;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
22 import java.net.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
23 import java.rmi.registry.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
24
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
25 import javax.net.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
26
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
27 import com.sun.cri.ci.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
28 import com.sun.cri.ci.CiDebugInfo.Frame;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
29 import com.sun.cri.ri.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
30 import com.sun.hotspot.c1x.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
31 import com.sun.hotspot.c1x.Compiler;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
32 import com.sun.hotspot.c1x.logging.*;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
33
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
34 /**
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
35 * Server side of the client/server compilation model.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
36 *
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
37 * @author Lukas Stadler
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
38 */
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
39 public class CompilationServer {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
40
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
41 private Registry registry;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
42 private ServerSocket serverSocket;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
43 private Socket socket;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
44 private ObjectOutputStream output;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
45 private ObjectInputStream input;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
46
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
47 public static void main(String[] args) throws Exception {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
48 new CompilationServer().run();
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
49 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
50
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
51 public static class Container implements Serializable {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
52
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
53 public final Class<?> clazz;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
54 public final Object[] values;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
55
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
56 public Container(Class<?> clazz, Object... values) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
57 this.clazz = clazz;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
58 this.values = values;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
59 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
60 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
61
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
62 /**
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
63 * Replaces certain cir objects that cannot easily be made Serializable.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
64 */
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
65 public static class ReplacingOutputStream extends ObjectOutputStream {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
66
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
67 public ReplacingOutputStream(OutputStream out) throws IOException {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
68 super(out);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
69 enableReplaceObject(true);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
70 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
71
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
72 @Override
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
73 protected Object replaceObject(Object obj) throws IOException {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
74 Class<? extends Object> clazz = obj.getClass();
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
75 if (clazz == CiConstant.class) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
76 CiConstant o = (CiConstant) obj;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
77 return new Container(clazz, o.kind, o.boxedValue());
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
78 } else if (clazz == CiDebugInfo.class) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
79 CiDebugInfo o = (CiDebugInfo)obj;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
80 return new Container(clazz, o.codePos, o.frame, o.registerRefMap, o.frameRefMap);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
81 } else if(clazz == CiCodePos.class) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
82 CiCodePos o = (CiCodePos)obj;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
83 return new Container(clazz, o.caller, o.method, o.bci);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
84 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
85 return obj;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
86 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
87 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
88
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
89 /**
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
90 * Replaces certain cir objects that cannot easily be made Serializable.
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
91 */
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
92 public static class ReplacingInputStream extends ObjectInputStream {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
93
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
94 public ReplacingInputStream(InputStream in) throws IOException {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
95 super(in);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
96 enableResolveObject(true);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
97 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
98
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
99 @Override
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
100 protected Object resolveObject(Object obj) throws IOException {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
101 if (obj instanceof Container) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
102 Container c = (Container)obj;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
103 if( c.clazz == CiConstant.class) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
104 return CiConstant.forBoxed((CiKind) c.values[0], c.values[1]);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
105 } else if (c.clazz == CiDebugInfo.class) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
106 return new CiDebugInfo((CiCodePos)c.values[0], (Frame)c.values[1], (byte[])c.values[2], (byte[])c.values[3]);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
107 } else if (c.clazz == CiCodePos.class) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
108 return new CiCodePos((CiCodePos)c.values[0], (RiMethod)c.values[1], (Integer)c.values[2]);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
109 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
110 throw new RuntimeException("unexpected container class");
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
111 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
112 return obj;
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
113 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
114 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
115
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
116 private void run() throws IOException, ClassNotFoundException {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
117 serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
118 while (true) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
119 try {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
120 Logger.log("Compilation server ready, waiting for client to connect...");
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
121 socket = serverSocket.accept();
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
122 Logger.log("Connected to " + socket.getRemoteSocketAddress());
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
123 output = new ReplacingOutputStream(socket.getOutputStream());
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
124 input = new ReplacingInputStream(socket.getInputStream());
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
125
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
126 InvocationSocket invocation = new InvocationSocket(output, input);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
127 VMEntries entries = (VMEntries) Proxy.newProxyInstance(VMEntries.class.getClassLoader(), new Class<?>[] { VMEntries.class}, invocation);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
128 VMExits exits = Compiler.initializeServer(entries);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
129 invocation.setDelegate(exits);
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
130
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
131 invocation.waitForResult();
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
132 } catch (IOException e) {
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
133 e.printStackTrace();
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
134 socket.close();
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
135 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
136 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
137 }
760213a60e8b * rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff changeset
138 }