lejos.nxt
Class VM

java.lang.Object
  extended by lejos.nxt.VM

public final class VM
extends Object

This class provides access to many of the internal structures of the leJOS virtual machine. In particular it provides Java level access to the classes, methods fields etc. that make up the currently executing program. These structures are used by the VM to create the in memory program. They are similar to the class file format used by a standard JVM, but with much of the detail stripped away. The structures fall into two genral types. Those that are contained within Java objects (and so can be made directly available to a user program) and those that are simply raw data. To allow access to the second type of data we create Java objects with a copy of the data in them. In some cases we also do this even for tables/etc. that are available as objects as wrapping the class in this way may make it easier to manipulate. NOTE: Many of the structures in this file are a direct mapping to internal data within the VM. Changes to the VM structures must also be reflected here. Take care when editing this code to ensure that changes do not modify this mapping. Also many of the tables use byte fields that really should be treated as unsigned values. We have to take great care when converting these to integers.

Author:
andy

Nested Class Summary
 class VM.VMClass
          Provide access to the internal class data
 class VM.VMClasses
          Provide access to a series of class records
static class VM.VMClone
          This class is used to create a Java class from in memory data.
 class VM.VMConstants
          This class allows access to all of the constant values.
static class VM.VMElements
           
static class VM.VMException
          An exception record
static class VM.VMExceptions
          Class to provide access to a series of exception records
 class VM.VMFields
           
 class VM.VMImage
          The image header for the currently active program.
static class VM.VMItems<E>
          This class provides the ability to iterate through a series of in memory structures and returns a Java accessible clone of the structure.
 class VM.VMMethod
          Provide access to information about a method
 class VM.VMMethods
          Provide access to a series of method records
 class VM.VMStackFrame
           
 class VM.VMStackFrames
           
static class VM.VMStaticFields
          This class can be used to gain access to all of the static fields.
 class VM.VMThread
          Internal version of a thread structure
 class VM.VMThreads
          Provide access to a series of internal thread records
static class VM.VMValue
          Class that represents a value within the VM.
 
Field Summary
static int VM_ASSERT
           
static int VM_BOOLEAN
           
static int VM_BYTE
           
static int VM_CHAR
           
static int VM_CLASS
           
static int VM_DOUBLE
           
static int VM_FLOAT
           
static int VM_INT
           
static int VM_LONG
           
static int VM_OBJECT
           
static int VM_OBJECTARRAY
           
static int VM_SHORT
           
static int VM_TYPECHECKS
           
static int VM_VOID
           
 
Method Summary
static void enableRunTimeTypeChecks(boolean on)
          Enable/Disable strict run time type checking for some operations within the Virtual Machine.
static void executeProgram(int progNo)
          leJOS allows several "programs" to be linked into a single nxj file the system by default will start execution of program 0.
static Class<?> getClass(int clsNo)
          Return the class for the specified primitive type.
 Class<?> getClass(Object obj)
          Return the Class object for the provided object.
static int getClassNumber(Class<?> cls)
           
 VM.VMElements getElements(Object obj)
           
 VM.VMFields getFields(Object obj)
          Provide access to the fields of an object
 VM.VMImage getImage()
          Return the image header for the currently running program
 VM.VMMethod getMethod(int methodNo)
          Return data about the specified method number
static VM getVM()
          Obtain access to the single instance of the VM class.
 VM.VMClass getVMClass(Class<?> cls)
          Return a VMClass object for the provided class object.
 VM.VMClass getVMClass(int clsNo)
          Return a VMClass object for the provided class number.
 VM.VMClass getVMClass(Object obj)
          Return a VMClass object for the provided object.
static int getVMOptions()
          Return the currently operating Virtual Machine options.
 VM.VMThread getVMThread(Thread thread)
           
 VM.VMThreads getVMThreads()
          Returns access to all of the current internal thread objects
 boolean isArray(Object obj)
          Return true if the specified object is an array
static boolean isAssignable(Class<?> src, Class<?> dst)
          Check to see if it is allowed to assign an object of class src to an oobject of class dst.
static void resumeThread(Object thread)
          Resume a thread.
static void setVMOptions(int options)
          Control the run time operation of the leJOS Virtual Machine.
static void suspendThread(Object thread)
          Suspend a thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VM_OBJECT

public static final int VM_OBJECT
See Also:
Constant Field Values

VM_CLASS

public static final int VM_CLASS
See Also:
Constant Field Values

VM_BOOLEAN

public static final int VM_BOOLEAN
See Also:
Constant Field Values

VM_CHAR

public static final int VM_CHAR
See Also:
Constant Field Values

VM_FLOAT

public static final int VM_FLOAT
See Also:
Constant Field Values

VM_DOUBLE

public static final int VM_DOUBLE
See Also:
Constant Field Values

VM_BYTE

public static final int VM_BYTE
See Also:
Constant Field Values

VM_SHORT

public static final int VM_SHORT
See Also:
Constant Field Values

VM_INT

public static final int VM_INT
See Also:
Constant Field Values

VM_LONG

public static final int VM_LONG
See Also:
Constant Field Values

VM_VOID

public static final int VM_VOID
See Also:
Constant Field Values

VM_OBJECTARRAY

public static final int VM_OBJECTARRAY
See Also:
Constant Field Values

VM_TYPECHECKS

public static final int VM_TYPECHECKS
See Also:
Constant Field Values

VM_ASSERT

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

getVM

public static VM getVM()
Obtain access to the single instance of the VM class. This can then be used to gain access to the more detailed information about the VM and it's internal structures.

Returns:
the VM object

getImage

public VM.VMImage getImage()
Return the image header for the currently running program

Returns:
Image header.

getClassNumber

public static int getClassNumber(Class<?> cls)

isAssignable

public static boolean isAssignable(Class<?> src,
                                   Class<?> dst)
Check to see if it is allowed to assign an object of class src to an oobject of class dst.

Parameters:
src - The src class.
dst - The destination class.
Returns:
true if the assignment is allowed.
Throws:
NullPointerException - if either class is null.

getClass

public Class<?> getClass(Object obj)
Return the Class object for the provided object. Note: The actual object returned actually resides in flash rom and is part of the leJOS loader. It is not possible to extend this class or modify the contents.

Parameters:
obj - the object for which the class is required
Returns:
the Class object

getVMClass

public VM.VMClass getVMClass(Object obj)
Return a VMClass object for the provided object. Note: The object returned is actually a copy of the in flash object.

Parameters:
obj - the object for which the class is required
Returns:
the VMClass object

getClass

public static Class<?> getClass(int clsNo)
Return the class for the specified primitive type.

Parameters:
clsNo -
Returns:
Class object for this type.

getVMClass

public final VM.VMClass getVMClass(Class<?> cls)
Return a VMClass object for the provided class object. Note: The object returned is actually a copy of the in flash object.

Parameters:
cls -
Returns:
the VMClass object

getVMClass

public final VM.VMClass getVMClass(int clsNo)
Return a VMClass object for the provided class number. Note: The object returned is actually a copy of the in flash object.

Parameters:
clsNo -
Returns:
the VMClass object

getMethod

public final VM.VMMethod getMethod(int methodNo)
Return data about the specified method number

Parameters:
methodNo -
Returns:
Method object

isArray

public final boolean isArray(Object obj)
Return true if the specified object is an array

Parameters:
obj - object to test
Returns:
true iff the specified object is an array

getFields

public final VM.VMFields getFields(Object obj)
Provide access to the fields of an object

Parameters:
obj - the object to obtain the fields for
Returns:
fields object

getElements

public final VM.VMElements getElements(Object obj)

getVMThreads

public final VM.VMThreads getVMThreads()
Returns access to all of the current internal thread objects

Returns:
the VMThreads object

getVMThread

public final VM.VMThread getVMThread(Thread thread)

suspendThread

public static final void suspendThread(Object thread)
Suspend a thread. This places the specified thread into a suspended state. If thread is null all threads except for the current thread will be suspended.

Parameters:
thread -

resumeThread

public static final void resumeThread(Object thread)
Resume a thread. A suspended thread will be resumed to it's previous state. If thread is null all suspended threads will be resumed.

Parameters:
thread -

executeProgram

public static final void executeProgram(int progNo)
leJOS allows several "programs" to be linked into a single nxj file the system by default will start execution of program 0. This function allows other programs to be called.

Parameters:
progNo - program number to call

setVMOptions

public static final void setVMOptions(int options)
Control the run time operation of the leJOS Virtual Machine.

Parameters:
options - Bit flags.

getVMOptions

public static final int getVMOptions()
Return the currently operating Virtual Machine options.

Returns:
the options

enableRunTimeTypeChecks

public static void enableRunTimeTypeChecks(boolean on)
Enable/Disable strict run time type checking for some operations within the Virtual Machine.

Parameters:
on -