Class JEmalloc
- java.lang.Object
-
- org.lwjgl.system.jemalloc.JEmalloc
-
public class JEmalloc extends java.lang.ObjectNative bindings to jemalloc.jemalloc is a general purpose malloc implementation that emphasizes fragmentation avoidance and scalable concurrency support. jemalloc first came into use as the FreeBSD libc allocator in 2005, and since then it has found its way into numerous applications that rely on its predictable behavior. In 2010 jemalloc development efforts broadened to include developer support features such as heap profiling, Valgrind integration, and extensive monitoring/tuning hooks. Modern jemalloc releases continue to be integrated back into FreeBSD, and therefore versatility remains critical. Ongoing development efforts trend toward making jemalloc among the best allocators for a broad range of demanding applications, and eliminating/mitigating weaknesses that have practical repercussions for real world applications.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classJEmalloc.FunctionsContains the function pointers loaded from the jemallocSharedLibrary.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static SharedLibrarygetLibrary()Returns the jemallocSharedLibrary.static java.nio.ByteBufferje_aligned_alloc(long alignment, long size)Allocatessizebytes of memory such that the allocation's base address is an even multiple ofalignment.static java.nio.ByteBufferje_calloc(long num, long size)Allocates space fornumobjects, eachsizebytes in length.static voidje_dallocx(java.nio.ByteBuffer ptr, int flags)Causes the memory referenced byptrto be made available for future allocations.static voidje_dallocx(double[] ptr, int flags)double[] version of:dallocxstatic voidje_dallocx(java.nio.DoubleBuffer ptr, int flags)DoubleBuffer version of:dallocxstatic voidje_dallocx(float[] ptr, int flags)float[] version of:dallocxstatic voidje_dallocx(java.nio.FloatBuffer ptr, int flags)FloatBuffer version of:dallocxstatic voidje_dallocx(int[] ptr, int flags)int[] version of:dallocxstatic voidje_dallocx(java.nio.IntBuffer ptr, int flags)IntBuffer version of:dallocxstatic voidje_dallocx(long[] ptr, int flags)long[] version of:dallocxstatic voidje_dallocx(java.nio.LongBuffer ptr, int flags)LongBuffer version of:dallocxstatic voidje_dallocx(PointerBuffer ptr, int flags)PointerBuffer version of:dallocxstatic voidje_dallocx(short[] ptr, int flags)short[] version of:dallocxstatic voidje_dallocx(java.nio.ShortBuffer ptr, int flags)ShortBuffer version of:dallocxstatic voidje_free(java.nio.ByteBuffer ptr)Causes the allocated memory referenced byptrto be made available for future allocations.static voidje_free(double[] ptr)double[] version of:freestatic voidje_free(java.nio.DoubleBuffer ptr)DoubleBuffer version of:freestatic voidje_free(float[] ptr)float[] version of:freestatic voidje_free(java.nio.FloatBuffer ptr)FloatBuffer version of:freestatic voidje_free(int[] ptr)int[] version of:freestatic voidje_free(java.nio.IntBuffer ptr)IntBuffer version of:freestatic voidje_free(long[] ptr)long[] version of:freestatic voidje_free(java.nio.LongBuffer ptr)LongBuffer version of:freestatic voidje_free(PointerBuffer ptr)PointerBuffer version of:freestatic voidje_free(short[] ptr)short[] version of:freestatic voidje_free(java.nio.ShortBuffer ptr)ShortBuffer version of:freestatic intje_mallctl(java.nio.ByteBuffer name, java.nio.ByteBuffer oldp, PointerBuffer oldlenp, java.nio.ByteBuffer newp)Provides a general interface for introspecting the memory allocator, as well as setting modifiable parameters and triggering actions.static intje_mallctl(java.lang.CharSequence name, java.nio.ByteBuffer oldp, PointerBuffer oldlenp, java.nio.ByteBuffer newp)Provides a general interface for introspecting the memory allocator, as well as setting modifiable parameters and triggering actions.static intje_mallctlbymib(PointerBuffer mib, java.nio.ByteBuffer oldp, PointerBuffer oldlenp, java.nio.ByteBuffer newp)Similar tomallctl, but uses MIBs instead of names.static intje_mallctlnametomib(java.nio.ByteBuffer name, PointerBuffer mibp, PointerBuffer miblenp)Provides a way to avoid repeated name lookups for applications that repeatedly query the same portion of the namespace, by translating a name to a “Management Information Base” (MIB) that can be passed repeatedly tomallctlbymib.static intje_mallctlnametomib(java.lang.CharSequence name, PointerBuffer mibp, PointerBuffer miblenp)Provides a way to avoid repeated name lookups for applications that repeatedly query the same portion of the namespace, by translating a name to a “Management Information Base” (MIB) that can be passed repeatedly tomallctlbymib.static PointerBufferje_malloc_message()Returns theje_malloc_messagevariable.static voidje_malloc_stats_print(MallocMessageCallbackI write_cb, java.nio.ByteBuffer je_cbopaque, java.nio.ByteBuffer opts)Writes human-readable summary statistics via thewrite_cbcallback function pointer andcbopaquedata passed towrite_cb, ormalloc_message()ifwrite_cbisNULL.static voidje_malloc_stats_print(MallocMessageCallbackI write_cb, java.nio.ByteBuffer je_cbopaque, java.lang.CharSequence opts)Writes human-readable summary statistics via thewrite_cbcallback function pointer andcbopaquedata passed towrite_cb, ormalloc_message()ifwrite_cbisNULL.static longje_malloc_usable_size(java.nio.ByteBuffer ptr)Returns the usable size of the allocation pointed to byptr.static java.nio.ByteBufferje_malloc(long size)Allocatessizebytes of uninitialized memory.static java.nio.ByteBufferje_mallocx(long size, int flags)Allocates at leastsizebytes of memory, and returns a pointer to the base address of the allocation.static java.nio.ByteBufferje_nallocx(long size, int flags)Allocates no memory, but it performs the same size computation as themallocxfunction, and returns the real size of the allocation that would result from the equivalentmallocx()function call.static intje_posix_memalign(PointerBuffer memptr, long alignment, long size)Allocatessizebytes of memory such that the allocation's base address is an even multiple ofalignment, and returns the allocation in the value pointed to bymemptr.static java.nio.ByteBufferje_rallocx(java.nio.ByteBuffer ptr, long size, int flags)Resizes the allocation atptrto be at leastsizebytes, and returns a pointer to the base address of the resulting allocation, which may or may not have moved from its original location.static java.nio.ByteBufferje_realloc(java.nio.ByteBuffer ptr, long size)Changes the size of the previously allocated memory referenced byptrtosizebytes.static longje_sallocx(java.nio.ByteBuffer ptr, int flags)Returns the real size of the allocation atptr.static voidje_sdallocx(java.nio.ByteBuffer ptr, int flags)Sized version ofdallocx.static voidje_sdallocx(double[] ptr, int flags)double[] version of:sdallocxstatic voidje_sdallocx(java.nio.DoubleBuffer ptr, int flags)DoubleBuffer version of:sdallocxstatic voidje_sdallocx(float[] ptr, int flags)float[] version of:sdallocxstatic voidje_sdallocx(java.nio.FloatBuffer ptr, int flags)FloatBuffer version of:sdallocxstatic voidje_sdallocx(int[] ptr, int flags)int[] version of:sdallocxstatic voidje_sdallocx(java.nio.IntBuffer ptr, int flags)IntBuffer version of:sdallocxstatic voidje_sdallocx(long[] ptr, int flags)long[] version of:sdallocxstatic voidje_sdallocx(java.nio.LongBuffer ptr, int flags)LongBuffer version of:sdallocxstatic voidje_sdallocx(PointerBuffer ptr, int flags)PointerBuffer version of:sdallocxstatic voidje_sdallocx(short[] ptr, int flags)short[] version of:sdallocxstatic voidje_sdallocx(java.nio.ShortBuffer ptr, int flags)ShortBuffer version of:sdallocxstatic longje_xallocx(java.nio.ByteBuffer ptr, long size, long extra, int flags)Resizes the allocation atptrin place to be at least size bytes, and returns the real size of the allocation.
-
-
-
Method Detail
-
getLibrary
public static SharedLibrary getLibrary()
Returns the jemallocSharedLibrary.
-
je_malloc_message
public static PointerBuffer je_malloc_message()
Returns theje_malloc_messagevariable.
-
je_malloc
public static java.nio.ByteBuffer je_malloc(long size)
Allocatessizebytes of uninitialized memory. The allocated space is suitably aligned (after possible pointer coercion) for storage of any type of object.- Parameters:
size- the number of bytes to allocate
-
je_calloc
public static java.nio.ByteBuffer je_calloc(long num, long size)Allocates space fornumobjects, eachsizebytes in length. The result is identical to callingmallocwith an argument ofnum * size, with the exception that the allocated memory is explicitly initialized to zero bytes.- Parameters:
num- the number of objects to allocatesize- the size of each object, in bytes
-
je_posix_memalign
public static int je_posix_memalign(PointerBuffer memptr, long alignment, long size)
Allocatessizebytes of memory such that the allocation's base address is an even multiple ofalignment, and returns the allocation in the value pointed to bymemptr. The requested alignment must be a power of 2 at least as large assizeof(void *).- Parameters:
memptr- returns the allocated memoryalignment- the allocation alignment, in bytessize- the number of bytes to allocate
-
je_aligned_alloc
public static java.nio.ByteBuffer je_aligned_alloc(long alignment, long size)Allocatessizebytes of memory such that the allocation's base address is an even multiple ofalignment. The requested alignment must be a power of 2. Behavior is undefined ifsizeis not an integral multiple ofalignment.- Parameters:
alignment- the allocation alignment, in bytessize- the number of bytes to allocate
-
je_realloc
public static java.nio.ByteBuffer je_realloc(java.nio.ByteBuffer ptr, long size)Changes the size of the previously allocated memory referenced byptrtosizebytes. The contents of the memory are unchanged up to the lesser of the new and old sizes. If the new size is larger, the contents of the newly allocated portion of the memory are undefined. Upon success, the memory referenced byptris freed and a pointer to the newly allocated memory is returned. Note that realloc() may move the memory allocation, resulting in a different return value thanptr. IfptrisNULL, the realloc() function behaves identically to malloc() for the specified size.- Parameters:
ptr- the previously allocated memory orNULLsize- the number of bytes to allocate
-
je_free
public static void je_free(java.nio.ByteBuffer ptr)
Causes the allocated memory referenced byptrto be made available for future allocations. IfptrisNULL, no action occurs.- Parameters:
ptr- the allocated memory to free
-
je_free
public static void je_free(java.nio.ShortBuffer ptr)
ShortBuffer version of:free
-
je_free
public static void je_free(java.nio.IntBuffer ptr)
IntBuffer version of:free
-
je_free
public static void je_free(java.nio.LongBuffer ptr)
LongBuffer version of:free
-
je_free
public static void je_free(java.nio.FloatBuffer ptr)
FloatBuffer version of:free
-
je_free
public static void je_free(java.nio.DoubleBuffer ptr)
DoubleBuffer version of:free
-
je_free
public static void je_free(PointerBuffer ptr)
PointerBuffer version of:free
-
je_mallocx
public static java.nio.ByteBuffer je_mallocx(long size, int flags)Allocates at leastsizebytes of memory, and returns a pointer to the base address of the allocation. Behavior is undefined ifsizeis 0, or if request size overflows due to size class and/or alignment constraints.- Parameters:
size- the number of bytes to allocateflags- a bitfield of zero or more of theMALLOCXmacros inJEmacros
-
je_rallocx
public static java.nio.ByteBuffer je_rallocx(java.nio.ByteBuffer ptr, long size, int flags)Resizes the allocation atptrto be at leastsizebytes, and returns a pointer to the base address of the resulting allocation, which may or may not have moved from its original location. Behavior is undefined ifsizeis 0, or if request size overflows due to size class and/or alignment constraints.- Parameters:
ptr- the previously allocated memory orNULLsize- the number of bytes to allocateflags- a bitfield of zero or more of theMALLOCXmacros inJEmacros
-
je_xallocx
public static long je_xallocx(java.nio.ByteBuffer ptr, long size, long extra, int flags)Resizes the allocation atptrin place to be at least size bytes, and returns the real size of the allocation. Ifextrais non-zero, an attempt is made to resize the allocation to be at least(size + extra)bytes, though inability to allocate the extra byte(s) will not by itself result in failure to resize. Behavior is undefined ifsizeis 0, or if(size + extra > SIZE_T_MAX).- Parameters:
ptr- the previously allocated memory orNULLsize- the number of bytes to allocateextra- the number of extra bytes to allocateflags- a bitfield of zero or more of theMALLOCXmacros inJEmacros
-
je_sallocx
public static long je_sallocx(java.nio.ByteBuffer ptr, int flags)Returns the real size of the allocation atptr.- Parameters:
ptr- the allocated memory to queryflags- a bitfield of zero or more of theMALLOCXmacros inJEmacros
-
je_dallocx
public static void je_dallocx(java.nio.ByteBuffer ptr, int flags)Causes the memory referenced byptrto be made available for future allocations.- Parameters:
ptr- the allocated memory to deallocateflags- a bitfield of zero or more of theMALLOCXmacros inJEmacros
-
je_dallocx
public static void je_dallocx(java.nio.ShortBuffer ptr, int flags)ShortBuffer version of:dallocx
-
je_dallocx
public static void je_dallocx(java.nio.IntBuffer ptr, int flags)IntBuffer version of:dallocx
-
je_dallocx
public static void je_dallocx(java.nio.LongBuffer ptr, int flags)LongBuffer version of:dallocx
-
je_dallocx
public static void je_dallocx(java.nio.FloatBuffer ptr, int flags)FloatBuffer version of:dallocx
-
je_dallocx
public static void je_dallocx(java.nio.DoubleBuffer ptr, int flags)DoubleBuffer version of:dallocx
-
je_dallocx
public static void je_dallocx(PointerBuffer ptr, int flags)
PointerBuffer version of:dallocx
-
je_sdallocx
public static void je_sdallocx(java.nio.ByteBuffer ptr, int flags)Sized version ofdallocx. The primary optimization overdallocx()is the removal of a metadata read, which often suffers an L1 cache miss.- Parameters:
ptr- the allocated memory to deallocateflags- a bitfield of zero or more of theMALLOCXmacros inJEmacros
-
je_sdallocx
public static void je_sdallocx(java.nio.ShortBuffer ptr, int flags)ShortBuffer version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(java.nio.IntBuffer ptr, int flags)IntBuffer version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(java.nio.LongBuffer ptr, int flags)LongBuffer version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(java.nio.FloatBuffer ptr, int flags)FloatBuffer version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(java.nio.DoubleBuffer ptr, int flags)DoubleBuffer version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(PointerBuffer ptr, int flags)
PointerBuffer version of:sdallocx
-
je_nallocx
public static java.nio.ByteBuffer je_nallocx(long size, int flags)Allocates no memory, but it performs the same size computation as themallocxfunction, and returns the real size of the allocation that would result from the equivalentmallocx()function call. Behavior is undefined ifsizeis 0, or if request size overflows due to size class and/or alignment constraints.- Parameters:
size- the number of bytes to allocateflags- a bitfield of zero or more of theMALLOCXmacros inJEmacros
-
je_mallctl
public static int je_mallctl(java.nio.ByteBuffer name, java.nio.ByteBuffer oldp, PointerBuffer oldlenp, java.nio.ByteBuffer newp)Provides a general interface for introspecting the memory allocator, as well as setting modifiable parameters and triggering actions. The period-separatednameargument specifies a location in a tree-structured namespace; see the MALLCTL NAMESPACE section for documentation on the tree contents. To read a value, pass a pointer viaoldpto adequate space to contain the value, and a pointer to its length viaoldlenp; otherwise passNULLandNULL. Similarly, to write a value, pass a pointer to the value vianewp, and its length vianewlen; otherwise passNULLand0.- Parameters:
name- the namespace locationoldp- returns a valueoldlenp- returns the value lengthnewp- the new value
-
je_mallctl
public static int je_mallctl(java.lang.CharSequence name, java.nio.ByteBuffer oldp, PointerBuffer oldlenp, java.nio.ByteBuffer newp)Provides a general interface for introspecting the memory allocator, as well as setting modifiable parameters and triggering actions. The period-separatednameargument specifies a location in a tree-structured namespace; see the MALLCTL NAMESPACE section for documentation on the tree contents. To read a value, pass a pointer viaoldpto adequate space to contain the value, and a pointer to its length viaoldlenp; otherwise passNULLandNULL. Similarly, to write a value, pass a pointer to the value vianewp, and its length vianewlen; otherwise passNULLand0.- Parameters:
name- the namespace locationoldp- returns a valueoldlenp- returns the value lengthnewp- the new value
-
je_mallctlnametomib
public static int je_mallctlnametomib(java.nio.ByteBuffer name, PointerBuffer mibp, PointerBuffer miblenp)Provides a way to avoid repeated name lookups for applications that repeatedly query the same portion of the namespace, by translating a name to a “Management Information Base” (MIB) that can be passed repeatedly tomallctlbymib. Upon successful return frommallctlnametomib(),mibpcontains an array of*miblenpintegers, where*miblenpis the lesser of the number of components in name and the input value of*miblenp. Thus it is possible to pass a*miblenpthat is smaller than the number of period-separated name components, which results in a partial MIB that can be used as the basis for constructing a complete MIB. For name components that are integers (e.g. the 2 in "arenas.bin.2.size"), the corresponding MIB component will always be that integer. Therefore, it is legitimate to construct code like the following:unsigned nbins, i; size_t mib[4]; size_t len, miblen; len = sizeof(nbins); mallctl("arenas.nbins", &nbins, &len, NULL, 0); miblen = 4; mallctlnametomib("arenas.bin.0.size", mib, &miblen); for (i = 0; i < nbins; i++) { size_t bin_size; mib[2] = i; len = sizeof(bin_size); mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0); // Do something with bin_size... }- Parameters:
name- the namespace locationmibp- an array of integersmiblenp- the number of components inmibp
-
je_mallctlnametomib
public static int je_mallctlnametomib(java.lang.CharSequence name, PointerBuffer mibp, PointerBuffer miblenp)Provides a way to avoid repeated name lookups for applications that repeatedly query the same portion of the namespace, by translating a name to a “Management Information Base” (MIB) that can be passed repeatedly tomallctlbymib. Upon successful return frommallctlnametomib(),mibpcontains an array of*miblenpintegers, where*miblenpis the lesser of the number of components in name and the input value of*miblenp. Thus it is possible to pass a*miblenpthat is smaller than the number of period-separated name components, which results in a partial MIB that can be used as the basis for constructing a complete MIB. For name components that are integers (e.g. the 2 in "arenas.bin.2.size"), the corresponding MIB component will always be that integer. Therefore, it is legitimate to construct code like the following:unsigned nbins, i; size_t mib[4]; size_t len, miblen; len = sizeof(nbins); mallctl("arenas.nbins", &nbins, &len, NULL, 0); miblen = 4; mallctlnametomib("arenas.bin.0.size", mib, &miblen); for (i = 0; i < nbins; i++) { size_t bin_size; mib[2] = i; len = sizeof(bin_size); mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0); // Do something with bin_size... }- Parameters:
name- the namespace locationmibp- an array of integersmiblenp- the number of components inmibp
-
je_mallctlbymib
public static int je_mallctlbymib(PointerBuffer mib, java.nio.ByteBuffer oldp, PointerBuffer oldlenp, java.nio.ByteBuffer newp)
Similar tomallctl, but uses MIBs instead of names. Seemallctlnametomibfor details.- Parameters:
mib- a MIBoldp- returns a valueoldlenp- returns the value lengthnewp- the new value
-
je_malloc_stats_print
public static void je_malloc_stats_print(MallocMessageCallbackI write_cb, java.nio.ByteBuffer je_cbopaque, java.nio.ByteBuffer opts)
Writes human-readable summary statistics via thewrite_cbcallback function pointer andcbopaquedata passed towrite_cb, ormalloc_message()ifwrite_cbisNULL. This function can be called repeatedly. General information that never changes during execution can be omitted by specifying "g" as a character within theoptsstring. Note thatmalloc_message()uses themallctl*()functions internally, so inconsistent statistics can be reported if multiple threads use these functions simultaneously. If--enable-statsis specified during configuration, “m” and “a” can be specified to omit merged arena and per arena statistics, respectively; “b” and “l” can be specified to omit per size class statistics for bins and large objects, respectively. Unrecognized characters are silently ignored. Note that thread caching may prevent some statistics from being completely up to date, since extra locking would be required to merge counters that track thread cache operations.- Parameters:
write_cb- the print callback, orNULLto usemalloc_message()je_cbopaque- an opaque pointer that will be passed towrite_cbopts- an options string
-
je_malloc_stats_print
public static void je_malloc_stats_print(MallocMessageCallbackI write_cb, java.nio.ByteBuffer je_cbopaque, java.lang.CharSequence opts)
Writes human-readable summary statistics via thewrite_cbcallback function pointer andcbopaquedata passed towrite_cb, ormalloc_message()ifwrite_cbisNULL. This function can be called repeatedly. General information that never changes during execution can be omitted by specifying "g" as a character within theoptsstring. Note thatmalloc_message()uses themallctl*()functions internally, so inconsistent statistics can be reported if multiple threads use these functions simultaneously. If--enable-statsis specified during configuration, “m” and “a” can be specified to omit merged arena and per arena statistics, respectively; “b” and “l” can be specified to omit per size class statistics for bins and large objects, respectively. Unrecognized characters are silently ignored. Note that thread caching may prevent some statistics from being completely up to date, since extra locking would be required to merge counters that track thread cache operations.- Parameters:
write_cb- the print callback, orNULLto usemalloc_message()je_cbopaque- an opaque pointer that will be passed towrite_cbopts- an options string
-
je_malloc_usable_size
public static long je_malloc_usable_size(java.nio.ByteBuffer ptr)
Returns the usable size of the allocation pointed to byptr. The return value may be larger than the size that was requested during allocation. Themalloc_usable_size()function is not a mechanism for in-placerealloc; rather it is provided solely as a tool for introspection purposes. Any discrepancy between the requested allocation size and the size reported bymalloc_usable_size()should not be depended on, since such behavior is entirely implementation-dependent.- Parameters:
ptr- the allocated memory to query
-
je_free
public static void je_free(short[] ptr)
short[] version of:free
-
je_free
public static void je_free(int[] ptr)
int[] version of:free
-
je_free
public static void je_free(long[] ptr)
long[] version of:free
-
je_free
public static void je_free(float[] ptr)
float[] version of:free
-
je_free
public static void je_free(double[] ptr)
double[] version of:free
-
je_dallocx
public static void je_dallocx(short[] ptr, int flags)short[] version of:dallocx
-
je_dallocx
public static void je_dallocx(int[] ptr, int flags)int[] version of:dallocx
-
je_dallocx
public static void je_dallocx(long[] ptr, int flags)long[] version of:dallocx
-
je_dallocx
public static void je_dallocx(float[] ptr, int flags)float[] version of:dallocx
-
je_dallocx
public static void je_dallocx(double[] ptr, int flags)double[] version of:dallocx
-
je_sdallocx
public static void je_sdallocx(short[] ptr, int flags)short[] version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(int[] ptr, int flags)int[] version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(long[] ptr, int flags)long[] version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(float[] ptr, int flags)float[] version of:sdallocx
-
je_sdallocx
public static void je_sdallocx(double[] ptr, int flags)double[] version of:sdallocx
-
-