--- old/src/share/vm/gc/g1/dirtyCardQueue.cpp 2015-11-11 14:22:30.165348026 -0500 +++ new/src/share/vm/gc/g1/dirtyCardQueue.cpp 2015-11-11 14:22:28.837272995 -0500 @@ -112,7 +112,7 @@ fl_owner); set_buffer_size(G1UpdateBufferSize); _shared_dirty_card_queue.set_lock(lock); - _free_ids = new FreeIdSet((int) num_par_ids(), _cbl_mon); + _free_ids = new FreeIdSet(num_par_ids(), _cbl_mon); } void DirtyCardQueueSet::handle_zero_index_for_thread(JavaThread* t) { --- old/src/share/vm/gc/shared/workgroup.cpp 2015-11-11 14:22:34.257579219 -0500 +++ new/src/share/vm/gc/shared/workgroup.cpp 2015-11-11 14:22:32.933504414 -0500 @@ -505,11 +505,12 @@ FreeIdSet* FreeIdSet::_sets[NSets]; bool FreeIdSet::_safepoint; -FreeIdSet::FreeIdSet(int sz, Monitor* mon) : +FreeIdSet::FreeIdSet(uint sz, Monitor* mon) : _sz(sz), _mon(mon), _hd(0), _waiters(0), _index(-1), _claimed(0) { - _ids = NEW_C_HEAP_ARRAY(int, sz, mtInternal); - for (int i = 0; i < sz; i++) _ids[i] = i+1; + guarantee(sz != 0, "must be"); + _ids = NEW_C_HEAP_ARRAY(uint, sz, mtInternal); + for (uint i = 0; i < sz - 1; i++) _ids[i] = i+1; _ids[sz-1] = end_of_list; // end of list. if (_stat_init) { for (int j = 0; j < NSets; j++) _sets[j] = NULL; @@ -528,7 +529,7 @@ FreeIdSet::~FreeIdSet() { _sets[_index] = NULL; - FREE_C_HEAP_ARRAY(int, _ids); + FREE_C_HEAP_ARRAY(uint, _ids); } void FreeIdSet::set_safepoint(bool b) { @@ -550,7 +551,7 @@ int FreeIdSet::claim_par_id() { #if FID_STATS thread_t tslf = thr_self(); - tty->print("claim_par_id[%d]: sz = %d, claimed = %d\n", tslf, _sz, _claimed); + tty->print("claim_par_id[%d]: sz = %u, claimed = %u\n", tslf, _sz, _claimed); #endif MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag); while (!_safepoint && _hd == end_of_list) { @@ -568,52 +569,28 @@ #if FID_STATS tty->print("claim_par_id[%d]: returning EOL.\n", tslf); #endif - return -1; + return UINT_MAX; } else { int res = _hd; _hd = _ids[res]; _ids[res] = claimed; // For debugging. _claimed++; #if FID_STATS - tty->print("claim_par_id[%d]: returning %d, claimed = %d.\n", + tty->print("claim_par_id[%d]: returning %d, claimed = %u.\n", tslf, res, _claimed); #endif return res; } } -bool FreeIdSet::claim_perm_id(int i) { - assert(0 <= i && i < _sz, "Out of range."); - MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag); - int prev = end_of_list; - int cur = _hd; - while (cur != end_of_list) { - if (cur == i) { - if (prev == end_of_list) { - _hd = _ids[cur]; - } else { - _ids[prev] = _ids[cur]; - } - _ids[cur] = claimed; - _claimed++; - return true; - } else { - prev = cur; - cur = _ids[cur]; - } - } - return false; - -} - -void FreeIdSet::release_par_id(int id) { +void FreeIdSet::release_par_id(uint id) { MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag); assert(_ids[id] == claimed, "Precondition."); _ids[id] = _hd; _hd = id; _claimed--; #if FID_STATS - tty->print("[%d] release_par_id(%d), waiters =%d, claimed = %d.\n", + tty->print("[%d] release_par_id(%u), waiters =%u, claimed = %u.\n", thr_self(), id, _waiters, _claimed); #endif if (_waiters > 0) --- old/src/share/vm/gc/shared/workgroup.hpp 2015-11-11 14:22:38.361811090 -0500 +++ new/src/share/vm/gc/shared/workgroup.hpp 2015-11-11 14:22:37.037736284 -0500 @@ -381,17 +381,17 @@ // Represents a set of free small integer ids. class FreeIdSet : public CHeapObj { enum { - end_of_list = -1, - claimed = -2 + end_of_list = UINT_MAX, + claimed = UINT_MAX - 1 }; int _sz; Monitor* _mon; - int* _ids; - int _hd; - int _waiters; - int _claimed; + uint* _ids; + uint _hd; + uint _waiters; + uint _claimed; static bool _safepoint; typedef FreeIdSet* FreeIdSetPtr; @@ -401,20 +401,16 @@ int _index; public: - FreeIdSet(int sz, Monitor* mon); + FreeIdSet(uint sz, Monitor* mon); ~FreeIdSet(); static void set_safepoint(bool b); - // Attempt to claim the given id permanently. Returns "true" iff - // successful. - bool claim_perm_id(int i); - // Returns an unclaimed parallel id (waiting for one to be released if - // necessary). Returns "-1" if a GC wakes up a wait for an id. + // necessary). Returns "UINT_MAX" if a GC wakes up a wait for an id. int claim_par_id(); - void release_par_id(int id); + void release_par_id(uint id); }; #endif // SHARE_VM_GC_SHARED_WORKGROUP_HPP