# HG changeset patch # User Christian Haeubl # Date 1327440316 28800 # Node ID 48756b901156929a4fb9a566cbd3a009a12607fc # Parent e2a477f9791b062bc984fc9a29743ad7270ca217 bugfixes diff -r e2a477f9791b -r 48756b901156 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/CompilerToVM.java Tue Jan 24 23:47:20 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/CompilerToVM.java Tue Jan 24 13:25:16 2012 -0800 @@ -51,6 +51,8 @@ HotSpotMethodData RiMethod_methodData(HotSpotMethodResolved method); + boolean HotSpotMethodData_isMature(HotSpotMethodData methodData); + RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass); Object RiConstantPool_lookupConstant(HotSpotTypeResolved pool, int cpi); diff -r e2a477f9791b -r 48756b901156 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/CompilerToVMImpl.java Tue Jan 24 23:47:20 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/CompilerToVMImpl.java Tue Jan 24 13:25:16 2012 -0800 @@ -114,6 +114,9 @@ public native HotSpotMethodData RiMethod_methodData(HotSpotMethodResolved method); @Override + public native boolean HotSpotMethodData_isMature(HotSpotMethodData methodData); + + @Override public native RiType getType(Class javaClass); @Override diff -r e2a477f9791b -r 48756b901156 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTNOPROFILINGINFO.JAVA --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTNOPROFILINGINFO.JAVA Tue Jan 24 13:25:16 2012 -0800 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.graal.hotspot.ri; + +import com.oracle.max.cri.ri.*; +import com.oracle.max.graal.hotspot.*; +import com.oracle.max.graal.hotspot.Compiler; + + +public final class HotSpotNoProfilingInfo extends CompilerObject implements RiProfilingInfo { + /** + * + */ + private static final long serialVersionUID = 4357945025049704109L; + private static final HotSpotMethodDataAccessor noData = HotSpotMethodData.getNoDataAccessor(); + + public HotSpotNoProfilingInfo(Compiler compiler) { + super(compiler); + } + + @Override + public RiTypeProfile getTypeProfile(int bci) { + return noData.getTypeProfile(null, -1); + } + + @Override + public double getBranchTakenProbability(int bci) { + return noData.getBranchTakenProbability(null, -1); + } + + @Override + public double[] getSwitchProbabilities(int bci) { + return noData.getSwitchProbabilities(null, -1); + } + + @Override + public boolean getImplicitExceptionSeen(int bci) { + return noData.getImplicitExceptionSeen(null, -1); + } + + @Override + public int getExecutionCount(int bci) { + return noData.getExecutionCount(null, -1); + } +} diff -r e2a477f9791b -r 48756b901156 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTPROFILINGINFO.JAVA --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTPROFILINGINFO.JAVA Tue Jan 24 13:25:16 2012 -0800 @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.graal.hotspot.ri; + +import com.oracle.max.cri.ri.*; +import com.oracle.max.graal.hotspot.*; +import com.oracle.max.graal.hotspot.Compiler; + + +public final class HotSpotProfilingInfo extends CompilerObject implements RiProfilingInfo { + + /** + * + */ + private static final long serialVersionUID = -8307682725047864875L; + + private int position; + private int hintPosition; + private int hintBCI; + private HotSpotMethodDataAccessor dataAccessor; + private HotSpotMethodData methodData; + + public HotSpotProfilingInfo(Compiler compiler, HotSpotMethodData methodData) { + super(compiler); + this.methodData = methodData; + hintPosition = 0; + hintBCI = -1; + } + + @Override + public RiTypeProfile getTypeProfile(int bci) { + findBCI(bci); + return dataAccessor.getTypeProfile(methodData, position); + } + + @Override + public double getBranchTakenProbability(int bci) { + findBCI(bci); + return dataAccessor.getBranchTakenProbability(methodData, position); + } + + @Override + public double[] getSwitchProbabilities(int bci) { + findBCI(bci); + return dataAccessor.getSwitchProbabilities(methodData, position); + } + + @Override + public boolean getImplicitExceptionSeen(int bci) { + findBCI(bci); + return dataAccessor.getImplicitExceptionSeen(methodData, position); + } + + @Override + public int getExecutionCount(int bci) { + findBCI(bci); + return dataAccessor.getExecutionCount(methodData, position); + } + + private void findBCI(int targetBCI) { + assert targetBCI >= 0 : "invalid BCI"; + + if (methodData.hasNormalData()) { + int currentPosition = targetBCI < hintBCI ? 0 : hintPosition; + HotSpotMethodDataAccessor currentAccessor; + while ((currentAccessor = methodData.getNormalData(currentPosition)) != null) { + int currentBCI = currentAccessor.getBCI(methodData, currentPosition); + if (currentBCI == targetBCI) { + normalDataFound(currentAccessor, currentPosition, currentBCI); + return; + } else if (currentBCI > targetBCI) { + break; + } + currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); + } + } + + if (methodData.hasExtraData()) { + int currentPosition = 0; + HotSpotMethodDataAccessor currentAccessor; + while ((currentAccessor = methodData.getExtraData(currentPosition)) != null) { + int currentBCI = currentAccessor.getBCI(methodData, currentPosition); + if (currentBCI == targetBCI) { + extraDataFound(currentAccessor, currentPosition); + return; + } + currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); + } + } + + noDataFound(); + } + + private void normalDataFound(HotSpotMethodDataAccessor data, int pos, int bci) { + setCurrentData(data, pos); + this.hintPosition = position; + this.hintBCI = bci; + } + + private void extraDataFound(HotSpotMethodDataAccessor data, int pos) { + setCurrentData(data, pos); + } + + private void noDataFound() { + setCurrentData(HotSpotMethodData.getNoDataAccessor(), -1); + } + + private void setCurrentData(HotSpotMethodDataAccessor dataAccessor, int position) { + this.dataAccessor = dataAccessor; + this.position = position; + } +} diff -r e2a477f9791b -r 48756b901156 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 Tue Jan 24 23:47:20 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.max.graal.hotspot.ri; - -import com.oracle.max.cri.ri.*; -import com.oracle.max.graal.hotspot.*; -import com.oracle.max.graal.hotspot.Compiler; - - -public final class HotSpotProfilingInfoImpl extends CompilerObject implements RiProfilingInfo { - - /** - * - */ - private static final long serialVersionUID = -8307682725047864875L; - - private int position; - private int hintPosition; - private int hintBCI; - private HotSpotMethodDataAccessor dataAccessor; - private HotSpotMethodData methodData; - - public HotSpotProfilingInfoImpl(Compiler compiler, HotSpotMethodData methodData) { - super(compiler); - this.methodData = methodData; - hintPosition = 0; - hintBCI = -1; - } - - @Override - public RiTypeProfile getTypeProfile(int bci) { - findBCI(bci); - return dataAccessor.getTypeProfile(methodData, position); - } - - @Override - public double getBranchTakenProbability(int bci) { - findBCI(bci); - return dataAccessor.getBranchTakenProbability(methodData, position); - } - - @Override - public double[] getSwitchProbabilities(int bci) { - findBCI(bci); - return dataAccessor.getSwitchProbabilities(methodData, position); - } - - @Override - public boolean getImplicitExceptionSeen(int bci) { - findBCI(bci); - return dataAccessor.getImplicitExceptionSeen(methodData, position); - } - - @Override - public int getExecutionCount(int bci) { - findBCI(bci); - return dataAccessor.getExecutionCount(methodData, position); - } - - private void findBCI(int targetBCI) { - assert targetBCI >= 0 : "invalid BCI"; - if (methodData != null) { - if (methodData.hasNormalData()) { - int currentPosition = targetBCI < hintBCI ? 0 : hintPosition; - HotSpotMethodDataAccessor currentAccessor; - while ((currentAccessor = methodData.getNormalData(currentPosition)) != null) { - int currentBCI = currentAccessor.getBCI(methodData, currentPosition); - if (currentBCI == targetBCI) { - normalDataFound(currentAccessor, currentPosition, currentBCI); - return; - } else if (currentBCI > targetBCI) { - break; - } - currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); - } - } - - if (methodData.hasExtraData()) { - int currentPosition = 0; - HotSpotMethodDataAccessor currentAccessor; - while ((currentAccessor = methodData.getExtraData(currentPosition)) != null) { - int currentBCI = currentAccessor.getBCI(methodData, currentPosition); - if (currentBCI == targetBCI) { - extraDataFound(currentAccessor, currentPosition); - return; - } - currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition); - } - } - } - - noDataFound(); - } - - private void normalDataFound(HotSpotMethodDataAccessor data, int pos, int bci) { - setCurrentData(data, pos); - this.hintPosition = position; - this.hintBCI = bci; - } - - private void extraDataFound(HotSpotMethodDataAccessor data, int pos) { - setCurrentData(data, pos); - } - - private void noDataFound() { - setCurrentData(HotSpotMethodData.getNoDataAccessor(), -1); - } - - private void setCurrentData(HotSpotMethodDataAccessor dataAccessor, int position) { - this.dataAccessor = dataAccessor; - this.position = position; - } -} diff -r e2a477f9791b -r 48756b901156 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 Tue Jan 24 23:47:20 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodData.java Tue Jan 24 13:25:16 2012 -0800 @@ -53,6 +53,7 @@ private Object hotspotMirror; private int normalDataSize; private int extraDataSize; + private boolean mature; // TODO (ch) how are we going to handle methodData->is_mature() @@ -69,6 +70,13 @@ return extraDataSize > 0; } + public boolean isMature() { + if (!mature) { + mature = compiler.getVMEntries().HotSpotMethodData_isMature(this); + } + return mature; + } + public boolean isWithin(int position) { return position >= 0 && position < normalDataSize + extraDataSize; } @@ -490,11 +498,17 @@ long totalCount = 0; double[] result = new double[length]; - for (int i = 0; i < length; i++) { - int offset = getCountOffset(i); - long count = data.readUnsignedInt(position, offset); + // default case is expected as last entry + int offset = getCountOffset(0); + long count = data.readUnsignedInt(position, offset); + totalCount += count; + result[length - 1] = count; + + for (int i = 1; i < length; i++) { + offset = getCountOffset(i); + count = data.readUnsignedInt(position, offset); totalCount += count; - result[i] = count; + result[i - 1] = count; } if (totalCount < 10 * (length + 2)) { @@ -503,13 +517,6 @@ for (int i = 0; i < length; i++) { result[i] = result[i] / totalCount; } - - // default case is expected as last entry - if (length >= 2) { - double defaultCase = result[0]; - result[0] = result[length - 1]; - result[length - 1] = defaultCase; - } return result; } } diff -r e2a477f9791b -r 48756b901156 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 Tue Jan 24 23:47:20 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl.java Tue Jan 24 13:25:16 2012 -0800 @@ -196,12 +196,16 @@ public RiProfilingInfo profilingInfo() { if (methodData == null) { methodData = compiler.getVMEntries().RiMethod_methodData(this); - // TEMP: if (methodData != null) { dumpProfile(); } } - return new HotSpotProfilingInfoImpl(compiler, methodData); + + if (methodData == null || !methodData.isMature()) { + return new HotSpotNoProfilingInfo(compiler); + } else { + return new HotSpotProfilingInfo(compiler, methodData); + } } @Override diff -r e2a477f9791b -r 48756b901156 src/share/vm/graal/graalCompiler.cpp --- a/src/share/vm/graal/graalCompiler.cpp Tue Jan 24 23:47:20 2012 -0800 +++ b/src/share/vm/graal/graalCompiler.cpp Tue Jan 24 13:25:16 2012 -0800 @@ -290,6 +290,7 @@ HotSpotMethodData::set_hotspotMirror(obj, method_data()); HotSpotMethodData::set_normalDataSize(obj, method_data()->data_size()); HotSpotMethodData::set_extraDataSize(obj, method_data()->extra_data_size()); + HotSpotMethodData::set_mature(obj, method_data()->is_mature()); method_data->set_graal_mirror(obj()); return obj; diff -r e2a477f9791b -r 48756b901156 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Tue Jan 24 23:47:20 2012 -0800 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Tue Jan 24 13:25:16 2012 -0800 @@ -44,6 +44,10 @@ return (methodOop)HotSpotMethodResolved::javaMirror(hotspot_method); } +methodDataOop getMethodDataFromHotSpotMethodData(jobject hotspot_method_data) { + return (methodDataOop)HotSpotMethodData::hotspotMirror(JNIHandles::resolve(hotspot_method_data)); +} + // public byte[] RiMethod_code(HotSpotResolvedMethod method); JNIEXPORT jbyteArray JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_RiMethod_1code(JNIEnv *env, jobject, jobject hotspot_method) { TRACE_graal_3("CompilerToVM::RiMethod_code"); @@ -192,13 +196,17 @@ return NULL; } else { Handle graalMethodData = GraalCompiler::createHotSpotMethodData(method_data, THREAD); - tty->print_cr("--------"); - method_data->print_on(tty); - tty->print_cr("--------"); return JNIHandles::make_local(THREAD, graalMethodData()); } } +JNIEXPORT jboolean JNICALL Java_com_oracle_max_graal_hotspot_bridge_CompilerToVMImpl_HotSpotMethodData_1isMature(JNIEnv *, jobject, jobject hotspot_method_data) { + TRACE_graal_3("CompilerToVM::HotSpotMethodData_isMature"); + VM_ENTRY_MARK; + methodDataHandle method_data = getMethodDataFromHotSpotMethodData(hotspot_method_data); + return method_data->is_mature(); +} + // ------------------------------------------------------------------ // Adjust a CounterData count to be commensurate with // interpreter_invocation_count. If the MDO exists for @@ -922,6 +930,7 @@ {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(RiMethod_1uniqueConcreteMethod)}, {CC"getRiMethod", CC"("REFLECT_METHOD")"METHOD, FN_PTR(getRiMethod)}, {CC"RiMethod_methodData", CC"("RESOLVED_METHOD")"METHOD_DATA, FN_PTR(RiMethod_1methodData)}, + {CC"HotSpotMethodData_isMature", CC"("METHOD_DATA")Z", FN_PTR(HotSpotMethodData_1isMature)}, {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(RiMethod_1invocationCount)}, {CC"RiMethod_hasCompiledCode", CC"("RESOLVED_METHOD")Z", FN_PTR(RiMethod_1hasCompiledCode)}, {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(RiSignature_1lookupType)}, diff -r e2a477f9791b -r 48756b901156 src/share/vm/graal/graalJavaAccess.hpp --- a/src/share/vm/graal/graalJavaAccess.hpp Tue Jan 24 23:47:20 2012 -0800 +++ b/src/share/vm/graal/graalJavaAccess.hpp Tue Jan 24 13:25:16 2012 -0800 @@ -74,6 +74,7 @@ oop_field(HotSpotMethodData, hotspotMirror, "Ljava/lang/Object;") \ int_field(HotSpotMethodData, normalDataSize) \ int_field(HotSpotMethodData, extraDataSize) \ + boolean_field(HotSpotMethodData, mature) \ end_class \ start_class(HotSpotType) \ oop_field(HotSpotType, name, "Ljava/lang/String;") \