src/share/vm/gc/shared/workgroup.cpp

Print this page

        

*** 503,517 **** bool FreeIdSet::_stat_init = false; FreeIdSet* FreeIdSet::_sets[NSets]; bool FreeIdSet::_safepoint; ! FreeIdSet::FreeIdSet(int 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; _ids[sz-1] = end_of_list; // end of list. if (_stat_init) { for (int j = 0; j < NSets; j++) _sets[j] = NULL; _stat_init = true; } --- 503,518 ---- bool FreeIdSet::_stat_init = false; FreeIdSet* FreeIdSet::_sets[NSets]; bool FreeIdSet::_safepoint; ! FreeIdSet::FreeIdSet(uint sz, Monitor* mon) : _sz(sz), _mon(mon), _hd(0), _waiters(0), _index(-1), _claimed(0) { ! 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; _stat_init = true; }
*** 526,536 **** guarantee(_index != -1, "Too many FreeIdSets in use!"); } FreeIdSet::~FreeIdSet() { _sets[_index] = NULL; ! FREE_C_HEAP_ARRAY(int, _ids); } void FreeIdSet::set_safepoint(bool b) { _safepoint = b; if (b) { --- 527,537 ---- guarantee(_index != -1, "Too many FreeIdSets in use!"); } FreeIdSet::~FreeIdSet() { _sets[_index] = NULL; ! FREE_C_HEAP_ARRAY(uint, _ids); } void FreeIdSet::set_safepoint(bool b) { _safepoint = b; if (b) {
*** 548,558 **** #define FID_STATS 0 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); #endif MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag); while (!_safepoint && _hd == end_of_list) { _waiters++; #if FID_STATS --- 549,559 ---- #define FID_STATS 0 int FreeIdSet::claim_par_id() { #if FID_STATS thread_t tslf = thr_self(); ! 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) { _waiters++; #if FID_STATS
*** 566,621 **** } if (_hd == end_of_list) { #if FID_STATS tty->print("claim_par_id[%d]: returning EOL.\n", tslf); #endif ! return -1; } 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", 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) { 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", thr_self(), id, _waiters, _claimed); #endif if (_waiters > 0) // Notify all would be safer, but this is OK, right? _mon->notify_all(); --- 567,598 ---- } if (_hd == end_of_list) { #if FID_STATS tty->print("claim_par_id[%d]: returning EOL.\n", tslf); #endif ! 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 = %u.\n", tslf, res, _claimed); #endif return res; } } ! 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(%u), waiters =%u, claimed = %u.\n", thr_self(), id, _waiters, _claimed); #endif if (_waiters > 0) // Notify all would be safer, but this is OK, right? _mon->notify_all();