# HG changeset patch # User Christian Haeubl # Date 1327353763 28800 # Node ID 4e3aaf14cbc60c61f9cc1027e5fa461665ee9b93 # Parent 271220b49abc4eb8e7416b203ce2d3a412f18dd0 fixed graal to hotspot diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiProfilingInfo.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiProfilingInfo.java Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiProfilingInfo.java Mon Jan 23 13:22:43 2012 -0800 @@ -35,23 +35,17 @@ /** * Returns an estimate of how often the switch cases are taken at the given BCI. - * @return An array of double values that contains the estimated probabilities, with 0.0 meaning never and 1.0 meaning always, - * or null if this information is not available. The default case is stored as the last entry. + * The default case is stored as the last entry. + * @return A double value that contains the estimated probabilities, with 0.0 meaning never and 1.0 meaning always, + * or -1 if this information is not available. */ double[] getSwitchProbabilities(int bci); /** - * Returns all types that were encountered at the given BCI. - * @return An array containing all types that were encountered during profiling at the given BCI, or null if not available. + * Returns the TypeProfile for the given BCI. + * @return Returns an RiTypeProfile object, or null if not available. */ - RiResolvedType[] getTypes(int bci); - - /** - * Returns an estimate of how often each individual type is encountered at the given BCI. - * @return An array of double values that contains the estimated probabilities, with 0.0 meaning never and 1.0 meaning always, - * or null if this information is not available. - */ - double[] getTypeProbabilities(int bci); + RiTypeProfile getTypeProfile(int bci); /** * Returns true if the given BCI did throw an implicit exception (NullPointerException, ClassCastException, diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiTypeProfile.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiTypeProfile.java Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiTypeProfile.java Mon Jan 23 13:22:43 2012 -0800 @@ -29,33 +29,33 @@ * the supplied values may vary, but a runtime that provides this information should be aware that it will be used to * guide performance-critical decisions like speculative inlining, etc. */ -public class RiTypeProfile implements Serializable { - +public final class RiTypeProfile implements Serializable { /** - * + * */ private static final long serialVersionUID = -6877016333706838441L; - /** - * How often the instruction was executed, which may be used to judge the maturity of this profile. - */ - public int count; + private RiResolvedType[] types; + private double[] probabilities; + + public RiTypeProfile(RiResolvedType[] types, double[] probabilites) { + this.types = types; + this.probabilities = probabilites; + } /** - * An estimation of how many different receiver types were encountered. This may or may not be the same as - * probabilities.length/types.length, as the runtime may store probabilities for a limited number of receivers. + * The estimated probabilities of the different receivers. This array needs to have the same length as + * {@link RiTypeProfile#types}. */ - public int morphism; + public double[] getProbabilities() { + return probabilities; + } /** * A list of receivers for which the runtime has recorded probability information. This array needs to have the same * length as {@link RiTypeProfile#probabilities}. */ - public RiResolvedType[] types; - - /** - * The estimated probabilities of the different receivers. This array needs to have the same length as - * {@link RiTypeProfile#types}. - */ - public float[] probabilities; + public RiResolvedType[] getTypes() { + return types; + } } diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java Mon Jan 23 13:22:43 2012 -0800 @@ -264,26 +264,29 @@ return null; } - int invokeBCI = invoke.bci(); RiProfilingInfo profilingInfo = parent.profilingInfo(); - RiResolvedType[] types = profilingInfo.getTypes(invokeBCI); - double[] typeProbabilities = profilingInfo.getTypeProbabilities(invokeBCI); - if (types != null && typeProbabilities != null && types.length == 1) { - assert types.length == typeProbabilities.length : "length must match"; - if (GraalOptions.InlineWithTypeCheck) { - // type check and inlining... - concrete = types[0].resolveMethodImpl(callTarget.targetMethod()); - if (concrete != null && checkTargetConditions(concrete)) { - double weight = callback == null ? 0 : callback.inliningWeight(parent, concrete, invoke); - return new TypeGuardInlineInfo(invoke, weight, level, concrete, types[0], typeProbabilities[0]); + RiTypeProfile typeProfile = profilingInfo.getTypeProfile(invoke.bci()); + if (typeProfile != null) { + RiResolvedType[] types = typeProfile.getTypes(); + double[] probabilities = typeProfile.getProbabilities(); + if (types != null && probabilities != null && types.length == 1) { + assert types.length == probabilities.length : "length must match"; + if (GraalOptions.InlineWithTypeCheck) { + // type check and inlining... + concrete = types[0].resolveMethodImpl(callTarget.targetMethod()); + if (concrete != null && checkTargetConditions(concrete)) { + double weight = callback == null ? 0 : callback.inliningWeight(parent, concrete, invoke); + return new TypeGuardInlineInfo(invoke, weight, level, concrete, types[0], probabilities[0]); + } + return null; + } else { + if (GraalOptions.TraceInlining) { + TTY.println("not inlining %s because GraalOptions.InlineWithTypeCheck == false", methodName(callTarget.targetMethod(), invoke)); + } + return null; } - return null; - } else { - if (GraalOptions.TraceInlining) { - TTY.println("not inlining %s because GraalOptions.InlineWithTypeCheck == false", methodName(callTarget.targetMethod(), invoke)); - } - return null; } + return null; } else { if (GraalOptions.TraceInlining) { TTY.println("not inlining %s because no monomorphic receiver could be found", methodName(callTarget.targetMethod(), invoke)); diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotVMConfig.java Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotVMConfig.java Mon Jan 23 13:22:43 2012 -0800 @@ -70,11 +70,12 @@ public int runtimeCallStackSize; public int klassModifierFlagsOffset; public int klassOopOffset; + public int klassOopGraalMirrorOffset; public int nmethodEntryOffset; // methodData information - public int methodDataDataOffset; - public int dataLayoutHeaderSizeInBytes; + public int methodDataOopDataOffset; + public int dataLayoutHeaderSize; public int dataLayoutTagOffset; public int dataLayoutFlagsOffset; public int dataLayoutBCIOffset; diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTMETHODDATAACCESSOR.JAVA --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTMETHODDATAACCESSOR.JAVA Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTMETHODDATAACCESSOR.JAVA Mon Jan 23 13:22:43 2012 -0800 @@ -29,8 +29,7 @@ int getBCI(HotSpotMethodData data, int position); int getSize(HotSpotMethodData data, int position); - RiResolvedType[] getTypes(HotSpotMethodData data, int position); - double[] getTypeProbabilities(HotSpotMethodData data, int position); + RiTypeProfile getTypeProfile(HotSpotMethodData data, int position); double getBranchTakenProbability(HotSpotMethodData data, int position); diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTPROFILINGINFOIMPL.JAVA --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTPROFILINGINFOIMPL.JAVA Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTPROFILINGINFOIMPL.JAVA Mon Jan 23 13:22:43 2012 -0800 @@ -48,15 +48,9 @@ } @Override - public RiResolvedType[] getTypes(int bci) { + public RiTypeProfile getTypeProfile(int bci) { findBCI(bci); - return dataAccessor.getTypes(methodData, position); - } - - @Override - public double[] getTypeProbabilities(int bci) { - findBCI(bci); - return dataAccessor.getTypeProbabilities(methodData, position); + return dataAccessor.getTypeProfile(methodData, position); } @Override diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodData.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodData.java Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodData.java Mon Jan 23 13:22:43 2012 -0800 @@ -48,6 +48,8 @@ private int normalDataSize; private int extraDataSize; + // TODO (ch) how are we going to handle methodData->is_mature() + private HotSpotMethodData(Compiler compiler) { super(compiler); throw new IllegalStateException("this constructor is never actually called, because the objects are allocated from within the VM"); @@ -94,18 +96,18 @@ } private int readUnsignedByte(int position, int offsetInCells) { - long fullOffset = computeFullOffset(position, offsetInCells); - return unsafe.getByte(javaMirror, fullOffset) & 0xFF; + long offsetInBytes = computeOffsetInBytes(position, offsetInCells); + return unsafe.getByte(javaMirror, offsetInBytes) & 0xFF; } private int readUnsignedShort(int position, int offsetInCells) { - long fullOffset = computeFullOffset(position, offsetInCells); - return unsafe.getShort(javaMirror, fullOffset) & 0xFFFF; + long offsetInBytes = computeOffsetInBytes(position, offsetInCells); + return unsafe.getShort(javaMirror, offsetInBytes) & 0xFFFF; } private long readUnsignedInt(int position, int offsetInCells) { - long fullOffset = computeFullOffset(position, offsetInCells); - return unsafe.getInt(javaMirror, fullOffset) & 0xFFFFFFFFL; + long offsetInBytes = computeOffsetInBytes(position, offsetInCells); + return unsafe.getInt(javaMirror, offsetInBytes) & 0xFFFFFFFFL; } private int readUnsignedIntAsSignedInt(int position, int offsetInCells) { @@ -114,22 +116,26 @@ } private int readInt(int position, int offsetInCells) { - long fullOffset = computeFullOffset(position, offsetInCells); - return unsafe.getInt(javaMirror, fullOffset); + long offsetInBytes = computeOffsetInBytes(position, offsetInCells); + return unsafe.getInt(javaMirror, offsetInBytes); + } + + private Object readObject(int position, int offsetInCells) { + long offsetInBytes = computeOffsetInBytes(position, offsetInCells); + return unsafe.getObject(javaMirror, offsetInBytes); } private static int truncateLongToInt(long value) { return value > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) value; } - private static int computeFullOffset(int position, int offsetInCells) { + private static int computeOffsetInBytes(int position, int offsetInCells) { HotSpotVMConfig config = getHotSpotVMConfig(); - return config.methodDataDataOffset + position + offsetInCells * config.dataLayoutCellSize; + return config.methodDataOopDataOffset + position + offsetInCells * config.dataLayoutCellSize; } private static HotSpotVMConfig getHotSpotVMConfig() { - // TODO: implement, cache config somewhere? - return null; + return CompilerImpl.getInstance().getConfig(); } private abstract static class AbstractMethodDataAccessor implements HotSpotMethodDataAccessor { @@ -162,7 +168,7 @@ @Override public int getSize(HotSpotMethodData data, int position) { HotSpotVMConfig config = getHotSpotVMConfig(); - return config.dataLayoutHeaderSizeInBytes + (staticCellCount + getDynamicCellCount(data, position)) * config.dataLayoutCellSize; + return config.dataLayoutHeaderSize + (staticCellCount + getDynamicCellCount(data, position)) * config.dataLayoutCellSize; } @Override @@ -172,12 +178,7 @@ } @Override - public RiResolvedType[] getTypes(HotSpotMethodData data, int position) { - return null; - } - - @Override - public double[] getTypeProbabilities(HotSpotMethodData data, int position) { + public RiTypeProfile getTypeProfile(HotSpotMethodData data, int position) { return null; } @@ -201,7 +202,7 @@ return data.readUnsignedByte(position, config.dataLayoutFlagsOffset); } - protected int getDynamicCellCount(HotSpotMethodData data, int position) { + protected int getDynamicCellCount(@SuppressWarnings("unused") HotSpotMethodData data, @SuppressWarnings("unused") int position) { return 0; } } @@ -306,31 +307,55 @@ } @Override - public double[] getTypeProbabilities(HotSpotMethodData data, int position) { + public RiTypeProfile getTypeProfile(HotSpotMethodData data, int position) { HotSpotVMConfig config = getHotSpotVMConfig(); int typeProfileWidth = config.typeProfileWidth; - long total = 0; - double[] result = new double[typeProfileWidth]; + RiResolvedType[] sparseTypes = new RiResolvedType[typeProfileWidth]; + double[] counts = new double[typeProfileWidth]; + long totalCount = 0; + int entries = 0; for (int i = 0; i < typeProfileWidth; i++) { - long count = data.readUnsignedInt(position, getCountOffset(i)); - total += count; - result[i] = count; + Object receiverKlassOop = data.readObject(position, getReceiverOffset(i)); + if (receiverKlassOop != null) { + Object graalMirror = unsafe.getObject(receiverKlassOop, (long) config.klassOopGraalMirrorOffset); + if (graalMirror == null) { + Class javaClass = (Class) unsafe.getObject(receiverKlassOop, (long) config.classMirrorOffset); + graalMirror = CompilerImpl.getInstance().getVMEntries().getType(javaClass); + assert graalMirror != null : "must not return null"; + } + + long count = data.readUnsignedInt(position, getCountOffset(i)); + if (count > 0) { + totalCount += count; + counts[entries] = count; + entries++; + } + + sparseTypes[i] = (RiResolvedType) graalMirror; + } } - if (total != 0) { - for (int i = 0; i < typeProfileWidth; i++) { - result[i] = result[i] / total; - } + RiResolvedType[] types; + double[] probabilities; + + if (entries <= 0) { + return null; + } else if (entries < typeProfileWidth) { + RiResolvedType[] compactedTypes = new RiResolvedType[entries]; + System.arraycopy(sparseTypes, 0, compactedTypes, 0, entries); + types = compactedTypes; + probabilities = new double[entries]; + } else { + types = sparseTypes; + probabilities = counts; } - return result; - } - @Override - public RiResolvedType[] getTypes(HotSpotMethodData data, int position) { - // TODO: seems to require a native call... - return null; + for (int i = 0; i < typeProfileWidth; i++) { + probabilities[i] = counts[i] / totalCount; + } + return new RiTypeProfile(types, probabilities); } @Override @@ -414,8 +439,13 @@ public double getBranchTakenProbability(HotSpotMethodData data, int position) { long takenCount = data.readUnsignedInt(position, TAKEN_COUNT_OFFSET); long notTakenCount = data.readUnsignedInt(position, NOT_TAKEN_COUNT_OFFSET); - double total = takenCount + notTakenCount; - return takenCount / total; + long total = takenCount + notTakenCount; + + if (total < 40) { + return -1; + } else { + return takenCount / (double) total; + } } } @@ -454,6 +484,8 @@ @Override public double[] getSwitchProbabilities(HotSpotMethodData data, int position) { int length = getLength(data, position); + assert length > 0 : "switch must have at least the default case"; + long total = 0; double[] result = new double[length]; @@ -464,7 +496,9 @@ result[i] = count; } - if (total != 0) { + if (total < 10 * (length + 2)) { + return null; + } else { for (int i = 0; i < length; i++) { result[i] = result[i] / total; } @@ -475,8 +509,8 @@ result[0] = result[length - 1]; result[length - 1] = defaultCase; } + return result; } - return result; } @Override diff -r 271220b49abc -r 4e3aaf14cbc6 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl.java Fri Jan 20 18:24:17 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl.java Mon Jan 23 13:22:43 2012 -0800 @@ -242,15 +242,18 @@ TTY.println(" implicitExceptionSeen@%d: true", i); } - RiResolvedType[] types = profilingInfo.getTypes(i); - double[] typeProbabilities = profilingInfo.getTypeProbabilities(i); - if (types != null && typeProbabilities != null) { - assert types.length == typeProbabilities.length : "length must match"; - TTY.print(" types@%d:", i); - for (int j = 0; j < types.length; j++) { - TTY.print(" %s (%f)", types[j], typeProbabilities[j]); + RiTypeProfile typeProfile = profilingInfo.getTypeProfile(i); + if (typeProfile != null) { + RiResolvedType[] types = typeProfile.getTypes(); + double[] probabilities = typeProfile.getProbabilities(); + if (types != null && probabilities != null) { + assert types.length == probabilities.length : "length must match"; + TTY.print(" types@%d:", i); + for (int j = 0; j < types.length; j++) { + TTY.print(" %s (%f)", types[j], probabilities[j]); + } + TTY.println(); } - TTY.println(); } } } diff -r 271220b49abc -r 4e3aaf14cbc6 src/share/vm/classfile/systemDictionary.hpp --- a/src/share/vm/classfile/systemDictionary.hpp Fri Jan 20 18:24:17 2012 -0800 +++ b/src/share/vm/classfile/systemDictionary.hpp Mon Jan 23 13:22:43 2012 -0800 @@ -193,6 +193,7 @@ template(HotSpotField_klass, com_oracle_max_graal_hotspot_HotSpotField, Opt) \ template(HotSpotCompiledMethod_klass, com_oracle_max_graal_hotspot_HotSpotCompiledMethod, Opt) \ template(HotSpotMethodResolved_klass, com_oracle_max_graal_hotspot_ri_HotSpotMethodResolved, Opt) \ + template(HotSpotMethodData_klass, com_oracle_max_graal_hotspot_HotSpotMethodData, Opt) \ template(HotSpotTargetMethod_klass, com_oracle_max_graal_hotspot_HotSpotTargetMethod, Opt) \ template(HotSpotExceptionHandler_klass, com_oracle_max_graal_hotspot_HotSpotExceptionHandler, Opt) \ template(HotSpotProxy_klass, com_oracle_max_graal_hotspot_HotSpotProxy, Opt) \ diff -r 271220b49abc -r 4e3aaf14cbc6 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Fri Jan 20 18:24:17 2012 -0800 +++ b/src/share/vm/classfile/vmSymbols.hpp Mon Jan 23 13:22:43 2012 -0800 @@ -272,6 +272,7 @@ template(com_oracle_max_graal_hotspot_bridge_VMToCompiler, "com/oracle/max/graal/hotspot/bridge/VMToCompiler") \ template(com_oracle_max_graal_hotspot_ri_HotSpotMethodResolved, "com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl") \ template(com_oracle_max_graal_hotspot_HotSpotTargetMethod, "com/oracle/max/graal/hotspot/HotSpotTargetMethod") \ + template(com_oracle_max_graal_hotspot_HotSpotMethodData, "com/oracle/max/graal/hotspot/HotSpotMethodData") \ template(com_oracle_max_graal_hotspot_HotSpotField, "com/oracle/max/graal/hotspot/ri/HotSpotField") \ template(com_oracle_max_graal_hotspot_HotSpotCompiledMethod, "com/oracle/max/graal/hotspot/ri/HotSpotCompiledMethod") \ template(com_oracle_max_graal_hotspot_HotSpotOptions, "com/oracle/max/graal/hotspot/HotSpotOptions") \ diff -r 271220b49abc -r 4e3aaf14cbc6 src/share/vm/graal/graalCompiler.cpp --- a/src/share/vm/graal/graalCompiler.cpp Fri Jan 20 18:24:17 2012 -0800 +++ b/src/share/vm/graal/graalCompiler.cpp Mon Jan 23 13:22:43 2012 -0800 @@ -275,18 +275,20 @@ return obj; } -Handle GraalCompiler::createHotSpotProfilingInfo(methodDataHandle method_data, TRAPS) { +Handle GraalCompiler::createHotSpotMethodData(methodDataHandle method_data, TRAPS) { if(method_data->graal_mirror() != NULL) { - assert(method_data->graal_mirror()->is_a(HotSpotProfilingInfo::klass()), "unexpected class"); + assert(method_data->graal_mirror()->is_a(HotSpotMethodData::klass()), "unexpected class"); return method_data->graal_mirror(); } - instanceKlass::cast(HotSpotProfilingInfo::klass())->initialize(CHECK_NULL); - Handle obj = instanceKlass::cast(HotSpotProfilingInfo::klass())->allocate_instance(CHECK_NULL); + instanceKlass::cast(HotSpotMethodData::klass())->initialize(CHECK_NULL); + Handle obj = instanceKlass::cast(HotSpotMethodData::klass())->allocate_instance(CHECK_NULL); assert(obj.not_null, "must be"); - HotSpotProfilingInfo::set_compiler(obj, VMToCompiler::compilerInstance()()); - HotSpotProfilingInfo::set_javaMirror(obj, method_data()); + HotSpotMethodData::set_compiler(obj, VMToCompiler::compilerInstance()()); + HotSpotMethodData::set_javaMirror(obj, method_data()); + HotSpotMethodData::set_normalDataSize(obj, method_data()->data_size()); + HotSpotMethodData::set_extraDataSize(obj, method_data()->extra_data_size()); method_data->set_graal_mirror(obj()); return obj; diff -r 271220b49abc -r 4e3aaf14cbc6 src/share/vm/graal/graalCompiler.hpp --- a/src/share/vm/graal/graalCompiler.hpp Fri Jan 20 18:24:17 2012 -0800 +++ b/src/share/vm/graal/graalCompiler.hpp Mon Jan 23 13:22:43 2012 -0800 @@ -67,6 +67,7 @@ static Handle createHotSpotTypeResolved(KlassHandle klass, Handle name, TRAPS); static Handle createHotSpotMethodResolved(methodHandle method, TRAPS); + static Handle createHotSpotMethodData(methodDataHandle method_data, TRAPS); void exit(); diff -r 271220b49abc -r 4e3aaf14cbc6 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Fri Jan 20 18:24:17 2012 -0800 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Mon Jan 23 13:22:43 2012 -0800 @@ -182,26 +182,13 @@ return getMethodFromHotSpotMethod(hotspot_method)->invocation_count(); } -// public native int RiMethod_exceptionProbability(long vmId, int bci); -JNIEXPORT jint JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2exceptionProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { - TRACE_graal_3("CompilerToVM::RiMethod_exceptionProbability"); +JNIEXPORT jobject JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1methodData(JNIEnv *, jobject, jobject hotspot_method) { + TRACE_graal_3("CompilerToVM::RiMethod_methodData"); VM_ENTRY_MARK; - ResourceMark rm; - methodHandle method = getMethodFromHotSpotMethod(hotspot_method); - methodDataHandle method_data = method->method_data(); - if (method_data == NULL || !method_data->is_mature()) { - return -1; - } - ProfileData* data = method_data->bci_to_data(bci); - if (data == NULL) { - return 0; - } - uint trap = Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0; - if (trap > 0) { - return 100; - } else { - return trap; - } + + methodDataHandle method_data = getMethodFromHotSpotMethod(hotspot_method)->method_data(); + Handle graalMethodData = GraalCompiler::createHotSpotMethodData(method_data, THREAD); + return JNIHandles::make_local(THREAD, graalMethodData()); } // ------------------------------------------------------------------ @@ -230,137 +217,6 @@ return count; } -// public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); -JNIEXPORT jobject JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) { - TRACE_graal_3("CompilerToVM::RiMethod_typeProfile"); - VM_ENTRY_MARK; - Handle obj; - - methodHandle method = getMethodFromHotSpotMethod(hotspot_method); - methodDataHandle method_data = method->method_data(); - if (method_data == NULL || !method_data->is_mature()) { - return NULL; - } - ResourceMark rm; - ProfileData* data = method_data->bci_to_data(bci); - if (data != NULL && data->is_ReceiverTypeData()) { - ReceiverTypeData* recv = data->as_ReceiverTypeData(); - GrowableArray receivers; - GrowableArray counts; - // determine morphism - uint total_count = 0; - for (uint i = 0; i < recv->row_limit(); i++) { - klassOop receiver = recv->receiver(i); - if (receiver == NULL) continue; - uint count = recv->receiver_count(i); - total_count += count; - receivers.append(receiver); - counts.append(count); - } - - instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); - obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); - assert(obj() != NULL, "must succeed in allocating instance"); - - int count = MAX2(total_count, recv->count()); - RiTypeProfile::set_count(obj, scale_count(method_data(), count)); - RiTypeProfile::set_morphism(obj, receivers.length()); - - if (receivers.length() > 0) { - typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, receivers.length(), CHECK_NULL); - objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), receivers.length(), CHECK_NULL); - for (int i = 0; i < receivers.length(); i++) { - KlassHandle receiver = receivers.at(i); - - float prob = counts.at(i) / (float) total_count; - Handle type = GraalCompiler::get_RiType(receiver, CHECK_NULL); - - probabilities->float_at_put(i, prob); - types->obj_at_put(i, type()); - - } - - RiTypeProfile::set_probabilities(obj, probabilities()); - RiTypeProfile::set_types(obj, types()); - } else { - RiTypeProfile::set_probabilities(obj, NULL); - RiTypeProfile::set_types(obj, NULL); - } - } - return JNIHandles::make_local(obj()); -} - -JNIEXPORT jdouble JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { - TRACE_graal_3("CompilerToVM::RiMethod_typeProfile"); - ResourceMark rm; - methodHandle method = getMethodFromHotSpotMethod(hotspot_method); - methodDataHandle method_data = method->method_data(); - - if (method_data == NULL || !method_data->is_mature()) return -1; - method_data->bci_to_data(bci); - - ProfileData* data = method_data->bci_to_data(bci); - if (data == NULL || !data->is_JumpData()) return -1; - - // get taken and not taken values - int taken = data->as_JumpData()->taken(); - int not_taken = 0; - if (data->is_BranchData()) { - not_taken = data->as_BranchData()->not_taken(); - } - - // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. - // We also check that individual counters are positive first, otherwise the sum can become positive. - if (taken < 0 || not_taken < 0 || taken + not_taken < 40) return -1; - - // Pin probability to sane limits - if (taken == 0) - return 0; - else if (not_taken == 0) - return 1; - else { // Compute probability of true path - return (jdouble)(taken) / (taken + not_taken); - } -} - -JNIEXPORT jobject JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_2switchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { - TRACE_graal_3("CompilerToVM::RiMethod_typeProfile"); - VM_ENTRY_MARK; - ResourceMark rm; - methodHandle method = getMethodFromHotSpotMethod(hotspot_method); - methodDataHandle method_data = method->method_data(); - - if (method_data == NULL || !method_data->is_mature()) return NULL; - - ProfileData* data = method_data->bci_to_data(bci); - if (data == NULL || !data->is_MultiBranchData()) return NULL; - - MultiBranchData* branch_data = data->as_MultiBranchData(); - - long sum = 0; - int cases = branch_data->number_of_cases(); - GrowableArray* counts = new GrowableArray(cases + 1); - - for (int i = 0; i < cases; i++) { - uint value = branch_data->count_at(i); - sum += value; - counts->append(value); - } - uint value = branch_data->default_count(); - sum += value; - counts->append(value); - - // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. - // We also check that individual counters are positive first, otherwise the sum can become positive. - if (sum < 10 * (cases + 3)) return NULL; - - typeArrayOop probability = oopFactory::new_typeArray(T_DOUBLE, cases + 1, CHECK_NULL); - for (int i = 0; i < cases + 1; i++) { - probability->double_at_put(i, counts->at(i) / (double) sum); - } - return JNIHandles::make_local(probability); -} - // public native boolean RiMethod_hasCompiledCode(HotSpotMethodResolved method); JNIEXPORT jboolean JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1hasCompiledCode(JNIEnv *, jobject, jobject hotspot_method) { TRACE_graal_3("CompilerToVM::RiMethod_hasCompiledCode"); @@ -873,7 +729,16 @@ set_int(env, config, "threadExceptionPcOffset", in_bytes(JavaThread::exception_pc_offset())); set_int(env, config, "threadMultiNewArrayStorage", in_bytes(JavaThread::graal_multinewarray_storage_offset())); set_int(env, config, "classMirrorOffset", klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes()); - set_int(env, config, "methodDataDataOffset", in_bytes(methodDataOopDesc::data_offset)); + + set_int(env, config, "methodDataOopDataOffset", in_bytes(methodDataOopDesc::data_offset())); + set_int(env, config, "dataLayoutHeaderSize", DataLayout::header_size_in_bytes()); + set_int(env, config, "dataLayoutTagOffset", in_bytes(DataLayout::tag_offset())); + set_int(env, config, "dataLayoutFlagsOffset", in_bytes(DataLayout::flags_offset())); + set_int(env, config, "dataLayoutBCIOffset", in_bytes(DataLayout::bci_offset())); + set_int(env, config, "dataLayoutCellsOffset", in_bytes(DataLayout::cell_offset(0))); + set_int(env, config, "dataLayoutCellSize", DataLayout::cell_size); + set_int(env, config, "bciProfileWidth", BciProfileWidth); + set_int(env, config, "typeProfileWidth", TypeProfileWidth); set_long(env, config, "debugStub", VmIds::addStub((address)warning)); set_long(env, config, "instanceofStub", VmIds::addStub(Runtime1::entry_for(Runtime1::slow_subtype_check_id))); @@ -897,7 +762,9 @@ set_long(env, config, "safepointPollingAddress", (jlong)(os::get_polling_page() + (SafepointPollOffset % os::vm_page_size()))); set_int(env, config, "runtimeCallStackSize", (jint)frame::arg_reg_save_area_bytes); set_int(env, config, "klassModifierFlagsOffset", Klass::modifier_flags_offset_in_bytes() + sizeof(oopDesc)); + set_int(env, config, "klassOopGraalMirrorOffset", klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes()); set_int(env, config, "klassOopOffset", java_lang_Class::klass_offset_in_bytes()); + set_boolean(env, config, "isPollingPageFar", Assembler::is_polling_page_far()); set_int(env, config, "nmethodEntryOffset", nmethod::verified_entry_point_offset()); @@ -986,7 +853,6 @@ #define METHOD "Lcom/oracle/max/cri/ri/RiMethod;" #define RESOLVED_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotMethodResolved;" #define REFLECT_METHOD "Ljava/lang/reflect/Method;" -#define PROFILING_INFO "Lcom/oracle/max/cri/ri/RiProfilingInfo;" #define SIGNATURE "Lcom/oracle/max/cri/ri/RiSignature;" #define FIELD "Lcom/oracle/max/cri/ri/RiField;" #define RESOLVED_FIELD "Lcom/oracle/max/cri/ri/RiResolvedField;" @@ -996,6 +862,7 @@ #define CONFIG "Lcom/oracle/max/graal/hotspot/HotSpotVMConfig;" #define HS_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotMethod;" #define HS_COMP_METHOD "Lcom/oracle/max/graal/hotspot/ri/HotSpotCompiledMethod;" +#define METHOD_DATA "Lcom/oracle/max/graal/hotspot/HotSpotMethodData;" #define CI_CONSTANT "Lcom/oracle/max/cri/ci/CiConstant;" #define CI_KIND "Lcom/oracle/max/cri/ci/CiKind;" #define CI_RUNTIME_CALL "Lcom/oracle/max/cri/ci/CiRuntimeCall;" @@ -1010,11 +877,8 @@ {CC"RiMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(RiMethod_1hasBalancedMonitors)}, {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(RiMethod_1uniqueConcreteMethod)}, {CC"getRiMethod", CC"("REFLECT_METHOD")"METHOD, FN_PTR(getRiMethod)}, - {CC"RiMethod_typeProfile", CC"("RESOLVED_METHOD"I)"TYPE_PROFILE, FN_PTR(RiMethod_2typeProfile)}, - {CC"RiMethod_branchProbability", CC"("RESOLVED_METHOD"I)D", FN_PTR(RiMethod_2branchProbability)}, - {CC"RiMethod_switchProbability", CC"("RESOLVED_METHOD"I)[D", FN_PTR(RiMethod_2switchProbability)}, + {CC"RiMethod_methodData", CC"("RESOLVED_METHOD"I)"METHOD_DATA, FN_PTR(RiMethod_1methodData)}, {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(RiMethod_1invocationCount)}, - {CC"RiMethod_exceptionProbability", CC"("RESOLVED_METHOD"I)I", FN_PTR(RiMethod_2exceptionProbability)}, {CC"RiMethod_hasCompiledCode", CC"("RESOLVED_METHOD")Z", FN_PTR(RiMethod_1hasCompiledCode)}, {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(RiSignature_1lookupType)}, {CC"RiConstantPool_lookupConstant", CC"("RESOLVED_TYPE"I)"OBJECT, FN_PTR(RiConstantPool_1lookupConstant)}, diff -r 271220b49abc -r 4e3aaf14cbc6 src/share/vm/graal/graalJavaAccess.hpp --- a/src/share/vm/graal/graalJavaAccess.hpp Fri Jan 20 18:24:17 2012 -0800 +++ b/src/share/vm/graal/graalJavaAccess.hpp Mon Jan 23 13:22:43 2012 -0800 @@ -68,9 +68,11 @@ int_field(HotSpotMethodResolved, maxLocals) \ int_field(HotSpotMethodResolved, maxStackSize) \ end_class \ - start_class(HotSpotProfilingInfo) \ - oop_field(HotSpotProfilingInfo, compiler, "Lcom/oracle/max/graal/hotspot/Compiler;") \ - oop_field(HotSpotProfilingInfo, javaMirror, "Ljava/lang/Object;") \ + start_class(HotSpotMethodData) \ + oop_field(HotSpotMethodData, compiler, "Lcom/oracle/max/graal/hotspot/Compiler;") \ + oop_field(HotSpotMethodData, javaMirror, "Ljava/lang/Object;") \ + int_field(HotSpotMethodData, normalDataSize) \ + int_field(HotSpotMethodData, extraDataSize) \ end_class \ start_class(HotSpotType) \ oop_field(HotSpotType, name, "Ljava/lang/String;") \