Author: mladen.turk(a)jboss.com
Date: 2007-10-06 05:53:30 -0400 (Sat, 06 Oct 2007)
New Revision: 1091
Modified:
trunk/sight/native/share/no.c
Log:
Check JNI calls for apr_pool_clear
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-06 08:41:59 UTC (rev 1090)
+++ trunk/sight/native/share/no.c 2007-10-06 09:53:30 UTC (rev 1091)
@@ -29,6 +29,10 @@
#include "sight_local.h"
extern apr_pool_t *sight_global_pool;
+
+#define OPTIMISTIC_LOCK_CNT 10000
+#define OPTIMISTIC_LOCK_MAX OPTIMISTIC_LOCK_CNT + 60000
+
/*
* NativeObject
* This is the core of object management in SIGHT.
@@ -76,8 +80,13 @@
sight_cnt_native_pcleanup++;
#endif
if (data) {
+#if SIGHT_APR_REFCOUNT
+ apr_uint32_t ioc = 0;
+ apr_uint32_t refcount;
+#endif
JNIEnv *_E = NULL;
jint em = sight_get_jnienv(&_E);
+
if (_E && no->object) {
jobject object = (*_E)->NewLocalRef(_E, no->object);
(*_E)->DeleteWeakGlobalRef(_E, no->object);
@@ -98,6 +107,24 @@
no->object = NULL;
}
}
+ apr_atomic_inc32(&no->interrupted);
+#if SIGHT_APR_REFCOUNT
+ refcount = apr_atomic_read32(&no->refcount);
+ while (refcount) {
+ apr_thread_yield();
+ refcount = apr_atomic_read32(&no->refcount);
+ if (ioc++ > OPTIMISTIC_LOCK_CNT) {
+ /* Sleep one millisecond */
+ apr_sleep(1000L);
+ }
+ if (ioc > OPTIMISTIC_LOCK_MAX) {
+ /* TODO: We have a zombie or a lengthy JNI op.
+ * Find a way to bail out without crushing JVM
+ */
+ break;
+ }
+ }
+#endif
if (no->clean) {
(*no->clean)(POOL_CALLBACK, no);
}
@@ -194,15 +221,12 @@
} SIGHT_LOCAL_END(no);
}
-#define OPTIMISTIC_LOCK_CNT 10000
-#define OPTIMISTIC_LOCK_MAX OPTIMISTIC_LOCK_CNT + 60000
-
SIGHT_EXPORT_DECLARE(void, NativeObject, free0)(SIGHT_STDARGS,
jlong instance)
{
sight_object_t *no = J2P(instance, sight_object_t *);
jobject object = NULL;
-#if SIGHT_APR_REFCOUNT
+#if SIGHT_APR_REFCOUNT
apr_uint32_t ioc = 0;
apr_uint32_t refcount;
#endif
@@ -316,7 +340,7 @@
no->opaque = NULL;
no->native = NULL;
}
- apr_atomic_set32(&no->interrupted, 0);
+ apr_atomic_set32(&no->interrupted, 0);
} SIGHT_GLOBAL_END();
}
Show replies by date