Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalCompilerToGPU.cpp @ 10577:9c7d9e2c8326
PTX kernel execution - no args or return value
author | Morris Meyer <morris.meyer@oracle.com> |
---|---|
date | Sat, 29 Jun 2013 21:29:34 -0400 |
parents | 7a3499bf5e2c |
children | f0551e15a416 |
comparison
equal
deleted
inserted
replaced
10576:aee899c96b0b | 10577:9c7d9e2c8326 |
---|---|
22 */ | 22 */ |
23 | 23 |
24 #include "precompiled.hpp" | 24 #include "precompiled.hpp" |
25 | 25 |
26 #include "graal/graalCompiler.hpp" | 26 #include "graal/graalCompiler.hpp" |
27 #include "graal/graalCompilerToVM.hpp" | |
27 #include "graal/graalEnv.hpp" | 28 #include "graal/graalEnv.hpp" |
29 #include "graal/graalJavaAccess.hpp" | |
28 #include "runtime/gpu.hpp" | 30 #include "runtime/gpu.hpp" |
29 | 31 |
30 | 32 |
31 // Entry to native method implementation that transitions current thread to '_thread_in_vm'. | 33 // Entry to native method implementation that transitions current thread to '_thread_in_vm'. |
32 #define C2V_VMENTRY(result_type, name, signature) \ | 34 #define C2V_VMENTRY(result_type, name, signature) \ |
51 jboolean is_copy; | 53 jboolean is_copy; |
52 jbyte *bytes = env->GetByteArrayElements(code, &is_copy); | 54 jbyte *bytes = env->GetByteArrayElements(code, &is_copy); |
53 jint len = env->GetArrayLength(code); | 55 jint len = env->GetArrayLength(code); |
54 const char *namestr = env->GetStringUTFChars(name, &is_copy); | 56 const char *namestr = env->GetStringUTFChars(name, &is_copy); |
55 void *kernel = gpu::generate_kernel((unsigned char *)bytes, len, namestr); | 57 void *kernel = gpu::generate_kernel((unsigned char *)bytes, len, namestr); |
58 tty->print_cr("generateKernel: %x", kernel); | |
56 env->ReleaseByteArrayElements(code, bytes, 0); | 59 env->ReleaseByteArrayElements(code, bytes, 0); |
57 env->ReleaseStringUTFChars(name, namestr); | 60 env->ReleaseStringUTFChars(name, namestr); |
58 | 61 |
59 return (jlong)kernel; | 62 return (jlong)kernel; |
63 C2V_END | |
64 | |
65 C2V_VMENTRY(jobject, executeExternalMethodVarargs, (JNIEnv *env, jobject, jobject args, jobject hotspotInstalledCode)) | |
66 ResourceMark rm; | |
67 HandleMark hm; | |
68 | |
69 if (gpu::is_available() == false || gpu::has_gpu_linkage() == false && gpu::is_initialized()) { | |
70 tty->print_cr("executeExternalMethodVarargs - not available / no linkage / not initialized"); | |
71 return NULL; | |
72 } | |
73 jlong nmethodValue = HotSpotInstalledCode::codeBlob(hotspotInstalledCode); | |
74 nmethod* nm = (nmethod*) (address) nmethodValue; | |
75 methodHandle mh = nm->method(); | |
76 Symbol* signature = mh->signature(); | |
77 JavaCallArguments jca(mh->size_of_parameters()); | |
78 | |
79 JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static()); | |
80 JavaValue result(jap.get_ret_type()); | |
81 jca.set_alternative_target(nm); | |
82 | |
83 // start value is the kernel | |
84 jlong startValue = HotSpotInstalledCode::start(hotspotInstalledCode); | |
85 | |
86 // JavaCalls::call(&result, mh, &jca, CHECK_NULL); | |
87 tty->print_cr("executeExternalMethodVarargs: start: %x", (address)startValue); | |
88 gpu::execute_kernel((address)startValue); | |
89 | |
90 if (jap.get_ret_type() == T_VOID) { | |
91 return NULL; | |
92 } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) { | |
93 return JNIHandles::make_local((oop) result.get_jobject()); | |
94 } else { | |
95 oop o = java_lang_boxing_object::create(jap.get_ret_type(), (jvalue *) result.get_value_addr(), CHECK_NULL); | |
96 return JNIHandles::make_local(o); | |
97 } | |
60 C2V_END | 98 C2V_END |
61 | 99 |
62 C2V_VMENTRY(jboolean, deviceInit, (JNIEnv *env, jobject)) | 100 C2V_VMENTRY(jboolean, deviceInit, (JNIEnv *env, jobject)) |
63 if (gpu::is_available() == false || gpu::has_gpu_linkage() == false) { | 101 if (gpu::is_available() == false || gpu::has_gpu_linkage() == false) { |
64 tty->print_cr("deviceInit - not available / no linkage"); | 102 tty->print_cr("deviceInit - not available / no linkage"); |
111 #define METASPACE_METHOD_DATA "J" | 149 #define METASPACE_METHOD_DATA "J" |
112 #define NMETHOD "J" | 150 #define NMETHOD "J" |
113 #define GPUSPACE_METHOD "J" | 151 #define GPUSPACE_METHOD "J" |
114 | 152 |
115 JNINativeMethod CompilerToGPU_methods[] = { | 153 JNINativeMethod CompilerToGPU_methods[] = { |
116 {CC"generateKernel", CC"([B" STRING ")"GPUSPACE_METHOD, FN_PTR(generateKernel)}, | 154 {CC"generateKernel", CC"([B" STRING ")"GPUSPACE_METHOD, FN_PTR(generateKernel)}, |
117 {CC"deviceInit", CC"()Z", FN_PTR(deviceInit)}, | 155 {CC"deviceInit", CC"()Z", FN_PTR(deviceInit)}, |
118 {CC"deviceDetach", CC"()Z", FN_PTR(deviceDetach)}, | 156 {CC"deviceDetach", CC"()Z", FN_PTR(deviceDetach)}, |
157 {CC"executeExternalMethodVarargs", CC"(["OBJECT HS_INSTALLED_CODE")"OBJECT, FN_PTR(executeExternalMethodVarargs)}, | |
119 }; | 158 }; |
120 | 159 |
121 int CompilerToGPU_methods_count() { | 160 int CompilerToGPU_methods_count() { |
122 return sizeof(CompilerToGPU_methods) / sizeof(JNINativeMethod); | 161 return sizeof(CompilerToGPU_methods) / sizeof(JNINativeMethod); |
123 } | 162 } |