# HG changeset patch # User Tom Rodriguez # Date 1394154699 28800 # Node ID 800057208a2c3018a0682115aa583f035c7ebf06 # Parent ca37cb080dadfc9b92da85b4132d9abe38eced2f enable C1 + Graal tiered diff -r ca37cb080dad -r 800057208a2c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 06 22:45:25 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 06 17:11:39 2014 -0800 @@ -212,11 +212,19 @@ long previousCompilationTime = CompilationTime.getCurrentValue(); HotSpotInstalledCode installedCode = null; try (TimerCloseable a = CompilationTime.start()) { - if (!tryToChangeStatus(CompilationStatus.Queued, CompilationStatus.Running) || method.hasCompiledCode()) { + if (!tryToChangeStatus(CompilationStatus.Queued, CompilationStatus.Running)) { + return; + } + boolean isOSR = entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI; + + // If there is already compiled code for this method on our level we simply return. + // Graal compiles are always at the highest compile level, even in non-tiered mode so we + // only need to check for that value. + if (method.hasCodeAtLevel(entryBCI, config.compilationLevelFullOptimization)) { return; } - CompilationStatistics stats = CompilationStatistics.create(method, entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI); + CompilationStatistics stats = CompilationStatistics.create(method, isOSR); final boolean printCompilation = PrintCompilation.getValue() && !TTY.isSuppressed(); if (printCompilation) { TTY.println(getMethodDescription() + "..."); diff -r ca37cb080dad -r 800057208a2c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Mar 06 22:45:25 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Mar 06 17:11:39 2014 -0800 @@ -1172,6 +1172,7 @@ @HotSpotVMField(name = "Method::_method_data", type = "MethodData*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOffset; @HotSpotVMField(name = "Method::_from_compiled_entry", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int methodCompiledEntryOffset; + @HotSpotVMField(name = "Method::_code", type = "nmethod*", get = HotSpotVMField.Type.OFFSET) @Stable public int methodCodeOffset; @HotSpotVMField(name = "MethodData::_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataSize; @HotSpotVMField(name = "MethodData::_data_size", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataDataSize; @@ -1179,6 +1180,9 @@ @HotSpotVMField(name = "MethodData::_trap_hist._array[0]", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodDataOopTrapHistoryOffset; @HotSpotVMField(name = "nmethod::_verified_entry_point", type = "address", get = HotSpotVMField.Type.OFFSET) @Stable public int nmethodEntryOffset; + @HotSpotVMField(name = "nmethod::_comp_level", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int nmethodCompLevelOffset; + + @HotSpotVMConstant(name = "CompLevel_full_optimization") @Stable public int compilationLevelFullOptimization; @HotSpotVMType(name = "BasicLock", get = HotSpotVMType.Type.SIZE) @Stable public int basicLockSize; @HotSpotVMField(name = "BasicLock::_displaced_header", type = "markOop", get = HotSpotVMField.Type.OFFSET) @Stable public int basicLockDisplacedHeaderOffset; diff -r ca37cb080dad -r 800057208a2c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 06 22:45:25 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 06 17:11:39 2014 -0800 @@ -320,4 +320,13 @@ * @return a comma separated list of names */ String getGPUs(); + + /** + * + * @param metaspaceMethod the method to check + * @param entryBCI + * @param level the compilation level + * @return true if the {@code metaspaceMethod} has code for {@code level} + */ + boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level); } diff -r ca37cb080dad -r 800057208a2c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 06 22:45:25 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 06 17:11:39 2014 -0800 @@ -189,4 +189,7 @@ public native boolean canInlineMethod(long metaspaceMethod); public native boolean shouldInlineMethod(long metaspaceMethod); + + public native boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level); + } diff -r ca37cb080dad -r 800057208a2c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Thu Mar 06 22:45:25 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Thu Mar 06 17:11:39 2014 -0800 @@ -38,6 +38,7 @@ import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.debug.*; +import com.oracle.graal.nodes.*; /** * Implementation of {@link JavaMethod} for resolved HotSpot methods. @@ -346,8 +347,36 @@ return runtime().getCompilerToVM().getCompiledCodeSize(metaspaceMethod); } + /** + * Gets the value of {@code Method::_code}. + * + * @return the value of {@code Method::_code} + */ + private long getCompiledCode() { + HotSpotVMConfig config = runtime().getConfig(); + return unsafe.getAddress(metaspaceMethod + config.methodCodeOffset); + } + + /** + * Returns whether this method has compiled code. + * + * @return true if this method has compiled code, false otherwise + */ public boolean hasCompiledCode() { - return getCompiledCodeSize() > 0; + return getCompiledCode() != 0L; + } + + /** + * Gets the compilation level of the currently installed code for this method. + * + * @return compilation level + */ + public boolean hasCompiledCodeAtLevel(int level) { + long compiledCode = getCompiledCode(); + if (compiledCode != 0) { + return unsafe.getInt(compiledCode + runtime().getConfig().nmethodCompLevelOffset) == level; + } + return false; } private static final String TraceMethodDataFilter = System.getProperty("graal.traceMethodDataFilter"); @@ -681,4 +710,11 @@ private long getAccessFlagsAddress() { return metaspaceMethod + runtime().getConfig().methodAccessFlagsOffset; } + + public boolean hasCodeAtLevel(int entryBCI, int level) { + if (entryBCI == StructuredGraph.INVOCATION_ENTRY_BCI) { + return hasCompiledCodeAtLevel(level); + } + return runtime().getCompilerToVM().hasCompiledCodeForOSR(metaspaceMethod, entryBCI, level); + } } diff -r ca37cb080dad -r 800057208a2c make/bsd/makefiles/graal.make --- a/make/bsd/makefiles/graal.make Thu Mar 06 22:45:25 2014 -0800 +++ b/make/bsd/makefiles/graal.make Thu Mar 06 17:11:39 2014 -0800 @@ -29,4 +29,7 @@ VM_SUBDIR = graal -CFLAGS += -DGRAAL +# To make a non-tiered Graal build, remove the -DCOMPILER1 below and +# in vm.make remove COMPILER1_PATHS from Src_Dirs/GRAAL and add +# COMPILER1_SPECIFIC_FILES to Src_Files_EXCLUDE/GRAAL +CFLAGS += -DGRAAL -DCOMPILER1 diff -r ca37cb080dad -r 800057208a2c make/bsd/makefiles/vm.make --- a/make/bsd/makefiles/vm.make Thu Mar 06 22:45:25 2014 -0800 +++ b/make/bsd/makefiles/vm.make Thu Mar 06 17:11:39 2014 -0800 @@ -211,7 +211,7 @@ Src_Dirs/TIERED := $(CORE_PATHS) $(COMPILER1_PATHS) $(COMPILER2_PATHS) $(GRAAL_PATHS) Src_Dirs/ZERO := $(CORE_PATHS) Src_Dirs/SHARK := $(CORE_PATHS) $(SHARK_PATHS) -Src_Dirs/GRAAL := $(CORE_PATHS) $(GRAAL_PATHS) +Src_Dirs/GRAAL := $(CORE_PATHS) $(COMPILER1_PATHS) $(GRAAL_PATHS) Src_Dirs := $(Src_Dirs/$(TYPE)) COMPILER2_SPECIFIC_FILES := opto libadt bcEscapeAnalyzer.cpp c2_\* runtime_\* @@ -237,7 +237,7 @@ Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) -Src_Files_EXCLUDE/GRAAL := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/GRAAL := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp Src_Files_EXCLUDE += $(Src_Files_EXCLUDE/$(TYPE)) diff -r ca37cb080dad -r 800057208a2c src/cpu/sparc/vm/graalGlobals_sparc.hpp --- a/src/cpu/sparc/vm/graalGlobals_sparc.hpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/cpu/sparc/vm/graalGlobals_sparc.hpp Thu Mar 06 17:11:39 2014 -0800 @@ -31,13 +31,13 @@ // Sets the default values for platform dependent flags used by the Graal compiler. // (see graalGlobals.hpp) -#if !defined(COMPILER1) && !defined(COMPILER2) +#if !defined(COMPILER2) define_pd_global(bool, BackgroundCompilation, true ); define_pd_global(bool, UseTLAB, true ); define_pd_global(bool, ResizeTLAB, true ); define_pd_global(bool, InlineIntrinsics, true ); define_pd_global(bool, PreferInterpreterNativeStubs, false); -define_pd_global(bool, TieredCompilation, false); +define_pd_global(bool, TieredCompilation, true); define_pd_global(intx, BackEdgeThreshold, 100000); define_pd_global(intx, OnStackReplacePercentage, 933 ); diff -r ca37cb080dad -r 800057208a2c src/cpu/x86/vm/graalGlobals_x86.hpp --- a/src/cpu/x86/vm/graalGlobals_x86.hpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/cpu/x86/vm/graalGlobals_x86.hpp Thu Mar 06 17:11:39 2014 -0800 @@ -31,13 +31,13 @@ // Sets the default values for platform dependent flags used by the Graal compiler. // (see graalGlobals.hpp) -#if !defined(COMPILER1) && !defined(COMPILER2) +#if !defined(COMPILER2) define_pd_global(bool, BackgroundCompilation, true ); define_pd_global(bool, UseTLAB, true ); define_pd_global(bool, ResizeTLAB, true ); define_pd_global(bool, InlineIntrinsics, true ); define_pd_global(bool, PreferInterpreterNativeStubs, false); -define_pd_global(bool, TieredCompilation, false); +define_pd_global(bool, TieredCompilation, true); define_pd_global(intx, BackEdgeThreshold, 100000); define_pd_global(intx, OnStackReplacePercentage, 933 ); diff -r ca37cb080dad -r 800057208a2c src/share/vm/compiler/compileBroker.cpp --- a/src/share/vm/compiler/compileBroker.cpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/share/vm/compiler/compileBroker.cpp Thu Mar 06 17:11:39 2014 -0800 @@ -795,23 +795,28 @@ #ifdef GRAAL GraalCompiler* graal = new GraalCompiler(); #endif -#ifdef GRAALVM +#if defined(GRAALVM) && !defined(TIERED) _compilers[0] = graal; c1_count = 0; c2_count = 0; -#else // GRAALVM +#endif // GRAALVM && !TIERED + #ifdef COMPILER1 if (c1_count > 0) { _compilers[0] = new Compiler(); } #endif // COMPILER1 +#if defined(GRAALVM) + _compilers[1] = graal; + c2_count = 0; +#endif // GRAALVM + #ifdef COMPILER2 if (c2_count > 0) { _compilers[1] = new C2Compiler(); } #endif // COMPILER2 -#endif // GRAALVM #else // SHARK int c1_count = 0; int c2_count = 1; @@ -1092,7 +1097,7 @@ if (osr_bci != InvocationEntryBci) { tty->print(" osr_bci: %d", osr_bci); } - tty->print(" comment: %s count: %d", comment, hot_count); + tty->print(" level: %d comment: %s count: %d", comp_level, comment, hot_count); if (!hot_method.is_null()) { tty->print(" hot: "); if (hot_method() != method()) { @@ -1142,15 +1147,25 @@ if (InstanceRefKlass::owns_pending_list_lock(JavaThread::current())) { return; } -#ifdef GRAALVM - if (!JavaThread::current()->is_graal_compiling()) { - bool blockingCompilation = is_compile_blocking(method, osr_bci) || - CompilationPolicy::can_be_offloaded_to_gpu(method); - GraalCompiler::instance()->compile_method(method, osr_bci, blockingCompilation); - } else { - // Recursive compile request => ignore. + +#if defined(GRAALVM) + // In tiered mode we want to only handle highest tier compiles and + // in non-tiered mode the default level should be + // CompLevel_full_optimization which equals CompLevel_highest_tier. + assert(TieredCompilation || comp_level == CompLevel_full_optimization, "incorrect compile level"); + assert(CompLevel_full_optimization == CompLevel_highest_tier, "incorrect level definition"); + if (comp_level == CompLevel_full_optimization) { + if (!JavaThread::current()->is_graal_compiling()) { + bool blockingCompilation = is_compile_blocking(method, osr_bci) || + CompilationPolicy::can_be_offloaded_to_gpu(method); + GraalCompiler::instance()->compile_method(method, osr_bci, blockingCompilation); + } else { + // Can't enqueue this request because there would be no one to service it, so simply return. + } + return; } -#else + assert(TieredCompilation, "should only reach here in tiered mode"); +#endif // GRAALVM // Outputs from the following MutexLocker block: CompileTask* task = NULL; @@ -1235,7 +1250,6 @@ if (blocking) { wait_for_completion(task); } -#endif } @@ -2365,11 +2379,11 @@ nmethods_code_size += stats->_nmethods_code_size; if (per_compiler) { - tty->print_cr(" %s {speed: %d bytes/s; standard: %6.3f s, %d bytes, %d methods; osr: %6.3f s, %d bytes, %d methods; nmethods_size: %d bytes; nmethods_code_size: %d bytes}", - comp->name(), stats->bytes_per_second(), - stats->_standard._time.seconds(), stats->_standard._bytes, stats->_standard._count, - stats->_osr._time.seconds(), stats->_osr._bytes, stats->_osr._count, - stats->_nmethods_size, stats->_nmethods_code_size); + tty->print_cr(" %s {speed: %d bytes/s; standard: %6.3f s, %d bytes, %d methods; osr: %6.3f s, %d bytes, %d methods; nmethods_size: %d bytes; nmethods_code_size: %d bytes}", + comp->name(), stats->bytes_per_second(), + stats->_standard._time.seconds(), stats->_standard._bytes, stats->_standard._count, + stats->_osr._time.seconds(), stats->_osr._bytes, stats->_osr._count, + stats->_nmethods_size, stats->_nmethods_code_size); } } } diff -r ca37cb080dad -r 800057208a2c src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Mar 06 17:11:39 2014 -0800 @@ -814,6 +814,11 @@ return mdo != NULL && mdo->is_mature(); C2V_END +C2V_VMENTRY(jboolean, hasCompiledCodeForOSR, (JNIEnv *env, jobject, jlong metaspace_method, int entry_bci, int comp_level)) + Method* method = asMethod(metaspace_method); + return method->lookup_osr_nmethod_for(entry_bci, comp_level, true) != NULL; +C2V_END + #define CC (char*) /*cast a literal from (const char*)*/ #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f)) @@ -884,6 +889,7 @@ {CC"getGPUs", CC"()"STRING, FN_PTR(getGPUs)}, {CC"allocateCompileId", CC"("METASPACE_METHOD"I)I", FN_PTR(allocateCompileId)}, {CC"isMature", CC"("METASPACE_METHOD_DATA")Z", FN_PTR(isMature)}, + {CC"hasCompiledCodeForOSR", CC"("METASPACE_METHOD"II)Z", FN_PTR(hasCompiledCodeForOSR)}, }; int CompilerToVM_methods_count() { diff -r ca37cb080dad -r 800057208a2c src/share/vm/graal/graalEnv.cpp --- a/src/share/vm/graal/graalEnv.cpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/share/vm/graal/graalEnv.cpp Thu Mar 06 17:11:39 2014 -0800 @@ -456,7 +456,7 @@ GRAAL_EXCEPTION_CONTEXT; NMethodSweeper::possibly_sweep(); nm = NULL; - int comp_level = CompLevel_simple; + int comp_level = CompLevel_full_optimization; { // To prevent compile queue updates. MutexLocker locker(MethodCompileQueue_lock, THREAD); diff -r ca37cb080dad -r 800057208a2c src/share/vm/runtime/vmStructs.cpp --- a/src/share/vm/runtime/vmStructs.cpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/share/vm/runtime/vmStructs.cpp Thu Mar 06 17:11:39 2014 -0800 @@ -2609,6 +2609,18 @@ declare_constant(InvocationEntryBci) \ declare_constant(InvalidOSREntryBci) \ \ + /*************/ \ + /* CompLevel */ \ + /*************/ \ + \ + declare_constant(CompLevel_any) \ + declare_constant(CompLevel_all) \ + declare_constant(CompLevel_none) \ + declare_constant(CompLevel_simple) \ + declare_constant(CompLevel_limited_profile) \ + declare_constant(CompLevel_full_profile) \ + declare_constant(CompLevel_full_optimization) \ + \ /***************/ \ /* OopMapValue */ \ /***************/ \ diff -r ca37cb080dad -r 800057208a2c src/share/vm/runtime/vm_version.cpp --- a/src/share/vm/runtime/vm_version.cpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/share/vm/runtime/vm_version.cpp Thu Mar 06 17:11:39 2014 -0800 @@ -112,7 +112,11 @@ #ifndef VMTYPE #ifdef TIERED - #define VMTYPE "Server" + #ifdef GRAAL + #define VMTYPE "Graal" + #else + #define VMTYPE "Server" + #endif #else // TIERED #ifdef ZERO #ifdef SHARK diff -r ca37cb080dad -r 800057208a2c src/share/vm/utilities/globalDefinitions.hpp --- a/src/share/vm/utilities/globalDefinitions.hpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/share/vm/utilities/globalDefinitions.hpp Thu Mar 06 17:11:39 2014 -0800 @@ -818,11 +818,11 @@ CompLevel_simple = 1, // C1 CompLevel_limited_profile = 2, // C1, invocation & backedge counters CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo - CompLevel_full_optimization = 4, // C2 or Shark + CompLevel_full_optimization = 4, // C2, Shark or Graal -#if defined(COMPILER2) || defined(SHARK) - CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered -#elif defined(COMPILER1) || defined(GRAAL) +#if defined(COMPILER2) || defined(SHARK) || defined(GRAAL) + CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered or Graal and tiered +#elif defined(COMPILER1) CompLevel_highest_tier = CompLevel_simple, // pure C1 or Graal #else CompLevel_highest_tier = CompLevel_none, diff -r ca37cb080dad -r 800057208a2c src/share/vm/utilities/macros.hpp --- a/src/share/vm/utilities/macros.hpp Thu Mar 06 22:45:25 2014 -0800 +++ b/src/share/vm/utilities/macros.hpp Thu Mar 06 17:11:39 2014 -0800 @@ -166,7 +166,7 @@ // COMPILER1 variant #ifdef COMPILER1 -#ifdef COMPILER2 +#if defined(COMPILER2) || defined(GRAAL) #define TIERED #endif #define COMPILER1_PRESENT(code) code @@ -187,7 +187,7 @@ #define GRAAL_ONLY(code) code #define NOT_GRAAL(code) #define IS_GRAAL_DEFINED true -#if !defined(COMPILER1) && !defined(COMPILER2) +#if !defined(COMPILER2) // Graal is the only compiler in the system and so will be used for compilation // requests issued by the compile broker. #define GRAALVM