boolean (final boolean entombYoung) { while (true) { final int packedState = statePacked; final int state = unpackState(packedState); final int usageCount = unpackUsageCount(packedState); switch (state) { case STATE_NOT_READY_YET: { if (entombYoung) { final int newPackedState = packState(STATE_PRE_TOMBSTONE, 0); if (STATE_UPDATER.compareAndSet(this, packedState, newPackedState)) { return true; } } return false; } case STATE_LOADING: { //page in this state is exclusively owned by the thread won [NOT_READY_YET=>LOADING] transition return false; } case STATE_USABLE: { if (usageCount > 0) { return false; } final int newPackedState = packState(STATE_ABOUT_TO_UNMAP, 0); if (STATE_UPDATER.compareAndSet(this, packedState, newPackedState)) { continue; } return false; } case STATE_ABOUT_TO_UNMAP: { if (usageCount > 0) { //return false; throw new AssertionError("Page[ABOUT_TO_UNMAP].usageCount=" + usageCount + " -- must be 0. " + this); } final int newPackedState = packState(STATE_PRE_TOMBSTONE, 0); if (STATE_UPDATER.compareAndSet(this, packedState, newPackedState)) { return true; } } case STATE_PRE_TOMBSTONE: { return false; } case STATE_TOMBSTONE: { return false; } default: { throw new AssertionError("Code bug: unknown state " + state + ": " + this); } } } }