|
|||||||||
| 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 |
| Constructor Summary | |
|---|---|
JMemory(java.nio.ByteBuffer peer)
|
|
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 | |
|---|---|
void |
check()
Checks if this peered object is initialized. |
protected void |
cleanup()
Called to clean up and release any allocated memory. |
protected void |
finalize()
Default finalizer which checks if there is any memory to free up. |
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()
|
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. |
protected void |
setSize(int size)
Changes the size of this memory block. |
int |
size()
Returns the size of the memory block that this peered structure is point to. |
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 |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String JNETPCAP_LIBRARY_NAME
| Constructor Detail |
|---|
public JMemory(java.nio.ByteBuffer peer)
peer - public JMemory(int size)
size - number of bytes to pre-allocate allocatepublic JMemory(JMemory src)
src - public JMemory(JMemory.Type type)
| Method Detail |
|---|
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()
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 void finalize()
finalize in class java.lang.Objectpublic boolean isInitialized()
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
cleanup() method to ensure that this object no longer references
memory which may have been or become deallocated.
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.
PeeringExceptionByteBuffer.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 spaceprotected void setSize(int size)
size - length in bytes for this memory bufferpublic int size()
public java.lang.String toHexdump()
public java.lang.String toDebugString()
JMemory@b052fa8: size=1506, owner=nio.JMemoryPool$Block.class(size=10240/offset=4064)
public boolean isJMemoryBasedOwner()
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 | ||||||||