Exemple #1
0
Point* Point_new0()
{
  Point* pthis = malloc( sizeof( Point ) );
  memset(pthis, 0, sizeof( Point ) );
  pthis->dtor  = FN_PTR(Point_dtor);
  pthis->print = FN_PTR(Point_print);
}
Exemple #2
0
Circle* Circle_new0()
{
  Circle* pthis = malloc( sizeof( Circle ) );
  memset(pthis, 0, sizeof( Circle ) );
  pthis->dtor  = FN_PTR(Circle_dtor);
  pthis->print = FN_PTR(Circle_print);
}
Exemple #3
0
Point* Point_copy(Point* p)
{
  Point* pthis = malloc( sizeof( Point ) );
  memcpy(pthis, p, sizeof( Point ) );
  pthis->dtor  = FN_PTR(Point_dtor);
  pthis->print = FN_PTR(Point_print);
  return pthis;
}
Exemple #4
0
Point* Point_new2(int x0, int y0)
{
  Point* pthis = malloc( sizeof( Point ) );
  pthis->x = x0;
  pthis->y = y0;
  pthis->dtor  = FN_PTR(Point_dtor);
  pthis->print = FN_PTR(Point_print);
}
Exemple #5
0
Circle* Circle_copy(Circle* c)
{
  Circle* pthis = malloc( sizeof( Circle ) );
  memcpy(pthis, c, sizeof( Circle ) );
  pthis->dtor  = FN_PTR(Circle_dtor);
  pthis->print = FN_PTR(Circle_print);
  return pthis;
}
Exemple #6
0
Circle* Circle_new2(int x0, int y0)
{
  Circle* pthis = malloc( sizeof( Circle ) );
  pthis->x = x0;
  pthis->y = y0;
  pthis->r = 0;
  pthis->dtor  = FN_PTR(Circle_dtor);
  pthis->print = FN_PTR(Circle_print);
}
Exemple #7
0
Circle* Circle_newP1(Point* p, int r0)
{
  Circle* pthis = malloc( sizeof( Circle ) );
  pthis->x = p->x;
  pthis->y = p->y;
  pthis->r = r0;
  pthis->dtor  = FN_PTR(Circle_dtor);
  pthis->print = FN_PTR(Circle_print);
}
Exemple #8
0
  JNIEXPORT result_type JNICALL name signature { \

#define GPU_END }

#define CC (char*)  /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f))

#define OBJECT                "Ljava/lang/Object;"
#define STRING                "Ljava/lang/String;"
#define JLTHREAD              "Ljava/lang/Thread;"
#define HS_INSTALLED_CODE     "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;"
#define HS_COMPILED_NMETHOD   "Lcom/oracle/graal/hotspot/HotSpotCompiledNmethod;"
#define HS_NMETHOD            "Lcom/oracle/graal/hotspot/meta/HotSpotNmethod;"

JNINativeMethod Hsail::HSAIL_methods[] = {
  {CC"initialize",       CC"()Z",                               FN_PTR(Hsail::initialize)},
  {CC"generateKernel",   CC"([B" STRING ")J",                   FN_PTR(Hsail::generate_kernel)},
  {CC"executeKernel0",   CC"("HS_INSTALLED_CODE"I["OBJECT"II[I)Z",  FN_PTR(Hsail::execute_kernel_void_1d)},
};

void* Hsail::_device_context = NULL;
jint  Hsail::_notice_safepoints = false;

Hsail::okra_get_context_func_t     Hsail::_okra_get_context;
Hsail::okra_create_kernel_func_t   Hsail::_okra_create_kernel;
Hsail::okra_push_pointer_func_t    Hsail::_okra_push_pointer;
Hsail::okra_push_boolean_func_t    Hsail::_okra_push_boolean;
Hsail::okra_push_byte_func_t       Hsail::_okra_push_byte;
Hsail::okra_push_double_func_t     Hsail::_okra_push_double;
Hsail::okra_push_float_func_t      Hsail::_okra_push_float;
Hsail::okra_push_int_func_t        Hsail::_okra_push_int;
Exemple #9
0
  mangle_name_on(&st, signature, 1, end);
  return st.as_string();
}

extern "C" {
  void JNICALL JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls);
  void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls);
  void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
}

#define CC (char*)  /* cast a literal from (const char*) */
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)

static JNINativeMethod lookup_special_native_methods[] = {
  // Next two functions only exist for compatibility with 1.3.1 and earlier.
  { CC"Java_java_io_ObjectOutputStream_getPrimitiveFieldValues",   NULL, FN_PTR(JVM_GetPrimitiveFieldValues)     },  // intercept ObjectOutputStream getPrimitiveFieldValues for faster serialization
  { CC"Java_java_io_ObjectInputStream_setPrimitiveFieldValues",    NULL, FN_PTR(JVM_SetPrimitiveFieldValues)     },  // intercept ObjectInputStream setPrimitiveFieldValues for faster serialization

  { CC"Java_sun_misc_Unsafe_registerNatives",                      NULL, FN_PTR(JVM_RegisterUnsafeMethods)       },
  { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
  { CC"Java_sun_misc_Perf_registerNatives",                        NULL, FN_PTR(JVM_RegisterPerfMethods)         }
};

/**
 * 特殊的本地方法,jdk1.4之前是5个,之后是3个
 */
static address lookup_special_native(char* jni_name) {
  int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2;  // see comment in lookup_special_native_methods
  int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  for (; i < count; i++) {
    // NB: To ignore the jni prefix and jni postfix strstr is used matching.
  mangle_name_on(&st, signature, 1, end);
  return st.as_string();
}

extern "C" {
  void JNICALL JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls);
  void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls);
  void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
  void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass);
}

#define CC (char*)  /* cast a literal from (const char*) */
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)

static JNINativeMethod lookup_special_native_methods[] = {
  { CC"Java_sun_misc_Unsafe_registerNatives",                      NULL, FN_PTR(JVM_RegisterUnsafeMethods)       },
  { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
  { CC"Java_sun_misc_Perf_registerNatives",                        NULL, FN_PTR(JVM_RegisterPerfMethods)         },
  { CC"Java_sun_hotspot_WhiteBox_registerNatives",                 NULL, FN_PTR(JVM_RegisterWhiteBoxMethods)     },
};

static address lookup_special_native(char* jni_name) {
  int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  for (int i = 0; i < count; i++) {
    // NB: To ignore the jni prefix and jni postfix strstr is used matching.
    if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) {
      return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr);
    }
  }
  return NULL;
}
Exemple #11
0
// Entry to GPU native method implementation that calls a JNI function
// and hence cannot transition current thread to '_thread_in_vm'.
#define GPU_ENTRY(result_type, name, signature) \
  JNIEXPORT result_type JNICALL name signature { \
  if (TraceGPUInteraction) tty->print_cr("[CUDA] Ptx::" #name); \

#define GPU_END }

#define CC (char*)  /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f))

#define STRING                "Ljava/lang/String;"

JNINativeMethod Ptx::PTX_methods[] = {
  {CC"initialize",              CC"()Z",               FN_PTR(Ptx::initialize)},
  {CC"generateKernel",          CC"([B" STRING ")J",   FN_PTR(Ptx::generate_kernel)},
  {CC"getLaunchKernelAddress",  CC"()J",               FN_PTR(Ptx::get_execute_kernel_from_vm_address)},
  {CC"getAvailableProcessors0", CC"()I",               FN_PTR(Ptx::get_total_cores)},
  {CC"destroyContext",          CC"()V",               FN_PTR(Ptx::destroy_ptx_context)},
};

void * Ptx::_device_context = 0;
int    Ptx::_cu_device = 0;

Ptx::cuda_cu_init_func_t Ptx::_cuda_cu_init;
Ptx::cuda_cu_ctx_create_func_t Ptx::_cuda_cu_ctx_create;
Ptx::cuda_cu_ctx_destroy_func_t Ptx::_cuda_cu_ctx_destroy;
Ptx::cuda_cu_ctx_synchronize_func_t Ptx::_cuda_cu_ctx_synchronize;
Ptx::cuda_cu_ctx_get_current_func_t Ptx::_cuda_cu_ctx_get_current;
Ptx::cuda_cu_ctx_set_current_func_t Ptx::_cuda_cu_ctx_set_current;