harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r487483 [3/4] - in /harmony/enhanced/drlvm/trunk: build/make/targets/ vm/interpreter/src/ vm/jitrino/src/jet/ vm/port/src/lil/em64t/pim/ vm/port/src/lil/ia32/pim/ vm/port/src/lil/ipf/pim/ vm/tests/smoke/shutdown/ vm/vmcore/include/ vm/vmcor...
Date Fri, 15 Dec 2006 08:33:23 GMT
Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp?view=diff&rev=487483&r1=487482&r2=487483
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp Fri Dec 15 00:33:21 2006
@@ -38,7 +38,7 @@
 #include "jni_utils.h"
 #include "exceptions.h"
 
-jsize JNICALL GetArrayLength(JNIEnv * UNREF env,
+jsize JNICALL GetArrayLength(JNIEnv * UNREF jni_env,
                              jarray array)
 {
     TRACE2("jni", "GetArrayLength called");
@@ -53,7 +53,7 @@
 } //GetArrayLength
 
 
-jarray JNICALL NewObjectArray(JNIEnv * UNREF env,
+jarray JNICALL NewObjectArray(JNIEnv * jni_env,
                               jsize length,
                               jclass elementClass,
                               jobject initialElement)
@@ -61,6 +61,10 @@
     ASSERT_RAISE_AREA;
     TRACE2("jni", "NewObjectArray called");
     assert(hythread_is_suspend_enabled());
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle elem_handle = (ObjectHandle)initialElement;
 
     Class* clss = jclass_to_struct_Class(elementClass);
@@ -68,7 +72,7 @@
     Class *arr_clss = (Class *)class_get_array_of_class(clss);
 
     if(!arr_clss) {
-         return 0;
+        return NULL;
     }
 
     // esostrov: vm_new_vector() may throw an exception. Throwing (not rising) 
@@ -105,8 +109,8 @@
     // only if the elem is non-null.
     if (elem != NULL) {
         ManagedObject **elems = (ManagedObject **)get_vector_element_address_ref(vector, 0);
-        Global_Env *global_env = VM_Global_State::loader_env;
-        if (global_env->compress_references) {
+        Global_Env * vm_env = VM_Global_State::loader_env;
+        if (vm_env->compress_references) {
             COMPRESSED_REFERENCE elem_offset = compress_reference((ManagedObject *)elem);
             COMPRESSED_REFERENCE *compressed_elems = (COMPRESSED_REFERENCE *)elems;
             for (int i = 0; i < length; i++) {
@@ -128,21 +132,20 @@
 
 
 
-jobject JNICALL GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
+jobject JNICALL GetObjectArrayElement(JNIEnv * jni_env, jobjectArray array, jsize index)
 {
     TRACE2("jni", "GetObjectArrayElement called");
     assert(hythread_is_suspend_enabled());
-    if (array == NULL) {
-        // This should not happen.
-        ASSERT(0, "Input parameter 'array' is NULL");
-        return 0;
-    }
+    assert(array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
 
-    jsize length = GetArrayLength(env, array);
+    jsize length = GetArrayLength(jni_env, array);
     if ((index < 0) || (index >= length)) {
         char msg[20];
         sprintf(msg, "%d", index);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return 0;
     }
 
@@ -165,39 +168,38 @@
 
 
 
-void JNICALL SetObjectArrayElement(JNIEnv *env,
+void JNICALL SetObjectArrayElement(JNIEnv * jni_env,
                                    jobjectArray array,
                                    jsize index,
                                    jobject value)
 {
     TRACE2("jni", "SetObjectArrayElement called");
     assert(hythread_is_suspend_enabled());
-    if (array == NULL) {
-        // This should not happen.
-        ASSERT(0, "Input parameter 'array' is NULL");
-        return;
-    }
+    assert(array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
 
-    jsize length = GetArrayLength(env, array);
+    jsize length = GetArrayLength(jni_env, array);
     if ((index < 0) || (index >= length)) {
         char msg[20];
         sprintf(msg, "%d", index);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
     if (value != NULL) {
-        jclass array_jclass = GetObjectClass(env, array);
-        jclass actual_element_jclass = GetObjectClass(env, value);
+        jclass array_jclass = GetObjectClass(jni_env, array);
+        jclass actual_element_jclass = GetObjectClass(jni_env, value);
         
         Class* array_class = jclass_to_struct_Class(array_jclass);
         Class* actual_element_class = jclass_to_struct_Class(actual_element_jclass);
 
-        DeleteLocalRef(env, array_jclass);
-        DeleteLocalRef(env, actual_element_jclass);
+        DeleteLocalRef(jni_env, array_jclass);
+        DeleteLocalRef(jni_env, actual_element_jclass);
 
         if (!actual_element_class->is_instanceof(array_class->get_array_element_class())) {
-            ThrowNew_Quick(env, "java/lang/ArrayStoreException", actual_element_class->get_name()->bytes);
+            ThrowNew_Quick(jni_env, "java/lang/ArrayStoreException", actual_element_class->get_name()->bytes);
             return;
         }
     }
@@ -227,12 +229,15 @@
 
 
 
-jbooleanArray JNICALL NewBooleanArray(JNIEnv * UNREF env, jsize length)
+jbooleanArray JNICALL NewBooleanArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewBooleanArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfBoolean_Class;
     
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+    
+    Class *clss = vm_env->ArrayOfBoolean_Class;    
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -259,13 +264,15 @@
 
 
 
-jbyteArray JNICALL NewByteArray(JNIEnv * UNREF env, jsize length)
+jbyteArray JNICALL NewByteArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewByteArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfByte_Class;
-    assert(clss);
- 
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+    
+    Class *clss = vm_env->ArrayOfByte_Class;
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -292,12 +299,15 @@
 
 
 
-jcharArray JNICALL NewCharArray(JNIEnv * UNREF env, jsize length)
+jcharArray JNICALL NewCharArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewCharArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfChar_Class;
- 
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
+    Class *clss = vm_env->ArrayOfChar_Class;
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -324,12 +334,15 @@
 
 
 
-jshortArray JNICALL NewShortArray(JNIEnv * UNREF env, jsize length)
+jshortArray JNICALL NewShortArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewShortArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfShort_Class;
- 
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+    
+    Class *clss = vm_env->ArrayOfShort_Class; 
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -357,11 +370,15 @@
 
 
 
-jintArray JNICALL NewIntArray(JNIEnv * UNREF env, jsize length)
+jintArray JNICALL NewIntArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewIntArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfInt_Class;
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+    
+    Class *clss = vm_env->ArrayOfInt_Class;
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -388,11 +405,15 @@
 
 
 
-jlongArray JNICALL NewLongArray(JNIEnv * UNREF env, jsize length)
+jlongArray JNICALL NewLongArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewLongArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfLong_Class;
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
+    Class *clss = vm_env->ArrayOfLong_Class;
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -419,11 +440,15 @@
 
 
 
-jfloatArray JNICALL NewFloatArray(JNIEnv * UNREF env, jsize length)
+jfloatArray JNICALL NewFloatArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewFloatArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfFloat_Class;
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+    
+    Class *clss = vm_env->ArrayOfFloat_Class;
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -450,11 +475,15 @@
 
 
 
-jdoubleArray JNICALL NewDoubleArray(JNIEnv * UNREF env, jsize length)
+jdoubleArray JNICALL NewDoubleArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewDoubleArray called");
     assert(hythread_is_suspend_enabled());
-    Class *clss = VM_Global_State::loader_env->ArrayOfDouble_Class;
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+    
+    Class *clss = vm_env->ArrayOfDouble_Class;
     unsigned sz = clss->calculate_array_size(length);
     tmn_suspend_disable();       //---------------------------------v
     ObjectHandle h = oh_allocate_local_handle();
@@ -489,12 +518,16 @@
 // begin Get<Type>ArrayElements functions
 
 
-jboolean *JNICALL GetBooleanArrayElements(JNIEnv * UNREF env,
+jboolean *JNICALL GetBooleanArrayElements(JNIEnv * jni_env,
                                           jbooleanArray array,
                                           jboolean *isCopy)
 {
     TRACE2("jni", "GetBooleanArrayElements called");
     assert(hythread_is_suspend_enabled());
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -529,12 +562,16 @@
 
 
 
-jbyte *JNICALL GetByteArrayElements(JNIEnv * UNREF env,
+jbyte *JNICALL GetByteArrayElements(JNIEnv * jni_env,
                                     jbyteArray array,
                                     jboolean *isCopy)
 {
     TRACE2("jni", "GetByteArrayElements called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -569,12 +606,16 @@
 
 
 
-jchar *JNICALL GetCharArrayElements(JNIEnv * UNREF env,
+jchar *JNICALL GetCharArrayElements(JNIEnv * jni_env,
                                     jcharArray array,
                                     jboolean *isCopy)
 {
     TRACE2("jni", "GetCharArrayElements called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -609,12 +650,16 @@
 
 
 
-jshort *JNICALL GetShortArrayElements(JNIEnv * UNREF env,
+jshort *JNICALL GetShortArrayElements(JNIEnv * jni_env,
                                       jshortArray array,
                                       jboolean *isCopy)
 {
     TRACE2("jni", "GetShortArrayElements called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -649,12 +694,16 @@
 
 
 
-jint *JNICALL GetIntArrayElements(JNIEnv *env,
+jint *JNICALL GetIntArrayElements(JNIEnv * jni_env,
                                   jintArray array,
                                   jboolean *isCopy)
 {
     TRACE2("jni", "GetIntArrayElements called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -670,7 +719,7 @@
         Vector_Handle java_array = (Vector_Handle)h->object;
         return (jint *)get_vector_element_address_int32(java_array, 0);
     } else {
-        jsize length = GetArrayLength(env, array);
+        jsize length = GetArrayLength(jni_env, array);
 
         jint *primitive_array = (jint *)STD_MALLOC(sizeof(jint) * length);
 
@@ -690,12 +739,16 @@
 
 
 
-jlong *JNICALL GetLongArrayElements(JNIEnv * UNREF env,
+jlong *JNICALL GetLongArrayElements(JNIEnv * jni_env,
                                     jlongArray array,
                                     jboolean *isCopy)
 {
     TRACE2("jni", "GetLongArrayElements called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -730,12 +783,16 @@
 
 
 
-jfloat *JNICALL GetFloatArrayElements(JNIEnv *env,
+jfloat *JNICALL GetFloatArrayElements(JNIEnv * jni_env,
                                       jfloatArray array,
                                       jboolean *isCopy)
 {
     TRACE2("jni", "GetFloatArrayElements called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -751,7 +808,7 @@
         Vector_Handle java_array = (Vector_Handle)h->object;
         return (jfloat *)get_vector_element_address_f32(java_array, 0);
     } else {
-        jsize length = GetArrayLength(env, array);
+        jsize length = GetArrayLength(jni_env, array);
 
         jfloat *primitive_array = (jfloat *)STD_MALLOC(sizeof(jfloat) * length);
 
@@ -771,12 +828,16 @@
 
 
 
-jdouble *JNICALL GetDoubleArrayElements(JNIEnv * UNREF env,
+jdouble *JNICALL GetDoubleArrayElements(JNIEnv * jni_env,
                                         jdoubleArray array,
                                         jboolean *isCopy)
 {
     TRACE2("jni", "GetDoubleArrayElements called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     ObjectHandle h = (ObjectHandle)array;
 
     tmn_suspend_disable();       //---------------------------------v
@@ -820,7 +881,7 @@
 // begin Release<Type>ArrayElements functions
 
 
-void JNICALL ReleaseBooleanArrayElements(JNIEnv *env,
+void JNICALL ReleaseBooleanArrayElements(JNIEnv * jni_env,
                                          jbooleanArray array,
                                          jboolean *elems,
                                          jint mode)
@@ -828,6 +889,10 @@
     TRACE2("jni", "ReleaseBooleanArrayElements called");
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
+
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -845,7 +910,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             tmn_suspend_disable();       //---------------------------------v
 
             Vector_Handle java_array = (Vector_Handle)h->object;
@@ -870,7 +935,7 @@
 
 
 
-void JNICALL ReleaseByteArrayElements(JNIEnv *env,
+void JNICALL ReleaseByteArrayElements(JNIEnv * jni_env,
                                       jbyteArray array,
                                       jbyte *elems,
                                       jint mode)
@@ -879,6 +944,9 @@
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
 
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -896,7 +964,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             tmn_suspend_disable();       //---------------------------------v
 
             Vector_Handle java_array = (Vector_Handle)h->object;
@@ -920,7 +988,7 @@
 
 
 
-void JNICALL ReleaseCharArrayElements(JNIEnv *env,
+void JNICALL ReleaseCharArrayElements(JNIEnv * jni_env,
                                       jcharArray array,
                                       jchar *elems,
                                       jint mode)
@@ -928,6 +996,10 @@
     TRACE2("jni", "ReleaseCharArrayElements called");
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
+
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -945,7 +1017,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             ObjectHandle h = (ObjectHandle)array;
             tmn_suspend_disable();       //---------------------------------v
 
@@ -970,7 +1042,7 @@
 
 
 
-void JNICALL ReleaseShortArrayElements(JNIEnv *env,
+void JNICALL ReleaseShortArrayElements(JNIEnv * jni_env,
                                        jshortArray array,
                                        jshort *elems,
                                        jint mode)
@@ -978,6 +1050,10 @@
     TRACE2("jni", "ReleaseShortArrayElements called");
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
+ 
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+    
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -995,7 +1071,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             ObjectHandle h = (ObjectHandle)array;
             tmn_suspend_disable();       //---------------------------------v
 
@@ -1020,7 +1096,7 @@
 
 
 
-void JNICALL ReleaseIntArrayElements(JNIEnv *env,
+void JNICALL ReleaseIntArrayElements(JNIEnv * jni_env,
                                      jintArray array,
                                      jint *elems,
                                      jint mode)
@@ -1028,6 +1104,10 @@
     TRACE2("jni", "ReleaseIntArrayElements called");
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
+
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -1045,7 +1125,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             ObjectHandle h = (ObjectHandle)array;
             tmn_suspend_disable();       //---------------------------------v
 
@@ -1070,7 +1150,7 @@
 
 
 
-void JNICALL ReleaseLongArrayElements(JNIEnv *env,
+void JNICALL ReleaseLongArrayElements(JNIEnv * jni_env,
                                       jlongArray array,
                                       jlong *elems,
                                       jint mode)
@@ -1078,6 +1158,10 @@
     TRACE2("jni", "ReleaseLongArrayElements called");
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
+
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -1095,7 +1179,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             ObjectHandle h = (ObjectHandle)array;
             tmn_suspend_disable();       //---------------------------------v
 
@@ -1120,7 +1204,7 @@
 
 
 
-void JNICALL ReleaseFloatArrayElements(JNIEnv *env,
+void JNICALL ReleaseFloatArrayElements(JNIEnv * jni_env,
                                        jfloatArray array,
                                        jfloat *elems,
                                        jint mode)
@@ -1128,6 +1212,10 @@
     TRACE2("jni", "ReleaseFloatArrayElements called");
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
+
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -1145,7 +1233,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             ObjectHandle h = (ObjectHandle)array;
             tmn_suspend_disable();       //---------------------------------v
 
@@ -1171,7 +1259,7 @@
 
 
 
-void JNICALL ReleaseDoubleArrayElements(JNIEnv *env,
+void JNICALL ReleaseDoubleArrayElements(JNIEnv * jni_env,
                                         jdoubleArray array,
                                         jdouble *elems,
                                         jint mode)
@@ -1179,6 +1267,10 @@
     TRACE2("jni", "ReleaseDoubleArrayElements called");
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)array;
+
+    // It is better to be user frendly and don't crash if nothing should be released.
+    if (elems == NULL) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Vector_Handle java_array = (Vector_Handle)h->object;
@@ -1196,7 +1288,7 @@
     case 0:
     case JNI_COMMIT:
         {
-            jsize length = GetArrayLength(env, array);
+            jsize length = GetArrayLength(jni_env, array);
             ObjectHandle h = (ObjectHandle)array;
             tmn_suspend_disable();       //---------------------------------v
 
@@ -1230,7 +1322,7 @@
 // begin Get<Type>ArrayRegion functions
 
 
-void JNICALL GetBooleanArrayRegion (JNIEnv *env,
+void JNICALL GetBooleanArrayRegion (JNIEnv * jni_env,
                                     jobjectArray array,
                                     jsize start,
                                     jsize len,
@@ -1238,12 +1330,16 @@
 {
     TRACE2("jni", "GetBooleanArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+    
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1259,7 +1355,7 @@
 
 
 
-void JNICALL GetByteArrayRegion    (JNIEnv *env,
+void JNICALL GetByteArrayRegion    (JNIEnv * jni_env,
                                     jobjectArray array,
                                     jsize start,
                                     jsize len,
@@ -1267,12 +1363,16 @@
 {
     TRACE2("jni", "GetByteArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1288,7 +1388,7 @@
 
 
 
-void JNICALL GetCharArrayRegion(JNIEnv *env,
+void JNICALL GetCharArrayRegion(JNIEnv * jni_env,
                                 jobjectArray array,
                                 jsize start,
                                 jsize len,
@@ -1296,12 +1396,16 @@
 {
     TRACE2("jni", "GetCharArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1317,7 +1421,7 @@
 
 
 
-void JNICALL GetShortArrayRegion(JNIEnv *env,
+void JNICALL GetShortArrayRegion(JNIEnv * jni_env,
                                  jobjectArray array, 
                                  jsize start,
                                  jsize len,
@@ -1325,12 +1429,16 @@
 {
     TRACE2("jni", "GetShortArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1346,7 +1454,7 @@
 
 
 
-void JNICALL GetIntArrayRegion(JNIEnv *env,
+void JNICALL GetIntArrayRegion(JNIEnv * jni_env,
                                jobjectArray array,
                                jsize start,
                                jsize len,
@@ -1354,12 +1462,16 @@
 {
     TRACE2("jni", "GetIntArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1375,7 +1487,7 @@
 
 
 
-void JNICALL GetLongArrayRegion(JNIEnv *env,
+void JNICALL GetLongArrayRegion(JNIEnv * jni_env,
                                 jobjectArray array,
                                 jsize start,
                                 jsize len,
@@ -1383,12 +1495,16 @@
 {
     TRACE2("jni", "GetLongArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1404,7 +1520,7 @@
 
 
 
-void JNICALL GetFloatArrayRegion(JNIEnv *env,
+void JNICALL GetFloatArrayRegion(JNIEnv * jni_env,
                                  jobjectArray array,
                                  jsize start,
                                  jsize len,
@@ -1412,12 +1528,16 @@
 {
     TRACE2("jni", "GetFloatArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1433,7 +1553,7 @@
 
 
 
-void JNICALL GetDoubleArrayRegion(JNIEnv *env,
+void JNICALL GetDoubleArrayRegion(JNIEnv * jni_env,
                                   jobjectArray array,
                                   jsize start,
                                   jsize len,
@@ -1441,12 +1561,16 @@
 {
     TRACE2("jni", "GetDoubleArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1470,7 +1594,7 @@
 // begin Set<Type>ArrayRegion functions
 
 
-void JNICALL SetBooleanArrayRegion(JNIEnv *env,
+void JNICALL SetBooleanArrayRegion(JNIEnv * jni_env,
                                    jobjectArray array,
                                    jsize start,
                                    jsize len,
@@ -1478,12 +1602,16 @@
 {
     TRACE2("jni", "SetBooleanArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1501,7 +1629,7 @@
 
 
 
-void JNICALL SetByteArrayRegion(JNIEnv *env,
+void JNICALL SetByteArrayRegion(JNIEnv * jni_env,
                                 jobjectArray array,
                                 jsize start,
                                 jsize len,
@@ -1509,12 +1637,16 @@
 {
     TRACE2("jni", "SetByteArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1532,7 +1664,7 @@
 
 
 
-void JNICALL SetCharArrayRegion(JNIEnv *env,
+void JNICALL SetCharArrayRegion(JNIEnv * jni_env,
                                 jobjectArray array,
                                 jsize start,
                                 jsize len,
@@ -1540,12 +1672,16 @@
 {
     TRACE2("jni", "SetCharArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1563,7 +1699,7 @@
 
 
 
-void JNICALL SetShortArrayRegion(JNIEnv *env,
+void JNICALL SetShortArrayRegion(JNIEnv * jni_env,
                                  jobjectArray array,
                                  jsize start,
                                  jsize len,
@@ -1571,12 +1707,16 @@
 {
     TRACE2("jni", "SetShortArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1594,7 +1734,7 @@
 
 
 
-void JNICALL SetIntArrayRegion(JNIEnv *env,
+void JNICALL SetIntArrayRegion(JNIEnv * jni_env,
                                jobjectArray array,
                                jsize start,
                                jsize len,
@@ -1602,12 +1742,16 @@
 {
     TRACE2("jni", "SetIntArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1625,7 +1769,7 @@
 
 
 
-void JNICALL SetLongArrayRegion(JNIEnv *env,
+void JNICALL SetLongArrayRegion(JNIEnv * jni_env,
                                 jobjectArray array,
                                 jsize start,
                                 jsize len,
@@ -1633,12 +1777,16 @@
 {
     TRACE2("jni", "SetLongArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1656,7 +1804,7 @@
 
 
 
-void JNICALL SetFloatArrayRegion(JNIEnv *env,
+void JNICALL SetFloatArrayRegion(JNIEnv * jni_env,
                                  jobjectArray array,
                                  jsize start,
                                  jsize len,
@@ -1664,12 +1812,16 @@
 {
     TRACE2("jni", "SetFloatArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 
@@ -1687,7 +1839,7 @@
 
 
 
-void JNICALL SetDoubleArrayRegion(JNIEnv *env,
+void JNICALL SetDoubleArrayRegion(JNIEnv * jni_env,
                                   jobjectArray array,
                                   jsize start,
                                   jsize len,
@@ -1695,12 +1847,16 @@
 {
     TRACE2("jni", "SetDoubleArrayRegion called");
     assert(hythread_is_suspend_enabled());
-    jsize length = GetArrayLength(env, array);
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
+    jsize length = GetArrayLength(jni_env, array);
     jsize end = start + len;
     if(start < 0 || len < 0 || end > length) {
         char msg[30];
         sprintf(msg, "%d..%d", start, end);
-        ThrowNew_Quick(env, "java/lang/ArrayIndexOutOfBoundsException", msg);
+        ThrowNew_Quick(jni_env, "java/lang/ArrayIndexOutOfBoundsException", msg);
         return;
     }
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_field.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_field.cpp?view=diff&rev=487483&r1=487482&r2=487483
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_field.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_field.cpp Fri Dec 15 00:33:21 2006
@@ -37,18 +37,22 @@
 #include "exceptions.h"
 
 
-jfieldID JNICALL GetFieldID(JNIEnv *env,
+jfieldID JNICALL GetFieldID(JNIEnv * jni_env,
                             jclass clazz,
                             const char *name,
                             const char *sig)
 {
     TRACE2("jni", "GetFieldID called");
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Class* clss = jclass_to_struct_Class(clazz);
     Field *field = class_lookup_field_recursive(clss, name, sig);
     if (NULL == field || field->is_static())
     {
-        ThrowNew_Quick(env, "java/lang/NoSuchFieldError", name);
+        ThrowNew_Quick(jni_env, "java/lang/NoSuchFieldError", name);
         return 0;
     }
     TRACE2("jni", "GetFieldID " << clss->get_name()->bytes
@@ -61,12 +65,16 @@
 
 
 // non-standard
-jfieldID JNICALL GetFieldID_Quick(JNIEnv * UNREF env,
+jfieldID JNICALL GetFieldID_Quick(JNIEnv * jni_env,
                                   const char *class_name,
                                   const char *field_name,
                                   const char *sig)
 {
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     String *class_string = VM_Global_State::loader_env->string_pool.lookup(class_name);
     assert(hythread_is_suspend_enabled());
     Class *clss =
@@ -78,7 +86,7 @@
     return (jfieldID)field;
 } //GetFieldID_Quick
 
-jfieldID JNICALL GetStaticFieldID(JNIEnv *env,
+jfieldID JNICALL GetStaticFieldID(JNIEnv * jni_env,
                                   jclass clazz,
                                   const char *name,
                                   const char *sig)
@@ -86,11 +94,14 @@
     TRACE2("jni", "GetStaticFieldID called");
     assert(hythread_is_suspend_enabled());
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Class* clss = jclass_to_struct_Class(clazz);
     Field *field = class_lookup_field_recursive(clss, name, sig);
     if(NULL == field || !field->is_static())
     {
-        ThrowNew_Quick(env, "java/lang/NoSuchFieldError", name);
+        ThrowNew_Quick(jni_env, "java/lang/NoSuchFieldError", name);
         return 0;
     }
     TRACE2("jni", "GetStaticFieldID " << clss->get_name()->bytes
@@ -104,11 +115,14 @@
 // begin Get<Type>Field functions
 
 
-jobject JNICALL GetObjectFieldOffset(JNIEnv* UNREF env, jobject obj, jint offset)
+jobject JNICALL GetObjectFieldOffset(JNIEnv* UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -125,27 +139,31 @@
     return (jobject)new_handle;
 }
 
-jobject JNICALL GetObjectField(JNIEnv *env,
+jobject JNICALL GetObjectField(JNIEnv * jni_env,
                                jobject obj,
                                jfieldID fieldID)
 {
     TRACE2("jni", "GetObjectField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return NULL;
     assert(!f->is_static());
-    return GetObjectFieldOffset(env, obj, f->get_offset());
+    return GetObjectFieldOffset(jni_env, obj, f->get_offset());
 } //GetObjectField
 
 
-jboolean JNICALL GetBooleanFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jboolean JNICALL GetBooleanFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -156,25 +174,29 @@
     return val;
 }
 
-jboolean JNICALL GetBooleanField(JNIEnv *env,
+jboolean JNICALL GetBooleanField(JNIEnv *jni_env,
                                  jobject obj,
                                  jfieldID fieldID)
 {
     TRACE2("jni", "GetBooleanField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetBooleanFieldOffset(env, obj, f->get_offset());
+    return GetBooleanFieldOffset(jni_env, obj, f->get_offset());
 } //GetBooleanField
 
 
-jbyte JNICALL GetByteFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jbyte JNICALL GetByteFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -185,27 +207,31 @@
     return val;
 }
 
-jbyte JNICALL GetByteField(JNIEnv *env,
+jbyte JNICALL GetByteField(JNIEnv * jni_env,
                            jobject obj,
                            jfieldID fieldID)
 {
     TRACE2("jni", "GetByteField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+    
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetByteFieldOffset(env, obj, f->get_offset());
+    return GetByteFieldOffset(jni_env, obj, f->get_offset());
 } //GetByteField
 
 
-jchar JNICALL GetCharFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jchar JNICALL GetCharFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     tmn_suspend_disable();     //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -216,27 +242,31 @@
     return val;
 }
 
-jchar JNICALL GetCharField(JNIEnv *env,
+jchar JNICALL GetCharField(JNIEnv * jni_env,
                            jobject obj,
                            jfieldID fieldID)
 {
     TRACE2("jni", "GetCharField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetCharFieldOffset(env, obj, f->get_offset());
+    return GetCharFieldOffset(jni_env, obj, f->get_offset());
 } //GetCharField
 
 
-jshort JNICALL GetShortFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jshort JNICALL GetShortFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -247,27 +277,31 @@
     return val;
 }
 
-jshort JNICALL GetShortField(JNIEnv *env,
+jshort JNICALL GetShortField(JNIEnv * jni_env,
                              jobject obj,
                              jfieldID fieldID)
 {
     TRACE2("jni", "GetShortField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetShortFieldOffset(env, obj, f->get_offset());
+    return GetShortFieldOffset(jni_env, obj, f->get_offset());
 } //GetShortField
 
 
-jint JNICALL GetIntFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jint JNICALL GetIntFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -278,27 +312,31 @@
     return val;
 }
 
-jint JNICALL GetIntField(JNIEnv *env,
+jint JNICALL GetIntField(JNIEnv * jni_env,
                          jobject obj,
                          jfieldID fieldID)
 {
     TRACE2("jni", "GetIntField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetIntFieldOffset(env, obj, f->get_offset());
+    return GetIntFieldOffset(jni_env, obj, f->get_offset());
 } //GetIntField
 
 
-jlong JNICALL GetLongFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jlong JNICALL GetLongFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -309,27 +347,31 @@
     return val;
 }
 
-jlong JNICALL GetLongField(JNIEnv *env,
+jlong JNICALL GetLongField(JNIEnv * jni_env,
                            jobject obj,
                            jfieldID fieldID)
 {
     TRACE2("jni", "GetLongField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetLongFieldOffset(env, obj, f->get_offset());
+    return GetLongFieldOffset(jni_env, obj, f->get_offset());
 } //GetLongField
 
 
-jfloat JNICALL GetFloatFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jfloat JNICALL GetFloatFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -340,27 +382,31 @@
     return val;
 }
 
-jfloat JNICALL GetFloatField(JNIEnv *env,
+jfloat JNICALL GetFloatField(JNIEnv * jni_env,
                              jobject obj,
                              jfieldID fieldID)
 {
     TRACE2("jni", "GetFloatField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetFloatFieldOffset(env, obj, f->get_offset());
+    return GetFloatFieldOffset(jni_env, obj, f->get_offset());
 } //GetFloatField
 
 
-jdouble JNICALL GetDoubleFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset)
+jdouble JNICALL GetDoubleFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+    
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -371,19 +417,20 @@
     return val;
 }
 
-jdouble JNICALL GetDoubleField(JNIEnv *env,
+jdouble JNICALL GetDoubleField(JNIEnv * jni_env,
                                jobject obj,
                                jfieldID fieldID)
 {
     TRACE2("jni", "GetDoubleField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(!f->is_static());
-    return GetDoubleFieldOffset(env, obj, f->get_offset());
+    return GetDoubleFieldOffset(jni_env, obj, f->get_offset());
 } //GetDoubleField
 
 
@@ -397,12 +444,15 @@
 // begin Set<Type>Field functions
 
 
-void JNICALL SetObjectFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jobject value)
+void JNICALL SetObjectFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jobject value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
     ObjectHandle v = (ObjectHandle)value;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -420,28 +470,32 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetObjectField(JNIEnv *env,
+void JNICALL SetObjectField(JNIEnv * jni_env,
                             jobject obj,
                             jfieldID fieldID,
                             jobject value)
 {
     TRACE2("jni", "SetObjectField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetObjectFieldOffset(env, obj, f->get_offset(), value);
+    SetObjectFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetObjectField
 
 
-void JNICALL SetBooleanFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jboolean value)
+void JNICALL SetBooleanFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jboolean value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -450,30 +504,34 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetBooleanField(JNIEnv *env,
+void JNICALL SetBooleanField(JNIEnv * jni_env,
                              jobject obj,
                              jfieldID fieldID,
                              jboolean value)
 {
     TRACE2("jni", "SetBooleanField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetBooleanFieldOffset(env, obj, f->get_offset(), value);
+    SetBooleanFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetBooleanField
 
 
-void JNICALL SetByteFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jbyte value)
+void JNICALL SetByteFieldOffset(JNIEnv * jni_env, jobject obj, jint offset, jbyte value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
-    if(VM_Global_State::loader_env->compact_fields)
+    if(vm_env->compact_fields)
         *(jbyte *)(java_ref + offset) = value;
     else
         *(jint *)(java_ref + offset) = value;
@@ -481,28 +539,32 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetByteField(JNIEnv *env,
+void JNICALL SetByteField(JNIEnv * jni_env,
                           jobject obj,
                           jfieldID fieldID,
                           jbyte value)
 {
     TRACE2("jni", "SetByteField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetByteFieldOffset(env, obj, f->get_offset(), value);
+    SetByteFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetByteField
 
 
-void JNICALL SetCharFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jchar value)
+void JNICALL SetCharFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jchar value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -511,32 +573,36 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetCharField(JNIEnv *env,
+void JNICALL SetCharField(JNIEnv * jni_env,
                           jobject obj,
                           jfieldID fieldID,
                           jchar value)
 {
     TRACE2("jni", "SetCharField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetCharFieldOffset(env, obj, f->get_offset(), value);
+    SetCharFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetCharField
 
 
-void JNICALL SetShortFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jshort value)
+void JNICALL SetShortFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jshort value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
-    if (VM_Global_State::loader_env->compact_fields)
+    if (vm_env->compact_fields)
         *(jshort *)(java_ref + offset) = value;
     else
         *(jint *)(java_ref + offset) = value;
@@ -544,28 +610,32 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetShortField(JNIEnv *env,
+void JNICALL SetShortField(JNIEnv * jni_env,
                            jobject obj,
                            jfieldID fieldID,
                            jshort value)
 {
     TRACE2("jni", "SetShortField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetShortFieldOffset(env, obj, f->get_offset(), value);
+    SetShortFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetShortField
 
 
-void JNICALL SetIntFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jint value)
+void JNICALL SetIntFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jint value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -574,28 +644,32 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetIntField(JNIEnv *env,
+void JNICALL SetIntField(JNIEnv * jni_env,
                          jobject obj,
                          jfieldID fieldID,
                          jint value)
 {
     TRACE2("jni", "SetIntField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetIntFieldOffset(env, obj, f->get_offset(), value);
+    SetIntFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetIntField
 
 
-void JNICALL SetLongFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jlong value)
+void JNICALL SetLongFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jlong value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -604,27 +678,31 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetLongField(JNIEnv *env,
+void JNICALL SetLongField(JNIEnv * jni_env,
                           jobject obj,
                           jfieldID fieldID,
                           jlong value)
 {
     TRACE2("jni", "SetLongField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
-    if (!ensure_initialised(env, f->get_class())) return;
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetLongFieldOffset(env, obj, f->get_offset(), value);
+    SetLongFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetLongField
 
 
-void JNICALL SetFloatFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jfloat value)
+void JNICALL SetFloatFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jfloat value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -633,28 +711,32 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetFloatField(JNIEnv *env,
+void JNICALL SetFloatField(JNIEnv * jni_env,
                            jobject obj,
                            jfieldID fieldID,
                            jfloat value)
 {
     TRACE2("jni", "SetFloatField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetFloatFieldOffset(env, obj, f->get_offset(), value);
+    SetFloatFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetFloatField
 
 
-void JNICALL SetDoubleFieldOffset(JNIEnv * UNREF env, jobject obj, jint offset, jdouble value)
+void JNICALL SetDoubleFieldOffset(JNIEnv * UNREF jni_env, jobject obj, jint offset, jdouble value)
 {
     assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     tmn_suspend_disable();       //---------------------------------v
 
     Byte *java_ref = (Byte *)h->object;
@@ -663,20 +745,21 @@
     tmn_suspend_enable();        //---------------------------------^
 }
 
-void JNICALL SetDoubleField(JNIEnv *env,
+void JNICALL SetDoubleField(JNIEnv * jni_env,
                             jobject obj,
                             jfieldID fieldID,
                             jdouble value)
 {
     TRACE2("jni", "SetDoubleField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
     Field *f = (Field *)fieldID;
     assert(f);
-    assert(IsInstanceOf(env, obj, struct_Class_to_jclass(f->get_class())));
+    assert(IsInstanceOf(jni_env, obj, struct_Class_to_jclass(f->get_class())));
 
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(!f->is_static());
-    SetDoubleFieldOffset(env, obj, f->get_offset(), value);
+    SetDoubleFieldOffset(jni_env, obj, f->get_offset(), value);
 } //SetDoubleField
 
 
@@ -693,15 +776,19 @@
 #include "jit_runtime_support_common.h"
 #endif
 
-jobject JNICALL GetStaticObjectField(JNIEnv *env,
+jobject JNICALL GetStaticObjectField(JNIEnv * jni_env,
                                      jclass UNREF clazz,
                                      jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticObjectField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return NULL;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return NULL;
     assert(f->is_static());
     tmn_suspend_disable();       //---------------------------------v
     ManagedObject **field_addr = (ManagedObject **)f->get_address();
@@ -721,113 +808,145 @@
     return (jobject)new_handle;
 } //GetStaticObjectField
 
-jboolean JNICALL GetStaticBooleanField(JNIEnv *env,
+jboolean JNICALL GetStaticBooleanField(JNIEnv * jni_env,
                                        jclass UNREF clazz,
                                        jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticBooleanField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jboolean *field_addr = (jboolean *)f->get_address();
     return *field_addr;
 } //GetStaticBooleanField
 
-jbyte JNICALL GetStaticByteField(JNIEnv *env,
+jbyte JNICALL GetStaticByteField(JNIEnv * jni_env,
                                  jclass UNREF clazz,
                                  jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticByteField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jbyte *field_addr = (jbyte *)f->get_address();
     return *field_addr;
 } //GetStaticByteField
 
-jchar JNICALL GetStaticCharField(JNIEnv *env,
+jchar JNICALL GetStaticCharField(JNIEnv * jni_env,
                                  jclass UNREF clazz,
                                  jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticCharField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jchar *field_addr = (jchar *)f->get_address();
     return *field_addr;
 } //GetStaticCharField
 
-jshort JNICALL GetStaticShortField(JNIEnv *env,
+jshort JNICALL GetStaticShortField(JNIEnv * jni_env,
                                    jclass UNREF clazz,
                                    jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticShortField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jshort *field_addr = (jshort *)f->get_address();
     return *field_addr;
 } //GetStaticShortField
 
-jint JNICALL GetStaticIntField(JNIEnv *env,
+jint JNICALL GetStaticIntField(JNIEnv * jni_env,
                                jclass UNREF clazz,
                                jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticIntField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jint *field_addr = (jint *)f->get_address();
     return *field_addr;
 } //GetStaticIntField
 
-jlong JNICALL GetStaticLongField(JNIEnv *env,
+jlong JNICALL GetStaticLongField(JNIEnv * jni_env,
                                  jclass UNREF clazz,
                                  jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticLongField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jlong *field_addr = (jlong *)f->get_address();
     return *field_addr;
 } //GetStaticLongField
 
-jfloat JNICALL GetStaticFloatField(JNIEnv *env,
+jfloat JNICALL GetStaticFloatField(JNIEnv * jni_env,
                                   jclass UNREF clazz,
                                   jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticFloatField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jfloat *field_addr = (jfloat *)f->get_address();
     return *field_addr;
 } //GetStaticFloatField
 
-jdouble JNICALL GetStaticDoubleField(JNIEnv *env,
+jdouble JNICALL GetStaticDoubleField(JNIEnv * jni_env,
                                      jclass UNREF clazz,
                                      jfieldID fieldID)
 {
     TRACE2("jni", "GetStaticDoubleField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return 0;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return 0;
+    if (!ensure_initialised(jni_env, f->get_class())) return 0;
     assert(f->is_static());
     jdouble *field_addr = (jdouble *)f->get_address();
     return *field_addr;
@@ -845,16 +964,20 @@
 // begin SetStatic<Type>Field functions
 
 
-void JNICALL SetStaticObjectField(JNIEnv *env,
+void JNICALL SetStaticObjectField(JNIEnv * jni_env,
                                   jclass UNREF clazz,
                                   jfieldID fieldID,
                                   jobject value)
 {
     TRACE2("jni", "SetStaticObjectField called, id = " << fieldID);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     tmn_suspend_disable();       //---------------------------------v
     ManagedObject **field_addr = (ManagedObject **)f->get_address();
@@ -871,88 +994,108 @@
 } //SetStaticObjectField
 
 
-void JNICALL SetStaticBooleanField(JNIEnv *env,
+void JNICALL SetStaticBooleanField(JNIEnv * jni_env,
                                    jclass UNREF clazz,
                                    jfieldID fieldID,
                                    jboolean value)
 {
     TRACE2("jni", "SetStaticBooleanField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jboolean *field_addr = (jboolean *)f->get_address();
     *field_addr = value;
 } //SetStaticBooleanField
 
 
-void JNICALL SetStaticByteField(JNIEnv *env,
+void JNICALL SetStaticByteField(JNIEnv * jni_env,
                                 jclass UNREF clazz,
                                 jfieldID fieldID,
                                 jbyte value)
 {
     TRACE2("jni", "SetStaticByteField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jbyte *field_addr = (jbyte *)f->get_address();
     jint *field_addr_int = (jint *)f->get_address();
-    if (VM_Global_State::loader_env->compact_fields)
+    if (vm_env->compact_fields)
         *field_addr = value;
     else
         *field_addr_int = value;
 } //SetStaticByteField
 
 
-void JNICALL SetStaticCharField(JNIEnv *env,
+void JNICALL SetStaticCharField(JNIEnv * jni_env,
                                 jclass UNREF clazz,
                                 jfieldID fieldID,
                                 jchar value)
 {
     TRACE2("jni", "SetStaticCharField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jchar *field_addr = (jchar *)f->get_address();
     *field_addr = value;
 } //SetStaticCharField
 
 
-void JNICALL SetStaticShortField(JNIEnv *env,
+void JNICALL SetStaticShortField(JNIEnv * jni_env,
                                  jclass UNREF clazz,
                                  jfieldID fieldID,
                                  jshort value)
 {
     TRACE2("jni", "SetStaticShortField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jshort *field_addr = (jshort *)f->get_address();
     jint *field_addr_int = (jint *)f->get_address();
-    if (VM_Global_State::loader_env->compact_fields)
+    if (vm_env->compact_fields)
         *field_addr = value;
     else
         *field_addr_int = value;
 } //SetStaticShortField
 
 
-void JNICALL SetStaticIntField(JNIEnv *env,
+void JNICALL SetStaticIntField(JNIEnv * jni_env,
                                jclass UNREF clazz,
                                jfieldID fieldID,
                                jint value)
 {
     TRACE2("jni", "SetStaticIntField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jint *field_addr = (jint *)f->get_address();
     *field_addr = value;
@@ -960,48 +1103,60 @@
 
 
 
-void JNICALL SetStaticLongField(JNIEnv *env,
+void JNICALL SetStaticLongField(JNIEnv * jni_env,
                                 jclass UNREF clazz,
                                 jfieldID fieldID,
                                 jlong value)
 {
     TRACE2("jni", "SetStaticLongField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jlong *field_addr = (jlong *)f->get_address();
     *field_addr = value;
 } //SetStaticLongField
 
 
-void JNICALL SetStaticFloatField(JNIEnv *env,
+void JNICALL SetStaticFloatField(JNIEnv * jni_env,
                                  jclass UNREF clazz,
                                  jfieldID fieldID,
                                  jfloat value)
 {
     TRACE2("jni", "SetStaticFloatField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jfloat *field_addr = (jfloat *)f->get_address();
     *field_addr = value;
 } //SetStaticFloatField
 
 
-void JNICALL SetStaticDoubleField(JNIEnv *env,
+void JNICALL SetStaticDoubleField(JNIEnv * jni_env,
                                   jclass UNREF clazz,
                                   jfieldID fieldID,
                                   jdouble value)
 {
     TRACE2("jni", "SetStaticDoubleField called, id = " << fieldID << " value = " << value);
     assert(hythread_is_suspend_enabled());
+
+    Global_Env * vm_env = jni_get_vm_env(jni_env);
+    if (vm_env->IsVmShutdowning()) return;
+
     Field *f = (Field *)fieldID;
     assert(f);
-    if (!ensure_initialised(env, f->get_class())) return;
+    if (!ensure_initialised(jni_env, f->get_class())) return;
     assert(f->is_static());
     jdouble *field_addr = (jdouble *)f->get_address();
     *field_addr = value;



Mime
View raw message