SunSPOT API V3.0


com.sun.squawk
Class Offset

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

public final class Offset
extends Object

The offset type is used by the runtime system and collector to denote the directed distance between two machine addresses. It is used instead of 'int' or 'Object' for coding clarity, machine-portability (it can map to 32 bit and 64 bit integral types) and access to unsigned operations (Java does not have unsigned int types).

This class is known specially by the translator as a Modifier#SQUAWKPRIMITIVE and programming with it requires adhering to the restrictions implied by this attribute.

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.

This mechanism was largely inspired by the VM_Address class in the Jikes RVM.

Author:
Doug Simon

Method Summary
 Offset add(int delta)
          Adds a value to this offset and return the resulting offset.
 Offset bytesToWords()
          Scales this offset which currently expresses an offset in bytes to express the same offset in words.
 boolean eq(Offset offset2)
          Determines if this offset is equal to a given offset.
static Offset fromPrimitive(int value)
          Casts an offset expressed as the appropriate Java primitive type for the platform (i.e. int or long) into a value of type Offset.
 boolean ge(Offset offset2)
          Determines if this offset is greater than or equal to a given offset.
 boolean gt(Offset offset2)
          Determines if this offset is greater than a given offset.
 boolean isZero()
          Determines if this offset is 0.
 boolean le(Offset offset2)
          Determines if this offset is less than or equal to a given offset.
 boolean lt(Offset offset2)
          Determines if this offset is less than a given offset.
 boolean ne(Offset offset2)
          Determines if this offset is not equal to a given offset.
 Offset sub(int delta)
          Subtracts a value from this offset and return the resulting offset.
 int toInt()
          Casts a value of type Offset into an int.
 int toPrimitive()
          Casts a value of type Offset into the appropriate Java primitive type for the platform (i.e. int or long).
 UWord toUWord()
          Casts a value of type Offset into a UWord.
 Offset wordsToBytes()
          Scales this offset which currently expresses an offset in words to express the same offset in bytes.
static Offset zero()
          Gets the canonical Offset representation of null.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

add

public Offset add(int delta)
Adds a value to this offset and return the resulting offset.

Parameters:
delta - the signed value to add
Returns:
the result of adding delta to this offset

bytesToWords

public Offset bytesToWords()
Scales this offset which currently expresses an offset in bytes to express the same offset in words. That is, the value of this offset is divided by the number of bytes in a machine word. This method should only be called for offsets which are guaranteed to be a muliple of the number of bytes in a machine word.

Returns:
the scaled down offset

eq

public boolean eq(Offset offset2)
Determines if this offset is equal to a given offset.

Parameters:
offset2 - the offset to compare this offset against
Returns:
true if this offset is equal to offset2

fromPrimitive

public static Offset fromPrimitive(int value)
Casts an offset expressed as the appropriate Java primitive type for the platform (i.e. int or long) into a value of type Offset.

Parameters:
value - an offset expressed as an int or long
Returns:
the canonical Offset instance for offset

ge

public boolean ge(Offset offset2)
Determines if this offset is greater than or equal to a given offset.

Parameters:
offset2 - the offset to compare this offset against
Returns:
true if this offset is greater than or equal to offset2

gt

public boolean gt(Offset offset2)
Determines if this offset is greater than a given offset.

Parameters:
offset2 - the offset to compare this offset against
Returns:
true if this offset is greater than offset2

isZero

public boolean isZero()
Determines if this offset is 0.

Returns:
true if this offset is 0.

le

public boolean le(Offset offset2)
Determines if this offset is less than or equal to a given offset.

Parameters:
offset2 - the offset to compare this offset against
Returns:
true if this offset is less than or equal to offset2

lt

public boolean lt(Offset offset2)
Determines if this offset is less than a given offset.

Parameters:
offset2 - the offset to compare this offset against
Returns:
true if this offset is less than or equals to offset2

ne

public boolean ne(Offset offset2)
Determines if this offset is not equal to a given offset.

Parameters:
offset2 - the offset to compare this offset against
Returns:
true if this offset is not equal to offset2

sub

public Offset sub(int delta)
Subtracts a value from this offset and return the resulting offset.

Parameters:
delta - the signed value to subract
Returns:
the result of subtracting delta from this offset

toInt

public int toInt()
Casts a value of type Offset into an int. This will cause a fatal error if this offset value cannot be expressed as a signed 32 bit Java int without changing its sign or truncating its magnitude.

Returns:
this Offset value as an int

toPrimitive

public int toPrimitive()
Casts a value of type Offset into the appropriate Java primitive type for the platform (i.e. int or long). This will cause a fatal error if this cast cannot occur without changing this offset's sign or truncating its magnitude.

Returns:
this Offset value as an int or long

toUWord

public UWord toUWord()
Casts a value of type Offset into a UWord.

Returns:
this Offset value as a UWord

wordsToBytes

public Offset wordsToBytes()
Scales this offset which currently expresses an offset in words to express the same offset in bytes. That is, the value of this offset is multiplied by the number of bytes in a machine word.

Returns:
the scaled up offset

zero

public static Offset zero()
Gets the canonical Offset representation of null.

Returns:
the canonical Offset representation of null

SunSPOT API V3.0


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