# HG changeset patch # User Thomas Wuerthinger # Date 1339179434 -7200 # Node ID d487ae06265d1eb81515ef644085bb76b8df3bcb # Parent 751b6ab65d5484363fd096480ea27ff6ff1fce73 Move graal.hotspot.server into its own project. diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/CompilationServer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/CompilationServer.java Fri Jun 08 20:17:14 2012 +0200 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.server; + +import java.io.*; +import java.net.*; +import java.util.*; + +import javax.net.*; + +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.bridge.*; +import com.oracle.graal.hotspot.logging.*; + +/** + * Server side of the client/server compilation model. The server listens for connections on the hardcoded port 1199. + */ +public class CompilationServer implements Runnable { + + public static void main(String[] args) throws Exception { + new CompilationServer(false).run(); + } + + public interface ConnectionObserver { + + void connectionStarted(HotSpotCompilerImpl compiler); + + void connectionFinished(HotSpotCompilerImpl compiler); + } + + private final boolean multiple; + private final ArrayList observers = new ArrayList<>(); + + /** + * Creates a new Compilation server. The server is activated by calling {@link #run()} directly or via a new + * {@link Thread}. + * + * @param multiple true if the server should server should serve an infinite amount of consecutive connections, + * false if it should terminate after the first connection ends. + */ + public CompilationServer(boolean multiple) { + this.multiple = multiple; + HotSpotOptions.setDefaultOptions(); + } + + public void addConnectionObserver(ConnectionObserver observer) { + observers.add(observer); + } + + public void removeConnectionObserver(ConnectionObserver observer) { + observers.remove(observer); + } + + public void run() { + final ServerSocket serverSocket; + try { + serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); + } catch (IOException e) { + throw new RuntimeException("Couldn't create compilation server", e); + } + do { + Socket socket = null; + try { + Logger.log("Compilation server ready, waiting for client to connect..."); + socket = serverSocket.accept(); + Logger.log("Connected to " + socket.getRemoteSocketAddress()); + + ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); + + // get the CompilerToVM proxy from the client + CompilerToVM toVM = (CompilerToVM) streams.getInvocation().waitForResult(false); + + // return the initialized compiler to the client + HotSpotCompilerImpl compiler = HotSpotCompilerImpl.initializeServer(toVM); + compiler.getCompiler(); + streams.getInvocation().sendResult(compiler); + + for (ConnectionObserver observer : observers) { + observer.connectionStarted(compiler); + } + + streams.getInvocation().waitForResult(true); + + for (ConnectionObserver observer : observers) { + observer.connectionFinished(compiler); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } finally { + if (socket != null) { + try { + socket.close(); + } catch (IOException e) { + } + } + } + } while (multiple); + } +} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/InvocationSocket.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/InvocationSocket.java Fri Jun 08 20:17:14 2012 +0200 @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.server; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.graal.hotspot.logging.*; + +/** + * A collection of java.lang.reflect proxies that communicate over a socket connection. + * + * Calling a method sends the method name and the parameters through the socket. Afterwards this class waits for a + * result. While waiting for a result three types of objects can arrive through the socket: a method invocation, a + * method result or an exception. Method invocation can thus be recursive. + */ +public class InvocationSocket { + + private static final boolean DEBUG = false; + private static final boolean COUNT_CALLS = false; + + private static final HashSet cachedMethodNames = new HashSet<>(); + private static final HashSet forbiddenMethodNames = new HashSet<>(); + + static { + cachedMethodNames.add("name"); + cachedMethodNames.add("kind"); + cachedMethodNames.add("isResolved"); + cachedMethodNames.add("getCompilerToVM"); + cachedMethodNames.add("exactType"); + cachedMethodNames.add("isInitialized"); + forbiddenMethodNames.add("javaClass"); + } + + private final ObjectOutputStream output; + private final ObjectInputStream input; + + private final Map counts = new HashMap<>(); + + public InvocationSocket(ObjectOutputStream output, ObjectInputStream input) { + this.output = output; + this.input = input; + + if (COUNT_CALLS) { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + SortedMap sorted = new TreeMap<>(); + for (Map.Entry entry : counts.entrySet()) { + sorted.put(entry.getValue(), entry.getKey()); + } + for (Map.Entry entry : sorted.entrySet()) { + System.out.println(entry.getKey() + ": " + entry.getValue()); + } + } + }); + } + } + + /** + * Represents one invocation of a method that is transferred via the socket connection. + * + */ + private static class Invocation implements Serializable { + + private static final long serialVersionUID = -799162779226626066L; + + public Object receiver; + public String methodName; + public Object[] args; + + public Invocation(Object receiver, String methodName, Object[] args) { + this.receiver = receiver; + this.methodName = methodName; + this.args = args; + } + } + + /** + * Represents the result of an invocation that is transferred via the socket connection. + * + */ + private static class Result implements Serializable { + + private static final long serialVersionUID = -7496058356272415814L; + + public Object result; + + public Result(Object result) { + this.result = result; + } + } + + private void incCount(String name, Object[] args) { + if (COUNT_CALLS) { + String nameAndArgCount = name + (args == null ? 0 : args.length); + if (counts.get(nameAndArgCount) != null) { + counts.put(nameAndArgCount, counts.get(nameAndArgCount) + 1); + } else { + counts.put(nameAndArgCount, 1); + } + } + } + + /** + * Each instance of this class handles remote invocations for one instance of a Remote class. It will forward all + * interface methods to the other end of the socket and cache the results of calls to certain methods. + * + */ + public class Handler implements InvocationHandler { + + private final Object receiver; + private final HashMap cache = new HashMap<>(); + + public Handler(Object receiver) { + this.receiver = receiver; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + // only interface methods can be transferred, java.lang.Object methods + if (method.getDeclaringClass() == Object.class) { + return method.invoke(receiver, args); + } + String methodName = method.getName(); + // check if the result of this zero-arg method was cached + if (args == null || args.length == 0) { + if (cache.containsKey(methodName)) { + return cache.get(methodName); + } + } + if (forbiddenMethodNames.contains(methodName)) { + throw new IllegalAccessException(methodName + " not allowed"); + } + Object result = null; + try { + if (DEBUG) { + Logger.startScope("invoking remote " + methodName); + } + incCount(methodName, args); + + output.writeObject(new Invocation(receiver, methodName, args)); + output.flush(); + result = waitForResult(false); + + // result caching for selected methods + if ((args == null || args.length == 0) && cachedMethodNames.contains(methodName)) { + cache.put(methodName, result); + } + return result; + } catch (Throwable t) { + t.printStackTrace(); + throw t; + } finally { + if (DEBUG) { + Logger.endScope(" = " + result); + } + } + } + } + + /** + * Waits for the result of a remote method invocation. Invocations that should be executed in this VM might arrive + * while waiting for the result, and these invocations will be executed before again waiting fort he result. + */ + @SuppressWarnings("unused") + public Object waitForResult(boolean eofExpected) throws IOException, ClassNotFoundException { + while (true) { + Object in; + try { + in = input.readObject(); + } catch (EOFException e) { + if (eofExpected) { + return null; + } + throw e; + } + if (in instanceof Result) { + return ((Result) in).result; + } else if (in instanceof RuntimeException) { + throw (RuntimeException) in; + } else if (in instanceof Throwable) { + throw new RuntimeException((Throwable) in); + } + + Invocation invoke = (Invocation) in; + Method method = null; + for (Class clazz = invoke.receiver.getClass(); clazz != null; clazz = clazz.getSuperclass()) { + for (Method m : clazz.getDeclaredMethods()) { + if (invoke.methodName.equals(m.getName())) { + method = m; + break; + } + } + } + if (method == null) { + Exception e = new UnsupportedOperationException("unknown method " + invoke.methodName); + e.printStackTrace(); + output.writeObject(e); + output.flush(); + } else { + Object result = null; + try { + if (invoke.args == null) { + if (DEBUG) { + Logger.startScope("invoking local " + invoke.methodName); + } + result = method.invoke(invoke.receiver); + } else { + if (Logger.ENABLED && DEBUG) { + StringBuilder str = new StringBuilder(); + str.append("invoking local " + invoke.methodName + "("); + for (int i = 0; i < invoke.args.length; i++) { + str.append(i == 0 ? "" : ", "); + str.append(Logger.pretty(invoke.args[i])); + } + str.append(")"); + Logger.startScope(str.toString()); + } + result = method.invoke(invoke.receiver, invoke.args); + } + result = new Result(result); + } catch (IllegalArgumentException e) { + System.out.println("error while invoking " + invoke.methodName); + e.getCause().printStackTrace(); + result = e.getCause(); + } catch (InvocationTargetException e) { + System.out.println("error while invoking " + invoke.methodName); + e.getCause().printStackTrace(); + result = e.getCause(); + } catch (IllegalAccessException e) { + System.out.println("error while invoking " + invoke.methodName); + e.getCause().printStackTrace(); + result = e.getCause(); + } finally { + if (DEBUG) { + if (result instanceof Result) { + Logger.endScope(" = " + ((Result) result).result); + } else { + Logger.endScope(" = " + result); + } + } + } + output.writeObject(result); + output.flush(); + } + } + } + + /** + * Sends a result without invoking a method, used by CompilationServer startup code. + */ + public void sendResult(Object obj) throws IOException { + output.writeObject(new Result(obj)); + output.flush(); + } +} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/Remote.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/Remote.java Fri Jun 08 20:17:14 2012 +0200 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.server; + + +public interface Remote { + +} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/ReplacingStreams.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/ReplacingStreams.java Fri Jun 08 20:17:14 2012 +0200 @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.server; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.logging.*; + +public class ReplacingStreams { + + private IdentityHashMap objectMap = new IdentityHashMap<>(); + private ArrayList objectList = new ArrayList<>(); + + private ReplacingOutputStream output; + private ReplacingInputStream input; + + private InvocationSocket invocation; + + public ReplacingStreams(OutputStream outputStream, InputStream inputStream) throws IOException { + output = new ReplacingOutputStream(new BufferedOutputStream(outputStream)); + // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream + output.flush(); + input = new ReplacingInputStream(new BufferedInputStream(inputStream)); + invocation = new InvocationSocket(output, input); + + addStaticObject(RiValue.IllegalValue); + addStaticObject(HotSpotProxy.DUMMY_CONSTANT_OBJ); + } + + public void setInvocationSocket(InvocationSocket invocation) { + this.invocation = invocation; + } + + public ReplacingOutputStream getOutput() { + return output; + } + + public ReplacingInputStream getInput() { + return input; + } + + public InvocationSocket getInvocation() { + return invocation; + } + + private void addStaticObject(Object obj) { + int id = objectList.size(); + objectList.add(obj); + objectMap.put(obj, new Placeholder(id)); + } + + public static class Placeholder implements Serializable { + + private static final long serialVersionUID = 6071894297788156945L; + public final int id; + + public Placeholder(int id) { + this.id = id; + } + + @Override + public String toString() { + return "#<" + id + ">"; + } + } + + public static class NewRemoteCallPlaceholder implements Serializable { + + private static final long serialVersionUID = 3084101671389500206L; + public final Class[] interfaces; + + public NewRemoteCallPlaceholder(Class[] interfaces) { + this.interfaces = interfaces; + } + } + + public static class NewDummyPlaceholder implements Serializable { + private static final long serialVersionUID = 2692666726573532288L; + } + + /** + * Replaces certain cir objects that cannot easily be made Serializable. + */ + public class ReplacingInputStream extends ObjectInputStream { + + public ReplacingInputStream(InputStream in) throws IOException { + super(in); + enableResolveObject(true); + } + + @Override + protected Object resolveObject(Object obj) throws IOException { + // see ReplacingInputStream.replaceObject for details on when these types of objects are created + + if (obj instanceof Placeholder) { + Placeholder placeholder = (Placeholder) obj; + Object resolvedObj = objectList.get(placeholder.id); + return resolvedObj; + } + + if (obj instanceof NewRemoteCallPlaceholder) { + NewRemoteCallPlaceholder newPlaceholder = (NewRemoteCallPlaceholder) obj; + Placeholder placeholder = new Placeholder(objectList.size()); + Object resolvedObj = Proxy.newProxyInstance(getClass().getClassLoader(), newPlaceholder.interfaces, invocation.new Handler(placeholder)); + objectMap.put(resolvedObj, placeholder); + objectList.add(resolvedObj); + return resolvedObj; + } + + if (obj instanceof NewDummyPlaceholder) { + Object resolvedObj = new Placeholder(objectList.size()); + objectMap.put(resolvedObj, (Placeholder) resolvedObj); + objectList.add(resolvedObj); + return resolvedObj; + } + + return obj; + } + } + + /** + * Replaces certain cir objects that cannot easily be made Serializable. + */ + public class ReplacingOutputStream extends ObjectOutputStream { + + public ReplacingOutputStream(OutputStream out) throws IOException { + super(out); + enableReplaceObject(true); + } + + @Override + protected Object replaceObject(Object obj) throws IOException { + // is the object a known instance? + Placeholder placeholder = objectMap.get(obj); + if (placeholder != null) { + return placeholder; + } + + // is the object an instance of a class that will always be executed remotely? + if (obj instanceof Remote) { + return createRemoteCallPlaceholder(obj); + } + + // is the object a constant of object type? + if (obj.getClass() == RiConstant.class) { + RiConstant constant = (RiConstant) obj; + if (constant.kind != RiKind.Object) { + return obj; + } + Object contents = constant.asObject(); + if (contents == null) { + return obj; + } + // don't replace if the object already is a placeholder + if (contents instanceof Placeholder || contents instanceof Long) { + return obj; + } + placeholder = objectMap.get(contents); + if (placeholder != null) { + return RiConstant.forObject(placeholder); + } + if (contents instanceof Remote) { + return RiConstant.forObject(createRemoteCallPlaceholder(contents)); + } + return RiConstant.forObject(createDummyPlaceholder(contents)); + } + return obj; + } + } + + private Object createRemoteCallPlaceholder(Object obj) { + // collect all interfaces that this object's class implements (proxies only support interfaces) + objectMap.put(obj, new Placeholder(objectList.size())); + objectList.add(obj); + return new NewRemoteCallPlaceholder(ProxyUtil.getAllInterfaces(obj.getClass())); + } + + public Object createDummyPlaceholder(Object obj) { + objectMap.put(obj, new Placeholder(objectList.size())); + objectList.add(obj); + return new NewDummyPlaceholder(); + } +} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.server/src/com/oracle/graal/hotspot/server/package-info.java Fri Jun 08 20:17:14 2012 +0200 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * Implementation of a compilation server socket that delegates incoming requests to Graal. + */ +package com.oracle.graal.hotspot.server; diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Fri Jun 08 18:35:28 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Fri Jun 08 20:17:14 2012 +0200 @@ -29,12 +29,11 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.ri.*; -import com.oracle.graal.hotspot.server.*; /** * Entries into the HotSpot VM from Java code. */ -public class CompilerToVMImpl implements CompilerToVM, Remote { +public class CompilerToVMImpl implements CompilerToVM { // Checkstyle: stop diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Fri Jun 08 18:35:28 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Fri Jun 08 20:17:14 2012 +0200 @@ -39,7 +39,6 @@ import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.counters.*; import com.oracle.graal.hotspot.ri.*; -import com.oracle.graal.hotspot.server.*; import com.oracle.graal.hotspot.snippets.*; import com.oracle.graal.java.*; import com.oracle.graal.snippets.*; @@ -48,7 +47,7 @@ /** * Exits from the HotSpot VM into Java code. */ -public class VMToCompilerImpl implements VMToCompiler, Remote { +public class VMToCompilerImpl implements VMToCompiler { private final HotSpotCompilerImpl compiler; private IntrinsifyArrayCopyPhase intrinsifyArrayCopy; diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/CountingProxy.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/CountingProxy.java Fri Jun 08 18:35:28 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/CountingProxy.java Fri Jun 08 20:17:14 2012 +0200 @@ -27,8 +27,6 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import com.oracle.graal.hotspot.server.*; - /** * A java.lang.reflect proxy that hierarchically logs all method invocations along with their parameters and return * values. @@ -73,7 +71,7 @@ } public static T getProxy(Class interf, T delegate) { - Class[] interfaces = ReplacingStreams.getAllInterfaces(delegate.getClass()); + Class[] interfaces = ProxyUtil.getAllInterfaces(delegate.getClass()); Object obj = Proxy.newProxyInstance(interf.getClassLoader(), interfaces, new CountingProxy<>(delegate)); return interf.cast(obj); } diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/LoggingProxy.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/LoggingProxy.java Fri Jun 08 18:35:28 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/LoggingProxy.java Fri Jun 08 20:17:14 2012 +0200 @@ -24,8 +24,6 @@ import java.lang.reflect.*; -import com.oracle.graal.hotspot.server.*; - /** * A java.lang.reflect proxy that hierarchically logs all method invocations along with their parameters and return values. */ @@ -70,7 +68,7 @@ * The object returned by this method will implement all interfaces that are implemented by delegate. */ public static T getProxy(Class interf, T delegate) { - Class[] interfaces = ReplacingStreams.getAllInterfaces(delegate.getClass()); + Class[] interfaces = ProxyUtil.getAllInterfaces(delegate.getClass()); Object obj = Proxy.newProxyInstance(interf.getClassLoader(), interfaces, new LoggingProxy<>(delegate)); return interf.cast(obj); } diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/ProxyUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/ProxyUtil.java Fri Jun 08 20:17:14 2012 +0200 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.logging; + +import java.util.*; + + +public final class ProxyUtil { + public static Class[] getAllInterfaces(Class clazz) { + HashSet> interfaces = new HashSet<>(); + getAllInterfaces(clazz, interfaces); + return interfaces.toArray(new Class[interfaces.size()]); + } + + private static void getAllInterfaces(Class clazz, HashSet> interfaces) { + for (Class< ? > iface : clazz.getInterfaces()) { + if (!interfaces.contains(iface)) { + interfaces.add(iface); + getAllInterfaces(iface, interfaces); + } + } + if (clazz.getSuperclass() != null) { + getAllInterfaces(clazz.getSuperclass(), interfaces); + } + } +} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotMethodResolved.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotMethodResolved.java Fri Jun 08 18:35:28 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotMethodResolved.java Fri Jun 08 20:17:14 2012 +0200 @@ -24,9 +24,8 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.server.*; -public interface HotSpotMethodResolved extends RiResolvedMethod, Remote { +public interface HotSpotMethodResolved extends RiResolvedMethod { RiResolvedMethod uniqueConcreteMethod(); int vtableEntryOffset(); diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotTypeResolved.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotTypeResolved.java Fri Jun 08 18:35:28 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotTypeResolved.java Fri Jun 08 20:17:14 2012 +0200 @@ -23,9 +23,8 @@ package com.oracle.graal.hotspot.ri; import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.server.*; -public interface HotSpotTypeResolved extends RiResolvedType, Remote { +public interface HotSpotTypeResolved extends RiResolvedType { String toString(); diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/CompilationServer.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/CompilationServer.java Fri Jun 08 18:35:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.server; - -import java.io.*; -import java.net.*; -import java.util.*; - -import javax.net.*; - -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.bridge.*; -import com.oracle.graal.hotspot.logging.*; - -/** - * Server side of the client/server compilation model. The server listens for connections on the hardcoded port 1199. - */ -public class CompilationServer implements Runnable { - - public static void main(String[] args) throws Exception { - new CompilationServer(false).run(); - } - - public interface ConnectionObserver { - - void connectionStarted(HotSpotCompilerImpl compiler); - - void connectionFinished(HotSpotCompilerImpl compiler); - } - - private final boolean multiple; - private final ArrayList observers = new ArrayList<>(); - - /** - * Creates a new Compilation server. The server is activated by calling {@link #run()} directly or via a new - * {@link Thread}. - * - * @param multiple true if the server should server should serve an infinite amount of consecutive connections, - * false if it should terminate after the first connection ends. - */ - public CompilationServer(boolean multiple) { - this.multiple = multiple; - HotSpotOptions.setDefaultOptions(); - } - - public void addConnectionObserver(ConnectionObserver observer) { - observers.add(observer); - } - - public void removeConnectionObserver(ConnectionObserver observer) { - observers.remove(observer); - } - - public void run() { - final ServerSocket serverSocket; - try { - serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); - } catch (IOException e) { - throw new RuntimeException("Couldn't create compilation server", e); - } - do { - Socket socket = null; - try { - Logger.log("Compilation server ready, waiting for client to connect..."); - socket = serverSocket.accept(); - Logger.log("Connected to " + socket.getRemoteSocketAddress()); - - ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream()); - - // get the CompilerToVM proxy from the client - CompilerToVM toVM = (CompilerToVM) streams.getInvocation().waitForResult(false); - - // return the initialized compiler to the client - HotSpotCompilerImpl compiler = HotSpotCompilerImpl.initializeServer(toVM); - compiler.getCompiler(); - streams.getInvocation().sendResult(compiler); - - for (ConnectionObserver observer : observers) { - observer.connectionStarted(compiler); - } - - streams.getInvocation().waitForResult(true); - - for (ConnectionObserver observer : observers) { - observer.connectionFinished(compiler); - } - } catch (IOException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } finally { - if (socket != null) { - try { - socket.close(); - } catch (IOException e) { - } - } - } - } while (multiple); - } -} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/InvocationSocket.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/InvocationSocket.java Fri Jun 08 18:35:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,278 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.server; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.graal.hotspot.logging.*; - -/** - * A collection of java.lang.reflect proxies that communicate over a socket connection. - * - * Calling a method sends the method name and the parameters through the socket. Afterwards this class waits for a - * result. While waiting for a result three types of objects can arrive through the socket: a method invocation, a - * method result or an exception. Method invocation can thus be recursive. - */ -public class InvocationSocket { - - private static final boolean DEBUG = false; - private static final boolean COUNT_CALLS = false; - - private static final HashSet cachedMethodNames = new HashSet<>(); - private static final HashSet forbiddenMethodNames = new HashSet<>(); - - static { - cachedMethodNames.add("name"); - cachedMethodNames.add("kind"); - cachedMethodNames.add("isResolved"); - cachedMethodNames.add("getCompilerToVM"); - cachedMethodNames.add("exactType"); - cachedMethodNames.add("isInitialized"); - forbiddenMethodNames.add("javaClass"); - } - - private final ObjectOutputStream output; - private final ObjectInputStream input; - - private final Map counts = new HashMap<>(); - - public InvocationSocket(ObjectOutputStream output, ObjectInputStream input) { - this.output = output; - this.input = input; - - if (COUNT_CALLS) { - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - SortedMap sorted = new TreeMap<>(); - for (Map.Entry entry : counts.entrySet()) { - sorted.put(entry.getValue(), entry.getKey()); - } - for (Map.Entry entry : sorted.entrySet()) { - System.out.println(entry.getKey() + ": " + entry.getValue()); - } - } - }); - } - } - - /** - * Represents one invocation of a method that is transferred via the socket connection. - * - */ - private static class Invocation implements Serializable { - - private static final long serialVersionUID = -799162779226626066L; - - public Object receiver; - public String methodName; - public Object[] args; - - public Invocation(Object receiver, String methodName, Object[] args) { - this.receiver = receiver; - this.methodName = methodName; - this.args = args; - } - } - - /** - * Represents the result of an invocation that is transferred via the socket connection. - * - */ - private static class Result implements Serializable { - - private static final long serialVersionUID = -7496058356272415814L; - - public Object result; - - public Result(Object result) { - this.result = result; - } - } - - private void incCount(String name, Object[] args) { - if (COUNT_CALLS) { - String nameAndArgCount = name + (args == null ? 0 : args.length); - if (counts.get(nameAndArgCount) != null) { - counts.put(nameAndArgCount, counts.get(nameAndArgCount) + 1); - } else { - counts.put(nameAndArgCount, 1); - } - } - } - - /** - * Each instance of this class handles remote invocations for one instance of a Remote class. It will forward all - * interface methods to the other end of the socket and cache the results of calls to certain methods. - * - */ - public class Handler implements InvocationHandler { - - private final Object receiver; - private final HashMap cache = new HashMap<>(); - - public Handler(Object receiver) { - this.receiver = receiver; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - // only interface methods can be transferred, java.lang.Object methods - if (method.getDeclaringClass() == Object.class) { - return method.invoke(receiver, args); - } - String methodName = method.getName(); - // check if the result of this zero-arg method was cached - if (args == null || args.length == 0) { - if (cache.containsKey(methodName)) { - return cache.get(methodName); - } - } - if (forbiddenMethodNames.contains(methodName)) { - throw new IllegalAccessException(methodName + " not allowed"); - } - Object result = null; - try { - if (DEBUG) { - Logger.startScope("invoking remote " + methodName); - } - incCount(methodName, args); - - output.writeObject(new Invocation(receiver, methodName, args)); - output.flush(); - result = waitForResult(false); - - // result caching for selected methods - if ((args == null || args.length == 0) && cachedMethodNames.contains(methodName)) { - cache.put(methodName, result); - } - return result; - } catch (Throwable t) { - t.printStackTrace(); - throw t; - } finally { - if (DEBUG) { - Logger.endScope(" = " + result); - } - } - } - } - - /** - * Waits for the result of a remote method invocation. Invocations that should be executed in this VM might arrive - * while waiting for the result, and these invocations will be executed before again waiting fort he result. - */ - @SuppressWarnings("unused") - public Object waitForResult(boolean eofExpected) throws IOException, ClassNotFoundException { - while (true) { - Object in; - try { - in = input.readObject(); - } catch (EOFException e) { - if (eofExpected) { - return null; - } - throw e; - } - if (in instanceof Result) { - return ((Result) in).result; - } else if (in instanceof RuntimeException) { - throw (RuntimeException) in; - } else if (in instanceof Throwable) { - throw new RuntimeException((Throwable) in); - } - - Invocation invoke = (Invocation) in; - Method method = null; - for (Class clazz = invoke.receiver.getClass(); clazz != null; clazz = clazz.getSuperclass()) { - for (Method m : clazz.getDeclaredMethods()) { - if (invoke.methodName.equals(m.getName())) { - method = m; - break; - } - } - } - if (method == null) { - Exception e = new UnsupportedOperationException("unknown method " + invoke.methodName); - e.printStackTrace(); - output.writeObject(e); - output.flush(); - } else { - Object result = null; - try { - if (invoke.args == null) { - if (DEBUG) { - Logger.startScope("invoking local " + invoke.methodName); - } - result = method.invoke(invoke.receiver); - } else { - if (Logger.ENABLED && DEBUG) { - StringBuilder str = new StringBuilder(); - str.append("invoking local " + invoke.methodName + "("); - for (int i = 0; i < invoke.args.length; i++) { - str.append(i == 0 ? "" : ", "); - str.append(Logger.pretty(invoke.args[i])); - } - str.append(")"); - Logger.startScope(str.toString()); - } - result = method.invoke(invoke.receiver, invoke.args); - } - result = new Result(result); - } catch (IllegalArgumentException e) { - System.out.println("error while invoking " + invoke.methodName); - e.getCause().printStackTrace(); - result = e.getCause(); - } catch (InvocationTargetException e) { - System.out.println("error while invoking " + invoke.methodName); - e.getCause().printStackTrace(); - result = e.getCause(); - } catch (IllegalAccessException e) { - System.out.println("error while invoking " + invoke.methodName); - e.getCause().printStackTrace(); - result = e.getCause(); - } finally { - if (DEBUG) { - if (result instanceof Result) { - Logger.endScope(" = " + ((Result) result).result); - } else { - Logger.endScope(" = " + result); - } - } - } - output.writeObject(result); - output.flush(); - } - } - } - - /** - * Sends a result without invoking a method, used by CompilationServer startup code. - */ - public void sendResult(Object obj) throws IOException { - output.writeObject(new Result(obj)); - output.flush(); - } -} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/Remote.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/Remote.java Fri Jun 08 18:35:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.server; - - -public interface Remote { - -} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/ReplacingStreams.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/ReplacingStreams.java Fri Jun 08 18:35:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.server; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.*; - -public class ReplacingStreams { - - private IdentityHashMap objectMap = new IdentityHashMap<>(); - private ArrayList objectList = new ArrayList<>(); - - private ReplacingOutputStream output; - private ReplacingInputStream input; - - private InvocationSocket invocation; - - public ReplacingStreams(OutputStream outputStream, InputStream inputStream) throws IOException { - output = new ReplacingOutputStream(new BufferedOutputStream(outputStream)); - // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream - output.flush(); - input = new ReplacingInputStream(new BufferedInputStream(inputStream)); - invocation = new InvocationSocket(output, input); - - addStaticObject(RiValue.IllegalValue); - addStaticObject(HotSpotProxy.DUMMY_CONSTANT_OBJ); - } - - public void setInvocationSocket(InvocationSocket invocation) { - this.invocation = invocation; - } - - public ReplacingOutputStream getOutput() { - return output; - } - - public ReplacingInputStream getInput() { - return input; - } - - public InvocationSocket getInvocation() { - return invocation; - } - - private void addStaticObject(Object obj) { - int id = objectList.size(); - objectList.add(obj); - objectMap.put(obj, new Placeholder(id)); - } - - public static class Placeholder implements Serializable { - - private static final long serialVersionUID = 6071894297788156945L; - public final int id; - - public Placeholder(int id) { - this.id = id; - } - - @Override - public String toString() { - return "#<" + id + ">"; - } - } - - public static class NewRemoteCallPlaceholder implements Serializable { - - private static final long serialVersionUID = 3084101671389500206L; - public final Class[] interfaces; - - public NewRemoteCallPlaceholder(Class[] interfaces) { - this.interfaces = interfaces; - } - } - - public static class NewDummyPlaceholder implements Serializable { - private static final long serialVersionUID = 2692666726573532288L; - } - - /** - * Replaces certain cir objects that cannot easily be made Serializable. - */ - public class ReplacingInputStream extends ObjectInputStream { - - public ReplacingInputStream(InputStream in) throws IOException { - super(in); - enableResolveObject(true); - } - - @Override - protected Object resolveObject(Object obj) throws IOException { - // see ReplacingInputStream.replaceObject for details on when these types of objects are created - - if (obj instanceof Placeholder) { - Placeholder placeholder = (Placeholder) obj; - Object resolvedObj = objectList.get(placeholder.id); - return resolvedObj; - } - - if (obj instanceof NewRemoteCallPlaceholder) { - NewRemoteCallPlaceholder newPlaceholder = (NewRemoteCallPlaceholder) obj; - Placeholder placeholder = new Placeholder(objectList.size()); - Object resolvedObj = Proxy.newProxyInstance(getClass().getClassLoader(), newPlaceholder.interfaces, invocation.new Handler(placeholder)); - objectMap.put(resolvedObj, placeholder); - objectList.add(resolvedObj); - return resolvedObj; - } - - if (obj instanceof NewDummyPlaceholder) { - Object resolvedObj = new Placeholder(objectList.size()); - objectMap.put(resolvedObj, (Placeholder) resolvedObj); - objectList.add(resolvedObj); - return resolvedObj; - } - - return obj; - } - } - - /** - * Replaces certain cir objects that cannot easily be made Serializable. - */ - public class ReplacingOutputStream extends ObjectOutputStream { - - public ReplacingOutputStream(OutputStream out) throws IOException { - super(out); - enableReplaceObject(true); - } - - @Override - protected Object replaceObject(Object obj) throws IOException { - // is the object a known instance? - Placeholder placeholder = objectMap.get(obj); - if (placeholder != null) { - return placeholder; - } - - // is the object an instance of a class that will always be executed remotely? - if (obj instanceof Remote) { - return createRemoteCallPlaceholder(obj); - } - - // is the object a constant of object type? - if (obj.getClass() == RiConstant.class) { - RiConstant constant = (RiConstant) obj; - if (constant.kind != RiKind.Object) { - return obj; - } - Object contents = constant.asObject(); - if (contents == null) { - return obj; - } - // don't replace if the object already is a placeholder - if (contents instanceof Placeholder || contents instanceof Long) { - return obj; - } - placeholder = objectMap.get(contents); - if (placeholder != null) { - return RiConstant.forObject(placeholder); - } - if (contents instanceof Remote) { - return RiConstant.forObject(createRemoteCallPlaceholder(contents)); - } - return RiConstant.forObject(createDummyPlaceholder(contents)); - } - return obj; - } - } - - public static Class[] getAllInterfaces(Class clazz) { - HashSet> interfaces = new HashSet<>(); - getAllInterfaces(clazz, interfaces); - return interfaces.toArray(new Class[interfaces.size()]); - } - - private static void getAllInterfaces(Class clazz, HashSet> interfaces) { - for (Class< ? > iface : clazz.getInterfaces()) { - if (!interfaces.contains(iface)) { - interfaces.add(iface); - getAllInterfaces(iface, interfaces); - } - } - if (clazz.getSuperclass() != null) { - getAllInterfaces(clazz.getSuperclass(), interfaces); - } - } - - private Object createRemoteCallPlaceholder(Object obj) { - // collect all interfaces that this object's class implements (proxies only support interfaces) - objectMap.put(obj, new Placeholder(objectList.size())); - objectList.add(obj); - return new NewRemoteCallPlaceholder(getAllInterfaces(obj.getClass())); - } - - public Object createDummyPlaceholder(Object obj) { - objectMap.put(obj, new Placeholder(objectList.size())); - objectList.add(obj); - return new NewDummyPlaceholder(); - } -} diff -r 751b6ab65d54 -r d487ae06265d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/package-info.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/server/package-info.java Fri Jun 08 18:35:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/** - * Implementation of a compilation server socket that delegates incoming requests to Graal. - */ -package com.oracle.graal.hotspot.server; diff -r 751b6ab65d54 -r d487ae06265d mx/projects --- a/mx/projects Fri Jun 08 18:35:28 2012 +0200 +++ b/mx/projects Fri Jun 08 20:17:14 2012 +0200 @@ -62,6 +62,13 @@ project@com.oracle.graal.hotspot@checkstyle=com.oracle.graal.graph project@com.oracle.graal.hotspot@javaCompliance=1.7 +# graal.hotspot.server +project@com.oracle.graal.hotspot.server@subDir=graal +project@com.oracle.graal.hotspot.server@sourceDirs=src +project@com.oracle.graal.hotspot.server@dependencies=com.oracle.graal.hotspot +project@com.oracle.graal.hotspot.server@checkstyle=com.oracle.graal.graph +project@com.oracle.graal.hotspot.server@javaCompliance=1.7 + # graal.graph project@com.oracle.graal.graph@subDir=graal project@com.oracle.graal.graph@sourceDirs=src