Off-heap memory tools based on sun.misc.Unsafe
Some tools to work with off-heap memory using
sun.misc.Unsafe class. Contains fallback
implementations for environments, where proper implementation of
sun.misc.Unsafe is not available.
All memory access code has boundary checks using assert keyword.
With assertions enabled in runtime (
-ea java switch) illegal memory access will throw
Without assertions illegal memory access will crash JVM.
Library has no third-party dependencies and is available in Maven central:
<dependency> <groupId>com.alexkasko.unsafe</groupId> <artifactId>unsafe-tools</artifactId> <version>1.4.4</version> </dependency>
Off-heap memory, data structures, operations
JVM allows to allocate and use memory outside of java heap. Such off-heap memory may be allocated/used/deallocated without additional load on garbage collector.
###Off-heap memory management
Off-heap memory manager implemented as a thin wrapper over
sun.misc.Unsafe. Other data structures implemented on top of it.
com.alexkasko.unsafe.offheap package description
###Off-heap collections of longs
Maximum array length in Java is bounded by
Integer.MAX_VALUE. This library provides long-sized fixed and growing arrays of longs.
com.alexkasko.unsafe.offheaplong package description
###Off-heap collections of structs (memory areas)
Equal-sized memory areas may be stored in off-heap memory contiguously as collections. Such memory areas also may be used
like C structs (without compiler checks, though). Sorting and searching of these collections may be done using
"fields" of such "structs" or using
Comparator. Sorting also can be performed "by-references" using additional array to
hold collections indices (without reordering elements in the collection itself).
com.alexkasko.unsafe.offheapstruct package description
The following operations are implemented for all off-heap data structures:
- Dual-Pivot Quicksort implementation, adapted from here.
- Binary Search implementation, adapted from here.
Byte array tool
sun.misc.Unsafe may be used for writing/reading primitive values to/from byte arrays and to copying memory between byte arrays.
Byte array tool is implemented on top of it.
com.alexkasko.unsafe.bytearray package description
This project is released under the Apache License 2.0
shrinkToFitfor struct array lists
- additional get method for accessors
- struct reference sort added to facade
- reference sorting for struct collections
- missed javadoc fixes
- accessors for struct parts in struct collections
- clone support for arrays
- remove zero length assertion for byte array copy
- comparator sort for collections of longs
- header-payload package removed
bytesort/search methods removed
- multisort methods removed
- javadocs cleanup
- parallel sort for long keys
- minor utility methods added
- fix race condition in parallel quicksort
- fix unsigned long sorter
- naive parallel quicksort for struct collections
- on-heap memory prototype
- comparator sort for struct collections
- struct binary search with comparator
- fail-fast on OOM during allocation
- faster multisort choosers
- sorting struct collections using unsigned fields comparison
- fix sort of empty struct collection using multiple keys
- struct collections sorting using
- struct collections sorting with multiple keys
- packages changed
- struct collectons added
- payload collections deprecated
- more strict checks for lists
assertchecks for off-heap memory
- binary search javadoc fixes
- prevent result object instantiation in ranged search
- ranges support for binary search
- bug fixed in
OffHeapPayloadSorter- in some circumstances in 1.1 sorting may overwrite payload values for equal headers. A lot of tests on random data have been run to check correctness of 1.2 version
- header-int_payload array, array list and sorting
- header-long_payload array, array list and sorting
- long-array list
- header-payload array and array list
- binary search for all collections
- initial version