Mercurial > hg > graal-compiler
diff 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 |
line wrap: on
line diff
--- a/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/CompilerImpl.java Fri Apr 08 13:47:56 2011 +0200 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/CompilerImpl.java Mon Apr 11 10:37:24 2011 +0200 @@ -22,7 +22,6 @@ import java.io.*; import java.lang.management.*; -import java.lang.reflect.Proxy; import java.net.*; import com.sun.c1x.*; @@ -30,15 +29,13 @@ import com.sun.cri.xir.*; import com.sun.hotspot.c1x.logging.*; import com.sun.hotspot.c1x.server.*; -import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingInputStream; -import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingOutputStream; /** * Singleton class holding the instance of the C1XCompiler. * * @author Thomas Wuerthinger, Lukas Stadler */ -public final class CompilerImpl implements Compiler { +public final class CompilerImpl implements Compiler, Remote { private static Compiler theInstance; private static boolean PrintGCStats = false; @@ -50,8 +47,27 @@ public static Compiler getInstance() { if (theInstance == null) { - theInstance = new CompilerImpl(null); - Runtime.getRuntime().addShutdownHook(new ShutdownThread()); + // remote compilation (will not create a C1XCompiler) + String remote = System.getProperty("c1x.remote"); + if (remote != null) { + try { + System.out.println("C1X compiler started in client/server mode, server: " + remote); + Socket socket = new Socket(remote, 1199); + ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); + streams.getInvocation().sendResult(new VMEntriesNative()); + + theInstance = (Compiler) streams.getInvocation().waitForResult(); + } catch (IOException e1) { + System.out.println("Connection to compilation server FAILED."); + throw new RuntimeException(e1); + } catch (ClassNotFoundException e2) { + System.out.println("Connection to compilation server FAILED."); + throw new RuntimeException(e2); + } + } else { + theInstance = new CompilerImpl(null); + Runtime.getRuntime().addShutdownHook(new ShutdownThread()); + } } return theInstance; } @@ -96,6 +112,7 @@ public static Compiler initializeServer(VMEntries entries) { assert theInstance == null; theInstance = new CompilerImpl(entries); + Runtime.getRuntime().addShutdownHook(new ShutdownThread()); return theInstance; } @@ -110,31 +127,6 @@ } private CompilerImpl(VMEntries entries) { - // remote compilation (will not create a C1XCompiler) - String remote = System.getProperty("c1x.remote"); - if (remote != null) { - try { - System.out.println("C1X compiler started in client/server mode, server: " + remote); - Socket socket = new Socket(remote, 1199); - ReplacingStreams streams = new ReplacingStreams(); - - ReplacingOutputStream output = streams.new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream())); - // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream - output.flush(); - ReplacingInputStream input = streams.new ReplacingInputStream(new BufferedInputStream(socket.getInputStream())); - input.setCompiler(this); - - InvocationSocket invocation = new InvocationSocket(output, input); - vmEntries = new VMEntriesNative(); - vmExits = (VMExits) Proxy.newProxyInstance(VMExits.class.getClassLoader(), new Class<?>[] { VMExits.class}, invocation); - invocation.setDelegate(vmEntries); - compiler = null; - return; - } catch (IOException t) { - System.out.println("Connection to compilation server FAILED."); - throw new RuntimeException(t); - } - } // initialize VMEntries if (entries == null)