SunSPOT API V3.0


com.sun.squawk
Class Unsafe

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

public final class Unsafe
extends Object

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

The Unsafe class is primarily concerned with accessing memory ouside of the Java heap, but improper use of the Unsafe class can corrupt the Java heap (hence the name).

Only "trusted" Isolates may use the methods of this class. Calls to Any memory accessor methods by an untrusted Isolate will throw a SecurityException.

Author:
Nik Shaylor, Doug Simon, Derek White
See Also:
Isolate

Method Summary
static Address getAddress(Address base, int offset)
          Gets a pointer from memory as an Address.
static int getByte(Address base, int offset)
          Gets a signed 8 bit value from memory.
static void getBytes(Address src, int boffset, byte[] bytes, int low, int number)
          Copy from memory to byte array.
static int getChar(Address base, int offset)
          Gets an unsigned 16 bit value from memory.
static int getInt(Address base, int offset)
          Gets a signed 32 bit value from memory.
static void getInts(Address src, int boffset, int[] ints, int low, int number)
          Copy from memory to int array.
static long getLong(Address base, int offset)
          Gets a 64 bit value from memory using a 64 bit word offset.
static long getLongAtWord(Address base, int offset)
          Gets a 64 bit value from memory using a 32 bit word offset.
static void getLongs(Address src, int boffset, long[] longs, int low, int number)
          Copy from memory to long array.
static int getShort(Address base, int offset)
          Gets a signed 16 bit value from memory.
static void getShorts(Address src, int boffset, short[] shorts, int low, int number)
          Copy from memory to short array.
static int getUByte(Address base, int offset)
          Gets an unsigned 8 bit value from memory.
static UWord getUWord(Address base, int offset)
          Gets an unsigned 32 or 64 bit value from memory.
static void setAddress(Address base, int offset, Address value)
          Sets a pointer value in memory without updating the write barrier.
static void setByte(Address base, int offset, int value)
          Sets an 8 bit value in memory.
static void setBytes(Address dst, int boffset, byte[] bytes, int low, int number)
          Copy from byte array to memory.
static void setChar(Address base, int offset, int value)
          Sets an unsigned 16 bit value in memory.
static void setInt(Address base, int offset, int value)
          Sets a 32 bit value in memory.
static void setInts(Address dst, int boffset, int[] ints, int low, int number)
          Copy from int array to memory.
static void setLong(Address base, int offset, long value)
          Sets a 64 bit value in memory.
static void setLongAtWord(Address base, int offset, long value)
          Sets a 64 bit value in memory at a 32 bit word offset.
static void setLongs(Address dst, int boffset, long[] longs, int low, int number)
          Copy from long array to memory.
static void setShort(Address base, int offset, int value)
          Sets a signed 16 bit value in memory.
static void setShorts(Address dst, int boffset, short[] shorts, int low, int number)
          Copy from short array to memory.
static void setUWord(Address base, int offset, UWord value)
          Sets a UWord value in memory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAddress

public static Address getAddress(Address base,
                                 int offset)
Gets a pointer from memory as an Address.

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

getByte

public static int getByte(Address base,
                          int offset)
Gets a signed 8 bit value from memory.

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

getBytes

public static void getBytes(Address src,
                            int boffset,
                            byte[] bytes,
                            int low,
                            int number)
Copy from memory to byte array. Copy number bytes from the memory location specified by the address dst and byte offset boffset to the byte array bytes starting at position low.

Parameters:
src - the base memory address
boffset - the byte offset to add to the base memory address
bytes - the destination byte array
low - the offset in the destination array
number - the number of bytes to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the dst array

getChar

public static int getChar(Address base,
                          int offset)
Gets an unsigned 16 bit value from memory.

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

getInt

public static int getInt(Address base,
                         int offset)
Gets a signed 32 bit value from memory.

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

getInts

public static void getInts(Address src,
                           int boffset,
                           int[] ints,
                           int low,
                           int number)
Copy from memory to int array. Copy number ints from the memory location specified by the address dst and byte offset boffset to the int array ints starting at position low.

Parameters:
src - the base memory address
boffset - the byte offset to add to the base memory address
ints - the destination int array
low - the offset in the destination array
number - the number of ints to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the dst array

getLong

public static long getLong(Address base,
                           int offset)
Gets a 64 bit value from memory using a 64 bit word offset.

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

getLongAtWord

public static long getLongAtWord(Address base,
                                 int offset)
Gets a 64 bit value from memory using a 32 bit word offset.

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

getLongs

public static void getLongs(Address src,
                            int boffset,
                            long[] longs,
                            int low,
                            int number)
Copy from memory to long array. Copy number longs from the memory location specified by the address dst and byte offset boffset to the long array longs starting at position low.

Parameters:
src - the base memory address
boffset - the byte offset to add to the base memory address
longs - the destination long array
low - the offset in the destination array
number - the number of ints to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the dst array

getShort

public static int getShort(Address base,
                           int offset)
Gets a signed 16 bit value from memory.

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

getShorts

public static void getShorts(Address src,
                             int boffset,
                             short[] shorts,
                             int low,
                             int number)
Copy from memory to short array. Copy number shorts from the memory location specified by the address dst and byte offset boffset to the short array shorts starting at position low.

Parameters:
src - the base memory address
boffset - the byte offset to add to the base memory address
shorts - the destination short array
low - the offset in the destination array
number - the number of shorts to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the dst array

getUByte

public static int getUByte(Address base,
                           int offset)
Gets an unsigned 8 bit value from memory.

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

getUWord

public static UWord getUWord(Address base,
                             int offset)
Gets an unsigned 32 or 64 bit value from memory.

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

setAddress

public static void setAddress(Address base,
                              int offset,
                              Address value)
Sets a pointer value in memory without updating the write barrier. If this method is being called in a hosted environment then the corresponding bit in the oop map (if any) is also set.

Parameters:
base - the base address
offset - the offset (in UWords) from base at which to write
value - the value to write

setByte

public static void setByte(Address base,
                           int offset,
                           int value)
Sets an 8 bit value in memory.

Parameters:
base - the base address
offset - the offset (in bytes) from base at which to write
value - the value to write

setBytes

public static void setBytes(Address dst,
                            int boffset,
                            byte[] bytes,
                            int low,
                            int number)
Copy from byte array to memory. Copy number bytes from byte array bytes starting at position low.to the memory location specified by the address dst and byte offset boffset.

Parameters:
dst - the base memory address
boffset - the byte offset to add to the base memory address
bytes - the src byte array
low - the offset in the src array
number - the number of bytes to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the src array

setChar

public static void setChar(Address base,
                           int offset,
                           int value)
Sets an unsigned 16 bit value in memory.

Parameters:
base - the base address
offset - the offset (in 16 bit words) from base at which to write
value - the value to write

setInt

public static void setInt(Address base,
                          int offset,
                          int value)
Sets a 32 bit value in memory.

Parameters:
base - the base address
offset - the offset (in 32 bit words) from base at which to write
value - the value to write

setInts

public static void setInts(Address dst,
                           int boffset,
                           int[] ints,
                           int low,
                           int number)
Copy from int array to memory. Copy number int from int array ints starting at position low.to the memory location specified by the address dst and byte offset boffset.

Parameters:
dst - the base memory address
boffset - the byte offset to add to the base memory address
ints - the src int array
low - the offset in the src array
number - the number of bytes to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the src array

setLong

public static void setLong(Address base,
                           int offset,
                           long value)
Sets a 64 bit value in memory.

Parameters:
base - the base address
offset - the offset (in 64 bit words) from base at which to write
value - the value to write

setLongAtWord

public static void setLongAtWord(Address base,
                                 int offset,
                                 long value)
Sets a 64 bit value in memory at a 32 bit word offset.

Parameters:
base - the base address
offset - the offset (in 32 bit words) from base at which to write
value - the value to write

setLongs

public static void setLongs(Address dst,
                            int boffset,
                            long[] longs,
                            int low,
                            int number)
Copy from long array to memory. Copy number longs from long array longs starting at position low.to the memory location specified by the address dst and byte offset boffset.

Parameters:
dst - the base memory address
boffset - the byte offset to add to the base memory address
longs - the src long array
low - the offset in the src array
number - the number of bytes to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the src array

setShort

public static void setShort(Address base,
                            int offset,
                            int value)
Sets a signed 16 bit value in memory.

Parameters:
base - the base address
offset - the offset (in 16 bit words) from base at which to write
value - the value to write

setShorts

public static void setShorts(Address dst,
                             int boffset,
                             short[] shorts,
                             int low,
                             int number)
Copy from short array to memory. Copy number shorts from short array shorts starting at position low.to the memory location specified by the address dst and byte offset boffset.

Parameters:
dst - the base memory address
boffset - the byte offset to add to the base memory address
shorts - the src short array
low - the offset in the src array
number - the number of bytes to copy
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the src array

setUWord

public static void setUWord(Address base,
                            int offset,
                            UWord value)
Sets a UWord value in memory.

Parameters:
base - the base address
offset - the offset (in UWords) from base at which to write
value - the value to write

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.