"

2013 FRC Java API

"

com.sun.squawk
Class NativeUnsafe

java.lang.Object
  extended by com.sun.squawk.NativeUnsafe

public final class NativeUnsafe
extends Object

A collection of methods for performing peek and poke operations on memory addresses.

Only the public methods of this class which do not override any of the methods in java.lang.Object will be available in a non-hosted environment. The translator replaces any calls to these methods to native method calls.


Field Summary
static int NATIVE_TASK_ARGS_OFFSET
           
static int NATIVE_TASK_EVENTID_OFFSET
           
static int NATIVE_TASK_LOW_RESULT_OFFSET
           
static int NATIVE_TASK_NT_ERRNO_RESULT_OFFSET
           
static int NATIVE_TASK_RESULT_OFFSET
           
 
Method Summary
static int call0(Address fptr)
          Call a function pointer with no arguments
static int call1(Address fptr, int i1)
          Call a function pointer with one arguments
static int call10(Address fptr, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i19)
          Call a function pointer with 10 arguments
static int call2(Address fptr, int i1, int i2)
          Call a function pointer with two arguments
static int call3(Address fptr, int i1, int i2, int i3)
          Call a function pointer with three arguments
static int call4(Address fptr, int i1, int i2, int i3, int i4)
          Call a function pointer with four arguments
static int call5(Address fptr, int i1, int i2, int i3, int i4, int i5)
          Call a function pointer with five arguments
static int call6(Address fptr, int i1, int i2, int i3, int i4, int i5, int i6)
          Call a function pointer with six arguments
static int call7(Address fptr, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
          Call a function pointer with seven arguments
static int call8(Address fptr, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8)
          Call a function pointer with eight arguments
static int call9(Address fptr, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9)
          Call a function pointer with nine arguments
static int cancelTaskExecutor(Address taskExecutor)
           
static char charAt(String str, int index)
          Gets character from a string.
static void clearObject(Object base, int offset)
          Clears a pointer value in memory.
static void copyMemory(byte[] buffer, int memoryOffset, int bufferOffset, int length)
          Copies a range of memory into a buffer.
static void copyTypes(Address src, Address dst, int length)
          Block copies the types recorded for a range of memory to another range of memory.
static Address createTaskExecutor(Address name, int priority, int stacksize)
           
static int deleteNativeTask(Address ntask)
           
static int deleteTaskExecutor(Address taskExecutor)
           
static void free(Address ptr)
           
static Address getAddress(Object base, int offset)
           
static int getAsByte(Object base, int offset)
          Gets a signed 8 bit value from memory ignoring any recorded type of the value at the designated location.
static int getAsInt(Object base, int offset)
          Gets a signed 32 bit value from memory ignoring any recorded type of the value at the designated location.
static int getAsShort(Object base, int offset)
          Gets a signed 16 bit value from memory ignoring any recorded type of the value at the designated location.
static UWord getAsUWord(Object base, int offset)
          Gets a UWord value from memory ignoring any recorded type of the value at the designated location.
static int getByte(Object base, int offset)
           
static int getChar(Object base, int offset)
           
static int getInt(Object base, int offset)
           
static long getLong(Object base, int offset)
           
static long getLongAtWord(Object base, int offset)
           
static int getNativeTaskErrno(Address ntask)
           
static int getNativeTaskEventID(Address ntask)
           
static int getNativeTaskResult(Address ntask)
           
static Object getObject(Object base, int offset)
           
static int getShort(Object base, int offset)
           
static byte getType(Address ea)
          Gets the type of a value at a given address.
static int getUByte(Object base, int offset)
           
static int getUnalignedInt(Address base, int boffset)
          Gets the int at the given byte offset in the memory, starting from base.
static long getUnalignedLong(Address base, int boffset)
          Gets the long at the given byte offset in the memory, starting from base.
static int getUnalignedShort(Address base, int boffset)
          Gets the short at the given byte offset in the memory, starting from base.
static UWord getUWord(Object base, int offset)
           
static void hostedInit()
          Do this little dance to avoid initializing static variables only used in a hosted environment.
static void initialize(byte[] buffer, BitSet oopMap, boolean append)
          Initialize or appends to the contents of memory.
static Address malloc(UWord size)
          Allocate a block of memory outside of the Java heap.
static Address runBlockingFunctionOn(Address taskExecutor, Address fptr, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10)
           
static void setAddress(Object base, int offset, Object value)
           
static void setArrayTypes(Address ea, byte componentType, int componentSize, int length)
          Sets the type of each value in an array.
static void setByte(Object base, int offset, int value)
           
static void setChar(Object base, int offset, int value)
           
static void setInt(Object base, int offset, int value)
           
static void setLong(Object base, int offset, long value)
           
static void setLongAtWord(Object base, int offset, long value)
           
static void setMemorySize(int newSize)
          Sets the size of used/initialized memory.
static void setObject(Object base, int offset, Object value)
           
static void setShort(Object base, int offset, int value)
           
static void setType(Address ea, byte type, int size)
          Sets the type of a value at a given address.
static void setUnalignedInt(Address base, int boffset, int value)
          Gets the int at the given byte offset in the memory, starting from base.
static void setUnalignedLong(Address base, int boffset, long value)
          Gets the long at the given byte offset in the memory, starting from base.
static void setUnalignedShort(Address base, int boffset, int value)
          Sets the short at the given byte offset in the memory, starting from base.
static void setUWord(Object base, int offset, UWord value)
           
static void swap(Address address, int dataSize)
          Swaps the endianess of a value.
static void swap2(Address address)
          Swaps the endianess of a 2 byte value.
static void swap4(Address address)
          Swaps the endianess of a 4 byte value.
static void swap8(Address address)
          Swaps the endianess of a 8 byte value.
static int waitForBlockingFunction(Address ntask)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NATIVE_TASK_EVENTID_OFFSET

public static final int NATIVE_TASK_EVENTID_OFFSET
See Also:
Constant Field Values

NATIVE_TASK_RESULT_OFFSET

public static final int NATIVE_TASK_RESULT_OFFSET
See Also:
Constant Field Values

NATIVE_TASK_LOW_RESULT_OFFSET

public static final int NATIVE_TASK_LOW_RESULT_OFFSET
See Also:
Constant Field Values

NATIVE_TASK_NT_ERRNO_RESULT_OFFSET

public static final int NATIVE_TASK_NT_ERRNO_RESULT_OFFSET
See Also:
Constant Field Values

NATIVE_TASK_ARGS_OFFSET

public static final int NATIVE_TASK_ARGS_OFFSET
See Also:
Constant Field Values
Method Detail

setByte

public static void setByte(Object base,
                           int offset,
                           int value)
                    throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setByte(com.sun.squawk.Address, int, int)

setShort

public static void setShort(Object base,
                            int offset,
                            int value)
                     throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setShort(com.sun.squawk.Address, int, int)

setChar

public static void setChar(Object base,
                           int offset,
                           int value)
                    throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setChar(com.sun.squawk.Address, int, int)

setInt

public static void setInt(Object base,
                          int offset,
                          int value)
                   throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setInt(com.sun.squawk.Address, int, int)

setUWord

public static void setUWord(Object base,
                            int offset,
                            UWord value)
                     throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setUWord(com.sun.squawk.Address, int, com.sun.squawk.UWord)

setLong

public static void setLong(Object base,
                           int offset,
                           long value)
                    throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setLong(com.sun.squawk.Address, int, long)

setLongAtWord

public static void setLongAtWord(Object base,
                                 int offset,
                                 long value)
                          throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setLongAtWord(com.sun.squawk.Address, int, long)

setAddress

public static void setAddress(Object base,
                              int offset,
                              Object value)
                       throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.setAddress(com.sun.squawk.Address, int, com.sun.squawk.Address)

setObject

public static void setObject(Object base,
                             int offset,
                             Object value)
                      throws NativePragma
Throws:
NativePragma
See Also:
Unsafe#setObject

setType

public static void setType(Address ea,
                           byte type,
                           int size)
                    throws NativePragma
Sets the type of a value at a given address. This operation is a nop when VM.usingTypeMap() returns false.

Parameters:
ea - the address of the value
type - the type of the value
size - the size (in bytes) of the value
Throws:
NativePragma

setArrayTypes

public static void setArrayTypes(Address ea,
                                 byte componentType,
                                 int componentSize,
                                 int length)
                          throws NativePragma
Sets the type of each value in an array. This operation is a nop when VM.usingTypeMap() returns false.

Parameters:
ea - the address of an array
componentType - the component type of the array
componentSize - the size (in bytes) of componentType
length - the length of the array
Throws:
NativePragma

getType

public static byte getType(Address ea)
                    throws NativePragma
Gets the type of a value at a given address. This operation is a nop when VM.usingTypeMap() returns false.

Parameters:
ea - the address to query
Returns:
the type of the value at ea
Throws:
NativePragma

copyTypes

public static void copyTypes(Address src,
                             Address dst,
                             int length)
                      throws NativePragma
Block copies the types recorded for a range of memory to another range of memory.

Parameters:
src - the start address of the source range
dst - the start address of the destination range
length - the length (in bytes) of the range
Throws:
NativePragma

getByte

public static int getByte(Object base,
                          int offset)
                   throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getByte(com.sun.squawk.Address, int)

getUByte

public static int getUByte(Object base,
                           int offset)
See Also:
Unsafe.getUByte(com.sun.squawk.Address, int)

getShort

public static int getShort(Object base,
                           int offset)
                    throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getShort(com.sun.squawk.Address, int)

getChar

public static int getChar(Object base,
                          int offset)
                   throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getChar(com.sun.squawk.Address, int)

getInt

public static int getInt(Object base,
                         int offset)
                  throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getInt(com.sun.squawk.Address, int)

getUWord

public static UWord getUWord(Object base,
                             int offset)
                      throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getUWord(com.sun.squawk.Address, int)

getLong

public static long getLong(Object base,
                           int offset)
                    throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getLong(com.sun.squawk.Address, int)

getLongAtWord

public static long getLongAtWord(Object base,
                                 int offset)
                          throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getLongAtWord(com.sun.squawk.Address, int)

getObject

public static Object getObject(Object base,
                               int offset)
                        throws NativePragma
Throws:
NativePragma
See Also:
Unsafe#getObject

getAddress

public static Address getAddress(Object base,
                                 int offset)
                          throws NativePragma
Throws:
NativePragma
See Also:
Unsafe.getAddress(com.sun.squawk.Address, int)

getAsUWord

public static UWord getAsUWord(Object base,
                               int offset)
                        throws NativePragma
Gets a UWord value from memory ignoring any recorded type of the value at the designated location. This operation is equivalent to getUWord(Object, int) when runtime type checking is disabled.

Parameters:
base - the base address
offset - the offset (in words) from base from which to load
Returns:
the value
Throws:
NativePragma

getAsByte

public static int getAsByte(Object base,
                            int offset)
                     throws NativePragma
Gets a signed 8 bit value from memory ignoring any recorded type of the value at the designated location. This operation is equivalent to getByte(Object, int) when runtime type checking is disabled.

Parameters:
base - the base address
offset - the offset (in 8 bit words) from base from which to load
Returns:
the value
Throws:
NativePragma

getAsShort

public static int getAsShort(Object base,
                             int offset)
                      throws NativePragma
Gets a signed 16 bit value from memory ignoring any recorded type of the value at the designated location. This operation is equivalent to getShort(Object, int) when runtime type checking is disabled.

Parameters:
base - the base address
offset - the offset (in 16 bit words) from base from which to load
Returns:
the value
Throws:
NativePragma

getAsInt

public static int getAsInt(Object base,
                           int offset)
                    throws NativePragma
Gets a signed 32 bit value from memory ignoring any recorded type of the value at the designated location. This operation is equivalent to getInt(Object, int) when runtime type checking is disabled.

Parameters:
base - the base address
offset - the offset (in 32 bit words) from base from which to load
Returns:
the value
Throws:
NativePragma

charAt

public static char charAt(String str,
                          int index)
                   throws NativePragma
Gets character from a string.

Parameters:
str - the string
index - the index to the character
Returns:
the value
Throws:
NativePragma

call0

public static int call0(Address fptr)
                 throws NativePragma
Call a function pointer with no arguments

Throws:
NativePragma

call1

public static int call1(Address fptr,
                        int i1)
                 throws NativePragma
Call a function pointer with one arguments

Throws:
NativePragma

call2

public static int call2(Address fptr,
                        int i1,
                        int i2)
                 throws NativePragma
Call a function pointer with two arguments

Throws:
NativePragma

call3

public static int call3(Address fptr,
                        int i1,
                        int i2,
                        int i3)
                 throws NativePragma
Call a function pointer with three arguments

Throws:
NativePragma

call4

public static int call4(Address fptr,
                        int i1,
                        int i2,
                        int i3,
                        int i4)
                 throws NativePragma
Call a function pointer with four arguments

Throws:
NativePragma

call5

public static int call5(Address fptr,
                        int i1,
                        int i2,
                        int i3,
                        int i4,
                        int i5)
                 throws NativePragma
Call a function pointer with five arguments

Throws:
NativePragma

call6

public static int call6(Address fptr,
                        int i1,
                        int i2,
                        int i3,
                        int i4,
                        int i5,
                        int i6)
                 throws NativePragma
Call a function pointer with six arguments

Throws:
NativePragma

call7

public static int call7(Address fptr,
                        int i1,
                        int i2,
                        int i3,
                        int i4,
                        int i5,
                        int i6,
                        int i7)
                 throws NativePragma
Call a function pointer with seven arguments

Throws:
NativePragma

call8

public static int call8(Address fptr,
                        int i1,
                        int i2,
                        int i3,
                        int i4,
                        int i5,
                        int i6,
                        int i7,
                        int i8)
                 throws NativePragma
Call a function pointer with eight arguments

Throws:
NativePragma

call9

public static int call9(Address fptr,
                        int i1,
                        int i2,
                        int i3,
                        int i4,
                        int i5,
                        int i6,
                        int i7,
                        int i8,
                        int i9)
                 throws NativePragma
Call a function pointer with nine arguments

Throws:
NativePragma

call10

public static int call10(Address fptr,
                         int i1,
                         int i2,
                         int i3,
                         int i4,
                         int i5,
                         int i6,
                         int i7,
                         int i8,
                         int i9,
                         int i19)
                  throws NativePragma
Call a function pointer with 10 arguments

Throws:
NativePragma

getNativeTaskEventID

public static int getNativeTaskEventID(Address ntask)

getNativeTaskResult

public static int getNativeTaskResult(Address ntask)

getNativeTaskErrno

public static int getNativeTaskErrno(Address ntask)

createTaskExecutor

public static Address createTaskExecutor(Address name,
                                         int priority,
                                         int stacksize)
                                  throws NativePragma
Throws:
NativePragma

cancelTaskExecutor

public static int cancelTaskExecutor(Address taskExecutor)
                              throws NativePragma
Throws:
NativePragma

deleteTaskExecutor

public static int deleteTaskExecutor(Address taskExecutor)
                              throws NativePragma
Throws:
NativePragma

runBlockingFunctionOn

public static Address runBlockingFunctionOn(Address taskExecutor,
                                            Address fptr,
                                            int arg1,
                                            int arg2,
                                            int arg3,
                                            int arg4,
                                            int arg5,
                                            int arg6,
                                            int arg7,
                                            int arg8,
                                            int arg9,
                                            int arg10)
                                     throws NativePragma
Throws:
NativePragma

deleteNativeTask

public static int deleteNativeTask(Address ntask)
                            throws NativePragma
Throws:
NativePragma

waitForBlockingFunction

public static int waitForBlockingFunction(Address ntask)

malloc

public static Address malloc(UWord size)
                      throws NativePragma
Allocate a block of memory outside of the Java heap.

Memory may be be very restricted on some platforms. Callers shouldn't rely on this memory unless they have a good understanding of the memory resvered for malloc on a particular platform.

Parameters:
size -
Returns:
address of memory block, or zero
Throws:
NativePragma

free

public static void free(Address ptr)
                 throws NativePragma
Throws:
NativePragma

getUnalignedShort

public static int getUnalignedShort(Address base,
                                    int boffset)
                             throws NativePragma
Gets the short at the given byte offset in the memory, starting from base. If the short is aligned on a "natural" boundary it is always loaded from memory in a single atomic operation. If it is not on a natural boundary it may not be loaded atomically, and the number and order of the load operations is unspecified.

Parameters:
base - address of to region of memory
boffset - The offset in bytes from base to the short to be loaded
Returns:
The integer from raw memory.
Throws:
NativePragma

getUnalignedInt

public static int getUnalignedInt(Address base,
                                  int boffset)
                           throws NativePragma
Gets the int at the given byte offset in the memory, starting from base. If the integer is aligned on a "natural" boundary it is always loaded from memory in a single atomic operation. If it is not on a natural boundary it may not be loaded atomically, and the number and order of the load operations is unspecified.

Parameters:
base - address of to region of memory
boffset - The offset in bytes from base to the int to be loaded
Returns:
The integer from raw memory.
Throws:
NativePragma

getUnalignedLong

public static long getUnalignedLong(Address base,
                                    int boffset)
                             throws NativePragma
Gets the long at the given byte offset in the memory, starting from base. If the long is aligned on a "natural" boundary it is always loaded from memory in a single atomic operation. If it is not on a natural boundary it may not be loaded atomically, and the number and order of the load operations is unspecified.

Parameters:
base - address of to region of memory
boffset - The offset in bytes from base to the long to be loaded
Returns:
The integer from raw memory.
Throws:
NativePragma

setUnalignedShort

public static void setUnalignedShort(Address base,
                                     int boffset,
                                     int value)
                              throws NativePragma
Sets the short at the given byte offset in the memory, starting from base. If the short is aligned on a "natural" boundary it is always stored to memory in a single atomic operation. If it is not on a natural boundary it may not be stored atomically, and the number and order of the store operations is unspecified.

Parameters:
base - address of to region of memory
boffset - The offset in bytes from base to the location to be stored
value -
Throws:
NativePragma

setUnalignedInt

public static void setUnalignedInt(Address base,
                                   int boffset,
                                   int value)
                            throws NativePragma
Gets the int at the given byte offset in the memory, starting from base. If the integer is aligned on a "natural" boundary it is always stored to memory in a single atomic operation. If it is not on a natural boundary it may not be stored atomically, and the number and order of the store operations is unspecified.

Parameters:
base - address of to region of memory
boffset - The offset in bytes from base to the location to be stored
value -
Throws:
NativePragma

setUnalignedLong

public static void setUnalignedLong(Address base,
                                    int boffset,
                                    long value)
                             throws NativePragma
Gets the long at the given byte offset in the memory, starting from base. If the long is aligned on a "natural" boundary it is always stored to memory in a single atomic operation. If it is not on a natural boundary it may not be stored atomically, and the number and order of the store operations is unspecified.

Parameters:
base - address of to region of memory
boffset - The offset in bytes from base to the location to be stored
value -
Throws:
NativePragma

swap

public static void swap(Address address,
                        int dataSize)
                 throws NativePragma
Swaps the endianess of a value.

Parameters:
address - the address of the value
dataSize - the size (in bytes) of the value
Throws:
NativePragma

swap2

public static void swap2(Address address)
                  throws NativePragma
Swaps the endianess of a 2 byte value.

Parameters:
address - the address of the value
Throws:
NativePragma

swap4

public static void swap4(Address address)
                  throws NativePragma
Swaps the endianess of a 4 byte value.

Parameters:
address - the address of the value
Throws:
NativePragma

swap8

public static void swap8(Address address)
                  throws NativePragma
Swaps the endianess of a 8 byte value.

Parameters:
address - the address of the value
Throws:
NativePragma

clearObject

public static void clearObject(Object base,
                               int offset)
                        throws HostedPragma
Clears a pointer value in memory.

Parameters:
base - the base address
offset - the offset (in UWords) from base of the pointer to clear
Throws:
HostedPragma

hostedInit

public static void hostedInit()
                       throws HostedPragma
Do this little dance to avoid initializing static variables only used in a hosted environment. Also used for testing.

Throws:
HostedPragma

initialize

public static void initialize(byte[] buffer,
                              BitSet oopMap,
                              boolean append)
                       throws HostedPragma
Initialize or appends to the contents of memory.

Parameters:
buffer - a buffer containing a serialized object memory relative to 0
oopMap - an oop map specifying where the pointers in the serialized object memory are
append - specifies if the memory is being appended to
Throws:
HostedPragma

setMemorySize

public static void setMemorySize(int newSize)
                          throws HostedPragma
Sets the size of used/initialized memory. If the new size is less than the current size, all memory locations at index newSize and greater are zeroed.

Parameters:
newSize - the new size of memory
Throws:
HostedPragma

copyMemory

public static void copyMemory(byte[] buffer,
                              int memoryOffset,
                              int bufferOffset,
                              int length)
                       throws HostedPragma
Copies a range of memory into a buffer.

Parameters:
buffer - the buffer to copy into
memoryOffset - the offset in memory at which to start copying from
bufferOffset - the offset in buffer at which to start copying to
length - the number of bytes to copy
Throws:
HostedPragma

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"