src/gpu/hsail/vm/gpu_hsail.cpp

Print this page




  49 // Entry to GPU native method implementation that calls a JNI function
  50 // and hence cannot transition current thread to '_thread_in_vm'.
  51 #define GPU_ENTRY(result_type, name, signature) \
  52   JNIEXPORT result_type JNICALL name signature { \
  53 
  54 #define GPU_END }
  55 
  56 #define CC (char*)  /*cast a literal from (const char*)*/
  57 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f))
  58 
  59 #define OBJECT                "Ljava/lang/Object;"
  60 #define STRING                "Ljava/lang/String;"
  61 #define JLTHREAD              "Ljava/lang/Thread;"
  62 #define HS_INSTALLED_CODE     "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;"
  63 #define HS_COMPILED_NMETHOD   "Lcom/oracle/graal/hotspot/HotSpotCompiledNmethod;"
  64 #define HS_NMETHOD            "Lcom/oracle/graal/hotspot/meta/HotSpotNmethod;"
  65 
  66 JNINativeMethod Hsail::HSAIL_methods[] = {
  67   {CC"initialize",       CC"()Z",                               FN_PTR(Hsail::initialize)},
  68   {CC"generateKernel",   CC"([B" STRING ")J",                   FN_PTR(Hsail::generate_kernel)},
  69   {CC"executeKernel0",   CC"("HS_INSTALLED_CODE"I["OBJECT"["JLTHREAD"I[I)Z",  FN_PTR(Hsail::execute_kernel_void_1d)},
  70 };
  71 
  72 void* Hsail::_device_context = NULL;
  73 jint  Hsail::_notice_safepoints = false;
  74 
  75 Hsail::okra_get_context_func_t     Hsail::_okra_get_context;
  76 Hsail::okra_create_kernel_func_t   Hsail::_okra_create_kernel;
  77 Hsail::okra_push_pointer_func_t    Hsail::_okra_push_pointer;
  78 Hsail::okra_push_boolean_func_t    Hsail::_okra_push_boolean;
  79 Hsail::okra_push_byte_func_t       Hsail::_okra_push_byte;
  80 Hsail::okra_push_double_func_t     Hsail::_okra_push_double;
  81 Hsail::okra_push_float_func_t      Hsail::_okra_push_float;
  82 Hsail::okra_push_int_func_t        Hsail::_okra_push_int;
  83 Hsail::okra_push_long_func_t       Hsail::_okra_push_long;
  84 Hsail::okra_execute_kernel_func_t  Hsail::_okra_execute_kernel;
  85 Hsail::okra_clear_args_func_t      Hsail::_okra_clear_args;
  86 Hsail::okra_dispose_kernel_func_t  Hsail::_okra_dispose_kernel;
  87 Hsail::okra_dispose_context_func_t Hsail::_okra_dispose_context;
  88 
  89 //static jint in_kernel = 0;
  90 
  91 void Hsail::notice_safepoints() {
  92   _notice_safepoints = true;
  93 //  if (TraceGPUInteraction) {
  94 //    tty->print_cr("[HSAIL] Notice safepoint in_kernel=%d", in_kernel);
  95 //  }
  96 }
  97 
  98 void Hsail::ignore_safepoints() {
  99   _notice_safepoints = false;
 100 }
 101 
 102 GPU_VMENTRY(jboolean, Hsail::execute_kernel_void_1d, (JNIEnv* env, jclass, jobject kernel_handle, jint dimX, jobject args,
 103                                                       jobject donor_threads, jint allocBytesPerWorkitem, jobject oop_map_array))
 104 
 105   ResourceMark rm;
 106   jlong nmethodValue = InstalledCode::address(kernel_handle);
 107   if (nmethodValue == 0) {
 108     SharedRuntime::throw_and_post_jvmti_exception(JavaThread::current(), vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException(), NULL);
 109   }
 110   nmethod* nm = (nmethod*) (address) nmethodValue;
 111   methodHandle mh = nm->method();
 112   Symbol* signature = mh->signature();
 113 
 114   void* kernel = (void*) HotSpotInstalledCode::codeStart(kernel_handle);
 115   if (kernel == NULL) {
 116     SharedRuntime::throw_and_post_jvmti_exception(JavaThread::current(), vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException(), NULL);
 117   }
 118 
 119 return execute_kernel_void_1d_internal((address) kernel, dimX, args, mh, nm, donor_threads, allocBytesPerWorkitem, oop_map_array, CHECK_0);
 120 GPU_END
 121 
 122 static void showRanges(jboolean* a, int len) {
 123   // show ranges
 124   bool lookFor = true;
 125   for (int i = 0; i < len; i++) {
 126     if ((lookFor == true) && (a[i] != 0)) {
 127       tty->print("%d", i);
 128       lookFor = false;
 129     } else if ((lookFor == false) && (a[i] == 0)) {
 130       tty->print_cr("-%d", i-1);
 131       lookFor = true;
 132     }
 133   }
 134   if (lookFor == false) {
 135     tty->print_cr("-%d", len-1);
 136   }
 137 }
 138 
 139 jboolean Hsail::execute_kernel_void_1d_internal(address kernel, int dimX, jobject args, methodHandle& mh, nmethod* nm,
 140                                                 jobject donor_threads, int allocBytesPerWorkitem, jobject oop_map_array, TRAPS) {
 141   ResourceMark rm(THREAD);
 142   objArrayOop argsArray = (objArrayOop) JNIHandles::resolve(args);
 143   assert(THREAD->is_Java_thread(), "must be a JavaThread");
 144 
 145   // We avoid HSAILAllocationInfo logic if kernel does not allocate
 146   // in which case the donor_thread array passed in will be null
 147   HSAILAllocationInfo* allocInfo = (donor_threads == NULL ? NULL : new HSAILAllocationInfo(donor_threads, dimX, allocBytesPerWorkitem));
 148   
 149   // Reset the kernel arguments
 150   _okra_clear_args(kernel);
 151 
 152   JavaThread* thread = (JavaThread*)THREAD;
 153   HSAILDeoptimizationInfo* e;
 154   if (UseHSAILDeoptimization) {
 155     // get how many bytes per deopt save area are required
 156     int saveAreaCounts = HSAILOopMapHelper::get_save_area_counts(oop_map_array);
 157     int numSRegs = saveAreaCounts & 0xff;
 158     int numDRegs = (saveAreaCounts >> 8) & 0xff;
 159     int numStackSlots = (saveAreaCounts >> 16);
 160     int bytesPerSaveArea = numSRegs * 4 + (numDRegs + numStackSlots) * 8;
 161 
 162     e = new (MAX_DEOPT_SLOTS, bytesPerSaveArea) HSAILDeoptimizationInfo(MAX_DEOPT_SLOTS, bytesPerSaveArea, dimX, allocInfo, oop_map_array);
 163     // copy cur_tlab_infos
 164     if (allocInfo != NULL) {
 165       e->set_cur_tlabInfos(allocInfo->getCurTlabInfos());
 166     }
 167     // set deopt info in thread so gc oops_do processing can find it




  49 // Entry to GPU native method implementation that calls a JNI function
  50 // and hence cannot transition current thread to '_thread_in_vm'.
  51 #define GPU_ENTRY(result_type, name, signature) \
  52   JNIEXPORT result_type JNICALL name signature { \
  53 
  54 #define GPU_END }
  55 
  56 #define CC (char*)  /*cast a literal from (const char*)*/
  57 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f))
  58 
  59 #define OBJECT                "Ljava/lang/Object;"
  60 #define STRING                "Ljava/lang/String;"
  61 #define JLTHREAD              "Ljava/lang/Thread;"
  62 #define HS_INSTALLED_CODE     "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;"
  63 #define HS_COMPILED_NMETHOD   "Lcom/oracle/graal/hotspot/HotSpotCompiledNmethod;"
  64 #define HS_NMETHOD            "Lcom/oracle/graal/hotspot/meta/HotSpotNmethod;"
  65 
  66 JNINativeMethod Hsail::HSAIL_methods[] = {
  67   {CC"initialize",       CC"()Z",                               FN_PTR(Hsail::initialize)},
  68   {CC"generateKernel",   CC"([B" STRING ")J",                   FN_PTR(Hsail::generate_kernel)},
  69   {CC"executeKernel0",   CC"("HS_INSTALLED_CODE"I["OBJECT"II[I)Z",  FN_PTR(Hsail::execute_kernel_void_1d)},
  70 };
  71 
  72 void* Hsail::_device_context = NULL;
  73 jint  Hsail::_notice_safepoints = false;
  74 
  75 Hsail::okra_get_context_func_t     Hsail::_okra_get_context;
  76 Hsail::okra_create_kernel_func_t   Hsail::_okra_create_kernel;
  77 Hsail::okra_push_pointer_func_t    Hsail::_okra_push_pointer;
  78 Hsail::okra_push_boolean_func_t    Hsail::_okra_push_boolean;
  79 Hsail::okra_push_byte_func_t       Hsail::_okra_push_byte;
  80 Hsail::okra_push_double_func_t     Hsail::_okra_push_double;
  81 Hsail::okra_push_float_func_t      Hsail::_okra_push_float;
  82 Hsail::okra_push_int_func_t        Hsail::_okra_push_int;
  83 Hsail::okra_push_long_func_t       Hsail::_okra_push_long;
  84 Hsail::okra_execute_kernel_func_t  Hsail::_okra_execute_kernel;
  85 Hsail::okra_clear_args_func_t      Hsail::_okra_clear_args;
  86 Hsail::okra_dispose_kernel_func_t  Hsail::_okra_dispose_kernel;
  87 Hsail::okra_dispose_context_func_t Hsail::_okra_dispose_context;
  88 
  89 //static jint in_kernel = 0;
  90 
  91 void Hsail::notice_safepoints() {
  92   _notice_safepoints = true;
  93 //  if (TraceGPUInteraction) {
  94 //    tty->print_cr("[HSAIL] Notice safepoint in_kernel=%d", in_kernel);
  95 //  }
  96 }
  97 
  98 void Hsail::ignore_safepoints() {
  99   _notice_safepoints = false;
 100 }
 101 
 102 GPU_VMENTRY(jboolean, Hsail::execute_kernel_void_1d, (JNIEnv* env, jclass, jobject kernel_handle, jint dimX, jobject args,
 103                                                       jint num_tlabs, jint allocBytesPerWorkitem, jobject oop_map_array))
 104 
 105   ResourceMark rm;
 106   jlong nmethodValue = InstalledCode::address(kernel_handle);
 107   if (nmethodValue == 0) {
 108     SharedRuntime::throw_and_post_jvmti_exception(JavaThread::current(), vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException(), NULL);
 109   }
 110   nmethod* nm = (nmethod*) (address) nmethodValue;
 111   methodHandle mh = nm->method();
 112   Symbol* signature = mh->signature();
 113 
 114   void* kernel = (void*) HotSpotInstalledCode::codeStart(kernel_handle);
 115   if (kernel == NULL) {
 116     SharedRuntime::throw_and_post_jvmti_exception(JavaThread::current(), vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException(), NULL);
 117   }
 118 
 119 return execute_kernel_void_1d_internal((address) kernel, dimX, args, mh, nm, num_tlabs, allocBytesPerWorkitem, oop_map_array, CHECK_0);
 120 GPU_END
 121 
 122 static void showRanges(jboolean* a, int len) {
 123   // show ranges
 124   bool lookFor = true;
 125   for (int i = 0; i < len; i++) {
 126     if ((lookFor == true) && (a[i] != 0)) {
 127       tty->print("%d", i);
 128       lookFor = false;
 129     } else if ((lookFor == false) && (a[i] == 0)) {
 130       tty->print_cr("-%d", i-1);
 131       lookFor = true;
 132     }
 133   }
 134   if (lookFor == false) {
 135     tty->print_cr("-%d", len-1);
 136   }
 137 }
 138 
 139 jboolean Hsail::execute_kernel_void_1d_internal(address kernel, int dimX, jobject args, methodHandle& mh, nmethod* nm,
 140                                                 jint num_tlabs, int allocBytesPerWorkitem, jobject oop_map_array, TRAPS) {
 141   ResourceMark rm(THREAD);
 142   objArrayOop argsArray = (objArrayOop) JNIHandles::resolve(args);
 143   assert(THREAD->is_Java_thread(), "must be a JavaThread");
 144 
 145   // We avoid HSAILAllocationInfo logic if kernel does not allocate
 146   // in which case the num_tlabs passed in will be 0
 147   HSAILAllocationInfo* allocInfo = (num_tlabs == 0 ?  NULL : new HSAILAllocationInfo(num_tlabs, dimX, allocBytesPerWorkitem));
 148   
 149   // Reset the kernel arguments
 150   _okra_clear_args(kernel);
 151 
 152   JavaThread* thread = (JavaThread*)THREAD;
 153   HSAILDeoptimizationInfo* e;
 154   if (UseHSAILDeoptimization) {
 155     // get how many bytes per deopt save area are required
 156     int saveAreaCounts = HSAILOopMapHelper::get_save_area_counts(oop_map_array);
 157     int numSRegs = saveAreaCounts & 0xff;
 158     int numDRegs = (saveAreaCounts >> 8) & 0xff;
 159     int numStackSlots = (saveAreaCounts >> 16);
 160     int bytesPerSaveArea = numSRegs * 4 + (numDRegs + numStackSlots) * 8;
 161 
 162     e = new (MAX_DEOPT_SLOTS, bytesPerSaveArea) HSAILDeoptimizationInfo(MAX_DEOPT_SLOTS, bytesPerSaveArea, dimX, allocInfo, oop_map_array);
 163     // copy cur_tlab_infos
 164     if (allocInfo != NULL) {
 165       e->set_cur_tlabInfos(allocInfo->getCurTlabInfos());
 166     }
 167     // set deopt info in thread so gc oops_do processing can find it