Class WordFactory

java.lang.Object
org.graalvm.word.WordFactory

public final class WordFactory extends Object
Provides factory method to create machine-word-sized values.

In an execution environment where value returned by this factory words are boxed values (e.g. not in Native Image runtime), a Pointer value will throw UnsatisfiedLinkError if any of its memory access operations (i.e., read, write, compare-and-swap etc.) or conversion-to-Object operations (i.e., toObject) are invoked.

In a Native Image runtime, word values are distinct from Object values. To avoid problems related to this, word values must never be used as Objects, even when javac would allow it (e.g., Map<Long, Pointer>). The Native Image builder will detect such usages and raise an error.

Since:
19.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends PointerBase>
    T
    The null pointer, i.e., a word with all bits set to 0.
    static <T extends PointerBase>
    T
    pointer(long val)
    Unsafe conversion from a Java long value to a pointer.
    static <T extends SignedWord>
    T
    signed(int val)
    Creates a word whose value is supplied by a val which is sign-extended on a 64-bit platform.
    static <T extends SignedWord>
    T
    signed(long val)
    Creates a word whose value is supplied by val.
    static <T extends UnsignedWord>
    T
    unsigned(int val)
    Creates a word whose value is supplied by val which is zero-extended on a 64-bit platform.
    static <T extends UnsignedWord>
    T
    unsigned(long val)
    Creates a word whose value is supplied by val which is (lossily) narrowed on a 32-bit platform.
    static <T extends WordBase>
    T
    The constant 0, i.e., the word with no bits set.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • zero

      public static <T extends WordBase> T zero()
      The constant 0, i.e., the word with no bits set. There is no difference between a signed and unsigned zero.
      Returns:
      the constant 0.
      Since:
      19.0
    • nullPointer

      public static <T extends PointerBase> T nullPointer()
      The null pointer, i.e., a word with all bits set to 0. There is no difference between a signed or unsigned zero().
      Returns:
      a word value representing the null pointer
      Since:
      19.0
    • unsigned

      public static <T extends UnsignedWord> T unsigned(long val)
      Creates a word whose value is supplied by val which is (lossily) narrowed on a 32-bit platform.
      Parameters:
      val - a 64-bit unsigned value
      Returns:
      the value cast to Word
      Since:
      19.0
    • pointer

      public static <T extends PointerBase> T pointer(long val)
      Unsafe conversion from a Java long value to a pointer. The parameter is treated as an unsigned 64-bit value (in contrast to the semantics of a Java long).
      Parameters:
      val - a 64 bit unsigned value
      Returns:
      the value cast to PointerBase
      Since:
      19.0
    • unsigned

      public static <T extends UnsignedWord> T unsigned(int val)
      Creates a word whose value is supplied by val which is zero-extended on a 64-bit platform.
      Parameters:
      val - a 32 bit unsigned value
      Returns:
      the value cast to Word
      Since:
      19.0
    • signed

      public static <T extends SignedWord> T signed(long val)
      Creates a word whose value is supplied by val.
      Parameters:
      val - a 64-bit signed value
      Returns:
      the value cast to Word
      Since:
      19.0
    • signed

      public static <T extends SignedWord> T signed(int val)
      Creates a word whose value is supplied by a val which is sign-extended on a 64-bit platform.
      Parameters:
      val - a 32-bit signed value
      Returns:
      the value cast to Word
      Since:
      19.0