# HG changeset patch # User Lukas Stadler # Date 1302262985 -7200 # Node ID 762de4b2678860667f4e7a080f4bd0fa302c7ab9 # Parent 569d3fe7d65c8d4383db1b0a3b3a33ed501a82ea turn Compiler and HotSpotTypeResolved into interfaces diff -r 569d3fe7d65c -r 762de4b26788 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/Compiler.java --- a/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/Compiler.java Thu Apr 07 15:32:25 2011 +0200 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/Compiler.java Fri Apr 08 13:43:05 2011 +0200 @@ -1,184 +1,33 @@ -/* - * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. - * - * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product - * that is described in this document. In particular, and without limitation, these intellectual property - * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or - * more additional patents or pending patent applications in the U.S. and in other countries. - * - * U.S. Government Rights - Commercial software. Government users are subject to the Sun - * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its - * supplements. - * - * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or - * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks - * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the - * U.S. and other countries. - * - * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open - * Company, Ltd. - */ -package com.sun.hotspot.c1x; - -import java.io.*; -import java.lang.management.*; -import java.lang.reflect.Proxy; -import java.net.*; - -import com.sun.c1x.*; -import com.sun.c1x.target.amd64.*; -import com.sun.cri.xir.*; -import com.sun.hotspot.c1x.logging.*; -import com.sun.hotspot.c1x.server.CompilationServer.ReplacingInputStream; -import com.sun.hotspot.c1x.server.CompilationServer.ReplacingOutputStream; - -/** - * Singleton class holding the instance of the C1XCompiler. - * - * @author Thomas Wuerthinger, Lukas Stadler - */ -public final class Compiler { - - private static Compiler theInstance; - private static boolean PrintGCStats = false; - - private final VMEntries vmEntries; - private final VMExits vmExits; - - public static Compiler getInstance() { - if (theInstance == null) { - theInstance = new Compiler(null); - Runtime.getRuntime().addShutdownHook(new ShutdownThread()); - } - return theInstance; - } - - public static class ShutdownThread extends Thread { - - @Override - public void run() { - VMExitsNative.compileMethods = false; - if (C1XOptions.PrintMetrics) { - C1XMetrics.print(); - } - if (C1XOptions.PrintTimers) { - C1XTimers.print(); - } - if (PrintGCStats) { - printGCStats(); - } - } - } - - public static void printGCStats() { - long totalGarbageCollections = 0; - long garbageCollectionTime = 0; - - for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { - long count = gc.getCollectionCount(); - if (count >= 0) { - totalGarbageCollections += count; - } - - long time = gc.getCollectionTime(); - if (time >= 0) { - garbageCollectionTime += time; - } - } - - System.out.println("Total Garbage Collections: " + totalGarbageCollections); - System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime); - } - - public static Compiler initializeServer(VMEntries entries) { - assert theInstance == null; - theInstance = new Compiler(entries); - return theInstance; - } - - public VMEntries getVMEntries() { - return vmEntries; - } - - public VMExits getVMExits() { - return vmExits; - } - - private final C1XCompiler compiler; - - private Compiler(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); - - ReplacingOutputStream output = new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream())); - // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream - output.flush(); - ReplacingInputStream input = 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) - entries = new VMEntriesNative(); - - // initialize VMExits - VMExits exits = new VMExitsNative(this); - - // logging, etc. - if (CountingProxy.ENABLED) { - exits = CountingProxy.getProxy(VMExits.class, exits); - entries = CountingProxy.getProxy(VMEntries.class, entries); - } - if (Logger.ENABLED) { - exits = LoggingProxy.getProxy(VMExits.class, exits); - entries = LoggingProxy.getProxy(VMEntries.class, entries); - } - - // set the final fields - vmEntries = entries; - vmExits = exits; - - // initialize compiler and C1XOptions - HotSpotVMConfig config = vmEntries.getConfiguration(); - config.check(); - - // these options are important - c1x4hotspot will not generate correct code without them - C1XOptions.GenSpecialDivChecks = true; - C1XOptions.NullCheckUniquePc = true; - C1XOptions.InvokeSnippetAfterArguments = true; - C1XOptions.StackShadowPages = config.stackShadowPages; - - HotSpotRuntime runtime = new HotSpotRuntime(config, this); - HotSpotRegisterConfig registerConfig = runtime.globalStubRegConfig; - - final int wordSize = 8; - final int stackFrameAlignment = 16; - HotSpotTarget target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true); - - RiXirGenerator generator = new HotSpotXirGenerator(config, target, registerConfig, this); - if (Logger.ENABLED) { - generator = LoggingProxy.getProxy(RiXirGenerator.class, generator); - } - compiler = new C1XCompiler(runtime, target, generator, registerConfig); - } - - public C1XCompiler getCompiler() { - return compiler; - } - -} +/* + * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. + * + * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product + * that is described in this document. In particular, and without limitation, these intellectual property + * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or + * more additional patents or pending patent applications in the U.S. and in other countries. + * + * U.S. Government Rights - Commercial software. Government users are subject to the Sun + * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its + * supplements. + * + * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or + * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks + * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the + * U.S. and other countries. + * + * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open + * Company, Ltd. + */ +package com.sun.hotspot.c1x; + +import com.sun.c1x.*; + +public interface Compiler { + + public VMEntries getVMEntries(); + + public VMExits getVMExits(); + + public C1XCompiler getCompiler(); + +} \ No newline at end of file diff -r 569d3fe7d65c -r 762de4b26788 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/CompilerImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/CompilerImpl.java Fri Apr 08 13:43:05 2011 +0200 @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. + * + * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product + * that is described in this document. In particular, and without limitation, these intellectual property + * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or + * more additional patents or pending patent applications in the U.S. and in other countries. + * + * U.S. Government Rights - Commercial software. Government users are subject to the Sun + * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its + * supplements. + * + * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or + * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks + * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the + * U.S. and other countries. + * + * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open + * Company, Ltd. + */ +package com.sun.hotspot.c1x; + +import java.io.*; +import java.lang.management.*; +import java.lang.reflect.Proxy; +import java.net.*; + +import com.sun.c1x.*; +import com.sun.c1x.target.amd64.*; +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 { + + private static Compiler theInstance; + private static boolean PrintGCStats = false; + + private final VMEntries vmEntries; + private final VMExits vmExits; + + private final C1XCompiler compiler; + + public static Compiler getInstance() { + if (theInstance == null) { + theInstance = new CompilerImpl(null); + Runtime.getRuntime().addShutdownHook(new ShutdownThread()); + } + return theInstance; + } + + public static class ShutdownThread extends Thread { + + @Override + public void run() { + VMExitsNative.compileMethods = false; + if (C1XOptions.PrintMetrics) { + C1XMetrics.print(); + } + if (C1XOptions.PrintTimers) { + C1XTimers.print(); + } + if (PrintGCStats) { + printGCStats(); + } + } + } + + public static void printGCStats() { + long totalGarbageCollections = 0; + long garbageCollectionTime = 0; + + for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { + long count = gc.getCollectionCount(); + if (count >= 0) { + totalGarbageCollections += count; + } + + long time = gc.getCollectionTime(); + if (time >= 0) { + garbageCollectionTime += time; + } + } + + System.out.println("Total Garbage Collections: " + totalGarbageCollections); + System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime); + } + + public static Compiler initializeServer(VMEntries entries) { + assert theInstance == null; + theInstance = new CompilerImpl(entries); + return theInstance; + } + + @Override + public VMEntries getVMEntries() { + return vmEntries; + } + + @Override + public VMExits getVMExits() { + return vmExits; + } + + 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) + entries = new VMEntriesNative(); + + // initialize VMExits + VMExits exits = new VMExitsNative(this); + + // logging, etc. + if (CountingProxy.ENABLED) { + exits = CountingProxy.getProxy(VMExits.class, exits); + entries = CountingProxy.getProxy(VMEntries.class, entries); + } + if (Logger.ENABLED) { + exits = LoggingProxy.getProxy(VMExits.class, exits); + entries = LoggingProxy.getProxy(VMEntries.class, entries); + } + + // set the final fields + vmEntries = entries; + vmExits = exits; + + // initialize compiler and C1XOptions + HotSpotVMConfig config = vmEntries.getConfiguration(); + config.check(); + + // these options are important - c1x4hotspot will not generate correct code without them + C1XOptions.GenSpecialDivChecks = true; + C1XOptions.NullCheckUniquePc = true; + C1XOptions.InvokeSnippetAfterArguments = true; + C1XOptions.StackShadowPages = config.stackShadowPages; + + HotSpotRuntime runtime = new HotSpotRuntime(config, this); + HotSpotRegisterConfig registerConfig = runtime.globalStubRegConfig; + + final int wordSize = 8; + final int stackFrameAlignment = 16; + HotSpotTarget target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true); + + RiXirGenerator generator = new HotSpotXirGenerator(config, target, registerConfig, this); + if (Logger.ENABLED) { + generator = LoggingProxy.getProxy(RiXirGenerator.class, generator); + } + compiler = new C1XCompiler(runtime, target, generator, registerConfig); + } + + @Override + public C1XCompiler getCompiler() { + return compiler; + } + +} diff -r 569d3fe7d65c -r 762de4b26788 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolved.java --- a/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolved.java Thu Apr 07 15:32:25 2011 +0200 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolved.java Fri Apr 08 13:43:05 2011 +0200 @@ -1,206 +1,76 @@ -/* - * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. - * - * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product - * that is described in this document. In particular, and without limitation, these intellectual property - * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or - * more additional patents or pending patent applications in the U.S. and in other countries. - * - * U.S. Government Rights - Commercial software. Government users are subject to the Sun - * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its - * supplements. - * - * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or - * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks - * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the - * U.S. and other countries. - * - * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open - * Company, Ltd. - */ -package com.sun.hotspot.c1x; - -import java.lang.reflect.*; -import java.util.*; - -import com.sun.cri.ci.*; -import com.sun.cri.ri.*; - -/** - * Implementation of RiType for resolved non-primitive HotSpot classes. - * - * @author Thomas Wuerthinger, Lukas Stadler - */ -public class HotSpotTypeResolved extends HotSpotType { - - private Class javaMirror; - private String simpleName; - private int accessFlags; - private boolean hasFinalizer; - private boolean hasSubclass; - private boolean hasFinalizableSubclass; - private boolean isInitialized; - private boolean isArrayClass; - private boolean isInstanceClass; - private boolean isInterface; - private int instanceSize; - private RiType componentType; - private HashMap fieldCache; - private RiConstantPool pool; - - private HotSpotTypeResolved() { - super(null); - } - - @Override - public int accessFlags() { - return accessFlags; - } - - @Override - public RiType arrayOf() { - return compiler.getVMEntries().RiType_arrayOf(this); - } - - @Override - public RiType componentType() { - return compiler.getVMEntries().RiType_componentType(this); - } - - @Override - public RiType uniqueConcreteSubtype() { - return compiler.getVMEntries().RiType_uniqueConcreteSubtype(this); - } - - @Override - public RiType exactType() { - if (Modifier.isFinal(accessFlags)) { - return this; - } - return null; - } - - @Override - public CiConstant getEncoding(Representation r) { - switch (r) { - case JavaClass: - return CiConstant.forObject(javaClass()); - case ObjectHub: - return CiConstant.forObject(this); - case StaticFields: - return CiConstant.forObject(this); - case TypeInfo: - return CiConstant.forObject(this); - default: - return null; - } - } - - @Override - public CiKind getRepresentationKind(Representation r) { - return CiKind.Object; - } - - @Override - public boolean hasFinalizableSubclass() { - return hasFinalizableSubclass; - } - - @Override - public boolean hasFinalizer() { - return hasFinalizer; - } - - @Override - public boolean hasSubclass() { - return hasSubclass; - } - - @Override - public boolean isArrayClass() { - return isArrayClass; - } - - @Override - public boolean isInitialized() { - return isInitialized; - } - - @Override - public boolean isInstance(Object obj) { - return javaMirror.isInstance(obj); - } - - @Override - public boolean isInstanceClass() { - return isInstanceClass; - } - - @Override - public boolean isInterface() { - return isInterface; - } - - @Override - public boolean isResolved() { - return true; - } - - @Override - public boolean isSubtypeOf(RiType other) { - if (other instanceof HotSpotTypeResolved) { - return compiler.getVMEntries().RiType_isSubtypeOf(this, other); - } - // No resolved type is a subtype of an unresolved type. - return false; - } - - @Override - public Class javaClass() { - return javaMirror; - } - - @Override - public CiKind kind() { - return CiKind.Object; - } - - @Override - public RiMethod resolveMethodImpl(RiMethod method) { - assert method instanceof HotSpotMethod; - return compiler.getVMEntries().RiType_resolveMethodImpl(this, method.name(), method.signature().asString()); - } - - @Override - public String toString() { - return "HotSpotType<" + simpleName + ", resolved>"; - } - - public RiConstantPool constantPool() { - // TODO: Implement constant pool without the need for VmId and cache the constant pool. - return compiler.getVMEntries().RiType_constantPool(this); - } - - public int instanceSize() { - return instanceSize; - } - - public RiField createRiField(String name, RiType type, int offset) { - RiField result = null; - - // (tw) Must cache the fields, because the local load elimination only works if the objects from two field lookups are equal. - if (fieldCache == null) { - fieldCache = new HashMap(8); - } else { - result = fieldCache.get(offset); - } - - if (result == null) { - result = new HotSpotField(compiler, this, name, type, offset); - fieldCache.put(offset, result); - } - - return result; - } - -} +/* + * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. + * + * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product + * that is described in this document. In particular, and without limitation, these intellectual property + * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or + * more additional patents or pending patent applications in the U.S. and in other countries. + * + * U.S. Government Rights - Commercial software. Government users are subject to the Sun + * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its + * supplements. + * + * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or + * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks + * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the + * U.S. and other countries. + * + * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open + * Company, Ltd. + */ +package com.sun.hotspot.c1x; + +import com.sun.cri.ci.*; +import com.sun.cri.ri.*; + +public interface HotSpotTypeResolved extends RiType { + + public int accessFlags(); + + public RiType arrayOf(); + + public RiType componentType(); + + public RiType uniqueConcreteSubtype(); + + public RiType exactType(); + + public CiConstant getEncoding(Representation r); + + public CiKind getRepresentationKind(Representation r); + + public boolean hasFinalizableSubclass(); + + public boolean hasFinalizer(); + + public boolean hasSubclass(); + + public boolean isArrayClass(); + + public boolean isInitialized(); + + public boolean isInstance(Object obj); + + public boolean isInstanceClass(); + + public boolean isInterface(); + + public boolean isResolved(); + + public boolean isSubtypeOf(RiType other); + + public Class javaClass(); + + public CiKind kind(); + + public RiMethod resolveMethodImpl(RiMethod method); + + public String toString(); + + public RiConstantPool constantPool(); + + public int instanceSize(); + + public RiField createRiField(String name, RiType type, int offset); + +} \ No newline at end of file diff -r 569d3fe7d65c -r 762de4b26788 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolvedImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolvedImpl.java Fri Apr 08 13:43:05 2011 +0200 @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. + * + * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product + * that is described in this document. In particular, and without limitation, these intellectual property + * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or + * more additional patents or pending patent applications in the U.S. and in other countries. + * + * U.S. Government Rights - Commercial software. Government users are subject to the Sun + * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its + * supplements. + * + * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or + * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks + * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the + * U.S. and other countries. + * + * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open + * Company, Ltd. + */ +package com.sun.hotspot.c1x; + +import java.lang.reflect.*; +import java.util.*; + +import com.sun.cri.ci.*; +import com.sun.cri.ri.*; + +/** + * Implementation of RiType for resolved non-primitive HotSpot classes. + * + * @author Thomas Wuerthinger, Lukas Stadler + */ +public class HotSpotTypeResolvedImpl extends HotSpotType implements HotSpotTypeResolved { + + private Class javaMirror; + private String simpleName; + private int accessFlags; + private boolean hasFinalizer; + private boolean hasSubclass; + private boolean hasFinalizableSubclass; + private boolean isInitialized; + private boolean isArrayClass; + private boolean isInstanceClass; + private boolean isInterface; + private int instanceSize; + private RiType componentType; + private HashMap fieldCache; + private RiConstantPool pool; + + private HotSpotTypeResolvedImpl() { + super(null); + } + + @Override + public int accessFlags() { + return accessFlags; + } + + @Override + public RiType arrayOf() { + return compiler.getVMEntries().RiType_arrayOf(this); + } + + @Override + public RiType componentType() { + return compiler.getVMEntries().RiType_componentType(this); + } + + @Override + public RiType uniqueConcreteSubtype() { + return compiler.getVMEntries().RiType_uniqueConcreteSubtype(this); + } + + @Override + public RiType exactType() { + if (Modifier.isFinal(accessFlags)) { + return this; + } + return null; + } + + @Override + public CiConstant getEncoding(Representation r) { + switch (r) { + case JavaClass: + return CiConstant.forObject(javaClass()); + case ObjectHub: + return CiConstant.forObject(this); + case StaticFields: + return CiConstant.forObject(this); + case TypeInfo: + return CiConstant.forObject(this); + default: + return null; + } + } + + @Override + public CiKind getRepresentationKind(Representation r) { + return CiKind.Object; + } + + @Override + public boolean hasFinalizableSubclass() { + return hasFinalizableSubclass; + } + + @Override + public boolean hasFinalizer() { + return hasFinalizer; + } + + @Override + public boolean hasSubclass() { + return hasSubclass; + } + + @Override + public boolean isArrayClass() { + return isArrayClass; + } + + @Override + public boolean isInitialized() { + return isInitialized; + } + + @Override + public boolean isInstance(Object obj) { + return javaMirror.isInstance(obj); + } + + @Override + public boolean isInstanceClass() { + return isInstanceClass; + } + + @Override + public boolean isInterface() { + return isInterface; + } + + @Override + public boolean isResolved() { + return true; + } + + @Override + public boolean isSubtypeOf(RiType other) { + if (other.isResolved()) { + return compiler.getVMEntries().RiType_isSubtypeOf(this, other); + } + // No resolved type is a subtype of an unresolved type. + return false; + } + + @Override + public Class javaClass() { + return javaMirror; + } + + @Override + public CiKind kind() { + return CiKind.Object; + } + + @Override + public RiMethod resolveMethodImpl(RiMethod method) { + assert method instanceof HotSpotMethod; + return compiler.getVMEntries().RiType_resolveMethodImpl(this, method.name(), method.signature().asString()); + } + + @Override + public String toString() { + return "HotSpotType<" + simpleName + ", resolved>"; + } + + @Override + public RiConstantPool constantPool() { + // TODO: Implement constant pool without the need for VmId and cache the constant pool. + return compiler.getVMEntries().RiType_constantPool(this); + } + + @Override + public int instanceSize() { + return instanceSize; + } + + @Override + public RiField createRiField(String name, RiType type, int offset) { + RiField result = null; + + // (tw) Must cache the fields, because the local load elimination only works if the objects from two field lookups are equal. + if (fieldCache == null) { + fieldCache = new HashMap(8); + } else { + result = fieldCache.get(offset); + } + + if (result == null) { + result = new HotSpotField(compiler, this, name, type, offset); + fieldCache.put(offset, result); + } + + return result; + } + +} diff -r 569d3fe7d65c -r 762de4b26788 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java --- a/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java Thu Apr 07 15:32:25 2011 +0200 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java Fri Apr 08 13:43:05 2011 +0200 @@ -1146,7 +1146,7 @@ @Override public XirSnippet genResolveClass(XirSite site, RiType type, Representation rep) { assert rep == Representation.ObjectHub || rep == Representation.StaticFields || rep == Representation.JavaClass : "unexpected representation: " + rep; - if (type instanceof HotSpotTypeResolved) { + if (type.isResolved()) { return new XirSnippet(resolveClassTemplates.get(site), XirArgument.forObject(type)); } return new XirSnippet(resolveClassTemplates.get(site, UNRESOLVED)); @@ -1226,7 +1226,7 @@ @Override public XirSnippet genNewInstance(XirSite site, RiType type) { - if (type instanceof HotSpotTypeResolved) { + if (type.isResolved()) { int instanceSize = ((HotSpotTypeResolved) type).instanceSize(); return new XirSnippet(newInstanceTemplates.get(site, instanceSize), XirArgument.forObject(type)); } @@ -1236,7 +1236,7 @@ @Override public XirSnippet genNewArray(XirSite site, XirArgument length, CiKind elementKind, RiType componentType, RiType arrayType) { if (elementKind == CiKind.Object) { - if (arrayType instanceof HotSpotTypeResolved) { + if (arrayType.isResolved()) { return new XirSnippet(newObjectArrayTemplates.get(site), length, XirArgument.forObject(arrayType)); } return new XirSnippet(newObjectArrayTemplates.get(site, UNRESOLVED), length); @@ -1253,7 +1253,7 @@ @Override public XirSnippet genNewMultiArray(XirSite site, XirArgument[] lengths, RiType type) { - if (type instanceof HotSpotTypeResolved) { + if (type.isResolved()) { XirArgument[] params = Arrays.copyOf(lengths, lengths.length + 1); params[lengths.length] = XirArgument.forObject(type); return new XirSnippet(multiNewArrayTemplate.get(site, lengths.length), params); diff -r 569d3fe7d65c -r 762de4b26788 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/CompilationServer.java --- a/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/CompilationServer.java Thu Apr 07 15:32:25 2011 +0200 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/CompilationServer.java Fri Apr 08 13:43:05 2011 +0200 @@ -27,11 +27,12 @@ import javax.net.*; -import com.sun.cri.ci.*; import com.sun.hotspot.c1x.*; import com.sun.hotspot.c1x.Compiler; import com.sun.hotspot.c1x.InvocationSocket.DelegateCallback; import com.sun.hotspot.c1x.logging.*; +import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingInputStream; +import com.sun.hotspot.c1x.server.ReplacingStreams.ReplacingOutputStream; /** * Server side of the client/server compilation model. @@ -40,105 +41,33 @@ */ public class CompilationServer { - private Registry registry; - private ServerSocket serverSocket; - private Socket socket; - private ReplacingOutputStream output; private ReplacingInputStream input; - public static void main(String[] args) throws Exception { new CompilationServer().run(); } - public static class Container implements Serializable { - - public final Class clazz; - public final Object[] values; - - public Container(Class clazz, Object... values) { - this.clazz = clazz; - this.values = values; - } - } - - /** - * Replaces certain cir objects that cannot easily be made Serializable. - */ - public static class ReplacingOutputStream extends ObjectOutputStream { - - public ReplacingOutputStream(OutputStream out) throws IOException { - super(out); - enableReplaceObject(true); - } - - @Override - protected Object replaceObject(Object obj) throws IOException { - Class clazz = obj.getClass(); - if (clazz == CiConstant.class) { - CiConstant o = (CiConstant) obj; - return new Container(clazz, o.kind, o.boxedValue()); - } else if (obj == CiValue.IllegalValue) { - return new Container(CiValue.class); - } else if (obj instanceof Compiler) { - return new Container(Compiler.class); - } - return obj; - } - } - - /** - * Replaces certain cir objects that cannot easily be made Serializable. - */ - public static class ReplacingInputStream extends ObjectInputStream { - private Compiler compiler; - - public ReplacingInputStream(InputStream in) throws IOException { - super(in); - enableResolveObject(true); - } - - public void setCompiler(Compiler compiler) { - this.compiler = compiler; - } - - @Override - protected Object resolveObject(Object obj) throws IOException { - if (obj instanceof Container) { - Container c = (Container) obj; - if (c.clazz == CiConstant.class) { - return CiConstant.forBoxed((CiKind) c.values[0], c.values[1]); - } else if (c.clazz == CiValue.class) { - return CiValue.IllegalValue; - } else if (c.clazz == Compiler.class) { - assert compiler != null; - return compiler; - } - throw new RuntimeException("unexpected container class: " + c.clazz); - } - return obj; - } - } - private void run() throws IOException, ClassNotFoundException { - serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); + ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(1199); do { + Socket socket = null; + ReplacingStreams streams = new ReplacingStreams(); try { Logger.log("Compilation server ready, waiting for client to connect..."); socket = serverSocket.accept(); Logger.log("Connected to " + socket.getRemoteSocketAddress()); - output = new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream())); + output = streams.new ReplacingOutputStream(new BufferedOutputStream(socket.getOutputStream())); // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream output.flush(); - input = new ReplacingInputStream(new BufferedInputStream(socket.getInputStream())); + input = streams.new ReplacingInputStream(new BufferedInputStream(socket.getInputStream())); final InvocationSocket invocation = new InvocationSocket(output, input); - invocation.setDelegateCallback( new DelegateCallback() { + invocation.setDelegateCallback(new DelegateCallback() { public Object getDelegate() { - VMEntries entries = (VMEntries) Proxy.newProxyInstance(VMEntries.class.getClassLoader(), new Class[] {VMEntries.class}, invocation); - Compiler compiler = Compiler.initializeServer(entries); + VMEntries entries = (VMEntries) Proxy.newProxyInstance(VMEntries.class.getClassLoader(), new Class[] { VMEntries.class}, invocation); + Compiler compiler = CompilerImpl.initializeServer(entries); input.setCompiler(compiler); return compiler.getVMExits(); } @@ -147,7 +76,9 @@ invocation.waitForResult(); } catch (IOException e) { e.printStackTrace(); - socket.close(); + if (socket != null) { + socket.close(); + } } } while (false); } diff -r 569d3fe7d65c -r 762de4b26788 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/ReplacingStreams.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/ReplacingStreams.java Fri Apr 08 13:43:05 2011 +0200 @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved. + * + * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product + * that is described in this document. In particular, and without limitation, these intellectual property + * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or + * more additional patents or pending patent applications in the U.S. and in other countries. + * + * U.S. Government Rights - Commercial software. Government users are subject to the Sun + * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its + * supplements. + * + * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or + * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks + * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the + * U.S. and other countries. + * + * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open + * Company, Ltd. + */ +package com.sun.hotspot.c1x.server; + +import java.io.*; +import java.util.*; + +import com.sun.cri.ci.*; +import com.sun.hotspot.c1x.Compiler; + +public class ReplacingStreams { + IdentityHashMap objectMap = new IdentityHashMap(); + ArrayList objectList = new ArrayList(); + + public static class Container implements Serializable { + + public final Class clazz; + public final Object[] values; + + public Container(Class clazz, Object... values) { + this.clazz = clazz; + this.values = values; + } + } + + public static enum PlaceholderType { + CI_CONSTANT_CONTENTS, RI_TYPE + } + + public static class Placeholder implements Serializable { + + public final int id; + public final PlaceholderType type; + + public Placeholder(int id, PlaceholderType type) { + this.id = id; + this.type = type; + } + + } + + /** + * Replaces certain cir objects that cannot easily be made Serializable. + */ + public class ReplacingInputStream extends ObjectInputStream { + + private Compiler compiler; + + public ReplacingInputStream(InputStream in) throws IOException { + super(in); + enableResolveObject(true); + } + + public void setCompiler(Compiler compiler) { + this.compiler = compiler; + } + + @Override + protected Object resolveObject(Object obj) throws IOException { + if (obj instanceof Container) { + Container c = (Container) obj; + if (c.clazz == CiConstant.class) { + return CiConstant.forBoxed((CiKind) c.values[0], c.values[1]); + } else if (c.clazz == CiValue.class) { + return CiValue.IllegalValue; + } else if (c.clazz == Compiler.class) { + assert compiler != null; + return compiler; + } + throw new RuntimeException("unexpected container class: " + c.clazz); + } /*else if (obj instanceof Placeholder) { + Placeholder ph = (Placeholder)obj; + if (ph.id >= objectList.size()) { + assert ph.id == objectList.size(); + switch (ph.type) { + case CI_CONSTANT_CONTENTS: + objectList.add(ph); + break; + case RI_TYPE: + objectList.add(e) + break; + } + } + return objectList.get(ph.id); + + }*/ + 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 { + Class clazz = obj.getClass(); + if (clazz == CiConstant.class) { + CiConstant o = (CiConstant) obj; + return new Container(clazz, o.kind, o.boxedValue()); + } else if (obj == CiValue.IllegalValue) { + return new Container(CiValue.class); + } else if (obj instanceof Compiler) { + return new Container(Compiler.class); + } + return obj; + } + } + +} diff -r 569d3fe7d65c -r 762de4b26788 src/share/vm/c1x/c1x_VMExits.cpp --- a/src/share/vm/c1x/c1x_VMExits.cpp Thu Apr 07 15:32:25 2011 +0200 +++ b/src/share/vm/c1x/c1x_VMExits.cpp Fri Apr 08 13:43:05 2011 +0200 @@ -27,27 +27,13 @@ // this is a *global* handle jobject VMExits::_compilerPermObject; -jobject VMExits::_compilerPermKlass; jobject VMExits::_vmExitsPermObject; jobject VMExits::_vmExitsPermKlass; -KlassHandle VMExits::compilerKlass() { - if (JNIHandles::resolve(_compilerPermKlass) == NULL) { - klassOop result = SystemDictionary::resolve_or_null(vmSymbols::com_sun_hotspot_c1x_Compiler(), SystemDictionary::java_system_loader(), NULL, Thread::current()); - if (result == NULL) { - fatal("Couldn't find class com.sun.hotspot.c1x.Compiler"); - } - _compilerPermKlass = JNIHandles::make_global(result); - } - return KlassHandle((klassOop)JNIHandles::resolve_non_null(_compilerPermKlass)); -} - KlassHandle VMExits::vmExitsKlass() { if (JNIHandles::resolve(_vmExitsPermKlass) == NULL) { klassOop result = SystemDictionary::resolve_or_null(vmSymbols::com_sun_hotspot_c1x_VMExits(), SystemDictionary::java_system_loader(), NULL, Thread::current()); - if (result == NULL) { - fatal("Couldn't find class com.sun.hotspot.c1x.VMExits"); - } + check_not_null(result, "Couldn't find class com.sun.hotspot.c1x.VMExits"); _vmExitsPermKlass = JNIHandles::make_global(result); } return KlassHandle((klassOop)JNIHandles::resolve_non_null(_vmExitsPermKlass)); @@ -55,8 +41,11 @@ Handle VMExits::compilerInstance() { if (JNIHandles::resolve(_compilerPermObject) == NULL) { + KlassHandle compilerImplKlass = SystemDictionary::resolve_or_null(vmSymbols::com_sun_hotspot_c1x_CompilerImpl(), SystemDictionary::java_system_loader(), NULL, Thread::current()); + check_not_null(compilerImplKlass(), "Couldn't find class com.sun.hotspot.c1x.CompilerImpl"); + JavaValue result(T_OBJECT); - JavaCalls::call_static(&result, compilerKlass(), vmSymbols::getInstance_name(), vmSymbols::getInstance_signature(), Thread::current()); + JavaCalls::call_static(&result, compilerImplKlass, vmSymbols::getInstance_name(), vmSymbols::getInstance_signature(), Thread::current()); check_pending_exception("Couldn't get Compiler"); _compilerPermObject = JNIHandles::make_global((oop) result.get_jobject()); } @@ -65,8 +54,13 @@ Handle VMExits::instance() { if (JNIHandles::resolve(_vmExitsPermObject) == NULL) { + KlassHandle compilerKlass = SystemDictionary::resolve_or_null(vmSymbols::com_sun_hotspot_c1x_Compiler(), SystemDictionary::java_system_loader(), NULL, Thread::current()); + check_not_null(compilerKlass(), "Couldn't find class com.sun.hotspot.c1x.Compiler"); + JavaValue result(T_OBJECT); - JavaCalls::call_virtual(&result, compilerInstance(), compilerKlass(), vmSymbols::getVMExits_name(), vmSymbols::getVMExits_signature(), Thread::current()); + JavaCallArguments args; + args.set_receiver(compilerInstance()); + JavaCalls::call_interface(&result, compilerKlass, vmSymbols::getVMExits_name(), vmSymbols::getVMExits_signature(), &args, Thread::current()); check_pending_exception("Couldn't get VMExits"); _vmExitsPermObject = JNIHandles::make_global((oop) result.get_jobject()); } diff -r 569d3fe7d65c -r 762de4b26788 src/share/vm/c1x/c1x_VMExits.hpp --- a/src/share/vm/c1x/c1x_VMExits.hpp Thu Apr 07 15:32:25 2011 +0200 +++ b/src/share/vm/c1x/c1x_VMExits.hpp Fri Apr 08 13:43:05 2011 +0200 @@ -25,12 +25,10 @@ class VMExits : public AllStatic { private: + static jobject _compilerPermObject; static jobject _vmExitsPermObject; - static jobject _compilerPermKlass; - static jobject _compilerPermObject; static jobject _vmExitsPermKlass; - static KlassHandle compilerKlass(); static KlassHandle vmExitsKlass(); static Handle instance(); @@ -85,9 +83,17 @@ if (THREAD->has_pending_exception()) { Handle exception = PENDING_EXCEPTION; CLEAR_PENDING_EXCEPTION; + tty->print_cr("%s", message); java_lang_Throwable::print(exception, tty); tty->cr(); java_lang_Throwable::print_stack_trace(exception(), tty); vm_abort(dump_core); } } + +inline void check_not_null(void* value, const char* message, bool dump_core = false) { + if (value == NULL) { + tty->print_cr("%s", message); + vm_abort(dump_core); + } +} diff -r 569d3fe7d65c -r 762de4b26788 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Thu Apr 07 15:32:25 2011 +0200 +++ b/src/share/vm/classfile/vmSymbols.hpp Fri Apr 08 13:43:05 2011 +0200 @@ -265,11 +265,12 @@ template(com_sun_hotspot_c1x_HotSpotTargetMethod, "com/sun/hotspot/c1x/HotSpotTargetMethod") \ template(com_sun_hotspot_c1x_HotSpotField, "com/sun/hotspot/c1x/HotSpotField") \ template(com_sun_c1x_C1XOptions, "com/sun/c1x/C1XOptions") \ - template(com_sun_hotspot_c1x_HotSpotTypeResolved, "com/sun/hotspot/c1x/HotSpotTypeResolved") \ + template(com_sun_hotspot_c1x_HotSpotTypeResolved, "com/sun/hotspot/c1x/HotSpotTypeResolvedImpl") \ template(com_sun_hotspot_c1x_HotSpotType, "com/sun/hotspot/c1x/HotSpotType") \ template(com_sun_hotspot_c1x_HotSpotExceptionHandler,"com/sun/hotspot/c1x/HotSpotExceptionHandler") \ template(com_sun_hotspot_c1x_HotSpotProxy, "com/sun/hotspot/c1x/HotSpotProxy") \ template(com_sun_hotspot_c1x_Compiler, "com/sun/hotspot/c1x/Compiler") \ + template(com_sun_hotspot_c1x_CompilerImpl, "com/sun/hotspot/c1x/CompilerImpl") \ template(com_sun_cri_ri_RiMethod, "com/sun/cri/ri/RiMethod") \ template(com_sun_cri_ri_RiField, "com/sun/cri/ri/RiField") \ template(com_sun_cri_ri_RiType, "com/sun/cri/ri/RiType") \