"

2013 FRC Java API

"

com.sun.squawk
Class VM

java.lang.Object
  extended by com.sun.squawk.VM
All Implemented Interfaces:
GlobalStaticFields

public class VM
extends Object
implements GlobalStaticFields

This is a Squawk VM specific class that is used to communicate between executing Java software and the low level core VM that is expressed in machine code. There are two parts to this. There are a set of native methods that are used to invoke very low level operations like manipulating memory at a very low level or performing I/O. In the other direction there are a number of methods that the low level core may call. These are used to implement high level operations that are better done in Java than in machine code.

A special version of this class exists for the romizer. The romizer version only implements the methods used to manipulate memory.

Version:
1.0

Nested Class Summary
static class VM.Stats
          Virtual machine statistics.
 
Field Summary
static int MAX_SYS_PRIORITY
          The maximum priority that a system thread can have.
static int STREAM_STDERR
          The identifier denoting the standard error output stream.
static int STREAM_STDOUT
          The identifier denoting the standard output stream.
 
Method Summary
static void addShutdownHook(Isolate iso, Runnable hook)
          Registers a new virtual-machine shutdown hook.
static void addShutdownHook(Thread hook)
          Registers a new virtual-machine shutdown hook.
static void allowUserGC(boolean value)
          Enable or disable Runtime.gc()
static void arraycopyObject0(Object src, int src_position, Object dst, int dst_position, int length)
          VM-private version of System.arraycopy for arrays of objects that does little error checking.
static void arraycopyPrimitive0(Object src, int src_position, Object dst, int dst_position, int totalLength, int dataSize)
          VM-private version of System.arraycopy for arrays of primitives that does little error checking.
static long branchCount()
          Enables a dynamically loaded class to call this.
static void collectGarbage(boolean forceFullGC)
          Switch to the service stack and call 'GC.collectGarbage()'
static void copyBytes(Address src, int srcPos, Address dst, int dstPos, int length, boolean nvmDst)
          Copy memory from one area to another.
static long doubleToLongBits(double value)
          Converts a double into bits.
static int execGraphicsIO(int op, int i1, int i2, int i3, int i4, int i5, int i6, Object send, Object receive)
          Executes an I/O operation on the graphics channel and return the result.
static int execIO(int op, int channel, int i1, int i2, int i3, int i4, int i5, int i6, Object send, Object receive)
          Executes a I/O operation that may block.
static long execIOLong(int op, int channel, int i1, int i2, int i3, int i4, int i5, int i6, Object send, Object receive)
          Executes an I/O operation that returns a long value.
static int execSyncIO(int op, int i1)
          Executes a non-blocking I/O operation whose result is guaranteed to be available immediately.
static int execSyncIO(int context, int op, int i1, int i2, int i3, int i4, int i5, int i6, Object send, Object receive)
          Executes a non-blocking I/O operation whose result is guaranteed to be available immediately.
static int execSyncIO(int op, int i1, int i2, int i3, int i4, int i5, int i6, Object send, Object receive)
          Executes a non-blocking I/O operation whose result is guaranteed to be available immediately.
static void fatalVMError()
          Halts the VM because of a fatal condition.
static void finalize(Object o)
           
static int floatToIntBits(float value)
          Converts a float into bits.
static void freeChannel(int channel)
          Frees a channel.
static Address getBootstrapEnd()
          Gets the address at which the object memory containing the bootstrap suite ends.
static int getBootstrapHash()
          Gets the hash of the object memory containing the bootstrap suite in it's canonical (i.e.
static Address getBootstrapStart()
          Gets the address at which the object memory containing the bootstrap suite starts.
static long getBranchCount()
          Gets the number of backward branch instructions the VM has executed.
static int getChannel(int type)
          Gets a new IO channel.
static Object getClass(Object object)
          Support routine to get the object representing the class of a given object.
static Isolate getCurrentIsolate()
          Gets the isolate of the currently executing thread.
static void getData(Address src, int boffset, Object dst, int low, int number, int elementSize)
          Do actual copy from memory at address + boffset to array Copy from memory to byte array.
static char getFileSeparatorChar()
          The system-dependent default name-separator character.
static long getGUIEvent()
          Gets the next available event on the GUI input channel, blocking until there is one.
static Object getKeyedGlobal(int key)
          Return the global registered using setGlobal with key.
static Object getKeyedGlobalsMutex()
           
static Hashtable getManifestPropertiesOfSuite(String uri)
          A helper method to provide access to the manifest of midlet suites from outside the bootstrap.
static String getManifestProperty(String name)
          Gets the value of an Suite.PROPERTIES_MANIFEST_RESOURCE_NAME property embedded in the suite.
static Enumeration getManifestPropertyNames()
          Gets the names of all manifest properties embedded in the leaf suite and all of its parents.
static int getNextHashcode()
          Gets the next available hashcode.
static OutOfMemoryError getOutOfMemoryError()
          Get the sentinal OutOfMemoryException object THIS IS PRIVATE TO THE BOOTSTRAP SUITE
static char getPathSeparatorChar()
          The system-dependent path-separator character.
static PeripheralRegistry getPeripheralRegistry()
           
static Address getRomStart()
          Gets the address of the start of the object memory in ROM.
static Thread[] getRunnableThreads()
          Answer an array of threads that are runnable now, in the order they appear in the runnable queue.
static Stack getTaskCache()
          Return a system global Stack of cached TaskExecutors.
static long getTimeBeforeAnotherThreadIsRunnable()
          Answer the time in millis until another thread is runnable.
static long getTimeMicros()
          Gets the current time.
static long getTimeMillis()
          Gets the current time.
static void haltVM(int code)
          Halt the VM without running exit hooks.
static float intBitsToFloat(int value)
          Converts bits into a float.
static boolean isArray(Object o)
          Support routine to test whether a given object is an array.
static boolean isBigEndian()
          Get the endianess.
static boolean isCurrentIsolateInitialized()
          Determines if the current isolate is set and initialized.
static boolean isHosted()
          Determines if code running at the moment is running inside of a Squawk VM or a JSE VM.
static boolean isInternal(Klass klass)
          Determines if the klass is internal, so should be retained (even if symbol gets stripped)
static boolean isInternal(Member member)
          Determines if the field or method is internal, so should be retained (even if symbol gets stripped)
static boolean isThreadingInitialized()
          Determines if the threading system is initialized.
static boolean isVerbose()
          Gets the flag indicating if the VM is running in verbose mode.
static boolean isVeryVerbose()
          Gets the flag indicating if the VM is running in very verbose mode.
static double longBitsToDouble(long value)
          Converts bits into a double.
static Mailbox lookupMailbox(String name)
           
static int lookupNative(String name)
          Gets the identifier for a native method.
static double math(int code, double a, double b)
          Performs a math operation.
static void outPrint(long val)
          Print val safely to System.err, or to VM.print if that fails.
static void outPrint(PrintStream stream, long val)
          Print val safely to Stream, or to VM.print if that fails.
static void outPrint(PrintStream stream, String str)
          Print str safely to Stream, or to VM.print if that fails.
static void outPrint(String str)
          Print str safely to System.err, or to VM.print if that fails.
static void outPrintBC()
          Print branch count as safely as possible.
static void outPrintln()
          Print new line safely to System.err, or to VM.print if that fails.
static void outPrintln(PrintStream stream)
          Print new line safely to Stream, or to VM.print if that fails.
static void outPrintln(PrintStream stream, String str)
          Print str safely to Stream, or to VM.print if that fails.
static void outPrintln(String str)
          Print str safely to System.err, or to VM.print if that fails.
static void outPrintThread(VMThread thr)
          Print thread name as safely as possible, to System.err, or VM.print if that fails.
static void print(boolean b)
          Prints a boolean to the VM output stream.
static void print(char x)
          Prints a character to the VM output stream.
static void print(double x)
          Prints a double to the VM output stream.
static void print(float x)
          Prints a float to the VM output stream.
static void print(int x)
          Prints an integer to the VM output stream.
static void print(long x)
          Prints a long to the VM output stream.
static void print(String x)
          Prints a string to the VM output stream.
static void printAddress(Address val)
          Prints an address to the VM stream.
static void printAddress(Object val)
          Prints an address to the VM stream.
static void printBytes(byte[] b, int off, int len)
          Prints bytes (as C chars) to the VM stream.
static Throwable printExceptionAndTrace(Throwable exc, String msg)
          Safely print exception and stack trace to System.err.
static Throwable printExceptionAndTrace(Throwable exc, String msg, boolean printUsingThrowable)
          Safely print exception and stack trace to System.err.
static void println()
          Prints a new line to the VM output stream.
static void println(boolean x)
          Prints a boolean followed by a new line to the VM output stream.
static void println(char x)
          Prints a character followed by a new line to the VM output stream.
static void println(double x)
          Prints a double followed by a new line to the VM output stream.
static void println(float x)
          Prints a float followed by a new line to the VM output stream.
static void println(int x)
          Prints an integer followed by a new line to the VM output stream.
static void println(long x)
          Prints a long followed by a new line to the VM output stream.
static void println(String x)
          Prints a string followed by a new line to the VM output stream.
static void printObject(Object obj)
          Prints the string representation of an object to the VM stream.
static void printOffset(Offset val)
          Prints an offset to the VM stream.
static void printThread(VMThread thr)
          Print thread name as safely as possible.
static void printUWord(UWord val)
          Prints an unsigned word to the VM stream.
static Object putKeyedGlobal(int key, Object value)
          Set the global registered for key.
static boolean registerMailbox(String name, Mailbox mailbox)
          Register named mailbox with the system.
static ExecutionPoint[] reifyCurrentStack(int count)
          Returns an array of stack trace elements, each representing one stack frame in the current call stack.
static boolean removeShutdownHook(Isolate iso, Runnable hook)
          De-registers a previously-registered virtual-machine shutdown hook.
static boolean removeShutdownHook(Thread hook)
          De-registers a previously-registered virtual-machine shutdown hook.
static void setAsDaemonThread(Thread t)
          Mark the specified thread to be a daemon thread (won't prevent VM from exiting).
static void setBytes(Address dst, byte value, int length)
          Set memory region to value.
static void setData(Address dst, int boffset, Object src, int low, int number, int elementSize)
          Do actual copy from array to memory at address + boffset Copy number bytes from byte array bytes starting at position low.to the memory location specified by the address dst and byte offset boffset.
static void setMaxSelectWait(long max)
          Set the maximum time that the system will wait in select.
static void setMaxSystemWait(long max)
          Set the maximum time that system will wait for IO, interrupts, etc.
static void setProperty(String name, String value)
          On a hosted system , this calls System.setProperty(), otherwise calls Isolate.currentIsolate().setProperty()
static int setStream(int stream)
          Sets the stream for the VM.print...
static void setSystemThreadPriority(Thread t, int level)
          Sets the given thread to the given priority, bounded by MAX_SYS_PRIORITY (eg.
static Object shallowCopy(Object original)
          Perform a shallow copy of the original object, without calling a constructor WARNING: This is bypassing the write barrier, which is (sort of) OK because we are writing to a new object.
static void startTracing()
          Start the VM tracing if tracing support is enabled.
static void stopVM(int code)
          Halt the VM in the normal way.
static boolean stripSymbols(Klass klass)
          Determines if all the symbolic information for a class should be stripped.
static boolean stripSymbols(Member member)
          Determines if all the symbolic information for a field or method should be stripped.
static void unregisterMailbox(String name, Mailbox mailbox)
          Unregister named mailbox with the system.
static void unregisterSuite(String uri)
          If the suite is registered, unregister it with the garbage collector.
static boolean userGCAllowed()
          Tests if Runtime.gc() is allowed.
static boolean usingTypeMap()
          Determines if the VM was built with memory access type checking enabled.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STREAM_STDOUT

public static final int STREAM_STDOUT
The identifier denoting the standard output stream.

See Also:
Constant Field Values

STREAM_STDERR

public static final int STREAM_STDERR
The identifier denoting the standard error output stream.

See Also:
Constant Field Values

MAX_SYS_PRIORITY

public static final int MAX_SYS_PRIORITY
The maximum priority that a system thread can have.

See Also:
Constant Field Values
Method Detail

reifyCurrentStack

public static ExecutionPoint[] reifyCurrentStack(int count)
Returns an array of stack trace elements, each representing one stack frame in the current call stack. The zeroth element of the array represents the top of the stack, which is the frame of the caller's method. The last element of the array represents the bottom of the stack, which is the first method invocation in the sequence. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
count - how many frames from the stack to reify, starting from the frame of the method that called this one. A negative value specifies that all frames are to be reified.
Returns:
the reified call stack

math

public static double math(int code,
                          double a,
                          double b)
Performs a math operation.

Parameters:
code - the opcode
a - the first operand
b - the second operand
Returns:
the result

floatToIntBits

public static int floatToIntBits(float value)
Converts a float into bits.

Parameters:
value - the input
Returns:
the result

doubleToLongBits

public static long doubleToLongBits(double value)
Converts a double into bits.

Parameters:
value - the input
Returns:
the result

intBitsToFloat

public static float intBitsToFloat(int value)
Converts bits into a float.

Parameters:
value - the input
Returns:
the result

longBitsToDouble

public static double longBitsToDouble(long value)
Converts bits into a double.

Parameters:
value - the input
Returns:
the result

isHosted

public static boolean isHosted()
                        throws AllowInlinedPragma
Determines if code running at the moment is running inside of a Squawk VM or a JSE VM.

Returns:
true if running in a hosted environment, ie in a JSE VM
Throws:
AllowInlinedPragma

isBigEndian

public static boolean isBigEndian()
Get the endianess.

Returns:
true if the system is big endian

setProperty

public static void setProperty(String name,
                               String value)
On a hosted system , this calls System.setProperty(), otherwise calls Isolate.currentIsolate().setProperty()

Parameters:
name - property name
value - property value

setStream

public static int setStream(int stream)
Sets the stream for the VM.print... methods to one of the STREAM_... constants.

Parameters:
stream - the stream to use for the print... methods
Returns:
the current stream used for VM printing

printUWord

public static void printUWord(UWord val)
Prints an unsigned word to the VM stream. This will be formatted as an unsigned 32 bit or 64 bit value depending on the underlying platform.

Parameters:
val - the word to print

printOffset

public static void printOffset(Offset val)
Prints an offset to the VM stream. This will be formatted as a signed 32 bit or 64 bit value depending on the underlying platform.

Parameters:
val - the offset to print

printAddress

public static void printAddress(Object val)
Prints an address to the VM stream. This will be formatted as an unsigned 32 bit or 64 bit value depending on the underlying platform.

Parameters:
val - the address to print

printAddress

public static void printAddress(Address val)
Prints an address to the VM stream. This will be formatted as an unsigned 32 bit or 64 bit value depending on the underlying platform.

Parameters:
val - the address to print

printBytes

public static void printBytes(byte[] b,
                              int off,
                              int len)
Prints bytes (as C chars) to the VM stream.

Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.

printObject

public static void printObject(Object obj)
Prints the string representation of an object to the VM stream.

Parameters:
obj - the object whose toString() result is to be printed

print

public static void print(char x)
Prints a character to the VM output stream.

Parameters:
x - the value

print

public static void print(String x)
Prints a string to the VM output stream.

Parameters:
x - the string

print

public static void print(int x)
Prints an integer to the VM output stream.

Parameters:
x - the value

print

public static void print(long x)
Prints a long to the VM output stream.

Parameters:
x - the value

print

public static void print(float x)
Prints a float to the VM output stream.

Parameters:
x - the value

print

public static void print(double x)
Prints a double to the VM output stream.

Parameters:
x - the value

print

public static void print(boolean b)
                  throws NotInlinedPragma
Prints a boolean to the VM output stream.

Parameters:
b - the value
Throws:
NotInlinedPragma

println

public static void println(char x)
Prints a character followed by a new line to the VM output stream.

Parameters:
x - the value

println

public static void println(String x)
                    throws NotInlinedPragma
Prints a string followed by a new line to the VM output stream.

Parameters:
x - the string
Throws:
NotInlinedPragma

println

public static void println(int x)
                    throws NotInlinedPragma
Prints an integer followed by a new line to the VM output stream.

Parameters:
x - the value
Throws:
NotInlinedPragma

println

public static void println(boolean x)
                    throws NotInlinedPragma
Prints a boolean followed by a new line to the VM output stream.

Parameters:
x - the value
Throws:
NotInlinedPragma

println

public static void println(long x)
                    throws NotInlinedPragma
Prints a long followed by a new line to the VM output stream.

Parameters:
x - the value
Throws:
NotInlinedPragma

println

public static void println(float x)
                    throws NotInlinedPragma
Prints a float followed by a new line to the VM output stream.

Parameters:
x - the value
Throws:
NotInlinedPragma

println

public static void println(double x)
                    throws NotInlinedPragma
Prints a double followed by a new line to the VM output stream.

Parameters:
x - the value
Throws:
NotInlinedPragma

println

public static void println()
                    throws NotInlinedPragma
Prints a new line to the VM output stream.

Throws:
NotInlinedPragma

finalize

public static void finalize(Object o)

getRomStart

public static Address getRomStart()
Gets the address of the start of the object memory in ROM.

Returns:
the address of the start of the object memory in ROM

getBootstrapStart

public static Address getBootstrapStart()
Gets the address at which the object memory containing the bootstrap suite starts.

Returns:
the bootstrap object memory start address

getBootstrapEnd

public static Address getBootstrapEnd()
Gets the address at which the object memory containing the bootstrap suite ends.

Returns:
the bootstrap object memory end address

getBootstrapHash

public static int getBootstrapHash()
Gets the hash of the object memory containing the bootstrap suite in it's canonical (i.e. relative to address 0) form.

Returns:
the hash of the bootstrap object memory

getPathSeparatorChar

public static char getPathSeparatorChar()
The system-dependent path-separator character. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Windows systems it is ';'.

Returns:
the system-dependent path-separator character

getFileSeparatorChar

public static char getFileSeparatorChar()
The system-dependent default name-separator character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\'.

Returns:
char
See Also:
System.getProperty(java.lang.String)

fatalVMError

public static void fatalVMError()
Halts the VM because of a fatal condition.


getBranchCount

public static long getBranchCount()
Gets the number of backward branch instructions the VM has executed.

Returns:
the number of backward branch instructions the VM has executed or -1 if instruction profiling is disabled

branchCount

public static long branchCount()
Enables a dynamically loaded class to call this.

Returns:
the number of instructions the VM has executed or -1 if instruction profiling is disabled

startTracing

public static void startTracing()
Start the VM tracing if tracing support is enabled.


isVerbose

public static boolean isVerbose()
Gets the flag indicating if the VM is running in verbose mode.

Returns:
true if the VM is running in verbose mode

isVeryVerbose

public static boolean isVeryVerbose()
Gets the flag indicating if the VM is running in very verbose mode.

Returns:
true if the VM is running in very verbose mode

getTimeMicros

public static long getTimeMicros()
Gets the current time.

Returns:
the time in microseconds

getTimeMillis

public static long getTimeMillis()
Gets the current time.

Returns:
the time in milliseconds

collectGarbage

public static void collectGarbage(boolean forceFullGC)
                           throws NotInlinedPragma
Switch to the service stack and call 'GC.collectGarbage()'

Parameters:
forceFullGC - forces a collection of the whole heap
Throws:
NotInlinedPragma - as the frame of this method will be the inner most frame on the current thread's stack. The inner most frame on any stack does not have it's local variables scanned by the garbage collector. As such, this method must not use any local variables.

stopVM

public static void stopVM(int code)
Halt the VM in the normal way. Any registered shutdown hooks will be run.

Parameters:
code - the exit status code.
See Also:
Isolate.addLifecycleListener(com.sun.squawk.Isolate.LifecycleListener, int)

haltVM

public static void haltVM(int code)
Halt the VM without running exit hooks.

Parameters:
code - the exit status code.

addShutdownHook

public static void addShutdownHook(Isolate iso,
                                   Runnable hook)
Registers a new virtual-machine shutdown hook.

The Java virtual machine shuts down in response to two kinds of events:

A shutdown hook is a runnable. When the virtual machine begins its shutdown sequence it will start all registered shutdown hooks in some unspecified order and let them run serially (this may result in lower memory requirements than running all hooks concurrently). Note that daemon threads will continue to run during the shutdown sequence, as will non-daemon threads if shutdown was initiated by invoking the stopVM method.

Once the shutdown sequence has begun it can be stopped only by invoking the haltVM method, which forcibly terminates the virtual machine.

Once the shutdown sequence has begun it is impossible to register a new shutdown hook or de-register a previously-registered hook. Attempting either of these operations will cause an IllegalStateException to be thrown.

Shutdown hooks run at a delicate time in the life cycle of a virtual machine and should therefore be coded defensively. They should, in particular, be written to be thread-safe and to avoid deadlocks insofar as possible. They should also not rely blindly upon services that may have registered their own shutdown hooks and therefore may themselves in the process of shutting down.

Shutdown hooks should also finish their work quickly. When a program invokes stopVM the expectation is that the virtual machine will promptly shut down and exit. When the virtual machine is terminated due to user logoff or system shutdown the underlying operating system may only allow a fixed amount of time in which to shut down and exit. It is therefore inadvisable to attempt any user interaction or to perform a long-running computation in a shutdown hook.

Uncaught exceptions are handled in shutdown hooks just as in any other thread - the VM prints the exception's stack trace to System.err; it does not cause the virtual machine to exit or halt.

In rare circumstances the virtual machine may abort, that is, stop running without shutting down cleanly. This occurs when the virtual machine is terminated externally, for example with the SIGKILL signal on Unix or the TerminateProcess call on Microsoft Windows. The virtual machine may also abort if a native method goes awry by, for example, corrupting internal data structures or attempting to access nonexistent memory. If the virtual machine aborts then no guarantee can be made about whether or not any shutdown hooks will be run.

THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
iso - the isolate context to run the hook in.
hook - A Runnable object
Throws:
IllegalArgumentException - If the specified hook has already been registered
IllegalStateException - If the virtual machine is already in the process of shutting down
See Also:
removeShutdownHook(com.sun.squawk.Isolate, java.lang.Runnable), haltVM(int), stopVM(int)

removeShutdownHook

public static boolean removeShutdownHook(Isolate iso,
                                         Runnable hook)
De-registers a previously-registered virtual-machine shutdown hook.

THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
iso - the isolate context the hook was registered with.
hook - the hook to remove
Returns:
true if the specified hook had previously been registered and was successfully de-registered, false otherwise.
Throws:
IllegalStateException - If the virtual machine is already in the process of shutting down
See Also:
addShutdownHook(com.sun.squawk.Isolate, java.lang.Runnable), stopVM(int)

addShutdownHook

public static void addShutdownHook(Thread hook)
Registers a new virtual-machine shutdown hook.

The Java virtual machine shuts down in response to two kinds of events:

A shutdown hook is a runnable. When the virtual machine begins its shutdown sequence it will start all registered shutdown hooks in some unspecified order and let them run serially (this may result in lower memory requirements than running all hooks concurrently). Note that daemon threads will continue to run during the shutdown sequence, as will non-daemon threads if shutdown was initiated by invoking the stopVM method.

Once the shutdown sequence has begun it can be stopped only by invoking the haltVM method, which forcibly terminates the virtual machine.

Once the shutdown sequence has begun it is impossible to register a new shutdown hook or de-register a previously-registered hook. Attempting either of these operations will cause an IllegalStateException to be thrown.

Shutdown hooks run at a delicate time in the life cycle of a virtual machine and should therefore be coded defensively. They should, in particular, be written to be thread-safe and to avoid deadlocks insofar as possible. They should also not rely blindly upon services that may have registered their own shutdown hooks and therefore may themselves in the process of shutting down.

Shutdown hooks should also finish their work quickly. When a program invokes stopVM the expectation is that the virtual machine will promptly shut down and exit. When the virtual machine is terminated due to user logoff or system shutdown the underlying operating system may only allow a fixed amount of time in which to shut down and exit. It is therefore inadvisable to attempt any user interaction or to perform a long-running computation in a shutdown hook.

Uncaught exceptions are handled in shutdown hooks just as in any other thread - the VM prints the exception's stack trace to System.err; it does not cause the virtual machine to exit or halt.

In rare circumstances the virtual machine may abort, that is, stop running without shutting down cleanly. This occurs when the virtual machine is terminated externally, for example with the SIGKILL signal on Unix or the TerminateProcess call on Microsoft Windows. The virtual machine may also abort if a native method goes awry by, for example, corrupting internal data structures or attempting to access nonexistent memory. If the virtual machine aborts then no guarantee can be made about whether or not any shutdown hooks will be run.

Parameters:
hook - A Thread object
Throws:
IllegalArgumentException - If the specified hook has already been registered
IllegalStateException - If the virtual machine is already in the process of shutting down
See Also:
removeShutdownHook(com.sun.squawk.Isolate, java.lang.Runnable), haltVM(int), stopVM(int)

removeShutdownHook

public static boolean removeShutdownHook(Thread hook)
De-registers a previously-registered virtual-machine shutdown hook.

Parameters:
hook - the shutdown hook to remove
Returns:
true if the specified hook had previously been registered and was successfully de-registered, false otherwise.
Throws:
IllegalStateException - If the virtual machine is already in the process of shutting down
See Also:
addShutdownHook(com.sun.squawk.Isolate, java.lang.Runnable), stopVM(int)

getTaskCache

public static Stack getTaskCache()
Return a system global Stack of cached TaskExecutors. Only for use by the JNA implementation.

Returns:

copyBytes

public static void copyBytes(Address src,
                             int srcPos,
                             Address dst,
                             int dstPos,
                             int length,
                             boolean nvmDst)
Copy memory from one area to another.

Parameters:
src - the source address.
srcPos - the byte offset into src.
dst - the destination address.
dstPos - the byte offset into dst.
length - the number of bytes to be copied.
nvmDst - the destination buffer is in NVM

setBytes

public static void setBytes(Address dst,
                            byte value,
                            int length)
Set memory region to value.

Parameters:
dst - the destination address.
length - the number of bytes to be copied.
value - the value to set

arraycopyPrimitive0

public static void arraycopyPrimitive0(Object src,
                                       int src_position,
                                       Object dst,
                                       int dst_position,
                                       int totalLength,
                                       int dataSize)
VM-private version of System.arraycopy for arrays of primitives that does little error checking.

THIS IS PRIVATE TO THE BOOTSTRAP SUITE Impose the following restrictions on the input arguments:

The caller is responsible that these restrictions are not violated. If any of the restrictions above is violated, the behavior is undefined.

Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dst. The number of components copied is equal to the length argument. The components at positions srcOffset through srcOffset+length-1 in the source array are copied into positions dstOffset through dstOffset+length-1, respectively, of the destination array.

If the src and dst arguments refer to the same array object, then the copying is performed as if the components at positions srcOffset through srcOffset+length-1 were first copied to a temporary array with length components and then the contents of the temporary array were copied into positions dstOffset through dstOffset+length-1 of the destination array.

This method will cooperate with the thread scheduler so that thread scheduling can occur during very long array copies.

Parameters:
src - the source array.
src_position - start position in the source array.
dst - the destination array.
dst_position - start position in the destination data.
totalLength - the number of array elements to be copied.
dataSize - the size of a data element (1, 2, 4, 8)

arraycopyObject0

public static void arraycopyObject0(Object src,
                                    int src_position,
                                    Object dst,
                                    int dst_position,
                                    int length)
VM-private version of System.arraycopy for arrays of objects that does little error checking.

THIS IS PRIVATE TO THE BOOTSTRAP SUITE Impose the following restrictions on the input arguments:

The caller is responsible that these restrictions are not violated. If any of the restrictions above is violated, the behavior is undefined.

Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dst. The number of components copied is equal to the length argument. The components at positions srcOffset through srcOffset+length-1 in the source array are copied into positions dstOffset through dstOffset+length-1, respectively, of the destination array.

If the src and dst arguments refer to the same array object, then the copying is performed as if the components at positions srcOffset through srcOffset+length-1 were first copied to a temporary array with length components and then the contents of the temporary array were copied into positions dstOffset through dstOffset+length-1 of the destination array.

This method will cooperate with the thread scheduler so that thread scheduling can occur during very long array copies. this method also handles GC write barriers if needed.

Parameters:
src - the source array.
src_position - start position in the source array.
dst - the destination array.
dst_position - start position in the destination data.
length - the number of array elements to be copied.

getData

public static void getData(Address src,
                           int boffset,
                           Object dst,
                           int low,
                           int number,
                           int elementSize)
Do actual copy from memory at address + boffset to array 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
dst - the destination array
low - the offset in the destination array
number - the number of elements to copy into the dst array
elementSize - the size of the array elements
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the dst array

setData

public static void setData(Address dst,
                           int boffset,
                           Object src,
                           int low,
                           int number,
                           int elementSize)
Do actual copy from array to memory at address + boffset 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
src - the src byte array
low - the offset in the src array
number - the number of bytes to copy
elementSize - the size of the array elements
Throws:
ArrayIndexOutOfBoundsException - if the range specified by low and number does not fit within the src array

shallowCopy

public static Object shallowCopy(Object original)
Perform a shallow copy of the original object, without calling a constructor WARNING: This is bypassing the write barrier, which is (sort of) OK because we are writing to a new object. This can't create a ptr from old->young gen, which is what write barrier is looking for. Don't copy this code for other purposes!

Parameters:
original - the iobject to copy
Returns:
a copy of the original object.

getOutOfMemoryError

public static OutOfMemoryError getOutOfMemoryError()
Get the sentinal OutOfMemoryException object THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Returns:
the object

printThread

public static void printThread(VMThread thr)
Print thread name as safely as possible. Called by error reporting code, so doesn't assert, or intentionally throw exceptions! THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
thr - the thread to print

outPrintThread

public static void outPrintThread(VMThread thr)
Print thread name as safely as possible, to System.err, or VM.print if that fails. Called by error reporting code, so doesn't assert, or intentionally throw exceptions! THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
thr - the thread to print

outPrintBC

public static void outPrintBC()
Print branch count as safely as possible. Called by error reporting code, so doesn't assert, or intentionally throw exceptions!


printExceptionAndTrace

public static Throwable printExceptionAndTrace(Throwable exc,
                                               String msg)
Safely print exception and stack trace to System.err. Handles exceptions in Throwable.toString and printStackTrace, including OutOfMemoryExceptions. In all cases, this should print the message, the thread name, and the orginal exception (cclass name or toString).

Parameters:
exc - excption to report
msg - message to print before exception.
Returns:
Secondary exception, or null if none.

outPrint

public static void outPrint(PrintStream stream,
                            String str)
Print str safely to Stream, or to VM.print if that fails.

Parameters:
stream - stream to print on
str - string to print

outPrintln

public static void outPrintln(PrintStream stream,
                              String str)
Print str safely to Stream, or to VM.print if that fails.

Parameters:
stream - stream to print on
str - string to print

outPrintln

public static void outPrintln(PrintStream stream)
Print new line safely to Stream, or to VM.print if that fails.

Parameters:
stream - stream to print on

outPrint

public static void outPrint(PrintStream stream,
                            long val)
Print val safely to Stream, or to VM.print if that fails.

Parameters:
stream - stream to print on
val - long to print

outPrint

public static void outPrint(String str)
Print str safely to System.err, or to VM.print if that fails.

Parameters:
str - string to print

outPrintln

public static void outPrintln(String str)
Print str safely to System.err, or to VM.print if that fails.

Parameters:
str - string to print

outPrintln

public static void outPrintln()
Print new line safely to System.err, or to VM.print if that fails.


outPrint

public static void outPrint(long val)
Print val safely to System.err, or to VM.print if that fails.

Parameters:
val - long to print

printExceptionAndTrace

public static Throwable printExceptionAndTrace(Throwable exc,
                                               String msg,
                                               boolean printUsingThrowable)
Safely print exception and stack trace to System.err. Handles exceptions in Throwable.toString and printStackTrace, including OutOfMemoryExceptions. In all cases, this should print the message, the thread name, and the orginal exception (cclass name or toString).

Parameters:
exc - excption to report
msg - message to print before exception.
printUsingThrowable - if true, try to use Throwable.printStackTrace(), otherwise use VM routines...
Returns:
Secondary exception, or null if none.

execSyncIO

public static int execSyncIO(int op,
                             int i1,
                             int i2,
                             int i3,
                             int i4,
                             int i5,
                             int i6,
                             Object send,
                             Object receive)
Executes a non-blocking I/O operation whose result is guaranteed to be available immediately. This mechanism requires 2 calls to the IO sub-system. The first sets up the globals used to pass the parameters and initiates the operation. The second retrieves the result from the global that the operation stored its result in.

Parameters:
op - the opcode
i1 - an integer parameter
i2 - an integer parameter
i3 - an integer parameter
i4 - an integer parameter
i5 - an integer parameter
i6 - an integer parameter
send - an outgoing array parameter
receive - an incoming array parameter
Returns:
the integer result value

execSyncIO

public static int execSyncIO(int context,
                             int op,
                             int i1,
                             int i2,
                             int i3,
                             int i4,
                             int i5,
                             int i6,
                             Object send,
                             Object receive)
Executes a non-blocking I/O operation whose result is guaranteed to be available immediately. This mechanism requires 2 calls to the IO sub-system. The first sets up the globals used to pass the parameters and initiates the operation. The second retrieves the result from the global that the operation stored its result in.

Parameters:
context - the I/O context
op - the opcode
i1 - an integer parameter
i2 - an integer parameter
i3 - an integer parameter
i4 - an integer parameter
i5 - an integer parameter
i6 - an integer parameter
send - an outgoing array parameter
receive - an incoming array parameter
Returns:
the integer result value

execSyncIO

public static int execSyncIO(int op,
                             int i1)
Executes a non-blocking I/O operation whose result is guaranteed to be available immediately.

Parameters:
op - the opcode
i1 - an integer parameter
Returns:
the integer result value

execIO

public static int execIO(int op,
                         int channel,
                         int i1,
                         int i2,
                         int i3,
                         int i4,
                         int i5,
                         int i6,
                         Object send,
                         Object receive)
                  throws IOException
Executes a I/O operation that may block. This requires at least 2 calls to the IO sub-system: the first to execute the operation and the second to get the status of the operation (success = 0, failure < 0 or blocked > 0). If the status is success, then a third call to the IO sub-system is made to retrieve the result of the operation. If the status indicates that an exception occcurred in the IO sub-system, then an IOException is thrown. If the status indicates that the IO sub-system is blocked, then the status value is used as an event number to block the current thread and put it on a queue of threads waiting for an event.

Parameters:
op - the opcode
channel - the channel number
i1 - an integer parameter
i2 - an integer parameter
i3 - an integer parameter
i4 - an integer parameter
i5 - an integer parameter
i6 - an integer parameter
send - an outgoing array parameter
receive - an incoming array parameter
Returns:
the integer result value
Throws:
IOException

execIOLong

public static long execIOLong(int op,
                              int channel,
                              int i1,
                              int i2,
                              int i3,
                              int i4,
                              int i5,
                              int i6,
                              Object send,
                              Object receive)
                       throws IOException
Executes an I/O operation that returns a long value.

Parameters:
op - the opcode
channel - the channel identifier
i1 - an integer parameter
i2 - an integer parameter
i3 - an integer parameter
i4 - an integer parameter
i5 - an integer parameter
i6 - an integer parameter
send - a outgoing reference parameter
receive - an incoming reference parameter (i.e. an array of some type)
Returns:
the long result
Throws:
IOException

execGraphicsIO

public static int execGraphicsIO(int op,
                                 int i1,
                                 int i2,
                                 int i3,
                                 int i4,
                                 int i5,
                                 int i6,
                                 Object send,
                                 Object receive)
Executes an I/O operation on the graphics channel and return the result.

Parameters:
op - the opcode
i1 - an integer parameter
i2 - an integer parameter
i3 - an integer parameter
i4 - an integer parameter
i5 - an integer parameter
i6 - an integer parameter
send - a outgoing reference parameter
receive - an incoming reference parameter (i.e. an array of some type)
Returns:
the event code to wait on or zero

getGUIEvent

public static long getGUIEvent()
Gets the next available event on the GUI input channel, blocking until there is one.

Returns:
the GUI event value

setAsDaemonThread

public static void setAsDaemonThread(Thread t)
Mark the specified thread to be a daemon thread (won't prevent VM from exiting). If this thread is alive, an IllegalThreadStateException is thrown.

Parameters:
t - The thread

setSystemThreadPriority

public static void setSystemThreadPriority(Thread t,
                                           int level)
Sets the given thread to the given priority, bounded by MAX_SYS_PRIORITY (eg. allowing higher than normal priority levels) Note that threads created by a thread with "system" priority do not inherit the system priority level, but default to NORM_PRIORITY. Should only be called by system code. This interface likely to change to more RTSJ-like scheme.

Parameters:
t - The thread
level - the system priority level (currently supports normal priorities as well as 11, and 12)
Throws:
IllegalArgumentException - If the priority is not in the range MIN_PRIORITY to MAX_SYS_PRIORITY.

getChannel

public static int getChannel(int type)
                      throws IOException
Gets a new IO channel. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
type - the channel type
Returns:
the identifier for the newly created channel
Throws:
IOException

freeChannel

public static void freeChannel(int channel)
                        throws IOException
Frees a channel. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
channel - the identifier of the channel to free
Throws:
IOException

setMaxSelectWait

public static void setMaxSelectWait(long max)
Set the maximum time that the system will wait in select. Used in PLATFORM_TYPE=NATIVE builds.

Parameters:
max - max wait time in ms. Must be > 0.

setMaxSystemWait

public static void setMaxSystemWait(long max)
Set the maximum time that system will wait for IO, interrupts, etc. WARNING: This can break system sleeping, and should only be used in emergencies.

Parameters:
max - max wait time in ms. Must be > 0.

allowUserGC

public static void allowUserGC(boolean value)
Enable or disable Runtime.gc()

Parameters:
value - true to enable

userGCAllowed

public static boolean userGCAllowed()
Tests if Runtime.gc() is allowed.

Returns:
true if calls to Runtime.gc() are allowed

usingTypeMap

public static boolean usingTypeMap()
Determines if the VM was built with memory access type checking enabled.

Returns:
true if the VM was built with memory access type checking enabled

getNextHashcode

public static int getNextHashcode()
Gets the next available hashcode. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Returns:
the hashcode

getCurrentIsolate

public static Isolate getCurrentIsolate()
Gets the isolate of the currently executing thread.

Returns:
the isolate

getManifestPropertyNames

public static Enumeration getManifestPropertyNames()
Gets the names of all manifest properties embedded in the leaf suite and all of its parents.

Returns:
enumeration over the names

getManifestProperty

public static String getManifestProperty(String name)
Gets the value of an Suite.PROPERTIES_MANIFEST_RESOURCE_NAME property embedded in the suite.

Parameters:
name - the name of the property whose value is to be retrieved
Returns:
the property value

getManifestPropertiesOfSuite

public static Hashtable getManifestPropertiesOfSuite(String uri)
A helper method to provide access to the manifest of midlet suites from outside the bootstrap.

Parameters:
uri - suite's uri
Returns:
hashtable of properties from manifest

unregisterSuite

public static void unregisterSuite(String uri)
If the suite is registered, unregister it with the garbage collector. Otherwise do nothing.

Parameters:
uri - the suite to unregister.

isCurrentIsolateInitialized

public static boolean isCurrentIsolateInitialized()
Determines if the current isolate is set and initialized.

Returns:
true if the current isolate is set and initialized

isThreadingInitialized

public static boolean isThreadingInitialized()
Determines if the threading system is initialized. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Returns:
true if the threading system is initialized.

lookupNative

public static int lookupNative(String name)
Gets the identifier for a native method. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
name - the fully qualified name of the native method
Returns:
the identifier for the method or -1 if the method does not exist or cannot be dynamically bound to

stripSymbols

public static boolean stripSymbols(Klass klass)
Determines if all the symbolic information for a class should be stripped. This is used during the bootstrap process by the romizer to strip certain classes based on their names.

Parameters:
klass - the class to consider
Returns:
true if the class symbols should be stripped

stripSymbols

public static boolean stripSymbols(Member member)
Determines if all the symbolic information for a field or method should be stripped. This is used during the bootstrap process by the romizer to strip certain fields and methods based on their names.

Parameters:
member - the method or field to consider
Returns:
true if the class symbols should be stripped

isInternal

public static boolean isInternal(Member member)
Determines if the field or method is internal, so should be retained (even if symbol gets stripped)

Parameters:
member - the method or field to consider
Returns:
true if the class symbols should be stripped

isInternal

public static boolean isInternal(Klass klass)
Determines if the klass is internal, so should be retained (even if symbol gets stripped)

Parameters:
klass - the class to consider
Returns:
true if the class symbols should be stripped

getClass

public static Object getClass(Object object)
Support routine to get the object representing the class of a given object. This takes into account whether or not the VM is running in hosted mode or not. The returned object can only be used for identity comparisons.

Parameters:
object -
Returns:
a VM internal object representing the Class

isArray

public static boolean isArray(Object o)
Support routine to test whether a given object is an array. This takes into account whether or not the VM is running in hosted mode or not.

Parameters:
o - object to test
Returns:
true if o is an array

registerMailbox

public static boolean registerMailbox(String name,
                                      Mailbox mailbox)
Register named mailbox with the system. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
name - the public name of the mailboz
mailbox - the mailbox to use with that name.
Returns:
false if the name is already registered to a mailbox.

unregisterMailbox

public static void unregisterMailbox(String name,
                                     Mailbox mailbox)
Unregister named mailbox with the system. THIS IS PRIVATE TO THE BOOTSTRAP SUITE

Parameters:
name - the public name of the mailboz
mailbox - the mailbox to use with that name.

lookupMailbox

public static Mailbox lookupMailbox(String name)

getTimeBeforeAnotherThreadIsRunnable

public static long getTimeBeforeAnotherThreadIsRunnable()
Answer the time in millis until another thread is runnable. Will return zero if another thread is already runnable, otherwise the delta until the first thread on the timer queue becomes runnable, otherwise Long.MAX_VALUE if there are no threads on the timer queue. This method takes no account of events.

Returns:
time in millis

getPeripheralRegistry

public static PeripheralRegistry getPeripheralRegistry()

getRunnableThreads

public static Thread[] getRunnableThreads()
Answer an array of threads that are runnable now, in the order they appear in the runnable queue.

Returns:
the runnable threads

getKeyedGlobalsMutex

public static Object getKeyedGlobalsMutex()

getKeyedGlobal

public static Object getKeyedGlobal(int key)
Return the global registered using setGlobal with key. All clients must wrap access to keyed globals in a synchronised block: synchronized (VM.getGlobalsMutex()) { // access/manipulate globals here ... }

Parameters:
key -
Returns:
the object last placed with putKeyedGlobal

putKeyedGlobal

public static Object putKeyedGlobal(int key,
                                    Object value)
Set the global registered for key. All clients must wrap access to keyed globals in a synchronised block: synchronized (VM.getGlobalsMutex()) { // access/manipulate globals here ... }

Parameters:
key -
value -
Returns:
value

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"