# HG changeset patch # User Lukas Stadler # Date 1307625927 -7200 # Node ID 0e3ec0a4eda4fa22df25309173a884b60bea1222 # Parent b78b4ae0757c6b8475b13df0c4e92fbeaf4cd853 RiTypeProfile information and invocation counters for RiMethods diff -r b78b4ae0757c -r 0e3ec0a4eda4 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Invoke.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Invoke.java Thu Jun 09 14:42:24 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Invoke.java Thu Jun 09 15:25:27 2011 +0200 @@ -84,6 +84,7 @@ public final RiMethod target; public final RiType returnType; public final int bci; // XXX needed because we can not compute the bci from the sateBefore bci of this Invoke was optimized from INVOKEINTERFACE to INVOKESPECIAL + public final RiTypeProfile profile; /** * Constructs a new Invoke instruction. @@ -95,12 +96,13 @@ * @param target the target method being called * @param stateBefore the state before executing the invocation */ - public Invoke(int bci, int opcode, CiKind result, Value[] args, RiMethod target, RiType returnType, Graph graph) { + public Invoke(int bci, int opcode, CiKind result, Value[] args, RiMethod target, RiType returnType, RiTypeProfile profile, Graph graph) { super(result, args.length, SUCCESSOR_COUNT, graph); this.opcode = opcode; this.target = target; this.returnType = returnType; this.bci = bci; + this.profile = profile; this.argumentCount = args.length; for (int i = 0; i < args.length; i++) { @@ -147,6 +149,10 @@ return target; } + public RiTypeProfile profile() { + return profile; + } + /** * Checks whether this invocation has a receiver object. * @return {@code true} if this invocation has a receiver object; {@code false} otherwise, if this is a @@ -196,7 +202,7 @@ @Override public Node copy(Graph into) { - Invoke x = new Invoke(bci, opcode, kind, new Value[argumentCount], target, returnType, into); + Invoke x = new Invoke(bci, opcode, kind, new Value[argumentCount], target, returnType, profile, into); return x; } } diff -r b78b4ae0757c -r 0e3ec0a4eda4 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java Thu Jun 09 14:42:24 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java Thu Jun 09 15:25:27 2011 +0200 @@ -906,7 +906,7 @@ private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool) { CiKind resultType = returnKind(target); - Invoke invoke = new Invoke(bci(), opcode, resultType.stackKind(), args, target, target.signature().returnType(method.holder()), graph); + Invoke invoke = new Invoke(bci(), opcode, resultType.stackKind(), args, target, target.signature().returnType(method.holder()), method.typeProfile(bci()), graph); Value result = appendWithBCI(invoke); invoke.setExceptionEdge(handleException(null, bci())); frameState.pushReturn(resultType, result); diff -r b78b4ae0757c -r 0e3ec0a4eda4 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Thu Jun 09 14:42:24 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Thu Jun 09 15:25:27 2011 +0200 @@ -135,6 +135,12 @@ private boolean checkInliningConditions(Invoke invoke) { String name = !trace ? null : invoke.id() + ": " + CiUtil.format("%H.%n(%p):%r", invoke.target, false); + if (invoke.profile() != null && invoke.profile().count < compilation.method.invocationCount() / 2) { + if (trace) { + System.out.println("not inlining " + name + " because the invocation counter is too low"); + } + return false; + } if (invoke.predecessors().size() == 0) { if (trace) { System.out.println("not inlining " + name + " because the invoke is dead code"); diff -r b78b4ae0757c -r 0e3ec0a4eda4 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolved.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolved.java Thu Jun 09 14:42:24 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolved.java Thu Jun 09 15:25:27 2011 +0200 @@ -39,6 +39,7 @@ private int accessFlags = -1; private int maxLocals = -1; private int maxStackSize = -1; + private int invocationCount = -1; private RiExceptionHandler[] exceptionHandlers; private RiSignature signature; private Boolean hasBalancedMonitors; @@ -89,12 +90,12 @@ @Override public boolean isClassInitializer() { - return "".equals(name); + return "".equals(name) && Modifier.isStatic(accessFlags()); } @Override public boolean isConstructor() { - return "".equals(name); + return "".equals(name) && !Modifier.isStatic(accessFlags()); } @Override @@ -189,4 +190,15 @@ public boolean minimalDebugInfo() { return false; } + + public int invocationCount() { + if (invocationCount == -1) { + invocationCount = compiler.getVMEntries().RiMethod_invocationCount(vmId); + } + return invocationCount; + } + + public RiTypeProfile typeProfile(int bci) { + return compiler.getVMEntries().RiMethod_typeProfile(vmId, bci); + } } diff -r b78b4ae0757c -r 0e3ec0a4eda4 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java Thu Jun 09 14:42:24 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java Thu Jun 09 15:25:27 2011 +0200 @@ -155,4 +155,12 @@ public int intrinsic() { return 0; } + + public int invocationCount() { + return -1; + } + + public RiTypeProfile typeProfile(int bci) { + return null; + } } diff -r b78b4ae0757c -r 0e3ec0a4eda4 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMEntries.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMEntries.java Thu Jun 09 14:42:24 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMEntries.java Thu Jun 09 15:25:27 2011 +0200 @@ -95,5 +95,9 @@ RiType getRiType(CiConstant constant); + int RiMethod_invocationCount(long vmId); + + RiTypeProfile RiMethod_typeProfile(long vmId, int bci); + // Checkstyle: resume } diff -r b78b4ae0757c -r 0e3ec0a4eda4 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMEntriesNative.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMEntriesNative.java Thu Jun 09 14:42:24 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMEntriesNative.java Thu Jun 09 15:25:27 2011 +0200 @@ -138,5 +138,11 @@ return getType(o.getClass()); } + @Override + public native int RiMethod_invocationCount(long vmId); + + @Override + public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); + // Checkstyle: resume } diff -r b78b4ae0757c -r 0e3ec0a4eda4 src/cpu/x86/vm/c1_globals_x86.hpp --- a/src/cpu/x86/vm/c1_globals_x86.hpp Thu Jun 09 14:42:24 2011 +0200 +++ b/src/cpu/x86/vm/c1_globals_x86.hpp Thu Jun 09 15:25:27 2011 +0200 @@ -48,7 +48,7 @@ define_pd_global(intx, NewSizeThreadIncrease, 4*K ); define_pd_global(intx, InitialCodeCacheSize, 160*K); define_pd_global(intx, ReservedCodeCacheSize, 32*M ); -define_pd_global(bool, ProfileInterpreter, false); +define_pd_global(bool, ProfileInterpreter, true ); // changed for GRAAL define_pd_global(intx, CodeCacheExpansionSize, 32*K ); define_pd_global(uintx,CodeCacheMinBlockLength, 1); define_pd_global(uintx,PermSize, 12*M ); @@ -57,7 +57,7 @@ define_pd_global(uint64_t,MaxRAM, 1ULL*G); define_pd_global(bool, CICompileOSR, true ); #endif // !TIERED -define_pd_global(bool, UseTypeProfile, false); +define_pd_global(bool, UseTypeProfile, true ); // changed for GRAAL define_pd_global(bool, RoundFPResults, true ); define_pd_global(bool, LIRFillDelaySlots, false); diff -r b78b4ae0757c -r 0e3ec0a4eda4 src/share/vm/classfile/systemDictionary.hpp --- a/src/share/vm/classfile/systemDictionary.hpp Thu Jun 09 14:42:24 2011 +0200 +++ b/src/share/vm/classfile/systemDictionary.hpp Thu Jun 09 15:25:27 2011 +0200 @@ -182,14 +182,14 @@ template(Integer_klass, java_lang_Integer, Pre) \ template(Long_klass, java_lang_Long, Pre) \ \ - template(graalOptions_klass, com_sun_graal_graalOptions, Opt) \ - template(HotSpotTypeResolved_klass, com_sun_hotspot_graal_HotSpotTypeResolved, Opt) \ - template(HotSpotType_klass, com_sun_hotspot_graal_HotSpotType, Opt) \ - template(HotSpotField_klass, com_sun_hotspot_graal_HotSpotField, Opt) \ - template(HotSpotMethodResolved_klass, com_sun_hotspot_graal_HotSpotMethodResolved, Opt) \ - template(HotSpotTargetMethod_klass, com_sun_hotspot_graal_HotSpotTargetMethod, Opt) \ - template(HotSpotExceptionHandler_klass,com_sun_hotspot_graal_HotSpotExceptionHandler, Opt) \ - template(HotSpotProxy_klass, com_sun_hotspot_graal_HotSpotProxy, Opt) \ + template(graalOptions_klass, com_sun_graal_graalOptions, Opt) \ + template(HotSpotTypeResolved_klass, com_sun_hotspot_graal_HotSpotTypeResolved, Opt) \ + template(HotSpotType_klass, com_sun_hotspot_graal_HotSpotType, Opt) \ + template(HotSpotField_klass, com_sun_hotspot_graal_HotSpotField, Opt) \ + template(HotSpotMethodResolved_klass, com_sun_hotspot_graal_HotSpotMethodResolved, Opt) \ + template(HotSpotTargetMethod_klass, com_sun_hotspot_graal_HotSpotTargetMethod, Opt) \ + template(HotSpotExceptionHandler_klass,com_sun_hotspot_graal_HotSpotExceptionHandler, Opt) \ + template(HotSpotProxy_klass, com_sun_hotspot_graal_HotSpotProxy, Opt) \ template(CiAssumptions_klass, com_sun_cri_ci_CiAssumptions, Opt) \ template(CiAssumptions_ConcreteSubtype_klass, com_sun_cri_ci_CiAssumptions_ConcreteSubtype, Opt) \ template(CiAssumptions_ConcreteMethod_klass, com_sun_cri_ci_CiAssumptions_ConcreteMethod, Opt) \ @@ -213,6 +213,7 @@ template(CiRuntimeCall_klass, com_sun_cri_ci_CiRuntimeCall, Opt) \ template(RiMethod_klass, com_sun_cri_ri_RiMethod, Opt) \ template(RiExceptionHandler_klass, com_sun_cri_ri_RiExceptionHandler, Opt) \ + template(RiTypeProfile_klass, com_sun_cri_ri_RiTypeProfile, Opt) \ /*end*/ diff -r b78b4ae0757c -r 0e3ec0a4eda4 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Thu Jun 09 14:42:24 2011 +0200 +++ b/src/share/vm/classfile/vmSymbols.hpp Thu Jun 09 15:25:27 2011 +0200 @@ -273,6 +273,7 @@ template(com_sun_cri_ri_RiMethod, "com/sun/cri/ri/RiMethod") \ template(com_sun_cri_ri_RiField, "com/sun/cri/ri/RiField") \ template(com_sun_cri_ri_RiType, "com/sun/cri/ri/RiType") \ + template(com_sun_cri_ri_RiTypeProfile, "com/sun/cri/ri/RiTypeProfile") \ template(com_sun_cri_ri_RiConstantPool, "com/sun/cri/ri/RiConstantPool") \ template(com_sun_cri_ri_RiExceptionHandler, "com/sun/cri/ri/RiExceptionHandler") \ template(com_sun_cri_ci_CiAssumptions, "com/sun/cri/ci/CiAssumptions") \ diff -r b78b4ae0757c -r 0e3ec0a4eda4 src/share/vm/graal/graalJavaAccess.cpp --- a/src/share/vm/graal/graalJavaAccess.cpp Thu Jun 09 14:42:24 2011 +0200 +++ b/src/share/vm/graal/graalJavaAccess.cpp Thu Jun 09 15:25:27 2011 +0200 @@ -61,12 +61,13 @@ #define INT_FIELD(klass, name) FIELD(klass, name, "I", false) #define BOOLEAN_FIELD(klass, name) FIELD(klass, name, "Z", false) #define LONG_FIELD(klass, name) FIELD(klass, name, "J", false) +#define FLOAT_FIELD(klass, name) FIELD(klass, name, "F", false) #define OOP_FIELD(klass, name, signature) FIELD(klass, name, signature, false) #define STATIC_OOP_FIELD(klass, name, signature) FIELD(klass, name, signature, true) void graal_compute_offsets() { - COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, OOP_FIELD, STATIC_OOP_FIELD) + COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OOP_FIELD, STATIC_OOP_FIELD) } #define EMPTY0 @@ -75,7 +76,7 @@ #define FIELD2(klass, name) int klass::_##name##_offset = 0; #define FIELD3(klass, name, sig) FIELD2(klass, name) -COMPILER_CLASSES_DO(EMPTY1, EMPTY0, FIELD2, FIELD2, FIELD2, FIELD2, FIELD3, FIELD3) +COMPILER_CLASSES_DO(EMPTY1, EMPTY0, FIELD2, FIELD2, FIELD2, FIELD2, FIELD2, FIELD3, FIELD3) diff -r b78b4ae0757c -r 0e3ec0a4eda4 src/share/vm/graal/graalJavaAccess.hpp --- a/src/share/vm/graal/graalJavaAccess.hpp Thu Jun 09 14:42:24 2011 +0200 +++ b/src/share/vm/graal/graalJavaAccess.hpp Thu Jun 09 15:25:27 2011 +0200 @@ -44,7 +44,7 @@ * */ -#define COMPILER_CLASSES_DO(start_class, end_class, char_field, int_field, boolean_field, long_field, oop_field, static_oop_field) \ +#define COMPILER_CLASSES_DO(start_class, end_class, char_field, int_field, boolean_field, long_field, float_field, oop_field, static_oop_field) \ start_class(HotSpotTypeResolved) \ oop_field(HotSpotTypeResolved, compiler, "Lcom/oracle/max/graal/runtime/Compiler;") \ oop_field(HotSpotTypeResolved, javaMirror, "Ljava/lang/Class;") \ @@ -200,11 +200,14 @@ start_class(CiStackSlot) \ int_field(CiStackSlot, index) \ end_class \ + start_class(RiTypeProfile) \ + int_field(RiTypeProfile, count) \ + int_field(RiTypeProfile, morphism) \ + oop_field(RiTypeProfile, probabilities, "[F") \ + oop_field(RiTypeProfile, types, "[Lcom/sun/cri/ri/RiType;") \ + end_class \ /* end*/ - - - #define START_CLASS(name) \ class name : AllStatic { \ private: \ @@ -229,6 +232,7 @@ #define INT_FIELD(klass, name) FIELD(name, jint, int_field) #define BOOLEAN_FIELD(klass, name) FIELD(name, jboolean, bool_field) #define LONG_FIELD(klass, name) FIELD(name, jlong, long_field) +#define FLOAT_FIELD(klass, name) FIELD(name, jfloat, float_field) #define OOP_FIELD(klass, name, signature) FIELD(name, oop, obj_field) #define STATIC_OOP_FIELD(klassName, name, signature) \ static int _##name##_offset; \ @@ -250,7 +254,7 @@ oopDesc::encode_store_heap_oop((oop*)addr, x); \ } \ } -COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, OOP_FIELD, STATIC_OOP_FIELD) +COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OOP_FIELD, STATIC_OOP_FIELD) #undef START_CLASS #undef END_CLASS #undef FIELD @@ -258,6 +262,7 @@ #undef INT_FIELD #undef BOOLEAN_FIELD #undef LONG_FIELD +#undef FLOAT_FIELD #undef OOP_FIELD #undef STATIC_OOP_FIELD diff -r b78b4ae0757c -r 0e3ec0a4eda4 src/share/vm/graal/graalVMEntries.cpp --- a/src/share/vm/graal/graalVMEntries.cpp Thu Jun 09 14:42:24 2011 +0200 +++ b/src/share/vm/graal/graalVMEntries.cpp Thu Jun 09 15:25:27 2011 +0200 @@ -158,6 +158,40 @@ return JNIHandles::make_local(THREAD, method_resolved); } +// public native int RiMethod_invocationCount(); +JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount(JNIEnv *, jobject, jlong vmId) { + TRACE_graal_3("VMEntries::RiMethod_invocationCount"); + return VmIds::get(vmId)->invocation_count(); +} + +// public native RiTypeProfile RiMethod_typeProfile(int bci); +JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1typeProfile(JNIEnv *, jobject, jlong vmId, jint bci) { + TRACE_graal_3("VMEntries::RiMethod_typeProfile"); + ciMethod* cimethod; + { + VM_ENTRY_MARK; + cimethod = (ciMethod*)CURRENT_ENV->get_object(VmIds::get(vmId)); + } + + ciCallProfile profile = cimethod->call_profile_at_bci(bci); + + Handle obj; + { + VM_ENTRY_MARK; + instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); + obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); + assert(obj() != NULL, "must succeed in allocating instance"); + + RiTypeProfile::set_count(obj, cimethod->scale_count(profile.count(), 1)); + RiTypeProfile::set_morphism(obj, profile.morphism()); + + RiTypeProfile::set_probabilities(obj, NULL); + RiTypeProfile::set_types(obj, NULL); + } + + return JNIHandles::make_local(obj()); +} + // public RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass); JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) { TRACE_graal_3("VMEntries::RiSignature_lookupType"); @@ -354,6 +388,7 @@ default: constant.print(); fatal("Unhandled constant"); + break; } if (constant_object != NULL) { HotSpotField::set_constant(field_handle, constant_object); @@ -614,6 +649,7 @@ #endif // SERIALGC default: ShouldNotReachHere(); + break; } jintArray arrayOffsets = env->NewIntArray(basicTypeCount); @@ -661,6 +697,7 @@ #define TYPE "Lcom/sun/cri/ri/RiType;" #define RESOLVED_TYPE "Lcom/oracle/max/graal/runtime/HotSpotTypeResolved;" #define METHOD "Lcom/sun/cri/ri/RiMethod;" +#define TYPE_PROFILE "Lcom/sun/cri/ri/RiTypeProfile;" #define SIGNATURE "Lcom/sun/cri/ri/RiSignature;" #define FIELD "Lcom/sun/cri/ri/RiField;" #define CONSTANT_POOL "Lcom/sun/cri/ri/RiConstantPool;" @@ -684,6 +721,8 @@ {CC"RiMethod_exceptionHandlers", CC"("PROXY")"EXCEPTION_HANDLERS, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1exceptionHandlers)}, {CC"RiMethod_hasBalancedMonitors", CC"("PROXY")Z", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1hasBalancedMonitors)}, {CC"RiMethod_uniqueConcreteMethod", CC"("PROXY")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod)}, + {CC"RiMethod_invocationCount", CC"("PROXY")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount)}, + {CC"RiMethod_typeProfile", CC"("PROXY"I)"TYPE_PROFILE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1typeProfile)}, {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType)}, {CC"RiConstantPool_lookupConstant", CC"("PROXY"I)"OBJECT, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupConstant)}, {CC"RiConstantPool_lookupMethod", CC"("PROXY"IB)"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupMethod)},