From dc943c250a249f3e75614f95fca769d9ea9ba934 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Feb 2013 08:15:39 -0700 Subject: [PATCH] delay incrementing Thread::criticalLevel until after entering ActiveState If we increment the value while we're still in IdleState, another thread may try to GC before we are able to enter ActiveState, which will lead to an assertion failure when the footprint function is called. --- src/jnienv.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 2a70b10855..e512b18066 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -160,10 +160,12 @@ GetStringRegion(Thread* t, jstring s, jsize start, jsize length, jchar* dst) const jchar* JNICALL GetStringCritical(Thread* t, jstring s, jboolean* isCopy) { - if ((t->criticalLevel ++) == 0) { + if (t->criticalLevel == 0) { enter(t, Thread::ActiveState); } + ++ t->criticalLevel; + if (isCopy) { *isCopy = true; } @@ -3141,9 +3143,11 @@ SetDoubleArrayRegion(Thread* t, jdoubleArray array, jint offset, jint length, void* JNICALL GetPrimitiveArrayCritical(Thread* t, jarray array, jboolean* isCopy) { - if ((t->criticalLevel ++) == 0) { + if (t->criticalLevel == 0) { enter(t, Thread::ActiveState); } + + ++ t->criticalLevel; if (isCopy) { *isCopy = true;