| 36 | import static io.questdb.std.MemoryTag.NATIVE_DEFAULT; |
| 37 | |
| 38 | @SuppressWarnings("removal") |
| 39 | public final class Unsafe { |
| 40 | // The various _ADDR fields are `long` in Java, but they are `* mut usize` in Rust, or `size_t*` in C. |
| 41 | // These are off-heap allocated atomic counters for memory usage tracking. |
| 42 | |
| 43 | public static final long BYTE_OFFSET; |
| 44 | public static final long BYTE_SCALE; |
| 45 | public static final long INT_OFFSET; |
| 46 | public static final long INT_SCALE; |
| 47 | public static final long LONG_OFFSET; |
| 48 | public static final long LONG_SCALE; |
| 49 | private static final LongAdder[] COUNTERS = new LongAdder[MemoryTag.SIZE]; |
| 50 | private static final long FREE_COUNT_ADDR; |
| 51 | private static final long MALLOC_COUNT_ADDR; |
| 52 | private static final long[] NATIVE_ALLOCATORS = new long[MemoryTag.SIZE - NATIVE_DEFAULT]; |
| 53 | private static final long[] NATIVE_MEM_COUNTER_ADDRS = new long[MemoryTag.SIZE]; |
| 54 | private static final long NON_RSS_MEM_USED_ADDR; |
| 55 | private static final long REALLOC_COUNT_ADDR; |
| 56 | private static final long RSS_MEM_LIMIT_ADDR; |
| 57 | private static final long RSS_MEM_USED_ADDR; |
| 58 | private static final sun.misc.Unsafe UNSAFE; |
| 59 | private static final AnonymousClassDefiner anonymousClassDefiner; |
| 60 | |
| 61 | private Unsafe() { |
| 62 | } |
| 63 | |
| 64 | public static long allocateMemory(long size) { |
| 65 | return UNSAFE.allocateMemory(size); |
| 66 | } |
| 67 | |
| 68 | public static int arrayBaseOffset(Class<?> arrayClass) { |
| 69 | return UNSAFE.arrayBaseOffset(arrayClass); |
| 70 | } |
| 71 | |
| 72 | public static long arrayGetVolatile(long[] array, int index) { |
| 73 | assert index > -1 && index < array.length; |
| 74 | return UNSAFE.getLongVolatile(array, LONG_OFFSET + ((long) index << LONG_SCALE)); |
| 75 | } |
| 76 | |
| 77 | public static int arrayGetVolatile(int[] array, int index) { |
| 78 | assert index > -1 && index < array.length; |
| 79 | return UNSAFE.getIntVolatile(array, INT_OFFSET + ((long) index << INT_SCALE)); |
| 80 | } |
| 81 | |
| 82 | public static int arrayIndexScale(Class<?> arrayClass) { |
| 83 | return UNSAFE.arrayIndexScale(arrayClass); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * This call has Atomic*#lazySet / memory_order_release semantics. |
| 88 | * |
| 89 | * @param array array to put into |
| 90 | * @param index index |
| 91 | * @param value value to put |
| 92 | */ |
| 93 | public static void arrayPutOrdered(long[] array, int index, long value) { |
| 94 | assert index > -1 && index < array.length; |
| 95 | UNSAFE.putOrderedLong(array, LONG_OFFSET + ((long) index << LONG_SCALE), value); |
nothing calls this directly
no test coverage detected
searching dependent graphs…