Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.squawk
Class Offset

    java.lang.Object
      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 `SQUAWKPRIMITIVE` and programming with it requires adhering to the restrictions implied by this attribute. Some of these constraints are imposed to keep the job of the translator simple. All of these constraints are currently enforced by the translator. The constraints are:

- A local variable slot allocated by javac for a Squawk primitive variable must never be used for a value of any other type (including a different Squawk primitive type). This is required as the translator cannot currently de-multiplex reference type slots into disjoint typed slots. This restriction on javac is achieved by declaring all Squawk primitive local variables at the outer most scope (as javac using lexical based scoping for register allocation liveness).
- A Squawk primitive value of type T cannot be assigned to or compared with values of any other type (including `null`) than T.
- A Squawk primitive value of type T cannot be passed as a parameter values of any other type than T. For example, you cannot call T.toString(), or String.valueOf(T). The methods of the classes NativeUnsafe and GC have a special permission to allow Squawk primitive values to passed in place of parameters of type Object.

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.

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.
`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.
`int` | `hashCode()` Gets a hashcode value for this offset which is just the value itself.
`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.
`String` | `toString()` Gets a string representation of this offset.
`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, notify, notifyAll, wait, wait, wait`

Method Detail

### fromPrimitive

    public static Offset fromPrimitive(int value)
                                throws NativePragma

  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`
  Throws:
    `NativePragma`

### toPrimitive

    public int toPrimitive()
                    throws NativePragma

  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
  Throws:
    `NativePragma`

### toInt

    public int toInt()
              throws NativePragma

  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
  Throws:
    `NativePragma`

### toUWord

    public UWord toUWord()
                  throws NativePragma

  Casts a value of type Offset into a UWord.

  Returns:
    this Offset value as a UWord
  Throws:
    `NativePragma`

### zero

    public static Offset zero()
                       throws NativePragma

  Gets the canonical Offset representation of `null`.

  Returns:
    the canonical Offset representation of `null`
  Throws:
    `NativePragma`

### add

    public Offset add(int delta)
               throws NativePragma

  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
  Throws:
    `NativePragma`

### sub

    public Offset sub(int delta)
               throws NativePragma

  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
  Throws:
    `NativePragma`

### wordsToBytes

    public Offset wordsToBytes()
                        throws NativePragma

  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
  Throws:
    `NativePragma`

### bytesToWords

    public Offset bytesToWords()
                        throws NativePragma

  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
  Throws:
    `NativePragma`

### isZero

    public boolean isZero()
                   throws NativePragma

  Determines if this offset is 0.

  Returns:
    true if this offset is 0.
  Throws:
    `NativePragma`

### eq

    public boolean eq(Offset offset2)
               throws NativePragma

  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`
  Throws:
    `NativePragma`

### ne

    public boolean ne(Offset offset2)
               throws NativePragma

  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`
  Throws:
    `NativePragma`

### lt

    public boolean lt(Offset offset2)
               throws NativePragma

  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`
  Throws:
    `NativePragma`

### le

    public boolean le(Offset offset2)
               throws NativePragma

  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`
  Throws:
    `NativePragma`

### gt

    public boolean gt(Offset offset2)
               throws NativePragma

  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`
  Throws:
    `NativePragma`

### ge

    public boolean ge(Offset offset2)
               throws NativePragma

  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`
  Throws:
    `NativePragma`

### hashCode

    public int hashCode()
                 throws HostedPragma

  Gets a hashcode value for this offset which is just the value itself.

  Overrides:
    `hashCode` in class `Object`
  Returns:
    the value of this offset
  Throws:
    `HostedPragma`
  See Also:
    `Object.equals(java.lang.Object)`, `Hashtable`

### toString

    public String toString()
                    throws HostedPragma

  Gets a string representation of this offset.

  Overrides:
    `toString` in class `Object`
  Returns:
    String
  Throws:
    `HostedPragma`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

"
For updated information see the Java FRC site
"