# HG changeset patch # User S.Bharadwaj Yadavalli # Date 1390424807 18000 # Node ID 9161ed8ce7964ca3df5e91894522b207a2bc4a3e # Parent 168976cae9cef4090493e27c342606ef7b2cd7cb Add graal-specific option -XX:+GPUOffload to trigger all GPU offload functionality. Cleanup function to decide GPU offload. Exclude GPU sources from nongraal builds. diff -r 168976cae9ce -r 9161ed8ce796 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Wed Jan 22 15:27:31 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Wed Jan 22 16:06:47 2014 -0500 @@ -148,7 +148,7 @@ } private boolean canOffloadToGPU(ResolvedJavaMethod method) { - return method.getName().contains("lambda$main$") & method.isSynthetic(); + return method.getName().contains("lambda$") & method.isSynthetic(); } }; } diff -r 168976cae9ce -r 9161ed8ce796 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Jan 22 15:27:31 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Jan 22 16:06:47 2014 -0500 @@ -556,9 +556,8 @@ int id = allocateCompileTaskId(method, entryBCI); HotSpotBackend backend = runtime.getHostBackend(); CompilationTask task = new CompilationTask(backend, method, entryBCI, id); - boolean isLambdaMethod = (method.getName().contains("lambda$main$") & method.isSynthetic()); - if (blocking || isLambdaMethod) { + if (blocking) { task.runCompilation(true); } else { try { diff -r 168976cae9ce -r 9161ed8ce796 make/bsd/makefiles/vm.make --- a/make/bsd/makefiles/vm.make Wed Jan 22 15:27:31 2014 +0100 +++ b/make/bsd/makefiles/vm.make Wed Jan 22 16:06:47 2014 -0500 @@ -222,20 +222,22 @@ ifneq ($(INCLUDE_GRAAL), true) GRAAL_SPECIFIC_FILES := graal\* + GRAAL_SPECIFIC_GPU_FILES := gpu\* ptx\* hsail\* else GRAAL_SPECIFIC_FILES := + GRAAL_SPECIFIC_GPU_FILES := endif # Always exclude these. Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp # Exclude per type. -Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) -Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) -Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) +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 += $(Src_Files_EXCLUDE/$(TYPE)) diff -r 168976cae9ce -r 9161ed8ce796 make/linux/makefiles/vm.make --- a/make/linux/makefiles/vm.make Wed Jan 22 15:27:31 2014 +0100 +++ b/make/linux/makefiles/vm.make Wed Jan 22 16:06:47 2014 -0500 @@ -201,21 +201,23 @@ ZERO_SPECIFIC_FILES := zero ifneq ($(INCLUDE_GRAAL), true) - GRAAL_SPECIFIC_FILES := graal\* + GRAAL_SPECIFIC_FILES := graal\* + GRAAL_SPECIFIC_GPU_FILES := gpu\* ptx\* hsail\* else GRAAL_SPECIFIC_FILES := + GRAAL_SPECIFIC_GPU_FILES := endif # Always exclude these. Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp # Exclude per type. -Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) -Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) -Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) +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 += $(Src_Files_EXCLUDE/$(TYPE)) diff -r 168976cae9ce -r 9161ed8ce796 make/solaris/makefiles/vm.make --- a/make/solaris/makefiles/vm.make Wed Jan 22 15:27:31 2014 +0100 +++ b/make/solaris/makefiles/vm.make Wed Jan 22 16:06:47 2014 -0500 @@ -219,17 +219,18 @@ SHARK_SPECIFIC_FILES := shark ZERO_SPECIFIC_FILES := zero GRAAL_SPECIFIC_FILES := graal +GRAAL_SPECIFIC_GPU_FILES := gpu\* ptx\* hsail\* # Always exclude these. Src_Files_EXCLUDE := dtrace jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp # Exclude per type. -Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) -Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) -Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) +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 += $(Src_Files_EXCLUDE/$(TYPE)) diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/compiler/compileBroker.cpp --- a/src/share/vm/compiler/compileBroker.cpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/compiler/compileBroker.cpp Wed Jan 22 16:06:47 2014 -0500 @@ -1144,7 +1144,9 @@ } #ifdef GRAALVM if (!JavaThread::current()->is_graal_compiling()) { - GraalCompiler::instance()->compile_method(method, osr_bci, is_compile_blocking(method, osr_bci)); + 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. } diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/graal/graalGlobals.hpp --- a/src/share/vm/graal/graalGlobals.hpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/graal/graalGlobals.hpp Wed Jan 22 16:06:47 2014 -0500 @@ -79,6 +79,12 @@ develop(bool, TraceUncollectedSpeculations, false, \ "Print message when a failed speculation was not collected") \ \ + product(bool, GPUOffload, false, \ + "Offload execution to GPU whenever possible") \ + \ + product(bool, TraceGPUInteraction, false, \ + "Trace external GPU Interaction") \ + \ // Read default values for Graal globals diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/oops/method.cpp --- a/src/share/vm/oops/method.cpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/oops/method.cpp Wed Jan 22 16:06:47 2014 -0500 @@ -2025,28 +2025,3 @@ guarantee(md == NULL || md->is_methodData(), "should be method data"); } - -#ifdef GRAAL - -// Return true if the name of the method indicates that this is a -// lambda method other than . Lambda method is one with a name -// that starts with lambda$ and is synthetic. - -bool Method::is_lambda() const { - Symbol * klass_name = method_holder()->name(); - Symbol * method_name = name(); - ResourceMark rm; - if (klass_name != NULL) { - if (klass_name != NULL && method_name != NULL) { - const char* lambdaPrefix = "lambda$main$"; - char* methodPrefix = strstr(method_name->as_C_string(), lambdaPrefix); - if (methodPrefix != 0) { - if ((strncmp(lambdaPrefix, methodPrefix, strlen(lambdaPrefix)) == 0) && is_synthetic()) { - return true; - } - } - } - } - return false; -} -#endif diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/oops/method.hpp --- a/src/share/vm/oops/method.hpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/oops/method.hpp Wed Jan 22 16:06:47 2014 -0500 @@ -617,11 +617,6 @@ // simultaneously. Use with caution. bool has_compiled_code() const { return code() != NULL; } -#ifdef GRAAL - // Return true if the name of the method indicates that this is a - // lambda method other than . - bool is_lambda() const; -#endif // sizing static int header_size() { return sizeof(Method)/HeapWordSize; } static int size(bool is_native); diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/runtime/compilationPolicy.cpp --- a/src/share/vm/runtime/compilationPolicy.cpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/runtime/compilationPolicy.cpp Wed Jan 22 16:06:47 2014 -0500 @@ -105,30 +105,7 @@ if (m->has_compiled_code()) return false; // already compiled -#ifdef GRAAL - // Check if this is a Lambda method that can be compiled to a GPU. - if (m->is_lambda()) { - // If GPU is available and the necessary linkage is available - // rerurn true indicatin that this method must be compiled. - if (gpu::is_available() && gpu::has_gpu_linkage()) { - if (TraceGPUInteraction) { - tty->print("Compiling Lambda method"); - m->print_short_name(); - switch (gpu::get_target_il_type()) { - case gpu::PTX : - tty->print_cr(" to PTX"); - break; - case gpu::HSAIL : - tty->print_cr(" to HSAIL"); - break; - default : - tty->print_cr(" to Unknown GPU!!!"); - } - } - return true; - } - } -#endif + if (CompilationPolicy::can_be_offloaded_to_gpu(m)) return true; if (!can_be_compiled(m, comp_level)) return false; @@ -184,6 +161,58 @@ return (result && can_be_compiled(m, comp_level)); } +bool CompilationPolicy::can_be_offloaded_to_gpu(methodHandle m) { +#ifdef GRAAL + if (GPUOffload) { + // Check if this method can be offloaded to GPU. + // 1. Offload it to GPU if it is a Lambda method + if (m->is_synthetic()) { + // A lambda method is a syntheric method. + Symbol * klass_name = m->method_holder()->name(); + Symbol * method_name = m->name(); + bool offloadToGPU = false; + { + ResourceMark rm; + if (klass_name != NULL) { + if (klass_name != NULL && method_name != NULL) { + const char* lambdaPrefix = "lambda$"; + char* methodPrefix = strstr(method_name->as_C_string(), lambdaPrefix); + if (methodPrefix != 0) { + if ((strncmp(lambdaPrefix, methodPrefix, strlen(lambdaPrefix)) == 0)) { + offloadToGPU = true; + } + } + } + } + } + if (offloadToGPU) { + // If GPU is available and the necessary linkage is available + // return true indicatin that this method must be compiled. + if (gpu::is_available() && gpu::has_gpu_linkage()) { + if (TraceGPUInteraction) { + tty->print("Compiling Lambda method "); + m->print_short_name(); + switch (gpu::get_target_il_type()) { + case gpu::PTX : + tty->print_cr("to PTX"); + break; + case gpu::HSAIL : + tty->print_cr("to HSAIL"); + break; + default : + tty->print_cr("to Unknown GPU!!!"); + } + } + return true; + } + } + } + } +#endif + + return false; +} + bool CompilationPolicy::is_compilation_enabled() { // NOTE: CompileBroker::should_compile_new_jobs() checks for UseCompiler return !delay_compilation_during_startup() && CompileBroker::should_compile_new_jobs(); diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/runtime/compilationPolicy.hpp --- a/src/share/vm/runtime/compilationPolicy.hpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/runtime/compilationPolicy.hpp Wed Jan 22 16:06:47 2014 -0500 @@ -58,6 +58,9 @@ static void set_policy(CompilationPolicy* policy) { _policy = policy; } static CompilationPolicy* policy() { return _policy; } + // m is allowed to be offloaded to a gpu + static bool can_be_offloaded_to_gpu(methodHandle m); + // Profiling elapsedTimer* accumulated_time() { return &_accumulated_time; } void print_time() PRODUCT_RETURN; diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/runtime/globals.hpp --- a/src/share/vm/runtime/globals.hpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/runtime/globals.hpp Wed Jan 22 16:06:47 2014 -0500 @@ -3840,9 +3840,6 @@ product(bool , AllowNonVirtualCalls, false, \ "Obey the ACC_SUPER flag and allow invokenonvirtual calls") \ \ - product(bool, TraceGPUInteraction, false, \ - "Trace external GPU Interaction") \ - \ product(bool, UseHSAILSimulator, false, \ "Run code on HSAIL Simulator") \ \ diff -r 168976cae9ce -r 9161ed8ce796 src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp Wed Jan 22 15:27:31 2014 +0100 +++ b/src/share/vm/runtime/thread.cpp Wed Jan 22 16:06:47 2014 -0500 @@ -3394,9 +3394,13 @@ jint parse_result = Arguments::parse(args); if (parse_result != JNI_OK) return parse_result; - // Probe for existance of supported GPU and initialize it if one - // exists. - gpu::init(); +#ifdef GRAAL + if (GPUOffload) { + // Probe for existance of supported GPU and initialize it if one + // exists. + gpu::init(); + } +#endif os::init_before_ergo();