*** jni.cc Fri Mar 30 16:21:44 2001 --- jni.cc- Fri Mar 30 16:18:15 2001 *************** *** 98,104 **** }; // This holds a reference count for all local and global references. ! static java::util::Hashtable *ref_table; // The only VM. static JavaVM *the_vm; --- 98,105 ---- }; // This holds a reference count for all local and global references. ! static java::util::Hashtable *local_ref_table; ! static java::util::Hashtable *global_ref_table; // The only VM. static JavaVM *the_vm; *************** *** 153,160 **** void _Jv_JNI_Init (void) { ! ref_table = new java::util::Hashtable; ! #ifdef ENABLE_JVMPI _Jv_JVMPI_Interface.version = 1; _Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent; --- 154,161 ---- void _Jv_JNI_Init (void) { ! local_ref_table = new java::util::Hashtable; ! global_ref_table = new java::util::Hashtable; #ifdef ENABLE_JVMPI _Jv_JVMPI_Interface.version = 1; _Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent; *************** *** 167,198 **** // Tell the GC that a certain pointer is live. static void ! mark_for_gc (jobject obj) { ! JvSynchronize sync (ref_table); using namespace java::lang; ! Integer *refcount = (Integer *) ref_table->get (obj); ! jint val = (refcount == NULL) ? 0 : refcount->intValue (); // FIXME: what about out of memory error? ! ref_table->put (obj, new Integer (val + 1)); } - // Unmark a pointer. static void ! unmark_for_gc (jobject obj) { ! JvSynchronize sync (ref_table); using namespace java::lang; ! Integer *refcount = (Integer *) ref_table->get (obj); JvAssert (refcount); jint val = refcount->intValue () - 1; if (val == 0) ! ref_table->remove (obj); else // FIXME: what about out of memory error? ! ref_table->put (obj, new Integer (val)); } --- 168,226 ---- // Tell the GC that a certain pointer is live. static void ! local_mark_for_gc (jobject obj) ! { ! JvSynchronize sync (local_ref_table); ! ! using namespace java::lang; ! Integer *refcount = (Integer *) local_ref_table->get (obj); ! jint val = ((refcount == NULL) ? 0 : refcount->intValue ()) + 1; ! // FIXME: what about out of memory error? ! local_ref_table->put (obj, new Integer (val)); ! } ! ! static void ! global_mark_for_gc (jobject obj) { ! JvSynchronize sync (global_ref_table); using namespace java::lang; ! Integer *refcount = (Integer *) global_ref_table->get (obj); ! jint val = ((refcount == NULL) ? 0 : refcount->intValue ()) + 1; // FIXME: what about out of memory error? ! global_ref_table->put (obj, new Integer (val)); ! } ! ! static void ! local_unmark_for_gc (jobject obj) ! { ! JvSynchronize sync (local_ref_table); ! ! using namespace java::lang; ! Integer *refcount = (Integer *) local_ref_table->get (obj); ! JvAssert (refcount); ! jint val = refcount->intValue () - 1; ! if (val == 0) ! local_ref_table->remove (obj); ! else ! // FIXME: what about out of memory error? ! local_ref_table->put (obj, new Integer (val)); } static void ! global_unmark_for_gc (jobject obj) { ! JvSynchronize sync (global_ref_table); using namespace java::lang; ! Integer *refcount = (Integer *) global_ref_table->get (obj); JvAssert (refcount); jint val = refcount->intValue () - 1; if (val == 0) ! global_ref_table->remove (obj); else // FIXME: what about out of memory error? ! global_ref_table->put (obj, new Integer (val)); } *************** *** 200,213 **** static jobject _Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj) { ! mark_for_gc (obj); return obj; } static void _Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj) { ! unmark_for_gc (obj); } static void --- 228,241 ---- static jobject _Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj) { ! global_mark_for_gc (obj); return obj; } static void _Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj) { ! global_unmark_for_gc (obj); } static void *************** *** 222,228 **** if (frame->vec[i] == obj) { frame->vec[i] = NULL; ! unmark_for_gc (obj); return; } } --- 250,256 ---- if (frame->vec[i] == obj) { frame->vec[i] = NULL; ! local_unmark_for_gc (obj); return; } } *************** *** 302,308 **** env->locals->vec[0] = obj; } ! mark_for_gc (obj); return obj; } --- 331,337 ---- env->locals->vec[0] = obj; } ! local_mark_for_gc (obj); return obj; } *************** *** 316,327 **** { for (int i = 0; i < rf->size; ++i) if (rf->vec[i] != NULL) ! unmark_for_gc (rf->vec[i]); // If the frame we just freed is the marker frame, we are done. done = (rf->marker == stop); _Jv_JNI_LocalFrame *n = rf->next; // When N==NULL, we've reached the stack-allocated frame, and we // must not free it. However, we must be sure to clear all its // elements, since we might conceivably reuse it. --- 345,358 ---- { for (int i = 0; i < rf->size; ++i) if (rf->vec[i] != NULL) ! local_unmark_for_gc (rf->vec[i]); // If the frame we just freed is the marker frame, we are done. done = (rf->marker == stop); _Jv_JNI_LocalFrame *n = rf->next; + + env->locals = n; // When N==NULL, we've reached the stack-allocated frame, and we // must not free it. However, we must be sure to clear all its // elements, since we might conceivably reuse it. *************** *** 1148,1154 **** _Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy) { jchar *result = _Jv_GetStringChars (string); ! mark_for_gc (string); if (isCopy) *isCopy = false; return (const jchar *) result; --- 1184,1190 ---- _Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy) { jchar *result = _Jv_GetStringChars (string); ! global_mark_for_gc (string); if (isCopy) *isCopy = false; return (const jchar *) result; *************** *** 1157,1163 **** static void _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *) { ! unmark_for_gc (string); } static jstring --- 1193,1199 ---- static void _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *) { ! global_unmark_for_gc (string); } static jstring *************** *** 1336,1342 **** // We elect never to copy. *isCopy = false; } ! mark_for_gc (array); return elts; } --- 1372,1378 ---- // We elect never to copy. *isCopy = false; } ! global_mark_for_gc (array); return elts; } *************** *** 1348,1354 **** // Note that we ignore MODE. We can do this because we never copy // the array elements. My reading of the JNI documentation is that // this is an option for the implementor. ! unmark_for_gc (array); } template --- 1384,1390 ---- // Note that we ignore MODE. We can do this because we never copy // the array elements. My reading of the JNI documentation is that // this is an option for the implementor. ! global_unmark_for_gc (array); } template