--- old/src/hotspot/share/gc/shared/gcLocker.cpp Wed Nov 8 08:12:40 2017 +++ new/src/hotspot/share/gc/shared/gcLocker.cpp Wed Nov 8 08:12:39 2017 @@ -46,9 +46,8 @@ assert(!needs_gc() || _debug_jni_lock_count == _jni_lock_count, "must agree"); int count = 0; // Count the number of threads with critical operations in progress - ThreadsListHandle tlh; - JavaThreadIterator jti(tlh.list()); - for (JavaThread* thr = jti.first(); thr != NULL; thr = jti.next()) { + JavaThreadIteratorWithHandle jtiwh; + for (; JavaThread *thr = jtiwh.next(); ) { if (thr->in_critical()) { count++; } @@ -55,7 +54,8 @@ } if (_jni_lock_count != count) { log_error(gc, verify)("critical counts don't match: %d != %d", _jni_lock_count, count); - for (JavaThread* thr = jti.first(); thr != NULL; thr = jti.next()) { + jtiwh.rewind(); + for (; JavaThread *thr = jtiwh.next(); ) { if (thr->in_critical()) { log_error(gc, verify)(INTPTR_FORMAT " in_critical %d", p2i(thr), thr->in_critical()); }