-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathTierCountersArea.java
More file actions
114 lines (96 loc) · 4.77 KB
/
Copy pathTierCountersArea.java
File metadata and controls
114 lines (96 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright 2013-2026 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.chronicle.hash.impl;
import net.openhft.chronicle.core.Memory;
import net.openhft.chronicle.core.OS;
import static net.openhft.chronicle.assertions.AssertUtil.SKIP_ASSERTIONS;
import static net.openhft.chronicle.map.internal.InternalAssertUtil.assertAddress;
/**
* The reason why this is not implemented via value interface, and offsets are allocated by hand --
* this functionality is accessed concurrently from many threads, and native value implementations
* are stateful - so need to keep an instance in thread local that seems to be overall more pain
* than gain.
*/
public enum TierCountersArea {
; // none
public static final long NEXT_TIER_INDEX_OFFSET = 0L;
public static final long PREV_TIER_INDEX_OFFSET = NEXT_TIER_INDEX_OFFSET + 8L;
public static final long LOWEST_POSSIBLY_FREE_CHUNK_TIERED_OFFSET = PREV_TIER_INDEX_OFFSET + 8L;
public static final long SEGMENT_INDEX_OFFSET = LOWEST_POSSIBLY_FREE_CHUNK_TIERED_OFFSET + 8L;
public static final long TIER_OFFSET = SEGMENT_INDEX_OFFSET + 4L;
public static final long ENTRIES_OFFSET = TIER_OFFSET + 4L;
public static final long DELETED_OFFSET = ENTRIES_OFFSET + 4L;
private static final long UNSIGNED_INT_MASK = 0xFFFFFFFFL;
private static final Memory MEMORY = OS.memory();
public static long nextTierIndex(final long address) {
assert SKIP_ASSERTIONS || assertAddress(address);
return MEMORY.readLong(address + NEXT_TIER_INDEX_OFFSET);
}
public static void nextTierIndex(final long address,
final long nextTierIndex) {
assert SKIP_ASSERTIONS || assertAddress(address);
MEMORY.writeLong(address + NEXT_TIER_INDEX_OFFSET, nextTierIndex);
}
public static long lowestPossiblyFreeChunkTiered(final long address) {
assert SKIP_ASSERTIONS || assertAddress(address);
return MEMORY.readLong(address + LOWEST_POSSIBLY_FREE_CHUNK_TIERED_OFFSET);
}
public static void lowestPossiblyFreeChunkTiered(final long address, final long lowestPossiblyFreeChunk) {
assert SKIP_ASSERTIONS || assertAddress(address);
MEMORY.writeLong(address + LOWEST_POSSIBLY_FREE_CHUNK_TIERED_OFFSET,
lowestPossiblyFreeChunk);
}
public static long prevTierIndex(final long address) {
assert SKIP_ASSERTIONS || assertAddress(address);
return MEMORY.readLong(address + PREV_TIER_INDEX_OFFSET);
}
public static void prevTierIndex(final long address,
final long prevTierIndex) {
assert SKIP_ASSERTIONS || assertAddress(address);
MEMORY.writeLong(address + PREV_TIER_INDEX_OFFSET, prevTierIndex);
}
public static int segmentIndex(final long address) {
assert SKIP_ASSERTIONS || assertAddress(address);
return MEMORY.readInt(address + SEGMENT_INDEX_OFFSET);
}
public static void segmentIndex(final long address, final int segmentIndex) {
assert SKIP_ASSERTIONS || assertAddress(address);
MEMORY.writeInt(address + SEGMENT_INDEX_OFFSET, segmentIndex);
}
public static int tier(final long address) {
assert SKIP_ASSERTIONS || assertAddress(address);
return MEMORY.readInt(address + TIER_OFFSET);
}
public static void tier(final long address,
final int tier) {
assert SKIP_ASSERTIONS || assertAddress(address);
MEMORY.writeInt(address + TIER_OFFSET, tier);
}
public static long entries(final long address) {
assert SKIP_ASSERTIONS || assertAddress(address);
return MEMORY.readInt(address + ENTRIES_OFFSET) & UNSIGNED_INT_MASK;
}
public static void entries(final long address,
final long entries) {
assert SKIP_ASSERTIONS || assertAddress(address);
if (entries >= (1L << 32)) {
throw new IllegalStateException("tier entries overflow: up to " + UNSIGNED_INT_MASK +
" supported, " + entries + " given");
}
MEMORY.writeInt(address + ENTRIES_OFFSET, (int) entries);
}
public static long deleted(final long address) {
assert SKIP_ASSERTIONS || assertAddress(address);
return MEMORY.readInt(address + DELETED_OFFSET) & UNSIGNED_INT_MASK;
}
public static void deleted(final long address,
final long deleted) {
assert SKIP_ASSERTIONS || assertAddress(address);
if (deleted >= (1L << 32)) {
throw new IllegalStateException("tier deleted entries count overflow: up to " +
UNSIGNED_INT_MASK + " supported, " + deleted + " given");
}
MEMORY.writeInt(address + DELETED_OFFSET, (int) deleted);
}
}