NativeLongArray Class — netty Architecture
Architecture documentation for the NativeLongArray class in NativeLongArray.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD d17350c3_e125_2323_980a_eae0f43600f1["NativeLongArray"] 59f59dae_9a8a_f568_684f_d471b090ca63["NativeLongArray.java"] d17350c3_e125_2323_980a_eae0f43600f1 -->|defined in| 59f59dae_9a8a_f568_684f_d471b090ca63 67c22978_1287_ad97_8694_204dbd3ac4b5["NativeLongArray()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 67c22978_1287_ad97_8694_204dbd3ac4b5 9bdf2012_76da_b38f_16a0_3d556595e9b6["idx()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 9bdf2012_76da_b38f_16a0_3d556595e9b6 ecba7f48_0fcf_5ca2_15c1_8da94f0bbce8["calculateBufferCapacity()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| ecba7f48_0fcf_5ca2_15c1_8da94f0bbce8 585f855d_185a_e249_9bc8_6e1397074cb7["add()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 585f855d_185a_e249_9bc8_6e1397074cb7 045c41a4_66f4_293b_6002_74345d3b30fb["clear()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 045c41a4_66f4_293b_6002_74345d3b30fb 60965f6e_3851_9c42_7e6e_e1d92d7ee031["isEmpty()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 60965f6e_3851_9c42_7e6e_e1d92d7ee031 f32c966f_8864_d238_734a_f888ac3cfb19["size()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| f32c966f_8864_d238_734a_f888ac3cfb19 5ac4810c_7af1_6576_940f_44a1b927b885["free()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 5ac4810c_7af1_6576_940f_44a1b927b885 2f42ea99_3a54_c982_26b6_4f5d891044d0["memoryAddress()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 2f42ea99_3a54_c982_26b6_4f5d891044d0 1a4ee852_8e39_1952_1183_7c2a5ee7bed1["memoryAddressEnd()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 1a4ee852_8e39_1952_1183_7c2a5ee7bed1 d2c10886_b527_ae57_27a3_a0ccffbf22eb["memoryOffset()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| d2c10886_b527_ae57_27a3_a0ccffbf22eb 682814d5_3a6f_0320_6ddc_71156d6dbd53["reallocIfNeeded()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 682814d5_3a6f_0320_6ddc_71156d6dbd53 0c6666aa_8345_8f03_0e2b_57e04257d320["String()"] d17350c3_e125_2323_980a_eae0f43600f1 -->|method| 0c6666aa_8345_8f03_0e2b_57e04257d320
Relationship Graph
Source Code
transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/NativeLongArray.java lines 27–112
final class NativeLongArray {
private CleanableDirectBuffer memoryCleanable;
private ByteBuffer memory;
private long memoryAddress;
private int capacity;
private int size;
NativeLongArray(int capacity) {
this.capacity = checkPositive(capacity, "capacity");
memoryCleanable = Buffer.allocateDirectBufferWithNativeOrder(calculateBufferCapacity(capacity));
memory = memoryCleanable.buffer();
memoryAddress = Buffer.memoryAddress(memory);
}
private static int idx(int index) {
return index * SIZEOF_JLONG;
}
private static int calculateBufferCapacity(int capacity) {
return capacity * SIZEOF_JLONG;
}
void add(long value) {
reallocIfNeeded();
if (PlatformDependent.hasUnsafe()) {
PlatformDependent.putLong(memoryOffset(size), value);
} else {
memory.putLong(idx(size), value);
}
++size;
}
void clear() {
size = 0;
}
boolean isEmpty() {
return size == 0;
}
int size() {
return size;
}
void free() {
memoryCleanable.clean();
memoryAddress = 0;
}
long memoryAddress() {
return memoryAddress;
}
long memoryAddressEnd() {
return memoryOffset(size);
}
private long memoryOffset(int index) {
return memoryAddress + idx(index);
}
private void reallocIfNeeded() {
if (size == capacity) {
// Double the capacity while it is "sufficiently small", and otherwise increase by 50%.
int newLength = capacity <= 65536 ? capacity << 1 : capacity + capacity >> 1;
int newCapacity = calculateBufferCapacity(newLength);
CleanableDirectBuffer buffer = Buffer.allocateDirectBufferWithNativeOrder(newCapacity);
// Copy over the old content of the memory and reset the position as we always act on the buffer as if
// the position was never increased.
memory.position(0).limit(size);
buffer.buffer().put(memory);
buffer.buffer().position(0);
memoryCleanable.clean();
memoryCleanable = buffer;
memory = buffer.buffer();
memoryAddress = Buffer.memoryAddress(memory);
capacity = newLength;
}
}
Source
Frequently Asked Questions
What is the NativeLongArray class?
NativeLongArray is a class in the netty codebase, defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/NativeLongArray.java.
Where is NativeLongArray defined?
NativeLongArray is defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/NativeLongArray.java at line 27.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free