|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jnetpcap.nio.JMemory
public abstract class JMemory
A base class for all other PEERED classes to native c structures. The class only contains the physical address of the native C structure. The class also contains a couple of convenience methods for allocating memory for the structure to be peered as well as doing cleanup and freeing up that memory when object is finalized().
This is one of the most important classes within jNetPcap library. It is responsible for most of the memory allocation and management behind the scenes of all jNetPcap native methods.
| Nested Class Summary | |
|---|---|
static class |
JMemory.Type
Used in special memory allocation. |
| Field Summary | |
|---|---|
static java.lang.String |
JNETPCAP_LIBRARY_NAME
Name of the native library that wraps around libpcap and extensions. |
static long |
MAX_DIRECT_MEMORY_DEFAULT
The default maximum value for 'nio.mx' system property, if not set. |
static JMemory.Type |
POINTER
Convenience constant that is synonym as JMemory.Type.POINTER. |
| Constructor Summary | |
|---|---|
JMemory(java.nio.ByteBuffer peer)
Instantiates a new j memory. |
|
JMemory(int size)
Pre-allocates memory for any structures the subclass may need to use. |
|
JMemory(JMemory.Type type)
No memory pre-allocation constructor. |
|
JMemory(JMemory src)
Performs a deep copy into a newly allocated memory block. |
|
| Method Summary | |
|---|---|
static long |
availableDirectMemory()
Returns how much native memory is available for allocation. |
void |
check()
Checks if this peered object is initialized. |
protected void |
cleanup()
Called to clean up and release any allocated memory. |
protected JMemoryReference |
createReference(long address,
long size)
Creates a cleanup/dispose weak reference object. |
boolean |
isInitialized()
Checks if this peered object is initialized. |
boolean |
isJMemoryBasedOwner()
Checks if physical memory pointed to by this object, is owned either by this JMemory based object or the actual owner is also JMemory based. |
boolean |
isOwner()
Checks if this object is the owner of native memory |
static long |
maxDirectMemory()
Returns the hard limit for the amount of memory native is allowed to allocate. |
protected int |
peer(java.nio.ByteBuffer peer)
Peers the src structure with this instance. |
protected int |
peer(JMemory peer)
Peers the peer structure with this instance. |
protected int |
peer(JMemory peer,
int offset,
int length)
Peers the peer structure with this instance. |
static long |
reservedDirectMemory()
Returns how much native memory has be used so far. |
void |
setSize(int size)
Changes the size of the current memory buffer. |
int |
size()
Returns the size of the memory block that this peered structure is point to. |
static long |
softDirectMemory()
Returns the soft limit for native memory allocation. |
java.lang.String |
toDebugString()
Returns a debug string about this JMemory state. |
java.lang.String |
toHexdump()
A debug method, similar to toString() which converts the contents of the memory to textual hexdump. |
java.lang.String |
toHexdump(int length,
boolean address,
boolean text,
boolean data)
A debug method, similar to toString() which converts the contents of the memory to textual hexdump. |
static long |
totalActiveAllocated()
Returns the total number of active native memory bytes currently allocated that have not been deallocated as of yet. |
static long |
totalAllocateCalls()
Returns total number of allocate calls through JMemory class. |
static long |
totalAllocated()
Returns total number of bytes allocated through JMemory class. |
static long |
totalAllocatedSegments0To255Bytes()
Returns the number of memory segments that were allocated by JMemory class in the range of 0 to 255 bytes in size. |
static long |
totalAllocatedSegments256OrAbove()
Returns the number of memory segments that were allocated by JMemory class in the range of 256 bytes or above in size. |
static long |
totalDeAllocateCalls()
Returns total number of deallocate calls through JMemory class. |
static long |
totalDeAllocated()
Returns total number of bytes deallocated through JMemory class. |
protected int |
transferFrom(byte[] buffer)
Copies contents of byte array to memory. |
protected int |
transferFrom(byte[] buffer,
int srcOffset,
int length,
int dstOffset)
Copies contents of byte array to memory. |
protected int |
transferFrom(java.nio.ByteBuffer src)
Copies data from memory from direct byte buffer to this memory. |
protected int |
transferFrom(java.nio.ByteBuffer src,
int dstOffset)
Copies data from memory from direct byte buffer to this memory. |
protected int |
transferFromDirect(java.nio.ByteBuffer src,
int dstOffset)
Copies data from memory from direct byte buffer to this memory. |
protected boolean |
transferOwnership(JMemory memory)
A special method that allows one object to transfer ownership of a memory block. |
protected int |
transferTo(byte[] buffer)
Copies data from memory to byte array. |
protected int |
transferTo(byte[] buffer,
int srcOffset,
int length,
int dstOffset)
Copies data from memory to byte array. |
int |
transferTo(java.nio.ByteBuffer dst)
Copies teh contents of this memory to buffer. |
int |
transferTo(java.nio.ByteBuffer dst,
int srcOffset,
int length)
Copies teh contents of this memory to buffer. |
int |
transferTo(JBuffer dst,
int srcOffset,
int length,
int dstOffset)
Transfers the contents of this memory to buffer. |
protected int |
transferTo(JMemory dst)
Copied the entire contents of this memory to destination memory. |
protected int |
transferTo(JMemory dst,
int srcOffset,
int length,
int dstOffset)
Copied the entire contents of this memory to destination memory. |
protected static int |
transferTo0(long address,
byte[] buffer,
int srcOffset,
int length,
int dstOffset)
Transfer to0. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String JNETPCAP_LIBRARY_NAME
public static final long MAX_DIRECT_MEMORY_DEFAULT
MAX_DIRECT_MEMORY_DEFAULT constant or the value
specified on the JVM command line using '-Xmx
public static final JMemory.Type POINTER
| Constructor Detail |
|---|
public JMemory(java.nio.ByteBuffer peer)
peer - the peerpublic JMemory(int size)
size - number of bytes to pre-allocate allocatepublic JMemory(JMemory src)
src - the srcpublic JMemory(JMemory.Type type)
type - type of memory allocation model| Method Detail |
|---|
public static long availableDirectMemory()
setMaxDirectMemorySize(long).
public static long maxDirectMemory()
This limit can be set at startup of the application using the following system properties, which are checked in the order listed below:
org.jnetsoft.nio.MaxDirectMemorySize
nio.MaxDirectMemorySize
org.jnetsoft.nio.mx
nio.mx
public static long reservedDirectMemory()
public static long softDirectMemory()
This limit can be set at startup of the application using the following system properties, which are checked in the order listed below:
org.jnetsoft.nio.SoftDirectMemorySize
nio.SoftDirectMemorySize
org.jnetsoft.nio.ms
nio.ms
public static long totalActiveAllocated()
totalAllocated() - totalDeAllocated()
public static long totalAllocateCalls()
public static long totalAllocated()
public static long totalAllocatedSegments0To255Bytes()
public static long totalAllocatedSegments256OrAbove()
public static long totalDeAllocateCalls()
public static long totalDeAllocated()
protected static int transferTo0(long address,
byte[] buffer,
int srcOffset,
int length,
int dstOffset)
address - the addressbuffer - the buffersrcOffset - the src offsetlength - the lengthdstOffset - the dst offset
public void check()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if peered object is not initialized this unchecked exception will
be thrown, otherwise it will exit silentlyprotected void cleanup()
protected JMemoryReference createReference(long address,
long size)
This method is protected and allows subclasses to provide their own cleanup code. If this method is not overriden, it will return a JMemoryReference object suitable to cleanup after this memory object.
address - native memory address to use in the disposablesize - the size
public boolean isInitialized()
public boolean isJMemoryBasedOwner()
public final boolean isOwner()
protected int peer(java.nio.ByteBuffer peer)
throws PeeringException
Further more, since we are peering with a ByteBuffer, the actual memory that is peered is between ByteBuffer's position and limit properties. Those 2 properties determine which portion of the memory that will be peered. This allows a larger ByteBuffer to be peered with different objects providing rudimentary memory allocation mechanism.
Lastly care must be taken, to ensure that the lifespans do not conflict. The memory that we are peering to must not be deallocated prior the termination of the lifespan of this object or at minimum calling
peer - The ByteBuffer whose allocated native memory we want to peer with.
The ByteByffer must be if direct buffer type which can be checked
using ByteBuffer.isDirect() call.
PeeringException - the peering exception cleanup() method to ensure that
this object no longer references memory which may have been or
become deallocated.
ByteBuffer.isDirect()protected int peer(JMemory peer)
peer - the object whose allocated native memory we want to peer with
protected int peer(JMemory peer,
int offset,
int length)
throws java.lang.IndexOutOfBoundsException
peer - object memory block to peer withoffset - offset into the memory blocklength - amount of memory to peer with
java.lang.IndexOutOfBoundsException - if the specified memory offset and length have negative or out of
bounds of peer objects address spacepublic void setSize(int size)
size - size in bytes that is smaller then existing sizepublic int size()
public java.lang.String toDebugString()
JMemory@b052fa8: size=1506, owner=nio.JMemoryPool$Block.class(size=10240/offset=4064)
public java.lang.String toHexdump()
public java.lang.String toHexdump(int length,
boolean address,
boolean text,
boolean data)
length - maximum number of bytes to dump to hex outputaddress - flag if set to true will print out address offset on every linetext - flag if set to true will print out a text characters at the end of
everylinedata - flag if set to true will print out raw HEX data on every line
protected int transferFrom(byte[] buffer)
buffer - source buffer
protected int transferFrom(byte[] buffer,
int srcOffset,
int length,
int dstOffset)
buffer - source buffersrcOffset - starting offset into the byte arraylength - number of bytes to copydstOffset - starting offset into memory buffer
protected int transferFrom(java.nio.ByteBuffer src)
src - source buffer
protected int transferFrom(java.nio.ByteBuffer src,
int dstOffset)
src - source bufferdstOffset - offset into our memory location
protected int transferFromDirect(java.nio.ByteBuffer src,
int dstOffset)
src - source bufferdstOffset - offset into our memory location
protected boolean transferOwnership(JMemory memory)
memory - memory block to transfer the ownership from
protected int transferTo(byte[] buffer)
buffer - destination buffer starting offset in byte array
protected int transferTo(byte[] buffer,
int srcOffset,
int length,
int dstOffset)
buffer - destination buffersrcOffset - starting offset in memorylength - number of bytes to copydstOffset - starting offset in byte array
public int transferTo(java.nio.ByteBuffer dst)
dst - destination buffer
public int transferTo(java.nio.ByteBuffer dst,
int srcOffset,
int length)
dst - destination buffersrcOffset - offset in sourcelength - number of bytes to copy
public int transferTo(JBuffer dst,
int srcOffset,
int length,
int dstOffset)
dst - destination buffersrcOffset - offset in sourcelength - number of bytes to copydstOffset - offset in destination buffer
protected int transferTo(JMemory dst)
dst - destination memory
protected int transferTo(JMemory dst,
int srcOffset,
int length,
int dstOffset)
dst - destination memorysrcOffset - offset in sourcelength - number of bytes to copydstOffset - offset in destination buffer
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||