src/runtime: use garbage collector constants when we have them
Этот коммит содержится в:
родитель
b2ccf12e98
коммит
23dc861ddb
1 изменённых файлов: 4 добавлений и 4 удалений
|
@ -143,7 +143,7 @@ func (b gcBlock) findNext() gcBlock {
|
||||||
// State returns the current block state.
|
// State returns the current block state.
|
||||||
func (b gcBlock) state() blockState {
|
func (b gcBlock) state() blockState {
|
||||||
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
||||||
return blockState(*stateBytePtr>>((b%blocksPerStateByte)*2)) % 4
|
return blockState(*stateBytePtr>>((b%blocksPerStateByte)*stateBits)) & blockStateMask
|
||||||
}
|
}
|
||||||
|
|
||||||
// setState sets the current block to the given state, which must contain more
|
// setState sets the current block to the given state, which must contain more
|
||||||
|
@ -151,7 +151,7 @@ func (b gcBlock) state() blockState {
|
||||||
// from head to mark.
|
// from head to mark.
|
||||||
func (b gcBlock) setState(newState blockState) {
|
func (b gcBlock) setState(newState blockState) {
|
||||||
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
||||||
*stateBytePtr |= uint8(newState << ((b % blocksPerStateByte) * 2))
|
*stateBytePtr |= uint8(newState << ((b % blocksPerStateByte) * stateBits))
|
||||||
if gcAsserts && b.state() != newState {
|
if gcAsserts && b.state() != newState {
|
||||||
runtimePanic("gc: setState() was not successful")
|
runtimePanic("gc: setState() was not successful")
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ func (b gcBlock) setState(newState blockState) {
|
||||||
// markFree sets the block state to free, no matter what state it was in before.
|
// markFree sets the block state to free, no matter what state it was in before.
|
||||||
func (b gcBlock) markFree() {
|
func (b gcBlock) markFree() {
|
||||||
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
||||||
*stateBytePtr &^= uint8(blockStateMask << ((b % blocksPerStateByte) * 2))
|
*stateBytePtr &^= uint8(blockStateMask << ((b % blocksPerStateByte) * stateBits))
|
||||||
if gcAsserts && b.state() != blockStateFree {
|
if gcAsserts && b.state() != blockStateFree {
|
||||||
runtimePanic("gc: markFree() was not successful")
|
runtimePanic("gc: markFree() was not successful")
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ func (b gcBlock) unmark() {
|
||||||
}
|
}
|
||||||
clearMask := blockStateMask ^ blockStateHead // the bits to clear from the state
|
clearMask := blockStateMask ^ blockStateHead // the bits to clear from the state
|
||||||
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
stateBytePtr := (*uint8)(unsafe.Pointer(uintptr(metadataStart) + uintptr(b/blocksPerStateByte)))
|
||||||
*stateBytePtr &^= uint8(clearMask << ((b % blocksPerStateByte) * 2))
|
*stateBytePtr &^= uint8(clearMask << ((b % blocksPerStateByte) * stateBits))
|
||||||
if gcAsserts && b.state() != blockStateHead {
|
if gcAsserts && b.state() != blockStateHead {
|
||||||
runtimePanic("gc: unmark() was not successful")
|
runtimePanic("gc: unmark() was not successful")
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче