< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.hpp

Print this page
rev 52100 : 8212083: Handle remaining gc/lock native code and fix two strings
Summary:
Reviewed-by:


  49  *  jclass klass = env->GetObjectClass(o);
  50  *
  51  *  Where now the JNI Exception checking and the NULL return checking are done
  52  *  internally and will perform whatever action the ErrorHandler requires.
  53  *
  54  *  By default, the error handler describes the exception via the JNI
  55  *  ExceptionDescribe method and calls FatalError.
  56  *
  57  *  Note: at a future date, this will also include the tracing mechanism done in
  58  *  NSK_VERIFY, which will thus embed its logic into the ExceptionCheckingJniEnv
  59  *  and clearing that up for the code readers and writers.
  60  */
  61 class ExceptionCheckingJniEnv {
  62  public:
  63   // JNIEnv API redefinitions.
  64   jfieldID GetFieldID(jclass klass, const char *name, const char* type);
  65   jclass GetObjectClass(jobject obj);
  66   jobject GetObjectField(jobject obj, jfieldID field);
  67   void SetObjectField(jobject obj, jfieldID field, jobject value);
  68 








  69   jobject NewGlobalRef(jobject obj);
  70   void DeleteGlobalRef(jobject obj);




  71 
  72   // ExceptionCheckingJniEnv methods.
  73   JNIEnv* GetJNIEnv() {
  74     return _jni_env;
  75   }
  76 
  77   void HandleError(const char* msg) {
  78     if (_error_handler) {
  79       _error_handler(_jni_env, msg);
  80     }
  81   }
  82 
  83   typedef void (*ErrorHandler)(JNIEnv* env, const char* error_message);
  84 
  85   static void FatalError(JNIEnv* env, const char* message) {
  86     if (env->ExceptionCheck()) {
  87       env->ExceptionDescribe();
  88     }
  89     env->FatalError(message);
  90   }




  49  *  jclass klass = env->GetObjectClass(o);
  50  *
  51  *  Where now the JNI Exception checking and the NULL return checking are done
  52  *  internally and will perform whatever action the ErrorHandler requires.
  53  *
  54  *  By default, the error handler describes the exception via the JNI
  55  *  ExceptionDescribe method and calls FatalError.
  56  *
  57  *  Note: at a future date, this will also include the tracing mechanism done in
  58  *  NSK_VERIFY, which will thus embed its logic into the ExceptionCheckingJniEnv
  59  *  and clearing that up for the code readers and writers.
  60  */
  61 class ExceptionCheckingJniEnv {
  62  public:
  63   // JNIEnv API redefinitions.
  64   jfieldID GetFieldID(jclass klass, const char *name, const char* type);
  65   jclass GetObjectClass(jobject obj);
  66   jobject GetObjectField(jobject obj, jfieldID field);
  67   void SetObjectField(jobject obj, jfieldID field, jobject value);
  68 
  69   jsize GetArrayLength(jarray array);
  70   jsize GetStringLength(jstring str);
  71 
  72   void* GetPrimitiveArrayCritical(jarray array, jboolean* isCopy);
  73   void ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode);
  74   const jchar* GetStringCritical(jstring str, jboolean* isCopy);
  75   void ReleaseStringCritical(jstring str, const jchar* carray);
  76 
  77   jobject NewGlobalRef(jobject obj);
  78   void DeleteGlobalRef(jobject obj);
  79   jobject NewLocalRef(jobject ref);
  80   void DeleteLocalRef(jobject ref);
  81   jweak NewWeakGlobalRef(jobject obj);
  82   void DeleteWeakGlobalRef(jweak obj);
  83 
  84   // ExceptionCheckingJniEnv methods.
  85   JNIEnv* GetJNIEnv() {
  86     return _jni_env;
  87   }
  88 
  89   void HandleError(const char* msg) {
  90     if (_error_handler) {
  91       _error_handler(_jni_env, msg);
  92     }
  93   }
  94 
  95   typedef void (*ErrorHandler)(JNIEnv* env, const char* error_message);
  96 
  97   static void FatalError(JNIEnv* env, const char* message) {
  98     if (env->ExceptionCheck()) {
  99       env->ExceptionDescribe();
 100     }
 101     env->FatalError(message);
 102   }


< prev index next >