# HG changeset patch # User Thomas Wuerthinger # Date 1277303818 -7200 # Node ID 1b41af477605e1e9a7279632da9f57ee4533b035 # Parent 712c7ff1afc1e5a73cbdab6e2c3797e7248616d9 Added HotSpotVM project Java source files. diff -r 712c7ff1afc1 -r 1b41af477605 .hgignore --- a/.hgignore Wed Jun 23 16:19:21 2010 +0200 +++ b/.hgignore Wed Jun 23 16:36:58 2010 +0200 @@ -2,8 +2,12 @@ ^dist/ ^java/ ^work/ +.metadata/ +.settings/ ~$ .swp$ +.class$ +.log$ /nbproject/private/ ^src/share/tools/hsdis/build/ ^src/share/tools/IdealGraphVisualizer/[a-zA-Z0-9]*/build/ diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/.classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/.classpath Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,9 @@ + + + + + + + + + diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/.project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/.project Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,17 @@ + + + HotSpotVM + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/README.txt Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,3 @@ +The classes from the projects C1X, CRI, and HotSpotVM have to be on the classpath. The classes of the HotSpotVM project have to be on the bootclasspath +Example command line arguments for HotSpot: +-XX:+UseC1X -XX:TraceC1X=5 -Xbootclasspath/a:THIS_DIRECTORY/bin SomeClass \ No newline at end of file diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/com_sun_hotspot_c1x_VMEntries.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/com_sun_hotspot_c1x_VMEntries.h Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,189 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_sun_hotspot_c1x_VMEntries */ + +#ifndef _Included_com_sun_hotspot_c1x_VMEntries +#define _Included_com_sun_hotspot_c1x_VMEntries +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiMethod_code + * Signature: (Ljava/lang/Object;)[B + */ +JNIEXPORT jbyteArray JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1code + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiMethod_maxStackSize + * Signature: (Ljava/lang/Object;)I + */ +JNIEXPORT jint JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1maxStackSize + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiMethod_maxLocals + * Signature: (Ljava/lang/Object;)I + */ +JNIEXPORT jint JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1maxLocals + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiMethod_holder + * Signature: (Ljava/lang/Object;)Lcom/sun/cri/ri/RiType; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1holder + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiMethod_signature + * Signature: (Ljava/lang/Object;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1signature + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiMethod_name + * Signature: (Ljava/lang/Object;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1name + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiSignature_lookupType + * Signature: (Ljava/lang/String;Ljava/lang/Object;)Lcom/sun/cri/ri/RiType; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiSignature_1lookupType + (JNIEnv *, jclass, jstring, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiSignature_symbolToString + * Signature: (Ljava/lang/Object;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiSignature_1symbolToString + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiType_javaClass + * Signature: (Ljava/lang/Object;)Ljava/lang/Class; + */ +JNIEXPORT jclass JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1javaClass + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiType_name + * Signature: (Ljava/lang/Object;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1name + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiConstantPool_lookupConstant + * Signature: (Ljava/lang/Object;I)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupConstant + (JNIEnv *, jclass, jobject, jint); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiConstantPool_lookupMethod + * Signature: (Ljava/lang/Object;IB)Lcom/sun/cri/ri/RiMethod; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupMethod + (JNIEnv *, jclass, jobject, jint, jbyte); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiConstantPool_lookupSignature + * Signature: (Ljava/lang/Object;I)Lcom/sun/cri/ri/RiSignature; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupSignature + (JNIEnv *, jclass, jobject, jint); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiConstantPool_lookupType + * Signature: (Ljava/lang/Object;I)Lcom/sun/cri/ri/RiType; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupType + (JNIEnv *, jclass, jobject, jint); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiConstantPool_lookupField + * Signature: (Ljava/lang/Object;I)Lcom/sun/cri/ri/RiField; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupField + (JNIEnv *, jclass, jobject, jint); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: findRiType + * Signature: (Ljava/lang/Object;)Lcom/sun/cri/ri/RiType; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_findRiType + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiRuntime_getConstantPool + * Signature: (Ljava/lang/Object;)Lcom/sun/cri/ri/RiConstantPool; + */ +JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiRuntime_1getConstantPool + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiType_isArrayClass + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1isArrayClass + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiType_isInstanceClass + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1isInstanceClass + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiType_isInterface + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1isInterface + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: RiMethod_accessFlags + * Signature: (Ljava/lang/Object;)I + */ +JNIEXPORT jint JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1accessFlags + (JNIEnv *, jclass, jobject); + +/* + * Class: com_sun_hotspot_c1x_VMEntries + * Method: installCode + * Signature: (Ljava/lang/Object;[BI)V + */ +JNIEXPORT void JNICALL Java_com_sun_hotspot_c1x_VMEntries_installCode + (JNIEnv *, jclass, jobject, jbyteArray, jint); + +#ifdef __cplusplus +} +#endif +#endif diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/create_native_header.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/create_native_header.bat Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,1 @@ +javah -classpath c1x4hotspot.jar com.sun.hotspot.c1x.VMEntries \ No newline at end of file diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/C1XHotSpotTests.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/C1XHotSpotTests.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,8 @@ +package com.sun.hotspot.c1x; + +public class C1XHotSpotTests { + + public static int add(int a, int b) { + return a + b; + } +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/Compiler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/Compiler.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2009 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.C1XCompiler; +import com.sun.c1x.C1XOptions; +import com.sun.c1x.target.amd64.AMD64; +import com.sun.cri.ci.CiCompiler; +import com.sun.cri.ci.CiTarget; +import com.sun.cri.ri.RiRegisterConfig; +import com.sun.cri.xir.RiXirGenerator; + +/** + * + * @author Thomas Wuerthinger + * + * Singleton class holding the instance of the C1XCompiler. + * + */ +public class Compiler { + + private static CiCompiler compiler; + + public static CiCompiler getCompiler() { + + if (compiler == null) { + compiler = createCompiler(); + } + + return compiler; + } + + + private static CiCompiler createCompiler() { + + final HotSpotRuntime runtime = new HotSpotRuntime(); + final RiXirGenerator generator = new HotSpotXirGenerator(); + final int wordSize = 8; + final int stackFrameAlignment = 8; + final int pageSize = 1024; + final RiRegisterConfig config = new HotSpotRegisterConfig(); + final CiTarget target = new CiTarget(new AMD64(), config, true, wordSize, wordSize, wordSize, stackFrameAlignment, pageSize, wordSize, wordSize, 16); + final CiCompiler compiler = new C1XCompiler(runtime, target, generator); + + C1XOptions.setOptimizationLevel(3); + C1XOptions.TraceBytecodeParserLevel = 4; + C1XOptions.PrintCFGToFile = false; + C1XOptions.PrintAssembly = false;//true; + C1XOptions.PrintCompilation = true; + return compiler; + + } +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotConstantPool.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotConstantPool.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,49 @@ +package com.sun.hotspot.c1x; + +import com.sun.cri.ci.CiConstant; +import com.sun.cri.ri.RiConstantPool; +import com.sun.cri.ri.RiField; +import com.sun.cri.ri.RiMethod; +import com.sun.cri.ri.RiSignature; +import com.sun.cri.ri.RiType; + +public class HotSpotConstantPool implements RiConstantPool { + + private final Object constantPoolOop; + + public HotSpotConstantPool(Object o) { + this.constantPoolOop = o; + } + + @Override + public CiConstant encoding() { + // TODO: Check if this is correct. + return CiConstant.forObject(constantPoolOop); + } + + @Override + public Object lookupConstant(int cpi) { + return VMEntries.RiConstantPool_lookupConstant(constantPoolOop, cpi); + } + + @Override + public RiMethod lookupMethod(int cpi, byte byteCode) { + return VMEntries.RiConstantPool_lookupMethod(constantPoolOop, cpi, byteCode); + } + + @Override + public RiSignature lookupSignature(int cpi) { + return VMEntries.RiConstantPool_lookupSignature(constantPoolOop, cpi); + } + + @Override + public RiType lookupType(int cpi) { + return VMEntries.RiConstantPool_lookupType(constantPoolOop, cpi); + } + + @Override + public RiField lookupField(int cpi) { + return VMEntries.RiConstantPool_lookupField(constantPoolOop, cpi); + } + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotField.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,66 @@ +package com.sun.hotspot.c1x; + +import com.sun.cri.ci.CiConstant; +import com.sun.cri.ci.CiKind; +import com.sun.cri.ri.RiField; +import com.sun.cri.ri.RiType; + +public class HotSpotField implements RiField { + + private final RiType holder; + private final Object nameSymbol; + private final RiType type; + private final int offset; + + public HotSpotField(RiType holder, Object nameSymbol, RiType type, int offset) { + this.holder = holder; + this.nameSymbol = nameSymbol; + this.type = type; + this.offset = offset; + } + + @Override + public int accessFlags() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public CiConstant constantValue(Object object) { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiType holder() { + return holder; + } + + @Override + public boolean isConstant() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isResolved() { + return offset != -1; + } + + @Override + public CiKind kind() { + return type().kind(); + } + + @Override + public String name() { + return VMEntries.RiSignature_symbolToString(nameSymbol); + } + + @Override + public RiType type() { + return type; + } + + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotMethod.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,123 @@ +package com.sun.hotspot.c1x; + +import com.sun.cri.ri.RiExceptionHandler; +import com.sun.cri.ri.RiMethod; +import com.sun.cri.ri.RiMethodProfile; +import com.sun.cri.ri.RiSignature; +import com.sun.cri.ri.RiType; + +public class HotSpotMethod implements RiMethod { + + Object methodOop; + private byte[] code; + + public HotSpotMethod(Object methodOop) { + this.methodOop = methodOop; + } + + @Override + public int accessFlags() { + return VMEntries.RiMethod_accessFlags(methodOop); + } + + @Override + public boolean canBeStaticallyBound() { + // TODO Auto-generated method stub + return false; + } + + @Override + public byte[] code() { + if (code == null) { + code = VMEntries.RiMethod_code(methodOop); + } + + return code; + } + + @Override + public RiExceptionHandler[] exceptionHandlers() { + // TODO: Add support for exception handlers + return new RiExceptionHandler[0]; + } + + @Override + public boolean hasBalancedMonitors() { + // TODO Auto-generated method stub + return false; + } + + @Override + public RiType holder() { + return VMEntries.RiMethod_holder(methodOop); + } + + @Override + public boolean isClassInitializer() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isConstructor() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isLeafMethod() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isOverridden() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isResolved() { + // TODO Auto-generated method stub + return false; + } + + @Override + public String jniSymbol() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object liveness(int bci) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int maxLocals() { + return VMEntries.RiMethod_maxLocals(methodOop); + } + + @Override + public int maxStackSize() { + return VMEntries.RiMethod_maxStackSize(methodOop); + } + + @Override + public RiMethodProfile methodData() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String name() { + return VMEntries.RiMethod_name(methodOop); + } + + @Override + public RiSignature signature() { + return new HotSpotSignature(VMEntries.RiMethod_signature(methodOop)); + } + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotRegisterConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotRegisterConfig.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2009 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.target.amd64.AMD64; +import com.sun.c1x.util.Util; +import com.sun.cri.ci.CiCallingConvention; +import com.sun.cri.ci.CiKind; +import com.sun.cri.ci.CiRegister; +import com.sun.cri.ci.CiStackSlot; +import com.sun.cri.ci.CiTarget; +import com.sun.cri.ci.CiValue; +import com.sun.cri.ri.RiRegisterConfig; + +/** + * @author Thomas Wuerthinger + * + */ +public class HotSpotRegisterConfig implements RiRegisterConfig { + + @Override + public CiRegister[] getAllocatableRegisters() { + return new CiRegister[]{ AMD64.rax, AMD64.rbx, AMD64.rcx, AMD64.rdx, AMD64.rsi, AMD64.rdi, AMD64.r10, AMD64.r11} ; + } + + + private final CiRegister[] generalParameterRegisters = new CiRegister[]{AMD64.rdx, AMD64.r8, AMD64.r9, AMD64.rdi, AMD64.rsi, AMD64.rcx}; + private final CiRegister[] xmmParameterRegisters = new CiRegister[]{AMD64.xmm0, AMD64.xmm1, AMD64.xmm2, AMD64.xmm3, AMD64.xmm4, AMD64.xmm5, AMD64.xmm6, AMD64.xmm7}; + + @Override + public int getCalleeSaveRegisterOffset(CiRegister register) { + return 0; + } + + @Override + public CiRegister[] getCallerSaveRegisters() { + return getAllocatableRegisters(); + } + + @Override + public CiRegister getFramePointerRegister() { + return AMD64.rbp; + } + + @Override + public CiRegister getIntegerRegister(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public CiCallingConvention getJavaCallingConvention(CiKind[] parameters, boolean outgoing, CiTarget target) { + return callingConvention(parameters, outgoing, target); + } + + private CiCallingConvention callingConvention(CiKind[] types, boolean outgoing, CiTarget target) { + CiValue[] locations = new CiValue[types.length]; + + int currentGeneral = 0; + int currentXMM = 0; + int currentStackIndex = 0; + + for (int i = 0; i < types.length; i++) { + final CiKind kind = types[i]; + + switch (kind) { + case Byte: + case Boolean: + case Short: + case Char: + case Int: + case Long: + case Word: + case Object: + if (currentGeneral < generalParameterRegisters.length) { + CiRegister register = generalParameterRegisters[currentGeneral++]; + locations[i] = register.asValue(kind); + } + break; + + case Float: + case Double: + if (currentXMM < xmmParameterRegisters.length) { + CiRegister register = xmmParameterRegisters[currentXMM++]; + locations[i] = register.asValue(kind); + } + break; + + default: + throw Util.shouldNotReachHere(); + } + + if (locations[i] == null) { + locations[i] = CiStackSlot.get(kind.stackKind(), currentStackIndex, !outgoing); + currentStackIndex += target.spillSlots(kind); + } + } + + return new CiCallingConvention(locations, currentStackIndex * target.spillSlotSize); + } + + @Override + public int getMinimumCalleeSaveFrameSize() { + return 0; + } + + @Override + public CiCallingConvention getNativeCallingConvention(CiKind[] parameters, boolean outgoing, CiTarget target) { + throw new UnsupportedOperationException(); + } + + @Override + public CiRegister[] getRegisterReferenceMapOrder() { + return getAllocatableRegisters(); + } + + @Override + public CiRegister getReturnRegister(CiKind kind) { + return AMD64.rax; + } + + @Override + public CiCallingConvention getRuntimeCallingConvention(CiKind[] parameters, CiTarget target) { + throw new UnsupportedOperationException(); + } + + @Override + public CiRegister getSafepointRegister() { + return AMD64.r13; + } + + @Override + public CiRegister getScratchRegister() { + return AMD64.r15; + } + + @Override + public CiRegister getStackPointerRegister() { + return AMD64.rsp; + } + + @Override + public CiRegister getThreadRegister() { + return AMD64.r14; + } + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotRuntime.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotRuntime.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2009 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.ByteArrayOutputStream; +import java.io.OutputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import com.sun.cri.ci.CiConstant; +import com.sun.cri.ci.CiMethodInvokeArguments; +import com.sun.cri.ci.CiTargetMethod; +import com.sun.cri.ci.CiTargetMethod.Call; +import com.sun.cri.ci.CiTargetMethod.DataPatch; +import com.sun.cri.ci.CiTargetMethod.Safepoint; +import com.sun.cri.ri.RiConstantPool; +import com.sun.cri.ri.RiField; +import com.sun.cri.ri.RiMethod; +import com.sun.cri.ri.RiOsrFrame; +import com.sun.cri.ri.RiRuntime; +import com.sun.cri.ri.RiSnippets; +import com.sun.cri.ri.RiType; +import com.sun.max.asm.InstructionSet; +import com.sun.max.asm.dis.DisassembledObject; +import com.sun.max.asm.dis.Disassembler; +import com.sun.max.asm.dis.DisassemblyPrinter; + +/** + * + * @author Thomas Wuerthinger + * + * CRI runtime implementation for the HotSpot VM. + * + */ +public class HotSpotRuntime implements RiRuntime { + + @Override + public int basicObjectLockOffsetInBytes() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int codeOffset() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void codePrologue(RiMethod method, OutputStream out) { + // TODO Auto-generated method stub + + } + + @Override + public String disassemble(byte[] code) { + return disassemble(code, new DisassemblyPrinter(false)); + } + + private String disassemble(byte[] code, DisassemblyPrinter disassemblyPrinter) { + final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + final InstructionSet instructionSet = InstructionSet.AMD64; + //Disassembler.disassemble(byteArrayOutputStream, code, instructionSet, null, 0, null, disassemblyPrinter); + return byteArrayOutputStream.toString(); + } + + @Override + public String disassemble(final CiTargetMethod targetMethod) { + + final DisassemblyPrinter disassemblyPrinter = new DisassemblyPrinter(false) { + + private String toString(Call call) { + if (call.runtimeCall != null) { + return "{" + call.runtimeCall.name() + "}"; + } else if (call.symbol != null) { + return "{" + call.symbol + "}"; + } else if (call.globalStubID != null) { + return "{" + call.globalStubID + "}"; + } else { + return "{" + call.method + "}"; + } + } + + private String siteInfo(int pcOffset) { + for (Call call : targetMethod.directCalls) { + if (call.pcOffset == pcOffset) { + return toString(call); + } + } + for (Call call : targetMethod.indirectCalls) { + if (call.pcOffset == pcOffset) { + return toString(call); + } + } + for (Safepoint site : targetMethod.safepoints) { + if (site.pcOffset == pcOffset) { + return "{safepoint}"; + } + } + for (DataPatch site : targetMethod.dataReferences) { + if (site.pcOffset == pcOffset) { + return "{" + site.data + "}"; + } + } + return null; + } + + @Override + protected String disassembledObjectString(Disassembler disassembler, DisassembledObject disassembledObject) { + final String string = super.disassembledObjectString(disassembler, disassembledObject); + + String site = siteInfo(disassembledObject.startPosition()); + if (site != null) { + return string + " " + site; + } + return string; + } + }; + return disassemble(targetMethod.targetCode(), disassemblyPrinter); + } + + @Override + public String disassemble(RiMethod method) { + return "No disassembler available"; + } + + @Override + public RiConstantPool getConstantPool(RiMethod method) { + return VMEntries.RiRuntime_getConstantPool(((HotSpotType)method.holder()).klassOop); + } + + @Override + public RiOsrFrame getOsrFrame(RiMethod method, int bci) { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiType getRiType(Class javaClass) { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiSnippets getSnippets() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean mustInline(RiMethod method) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean mustNotCompile(RiMethod method) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean mustNotInline(RiMethod method) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Object registerTargetMethod(CiTargetMethod targetMethod, String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int sizeofBasicObjectLock() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int threadExceptionOffset() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public RiField getRiField(Field javaField) { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiMethod getRiMethod(Method javaMethod) { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiMethod getRiMethod(Constructor javaConstructor) { + // TODO Auto-generated method stub + return null; + } + + @Override + public CiConstant invoke(RiMethod method, CiMethodInvokeArguments args) { + // TODO Auto-generated method stub + return null; + } + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotSignature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotSignature.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,120 @@ +package com.sun.hotspot.c1x; + +import java.util.ArrayList; +import java.util.List; + +import com.sun.cri.ci.CiKind; +import com.sun.cri.ri.RiSignature; +import com.sun.cri.ri.RiType; + +public class HotSpotSignature implements RiSignature { + + private final List arguments = new ArrayList(); + private final String returnType; + private final String originalString; + + public HotSpotSignature(String signature) { + + assert signature.length() > 0; + this.originalString = signature; + + if (signature.charAt(0) == '(') { + int cur = 1; + while (cur < signature.length() && signature.charAt(cur) != ')') { + int nextCur = parseSignature(signature, cur); + arguments.add(signature.substring(cur, nextCur)); + cur = nextCur; + } + + cur++; + int nextCur = parseSignature(signature, cur); + returnType = signature.substring(cur, nextCur); + assert nextCur == signature.length(); + } else { + returnType = null; + } + } + + private int parseSignature(String signature, int cur) { + + char first = signature.charAt(cur); + switch (first) { + + case '[': + return parseSignature(signature, cur + 1); + + case 'L': + while (signature.charAt(cur) != ';') + cur++; + cur++; + break; + + case 'V': + case 'I': + case 'B': + case 'C': + case 'D': + case 'F': + case 'J': + case 'S': + case 'Z': + cur++; + break; + + default: + assert false; + + } + + return cur; + } + + @Override + public int argumentCount(boolean withReceiver) { + return arguments.size() + (withReceiver ? 1 : 0); + } + + @Override + public CiKind argumentKindAt(int index) { + CiKind kind = CiKind.fromTypeString(arguments.get(index)); + System.out.println("argument kind: " + index + " is " + kind); + return kind; + } + + @Override + public int argumentSlots(boolean withReceiver) { + + int argSlots = 0; + for (int i = 0; i < argumentCount(false); i++) { + argSlots += argumentKindAt(i).sizeInSlots(); + } + + return argSlots + (withReceiver ? 1 : 0); + } + + @Override + public RiType argumentTypeAt(int index, RiType accessingClass) { + System.out.println("argument type at " + index); + Object accessor = null; + if (accessingClass instanceof HotSpotType) { + accessor = ((HotSpotType)accessingClass).klassOop; + } + return VMEntries.RiSignature_lookupType(arguments.get(index), accessor); + } + + @Override + public String asString() { + return originalString; + } + + @Override + public CiKind returnKind() { + return CiKind.fromTypeString(returnType); + } + + @Override + public RiType returnType(RiType accessingClass) { + return VMEntries.RiSignature_lookupType(returnType, accessingClass); + } + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotType.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,130 @@ +package com.sun.hotspot.c1x; + +import com.sun.cri.ci.CiConstant; +import com.sun.cri.ci.CiKind; +import com.sun.cri.ri.*; + +public class HotSpotType implements RiType { + + final Object klassOop; + + public HotSpotType(Object o) { + this.klassOop = o; + assert klassOop != null; + } + + @Override + public int accessFlags() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public RiType arrayOf() { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiType componentType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiType exactType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public CiConstant getEncoding(Representation r) { + // TODO Auto-generated method stub + return null; + } + + @Override + public CiKind getRepresentationKind(Representation r) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean hasFinalizableSubclass() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasFinalizer() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasSubclass() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isArrayClass() { + System.out.println("Checking for array class " + name()); + return VMEntries.RiType_isArrayClass(klassOop); + } + + @Override + public boolean isInitialized() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isInstance(Object obj) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isInstanceClass() { + return VMEntries.RiType_isInstanceClass(klassOop); + } + + @Override + public boolean isInterface() { + return VMEntries.RiType_isInterface(klassOop); + } + + @Override + public boolean isResolved() { + return true; + } + + @Override + public boolean isSubtypeOf(RiType other) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Class javaClass() { + return VMEntries.RiType_javaClass(klassOop); + } + + @Override + public CiKind kind() { + return CiKind.Object; + } + + @Override + public String name() { + return VMEntries.RiType_name(klassOop); + } + + @Override + public RiMethod resolveMethodImpl(RiMethod method) { + // TODO Auto-generated method stub + return null; + } + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypePrimitive.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypePrimitive.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,133 @@ +package com.sun.hotspot.c1x; + +import com.sun.cri.ci.CiConstant; +import com.sun.cri.ci.CiKind; +import com.sun.cri.ri.RiMethod; +import com.sun.cri.ri.RiType; + +public class HotSpotTypePrimitive implements RiType { + + private CiKind kind; + + public HotSpotTypePrimitive(CiKind kind) { + this.kind = kind; + } + + @Override + public int accessFlags() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public RiType arrayOf() { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiType componentType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public RiType exactType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public CiConstant getEncoding(Representation r) { + // TODO Auto-generated method stub + + return null; + } + + @Override + public CiKind getRepresentationKind(Representation r) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean hasFinalizableSubclass() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasFinalizer() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasSubclass() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isArrayClass() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isInitialized() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isInstance(Object obj) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isInstanceClass() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isInterface() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isResolved() { + // TODO Auto-generated method stub + return true; + } + + @Override + public boolean isSubtypeOf(RiType other) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Class javaClass() { + return kind.toJavaClass(); + } + + @Override + public CiKind kind() { + return kind; + } + + @Override + public String name() { + return kind.toString(); + } + + @Override + public RiMethod resolveMethodImpl(RiMethod method) { + return null; + } + +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeUnresolved.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeUnresolved.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2009 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.*; + +/** + * @author Thomas Wuerthinger + */ +public class HotSpotTypeUnresolved implements RiType { + + public final String name; + + /** + * Creates a new unresolved type for a specified type descriptor. + * + * @param typeDescriptor the type's descriptor + * @param pool the constant pool containing the unresolved type reference + * @param cpi the index in {@code constantPool} of the unresolved type reference + */ + public HotSpotTypeUnresolved(String name) { + this.name = name; + } + + public String name() { + return name; + } + + public Class javaClass() { + throw unresolved("javaClass"); + } + + public boolean hasSubclass() { + throw unresolved("hasSubclass()"); + } + + public boolean hasFinalizer() { + throw unresolved("hasFinalizer()"); + } + + public boolean hasFinalizableSubclass() { + throw unresolved("hasFinalizableSubclass()"); + } + + public boolean isInterface() { + throw unresolved("isInterface()"); + } + + public boolean isArrayClass() { + throw unresolved("isArrayClass()"); + } + + public boolean isInstanceClass() { + throw unresolved("isInstanceClass()"); + } + + public int accessFlags() { + throw unresolved("accessFlags()"); + } + + public boolean isResolved() { + return false; + } + + public boolean isInitialized() { + throw unresolved("isInitialized()"); + } + + public boolean isSubtypeOf(RiType other) { + throw unresolved("isSubtypeOf()"); + } + + public boolean isInstance(Object obj) { + throw unresolved("isInstance()"); + } + + public RiType componentType() { + // TODO: Implement + throw new UnsupportedOperationException(); + } + + public RiType exactType() { + throw unresolved("exactType()"); + } + + public RiType arrayOf() { + // TODO: Implement + throw new UnsupportedOperationException(); + } + + public RiMethod resolveMethodImpl(RiMethod method) { + throw unresolved("resolveMethodImpl()"); + } + + public CiKind kind() { + // TODO: Check if this is correct. + return CiKind.Object; + } + + private CiUnresolvedException unresolved(String operation) { + throw new CiUnresolvedException(operation + " not defined for unresolved class " + name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object o) { + return o == this; + } + + @Override + public String toString() { + return name() + " [unresolved]"; + } + + public CiConstant getEncoding(RiType.Representation r) { + throw unresolved("getEncoding()"); + } + + public CiKind getRepresentationKind(RiType.Representation r) { + // TODO: Check if this is correct. + return CiKind.Object; + } +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2009 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.util.ArrayList; +import java.util.List; + +import com.sun.cri.ci.CiKind; +import com.sun.cri.ri.RiField; +import com.sun.cri.ri.RiMethod; +import com.sun.cri.ri.RiType; +import com.sun.cri.ri.RiType.Representation; +import com.sun.cri.xir.CiXirAssembler; +import com.sun.cri.xir.RiXirGenerator; +import com.sun.cri.xir.XirArgument; +import com.sun.cri.xir.XirSite; +import com.sun.cri.xir.XirSnippet; +import com.sun.cri.xir.XirTemplate; +import com.sun.cri.xir.CiXirAssembler.XirOperand; + +/** + * + * @author Thomas Wuerthinger + * + */ +public class HotSpotXirGenerator extends RiXirGenerator { + + private XirTemplate[] emptyTemplates = new XirTemplate[CiKind.values().length]; + + @Override + public List buildTemplates(CiXirAssembler asm) { + + List templates = new ArrayList(); + for (int i=0; i RiType_javaClass(Object klassOop); + public static native String RiType_name(Object klassOop); + public static native Object RiConstantPool_lookupConstant(Object constantPoolOop, int cpi); + public static native RiMethod RiConstantPool_lookupMethod(Object constantPoolOop, int cpi, byte byteCode); + public static native RiSignature RiConstantPool_lookupSignature(Object constantPoolOop, int cpi); + public static native RiType RiConstantPool_lookupType(Object constantPoolOop, int cpi); + public static native RiField RiConstantPool_lookupField(Object constantPoolOop, int cpi); + public static native RiType findRiType(Object holderKlassOop); + public static native RiConstantPool RiRuntime_getConstantPool(Object klassOop); + public static native boolean RiType_isArrayClass(Object klassOop); + public static native boolean RiType_isInstanceClass(Object klassOop); + public static native boolean RiType_isInterface(Object klassOop); + public static native int RiMethod_accessFlags(Object methodOop); + public static native void installCode(Object methodOop, byte[] code, int frameSize); +} diff -r 712c7ff1afc1 -r 1b41af477605 c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/VMExits.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/VMExits.java Wed Jun 23 16:36:58 2010 +0200 @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2009 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.CiCompiler; +import com.sun.cri.ci.CiConstant; +import com.sun.cri.ci.CiKind; +import com.sun.cri.ci.CiResult; +import com.sun.cri.ri.RiConstantPool; +import com.sun.cri.ri.RiField; +import com.sun.cri.ri.RiMethod; +import com.sun.cri.ri.RiSignature; +import com.sun.cri.ri.RiType; + +/** + * + * @author Thomas Wuerthinger + * + * Exits from the HotSpot VM into Java code. + * + */ +public class VMExits { + + public static void compileMethod(RiMethod method, int entry_bci) { + + assert method instanceof RiMethod : "And YES, this assert is necessary and a potential life saver as this method is called from the VM ;-)"; + + System.out.println("compileMethod in Java code called!!"); + + CiCompiler compiler = Compiler.getCompiler(); + CiResult result = compiler.compileMethod(method, null); + + System.out.println("Compilation result: "); + if (result.bailout() != null) { + System.out.println("Bailout:"); + result.bailout().printStackTrace(); + } else { + System.out.println(result.targetMethod()); + VMEntries.installCode(((HotSpotMethod)method).methodOop, result.targetMethod().targetCode(), result.targetMethod().frameSize()); + } + } + + public static RiMethod createRiMethod(Object methodOop) { + System.out.println("creating RiMethod object"); + RiMethod m = new HotSpotMethod(methodOop); + System.out.println("returning " + m); + return m; + } + + public static RiSignature createRiSignature(Object symbolOop) { + System.out.println("Creating RiSignature object"); + String name = VMEntries.RiSignature_symbolToString(symbolOop); + System.out.println("Signature name: " + name); + return new HotSpotSignature(name); + } + + public static RiField createRiField(RiType holder, Object nameSymbol, RiType type, int offset) { + System.out.println("creating RiField object"); + return new HotSpotField(holder, nameSymbol, type, offset); + } + + public static RiType createRiType(Object klassOop) { + System.out.println("creating RiType object"); + return new HotSpotType(klassOop); + } + + public static RiType createRiTypePrimitive(int basicType) { + System.out.println("Creating primitive type with basicType " + basicType); + CiKind kind = null; + switch (basicType) { + case 4: + kind = CiKind.Boolean; + break; + case 5: + kind = CiKind.Char; + break; + case 6: + kind = CiKind.Float; + break; + case 7: + kind = CiKind.Double; + break; + case 8: + kind = CiKind.Byte; + break; + case 9: + kind = CiKind.Short; + break; + case 10: + kind = CiKind.Int; + break; + case 11: + kind = CiKind.Long; + break; + case 14: + kind = CiKind.Void; + break; + default: + throw new IllegalArgumentException("Unknown basic type: " + basicType); + } + System.out.println("Chosen kind: " + kind); + return new HotSpotTypePrimitive(kind); + } + + public static RiType createRiTypeUnresolved(Object symbolOop, Object accessingKlassOop) { + System.out.println("Creating unresolved RiType object"); + String name = VMEntries.RiSignature_symbolToString(symbolOop); + System.out.println("Class name: " + name); + return new HotSpotTypeUnresolved(name); + } + + public static RiConstantPool createRiConstantPool(Object constantPoolOop) { + System.out.println("creating RiConstantPool object"); + return new HotSpotConstantPool(constantPoolOop); + } + + public static CiConstant createCiConstantInt(int value) { + return CiConstant.forInt(value); + } + + public static CiConstant createCiConstantLong(long value) { + return CiConstant.forLong(value); + } + + public static CiConstant createCiConstantFloat(float value) { + return CiConstant.forFloat(value); + } + + public static CiConstant createCiConstantDouble(double value) { + return CiConstant.forDouble(value); + } + + public static CiConstant createCiConstantObject(Object value) { + return CiConstant.forObject(value); + } + + public static void main(String[] args) throws InterruptedException { + System.out.println(C1XHotSpotTests.add(1, 2)); + Thread.sleep(5000); + System.out.println(C1XHotSpotTests.add(1, 2)); + } +} diff -r 712c7ff1afc1 -r 1b41af477605 src/share/vm/classfile/classLoader.cpp --- a/src/share/vm/classfile/classLoader.cpp Wed Jun 23 16:19:21 2010 +0200 +++ b/src/share/vm/classfile/classLoader.cpp Wed Jun 23 16:36:58 2010 +0200 @@ -164,7 +164,7 @@ if (file_handle != -1) { // read contents into resource array u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size); - size_t num_read = os::read(file_handle, (char*) buffer, st.st_size); + size_t num_read = hpi::read(file_handle, (char*) buffer, st.st_size); // close file hpi::close(file_handle); // construct ClassFileStream