|
JNodeOS v1.1.5 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.utah.janos.nodeos.pj_BufferHandle | +--edu.utah.janos.nodeos.BufferHandle
A Java wrapper around the native buffer handle object. The Java wrapper protects the NodeOS buffer handle from errant or malicious Java code.
A BufferHandle is a process's handle to a buffer. A BufferHandle object is seen by only one process--it cannot be shared between processes. However, the underlying buffer object may be visible in more than one process. The underlying buffer is never directly accessible to a process, it can only be accessed through the BufferHandle.
The "offset" and "length" associated with a buffer handle are immutable once a buffer is associated with the handle. They can thus be used to provide safe views onto subsequences of a buffer.
A process is charged for the memory occupied by all buffers reachable
from the process's BufferHandle objects. To avoid paying for a buffer
which is no longer needed, a process can explicitly reset()
a
BufferHandle object, which tells Janos that the process no longer
needs the buffer data associated with the BufferHandle.
An access to a BufferHandle after it has been recycled behaves
unpredictably: it may continue to access the old buffer, it
may access another one of the processes's buffers, or it may
raise a NullPointerException. However, such an access will never
read another process's buffer.
Currently, all access methods in BufferHandle are synchronized. This is inefficient. The virtual machine can eliminate these locks in a section of code by incrementing a per-BufferHandle reference count before the code section and decrementing the reference count after the code section (and postponing all resets until the reference count is zero). Unfortunately, this optimization cannot be expressed at the Java source level (without using synchronization).
Since a BufferHandle is visible only to one process, and a process can only run on one processor at a time, simple preemption points can eliminate the per-access synchronization.
Buffers are mutable.
This class is not final so that you can subclass it an add things like buffer aggregates on top. XXX need to be sure NATIVE_BUFFERHANDLE methods are not exposed...
XXX Perhaps BufferHandle shouldn't be doing any run-time checks? That should be the responsibility of the EE, right?
XXX WARNING DO NOT ADD ANY INSTANCE FIELDS TO THIS CLASS WITHOUT CHANGING THE GLUE CODE IN moabthread.c. THAT CODE ASSUMES THAT "owner" IS THE FIRST AND ONLY FIELD IN THIS CLASS. THAT IS A STRONG ASSUMPTION TO MAKE. ALSO ASSUMES THE VALUE '2' IS FOR THE USER_OWNER.
Method Summary | |
void |
cloneHandle(BufferHandle src)
Set this BufferHandle's buffer to point to src's buffer. |
void |
cloneHandle(BufferHandle src,
int fromOffset,
int fromLength)
Set this BufferHandle's buffer to point to some sub-sequence of src's buffer. |
boolean |
compareBytes(int offset,
byte[] bytes)
Compare the given sequence of bytes to a sequence in this buffer. |
short |
computeChecksum(int offset,
int count)
Compute an IP style checksum over the given segment of the buffer. |
static BufferHandle |
create()
Construct a new BufferHandle. |
static BufferHandle |
create(BufferHandle other)
Construct a new BufferHandle that points to the same data as the given handle. |
static BufferHandle |
create(BufferHandle other,
int offset,
int length)
Construct a new BufferHandle that points to the same data as the given handle. |
static BufferHandle |
create(int offset,
int length)
Constructs a new buffer handle with the given offset and "length". |
byte |
getByte(int index)
|
void |
getBytes(byte[] dest,
int destPosition)
|
void |
getBytes(int srcPosition,
byte[] dest,
int destPosition,
int destLength)
|
int |
getInt(int index)
|
void |
getInts(int srcPosition,
int[] dest,
int destPosition,
int destLength)
|
int |
getLength()
Get the valid data length of the underlying NodeOS pbuf. |
short |
getShort(int index)
|
void |
newBuffer(int offset,
int length)
Point this BufferHandle to a new buffer. |
void |
reset()
Release the buffer held by this BufferHandle. |
void |
setByte(int index,
byte val)
|
void |
setBytes(int destPosition,
byte[] src,
int srcPosition,
int srcLength)
|
void |
setInt(int index,
int val)
|
void |
setInts(int destPosition,
int[] src,
int srcPosition,
int srcLength)
|
void |
setShort(int index,
short val)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Method Detail |
public static BufferHandle create()
public static BufferHandle create(int offset, int length)
public static BufferHandle create(BufferHandle other)
bh
- the BufferHandle to copy fromcloneHandle(BufferHandle)
public static BufferHandle create(BufferHandle other, int offset, int length)
other
- the buffer handle to "copy" from (or null).offset
- the new offset this bufferhandle will have.length
- the new length this bufferhandle will have.cloneHandle(BufferHandle)
public final void reset()
public final void newBuffer(int offset, int length) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.NegativeArraySizeException
public final void cloneHandle(BufferHandle src, int fromOffset, int fromLength) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.NegativeArraySizeException
public final void cloneHandle(BufferHandle src)
public final int getLength()
public final byte getByte(int index) throws java.lang.ArrayIndexOutOfBoundsException
public final void setByte(int index, byte val) throws java.lang.ArrayIndexOutOfBoundsException
public final short getShort(int index) throws java.lang.ArrayIndexOutOfBoundsException
public final void setShort(int index, short val) throws java.lang.ArrayIndexOutOfBoundsException
public final int getInt(int index) throws java.lang.ArrayIndexOutOfBoundsException
public final void setInt(int index, int val) throws java.lang.ArrayIndexOutOfBoundsException
public final void getBytes(byte[] dest, int destPosition)
public final void getBytes(int srcPosition, byte[] dest, int destPosition, int destLength) throws java.lang.ArrayIndexOutOfBoundsException
public final void setBytes(int destPosition, byte[] src, int srcPosition, int srcLength) throws java.lang.ArrayIndexOutOfBoundsException
public final void getInts(int srcPosition, int[] dest, int destPosition, int destLength) throws java.lang.ArrayIndexOutOfBoundsException
public final void setInts(int destPosition, int[] src, int srcPosition, int srcLength) throws java.lang.ArrayIndexOutOfBoundsException
public final short computeChecksum(int offset, int count)
offset
- Offset into the buffer to start computing the checksumcount
- The number of bytes the checksum should cover.public final boolean compareBytes(int offset, byte[] bytes) throws java.lang.ArrayIndexOutOfBoundsException
XXX a more generic version that allows sub-sequences of 'bytes' might be handy.
offset
- Offset into the buffer to start comparisonbytes
- The byte sequence to compare with.public java.lang.String toString()
|
JNodeOS v1.1.5 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |