org.lwjgl.system.jemalloc.ExtentHooks Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lwjgl-jemalloc Show documentation
Show all versions of lwjgl-jemalloc Show documentation
A general purpose malloc implementation that emphasizes fragmentation avoidance and scalable concurrency support.
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
package org.lwjgl.system.jemalloc;
import java.nio.*;
import org.lwjgl.*;
import org.lwjgl.system.*;
import static org.lwjgl.system.Checks.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.MemoryStack.*;
/**
* The {@code extent_hooks_t} structure comprises function pointers which are described individually below. jemalloc uses these functions to manage extent
* lifetime, which starts off with allocation of mapped committed memory, in the simplest case followed by deallocation. However, there are performance
* and platform reasons to retain extents for later reuse. Cleanup attempts cascade from deallocation to decommit to forced purging to lazy purging, which
* gives the extent management functions opportunities to reject the most permanent cleanup operations in favor of less permanent (and often less costly)
* operations. All operations except allocation can be universally opted out of by setting the hook pointers to {@code NULL}, or selectively opted out of by
* returning failure.
*
* Member documentation
*
*
* - {@code alloc} – the extent allocation hook
* - {@code dalloc} – the extent deallocation hook
* - {@code destroy} – the extent destruction hook
* - {@code commit} – the extent commit hook
* - {@code decommit} – the extent decommit hook
* - {@code purge_lazy} – the extent lazy purge hook
* - {@code purge_forced} – the extent forced purge hook
* - {@code split} – the extent split hook
* - {@code merge} – the extent merge hook
*
*
* Layout
*
*
* struct extent_hooks_t {
* {@link ExtentAllocI extent_alloc_t} alloc;
* {@link ExtentDallocI extent_dalloc_t} dalloc;
* {@link ExtentDestroyI extent_destroy_t} destroy;
* {@link ExtentCommitI extent_commit_t} commit;
* {@link ExtentDecommitI extent_decommit_t} decommit;
* {@link ExtentPurgeI extent_purge_t} purge_lazy;
* {@link ExtentPurgeI extent_purge_t} purge_forced;
* {@link ExtentSplitI extent_split_t} split;
* {@link ExtentMergeI extent_merge_t} merge;
* }
*/
@NativeType("struct extent_hooks_t")
public class ExtentHooks extends Struct implements NativeResource {
/** The struct size in bytes. */
public static final int SIZEOF;
public static final int ALIGNOF;
/** The struct member offsets. */
public static final int
ALLOC,
DALLOC,
DESTROY,
COMMIT,
DECOMMIT,
PURGE_LAZY,
PURGE_FORCED,
SPLIT,
MERGE;
static {
Layout layout = __struct(
__member(POINTER_SIZE),
__member(POINTER_SIZE),
__member(POINTER_SIZE),
__member(POINTER_SIZE),
__member(POINTER_SIZE),
__member(POINTER_SIZE),
__member(POINTER_SIZE),
__member(POINTER_SIZE),
__member(POINTER_SIZE)
);
SIZEOF = layout.getSize();
ALIGNOF = layout.getAlignment();
ALLOC = layout.offsetof(0);
DALLOC = layout.offsetof(1);
DESTROY = layout.offsetof(2);
COMMIT = layout.offsetof(3);
DECOMMIT = layout.offsetof(4);
PURGE_LAZY = layout.offsetof(5);
PURGE_FORCED = layout.offsetof(6);
SPLIT = layout.offsetof(7);
MERGE = layout.offsetof(8);
}
ExtentHooks(long address, ByteBuffer container) {
super(address, container);
}
/**
* Creates a {@link ExtentHooks} instance at the current position of the specified {@link ByteBuffer} container. Changes to the buffer's content will be
* visible to the struct instance and vice versa.
*
* The created instance holds a strong reference to the container object.
*/
public ExtentHooks(ByteBuffer container) {
this(memAddress(container), checkContainer(container, SIZEOF));
}
@Override
public int sizeof() { return SIZEOF; }
/** Returns the value of the {@code alloc} field. */
@NativeType("extent_alloc_t")
public ExtentAlloc alloc() { return nalloc(address()); }
/** Returns the value of the {@code dalloc} field. */
@NativeType("extent_dalloc_t")
public ExtentDalloc dalloc() { return ndalloc(address()); }
/** Returns the value of the {@code destroy} field. */
@NativeType("extent_destroy_t")
public ExtentDestroy destroy() { return ndestroy(address()); }
/** Returns the value of the {@code commit} field. */
@NativeType("extent_commit_t")
public ExtentCommit commit() { return ncommit(address()); }
/** Returns the value of the {@code decommit} field. */
@NativeType("extent_decommit_t")
public ExtentDecommit decommit() { return ndecommit(address()); }
/** Returns the value of the {@code purge_lazy} field. */
@NativeType("extent_purge_t")
public ExtentPurge purge_lazy() { return npurge_lazy(address()); }
/** Returns the value of the {@code purge_forced} field. */
@NativeType("extent_purge_t")
public ExtentPurge purge_forced() { return npurge_forced(address()); }
/** Returns the value of the {@code split} field. */
@NativeType("extent_split_t")
public ExtentSplit split() { return nsplit(address()); }
/** Returns the value of the {@code merge} field. */
@NativeType("extent_merge_t")
public ExtentMerge merge() { return nmerge(address()); }
/** Sets the specified value to the {@code alloc} field. */
public ExtentHooks alloc(@NativeType("extent_alloc_t") ExtentAllocI value) { nalloc(address(), value); return this; }
/** Sets the specified value to the {@code dalloc} field. */
public ExtentHooks dalloc(@NativeType("extent_dalloc_t") ExtentDallocI value) { ndalloc(address(), value); return this; }
/** Sets the specified value to the {@code destroy} field. */
public ExtentHooks destroy(@NativeType("extent_destroy_t") ExtentDestroyI value) { ndestroy(address(), value); return this; }
/** Sets the specified value to the {@code commit} field. */
public ExtentHooks commit(@NativeType("extent_commit_t") ExtentCommitI value) { ncommit(address(), value); return this; }
/** Sets the specified value to the {@code decommit} field. */
public ExtentHooks decommit(@NativeType("extent_decommit_t") ExtentDecommitI value) { ndecommit(address(), value); return this; }
/** Sets the specified value to the {@code purge_lazy} field. */
public ExtentHooks purge_lazy(@NativeType("extent_purge_t") ExtentPurgeI value) { npurge_lazy(address(), value); return this; }
/** Sets the specified value to the {@code purge_forced} field. */
public ExtentHooks purge_forced(@NativeType("extent_purge_t") ExtentPurgeI value) { npurge_forced(address(), value); return this; }
/** Sets the specified value to the {@code split} field. */
public ExtentHooks split(@NativeType("extent_split_t") ExtentSplitI value) { nsplit(address(), value); return this; }
/** Sets the specified value to the {@code merge} field. */
public ExtentHooks merge(@NativeType("extent_merge_t") ExtentMergeI value) { nmerge(address(), value); return this; }
/** Initializes this struct with the specified values. */
public ExtentHooks set(
ExtentAllocI alloc,
ExtentDallocI dalloc,
ExtentDestroyI destroy,
ExtentCommitI commit,
ExtentDecommitI decommit,
ExtentPurgeI purge_lazy,
ExtentPurgeI purge_forced,
ExtentSplitI split,
ExtentMergeI merge
) {
alloc(alloc);
dalloc(dalloc);
destroy(destroy);
commit(commit);
decommit(decommit);
purge_lazy(purge_lazy);
purge_forced(purge_forced);
split(split);
merge(merge);
return this;
}
/**
* Copies the specified struct data to this struct.
*
* @param src the source struct
*
* @return this struct
*/
public ExtentHooks set(ExtentHooks src) {
memCopy(src.address(), address(), SIZEOF);
return this;
}
// -----------------------------------
/** Returns a new {@link ExtentHooks} instance allocated with {@link MemoryUtil#memAlloc memAlloc}. The instance must be explicitly freed. */
public static ExtentHooks malloc() {
return create(nmemAlloc(SIZEOF));
}
/** Returns a new {@link ExtentHooks} instance allocated with {@link MemoryUtil#memCalloc memCalloc}. The instance must be explicitly freed. */
public static ExtentHooks calloc() {
return create(nmemCalloc(1, SIZEOF));
}
/** Returns a new {@link ExtentHooks} instance allocated with {@link BufferUtils}. */
public static ExtentHooks create() {
return new ExtentHooks(BufferUtils.createByteBuffer(SIZEOF));
}
/** Returns a new {@link ExtentHooks} instance for the specified memory address or {@code null} if the address is {@code NULL}. */
public static ExtentHooks create(long address) {
return address == NULL ? null : new ExtentHooks(address, null);
}
/**
* Returns a new {@link ExtentHooks.Buffer} instance allocated with {@link MemoryUtil#memAlloc memAlloc}. The instance must be explicitly freed.
*
* @param capacity the buffer capacity
*/
public static Buffer malloc(int capacity) {
return create(__malloc(capacity, SIZEOF), capacity);
}
/**
* Returns a new {@link ExtentHooks.Buffer} instance allocated with {@link MemoryUtil#memCalloc memCalloc}. The instance must be explicitly freed.
*
* @param capacity the buffer capacity
*/
public static Buffer calloc(int capacity) {
return create(nmemCalloc(capacity, SIZEOF), capacity);
}
/**
* Returns a new {@link ExtentHooks.Buffer} instance allocated with {@link BufferUtils}.
*
* @param capacity the buffer capacity
*/
public static Buffer create(int capacity) {
return new Buffer(__create(capacity, SIZEOF));
}
/**
* Create a {@link ExtentHooks.Buffer} instance at the specified memory.
*
* @param address the memory address
* @param capacity the buffer capacity
*/
public static Buffer create(long address, int capacity) {
return address == NULL ? null : new Buffer(address, null, -1, 0, capacity, capacity);
}
// -----------------------------------
/** Returns a new {@link ExtentHooks} instance allocated on the thread-local {@link MemoryStack}. */
public static ExtentHooks mallocStack() {
return mallocStack(stackGet());
}
/** Returns a new {@link ExtentHooks} instance allocated on the thread-local {@link MemoryStack} and initializes all its bits to zero. */
public static ExtentHooks callocStack() {
return callocStack(stackGet());
}
/**
* Returns a new {@link ExtentHooks} instance allocated on the specified {@link MemoryStack}.
*
* @param stack the stack from which to allocate
*/
public static ExtentHooks mallocStack(MemoryStack stack) {
return create(stack.nmalloc(ALIGNOF, SIZEOF));
}
/**
* Returns a new {@link ExtentHooks} instance allocated on the specified {@link MemoryStack} and initializes all its bits to zero.
*
* @param stack the stack from which to allocate
*/
public static ExtentHooks callocStack(MemoryStack stack) {
return create(stack.ncalloc(ALIGNOF, 1, SIZEOF));
}
/**
* Returns a new {@link ExtentHooks.Buffer} instance allocated on the thread-local {@link MemoryStack}.
*
* @param capacity the buffer capacity
*/
public static Buffer mallocStack(int capacity) {
return mallocStack(capacity, stackGet());
}
/**
* Returns a new {@link ExtentHooks.Buffer} instance allocated on the thread-local {@link MemoryStack} and initializes all its bits to zero.
*
* @param capacity the buffer capacity
*/
public static Buffer callocStack(int capacity) {
return callocStack(capacity, stackGet());
}
/**
* Returns a new {@link ExtentHooks.Buffer} instance allocated on the specified {@link MemoryStack}.
*
* @param stack the stack from which to allocate
* @param capacity the buffer capacity
*/
public static Buffer mallocStack(int capacity, MemoryStack stack) {
return create(stack.nmalloc(ALIGNOF, capacity * SIZEOF), capacity);
}
/**
* Returns a new {@link ExtentHooks.Buffer} instance allocated on the specified {@link MemoryStack} and initializes all its bits to zero.
*
* @param stack the stack from which to allocate
* @param capacity the buffer capacity
*/
public static Buffer callocStack(int capacity, MemoryStack stack) {
return create(stack.ncalloc(ALIGNOF, capacity, SIZEOF), capacity);
}
// -----------------------------------
/** Unsafe version of {@link #alloc}. */
public static ExtentAlloc nalloc(long struct) { return ExtentAlloc.create(memGetAddress(struct + ExtentHooks.ALLOC)); }
/** Unsafe version of {@link #dalloc}. */
public static ExtentDalloc ndalloc(long struct) { return ExtentDalloc.create(memGetAddress(struct + ExtentHooks.DALLOC)); }
/** Unsafe version of {@link #destroy}. */
public static ExtentDestroy ndestroy(long struct) { return ExtentDestroy.create(memGetAddress(struct + ExtentHooks.DESTROY)); }
/** Unsafe version of {@link #commit}. */
public static ExtentCommit ncommit(long struct) { return ExtentCommit.create(memGetAddress(struct + ExtentHooks.COMMIT)); }
/** Unsafe version of {@link #decommit}. */
public static ExtentDecommit ndecommit(long struct) { return ExtentDecommit.create(memGetAddress(struct + ExtentHooks.DECOMMIT)); }
/** Unsafe version of {@link #purge_lazy}. */
public static ExtentPurge npurge_lazy(long struct) { return ExtentPurge.create(memGetAddress(struct + ExtentHooks.PURGE_LAZY)); }
/** Unsafe version of {@link #purge_forced}. */
public static ExtentPurge npurge_forced(long struct) { return ExtentPurge.create(memGetAddress(struct + ExtentHooks.PURGE_FORCED)); }
/** Unsafe version of {@link #split}. */
public static ExtentSplit nsplit(long struct) { return ExtentSplit.create(memGetAddress(struct + ExtentHooks.SPLIT)); }
/** Unsafe version of {@link #merge}. */
public static ExtentMerge nmerge(long struct) { return ExtentMerge.create(memGetAddress(struct + ExtentHooks.MERGE)); }
/** Unsafe version of {@link #alloc(ExtentAllocI) alloc}. */
public static void nalloc(long struct, ExtentAllocI value) { memPutAddress(struct + ExtentHooks.ALLOC, value.address()); }
/** Unsafe version of {@link #dalloc(ExtentDallocI) dalloc}. */
public static void ndalloc(long struct, ExtentDallocI value) { memPutAddress(struct + ExtentHooks.DALLOC, memAddressSafe(value)); }
/** Unsafe version of {@link #destroy(ExtentDestroyI) destroy}. */
public static void ndestroy(long struct, ExtentDestroyI value) { memPutAddress(struct + ExtentHooks.DESTROY, memAddressSafe(value)); }
/** Unsafe version of {@link #commit(ExtentCommitI) commit}. */
public static void ncommit(long struct, ExtentCommitI value) { memPutAddress(struct + ExtentHooks.COMMIT, memAddressSafe(value)); }
/** Unsafe version of {@link #decommit(ExtentDecommitI) decommit}. */
public static void ndecommit(long struct, ExtentDecommitI value) { memPutAddress(struct + ExtentHooks.DECOMMIT, memAddressSafe(value)); }
/** Unsafe version of {@link #purge_lazy(ExtentPurgeI) purge_lazy}. */
public static void npurge_lazy(long struct, ExtentPurgeI value) { memPutAddress(struct + ExtentHooks.PURGE_LAZY, memAddressSafe(value)); }
/** Unsafe version of {@link #purge_forced(ExtentPurgeI) purge_forced}. */
public static void npurge_forced(long struct, ExtentPurgeI value) { memPutAddress(struct + ExtentHooks.PURGE_FORCED, memAddressSafe(value)); }
/** Unsafe version of {@link #split(ExtentSplitI) split}. */
public static void nsplit(long struct, ExtentSplitI value) { memPutAddress(struct + ExtentHooks.SPLIT, memAddressSafe(value)); }
/** Unsafe version of {@link #merge(ExtentMergeI) merge}. */
public static void nmerge(long struct, ExtentMergeI value) { memPutAddress(struct + ExtentHooks.MERGE, memAddressSafe(value)); }
/**
* Validates pointer members that should not be {@code NULL}.
*
* @param struct the struct to validate
*/
public static void validate(long struct) {
check(memGetAddress(struct + ExtentHooks.ALLOC));
}
/**
* Calls {@link #validate(long)} for each struct contained in the specified struct array.
*
* @param array the struct array to validate
* @param count the number of structs in {@code array}
*/
public static void validate(long array, int count) {
for (int i = 0; i < count; i++) {
validate(array + i * SIZEOF);
}
}
// -----------------------------------
/** An array of {@link ExtentHooks} structs. */
public static class Buffer extends StructBuffer implements NativeResource {
/**
* Creates a new {@link ExtentHooks.Buffer} instance backed by the specified container.
*
* Changes to the container's content will be visible to the struct buffer instance and vice versa. The two buffers' position, limit, and mark values
* will be independent. The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided
* by {@link ExtentHooks#SIZEOF}, and its mark will be undefined.
*
* The created buffer instance holds a strong reference to the container object.
*/
public Buffer(ByteBuffer container) {
super(container, container.remaining() / SIZEOF);
}
Buffer(long address, ByteBuffer container, int mark, int pos, int lim, int cap) {
super(address, container, mark, pos, lim, cap);
}
@Override
protected Buffer self() {
return this;
}
@Override
protected Buffer newBufferInstance(long address, ByteBuffer container, int mark, int pos, int lim, int cap) {
return new Buffer(address, container, mark, pos, lim, cap);
}
@Override
protected ExtentHooks newInstance(long address) {
return new ExtentHooks(address, container);
}
@Override
public int sizeof() {
return SIZEOF;
}
/** Returns the value of the {@code alloc} field. */
@NativeType("extent_alloc_t")
public ExtentAlloc alloc() { return ExtentHooks.nalloc(address()); }
/** Returns the value of the {@code dalloc} field. */
@NativeType("extent_dalloc_t")
public ExtentDalloc dalloc() { return ExtentHooks.ndalloc(address()); }
/** Returns the value of the {@code destroy} field. */
@NativeType("extent_destroy_t")
public ExtentDestroy destroy() { return ExtentHooks.ndestroy(address()); }
/** Returns the value of the {@code commit} field. */
@NativeType("extent_commit_t")
public ExtentCommit commit() { return ExtentHooks.ncommit(address()); }
/** Returns the value of the {@code decommit} field. */
@NativeType("extent_decommit_t")
public ExtentDecommit decommit() { return ExtentHooks.ndecommit(address()); }
/** Returns the value of the {@code purge_lazy} field. */
@NativeType("extent_purge_t")
public ExtentPurge purge_lazy() { return ExtentHooks.npurge_lazy(address()); }
/** Returns the value of the {@code purge_forced} field. */
@NativeType("extent_purge_t")
public ExtentPurge purge_forced() { return ExtentHooks.npurge_forced(address()); }
/** Returns the value of the {@code split} field. */
@NativeType("extent_split_t")
public ExtentSplit split() { return ExtentHooks.nsplit(address()); }
/** Returns the value of the {@code merge} field. */
@NativeType("extent_merge_t")
public ExtentMerge merge() { return ExtentHooks.nmerge(address()); }
/** Sets the specified value to the {@code alloc} field. */
public ExtentHooks.Buffer alloc(@NativeType("extent_alloc_t") ExtentAllocI value) { ExtentHooks.nalloc(address(), value); return this; }
/** Sets the specified value to the {@code dalloc} field. */
public ExtentHooks.Buffer dalloc(@NativeType("extent_dalloc_t") ExtentDallocI value) { ExtentHooks.ndalloc(address(), value); return this; }
/** Sets the specified value to the {@code destroy} field. */
public ExtentHooks.Buffer destroy(@NativeType("extent_destroy_t") ExtentDestroyI value) { ExtentHooks.ndestroy(address(), value); return this; }
/** Sets the specified value to the {@code commit} field. */
public ExtentHooks.Buffer commit(@NativeType("extent_commit_t") ExtentCommitI value) { ExtentHooks.ncommit(address(), value); return this; }
/** Sets the specified value to the {@code decommit} field. */
public ExtentHooks.Buffer decommit(@NativeType("extent_decommit_t") ExtentDecommitI value) { ExtentHooks.ndecommit(address(), value); return this; }
/** Sets the specified value to the {@code purge_lazy} field. */
public ExtentHooks.Buffer purge_lazy(@NativeType("extent_purge_t") ExtentPurgeI value) { ExtentHooks.npurge_lazy(address(), value); return this; }
/** Sets the specified value to the {@code purge_forced} field. */
public ExtentHooks.Buffer purge_forced(@NativeType("extent_purge_t") ExtentPurgeI value) { ExtentHooks.npurge_forced(address(), value); return this; }
/** Sets the specified value to the {@code split} field. */
public ExtentHooks.Buffer split(@NativeType("extent_split_t") ExtentSplitI value) { ExtentHooks.nsplit(address(), value); return this; }
/** Sets the specified value to the {@code merge} field. */
public ExtentHooks.Buffer merge(@NativeType("extent_merge_t") ExtentMergeI value) { ExtentHooks.nmerge(address(), value); return this; }
}
}