|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * The Universal Permissive License (UPL), Version 1.0
|
@@ -89,67 +89,41 @@ public class ArrowArray {
|
89 | 89 | private static final long RELEASE_CALLBACK_INDEX = 8 * POINTER_SIZE;
|
90 | 90 | private static final long PRIVATE_DATA_INDEX = 9 * POINTER_SIZE;
|
91 | 91 |
|
92 |
| - public final long memoryAddr; |
| 92 | + private final long memoryAddr; |
93 | 93 |
|
94 | 94 | private ArrowArray(long memoryAddr) {
|
95 | 95 | this.memoryAddr = memoryAddr;
|
96 | 96 | }
|
97 | 97 |
|
98 |
| - public static ArrowArray allocate() { |
99 |
| - var arrowArray = new ArrowArray(unsafe.allocateMemory(SIZE_OF)); |
100 |
| - arrowArray.markReleased(); |
101 |
| - return arrowArray; |
| 98 | + public static ArrowArray allocate(long length, long nullCount, long offset, long nBuffers, long nChildren, long buffers, long children, long dictionary, long release, long privateData) { |
| 99 | + var memoryAddr = unsafe.allocateMemory(SIZE_OF); |
| 100 | + unsafe.putLong(memoryAddr + LENGTH_INDEX, length); |
| 101 | + unsafe.putLong(memoryAddr + NULL_COUNT_INDEX, nullCount); |
| 102 | + unsafe.putLong(memoryAddr + OFFSET_INDEX, offset); |
| 103 | + unsafe.putLong(memoryAddr + N_BUFFERS_INDEX, nBuffers); |
| 104 | + unsafe.putLong(memoryAddr + N_CHILDREN_INDEX, nChildren); |
| 105 | + unsafe.putLong(memoryAddr + BUFFERS_INDEX, buffers); |
| 106 | + unsafe.putLong(memoryAddr + CHILDREN_INDEX, children); |
| 107 | + unsafe.putLong(memoryAddr + DICTIONARY_INDEX, dictionary); |
| 108 | + unsafe.putLong(memoryAddr + RELEASE_CALLBACK_INDEX, release); |
| 109 | + unsafe.putLong(memoryAddr + PRIVATE_DATA_INDEX, privateData); |
| 110 | + |
| 111 | + return new ArrowArray(memoryAddr); |
102 | 112 | }
|
103 | 113 |
|
104 |
| - public static ArrowArray allocateFromSnapshot(Snapshot snapshot) { |
105 |
| - var arrowArray = new ArrowArray(unsafe.allocateMemory(SIZE_OF)); |
106 |
| - arrowArray.load(snapshot); |
107 |
| - return arrowArray; |
| 114 | + public long memoryAddress() { |
| 115 | + return memoryAddr; |
108 | 116 | }
|
109 | 117 |
|
110 |
| - public static ArrowArray wrap(long arrowArrayPointer) { |
111 |
| - return new ArrowArray(arrowArrayPointer); |
| 118 | + public long releaseCallback() { |
| 119 | + return unsafe.getLong(memoryAddr + RELEASE_CALLBACK_INDEX); |
112 | 120 | }
|
113 | 121 |
|
114 |
| - public void markReleased() { |
115 |
| - unsafe.putLong(memoryAddr + RELEASE_CALLBACK_INDEX, NULL); |
| 122 | + public static ArrowArray wrap(long arrowArrayPointer) { |
| 123 | + return new ArrowArray(arrowArrayPointer); |
116 | 124 | }
|
117 | 125 |
|
118 | 126 | public boolean isReleased() {
|
119 |
| - return unsafe.getLong(memoryAddr + RELEASE_CALLBACK_INDEX) == NULL; |
120 |
| - } |
121 |
| - |
122 |
| - public long getBuffers() { |
123 |
| - return unsafe.getLong(memoryAddr + BUFFERS_INDEX); |
124 |
| - } |
125 |
| - |
126 |
| - public long getValueBuffer() { |
127 |
| - return unsafe.getLong(getBuffers() + POINTER_SIZE); |
128 |
| - } |
129 |
| - |
130 |
| - private void load(Snapshot snapshot) { |
131 |
| - unsafe.putLong(memoryAddr + LENGTH_INDEX, snapshot.length); |
132 |
| - unsafe.putLong(memoryAddr + NULL_COUNT_INDEX, snapshot.null_count); |
133 |
| - unsafe.putLong(memoryAddr + OFFSET_INDEX, snapshot.offset); |
134 |
| - unsafe.putLong(memoryAddr + N_BUFFERS_INDEX, snapshot.n_buffers); |
135 |
| - unsafe.putLong(memoryAddr + N_CHILDREN_INDEX, snapshot.n_children); |
136 |
| - unsafe.putLong(memoryAddr + BUFFERS_INDEX, snapshot.buffers); |
137 |
| - unsafe.putLong(memoryAddr + CHILDREN_INDEX, snapshot.children); |
138 |
| - unsafe.putLong(memoryAddr + DICTIONARY_INDEX, snapshot.dictionary); |
139 |
| - unsafe.putLong(memoryAddr + RELEASE_CALLBACK_INDEX, snapshot.release); |
140 |
| - unsafe.putLong(memoryAddr + PRIVATE_DATA_INDEX, snapshot.private_data); |
141 |
| - } |
142 |
| - |
143 |
| - public static class Snapshot { |
144 |
| - public long length = 0L; |
145 |
| - public long null_count = 0L; |
146 |
| - public long offset = 0L; |
147 |
| - public long n_buffers = 0L; |
148 |
| - public long n_children = 0L; |
149 |
| - public long buffers = 0L; |
150 |
| - public long children = 0L; |
151 |
| - public long dictionary = 0L; |
152 |
| - public long release = 0L; |
153 |
| - public long private_data = 0L; |
| 127 | + return releaseCallback() == NULL; |
154 | 128 | }
|
155 | 129 | }
|
0 commit comments