Skip to content

Commit

Permalink
Move Slice to use MemorySegment
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Jul 1, 2024
1 parent 86fe760 commit 3855919
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 321 deletions.
82 changes: 0 additions & 82 deletions src/main/java/io/airlift/slice/JvmUtils.java

This file was deleted.

19 changes: 19 additions & 0 deletions src/main/java/io/airlift/slice/SizeOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openjdk.jol.vm.VM;
import org.openjdk.jol.vm.VirtualMachine;

import java.lang.foreign.MemorySegment;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -79,6 +80,24 @@ public final class SizeOf

private static final int SIMPLE_ENTRY_INSTANCE_SIZE = instanceSize(AbstractMap.SimpleEntry.class);

public static long sizeOf(MemorySegment segment)
{
// final long length;
// final boolean readOnly;
// final MemorySessionImpl scope (int state);
long size = LONG_INSTANCE_SIZE + BOOLEAN_INSTANCE_SIZE + INTEGER_INSTANCE_SIZE;
if (segment.isNative()) {
return size
+ LONG_INSTANCE_SIZE; // addr;
}

return size
+ LONG_INSTANCE_SIZE // offset
+ segment.heapBase() // base
.map(value -> sizeOfByteArray(((byte[]) value).length))
.orElse(0L);
}

public static long sizeOf(boolean[] array)
{
return (array == null) ? 0 : sizeOfBooleanArray(array.length);
Expand Down
Loading

0 comments on commit 3855919

Please sign in to comment.