|
PenProfile 2.x | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.cldc.isolate.Isolate
public final class Isolate
The
Last modified: 05/03/31 13:22:49.Note: this document is still a draft. Details in the API are subject to change.
Isolate class provides the means of creating and managing
isolated computations and arranging for their communication with each
other.
When two Isolate objects represent the same task, they are said to
be equivalent to each other. Equivalent Isolate objects are
created to avoid the sharing of Isolate objects across task
boundaries. For example, in the following program, task A launches
task B using the object b1, and task B gets a
reference to itself using the object
b2. b1 and b2 are two
distinct objects:
class TaskA {
void launchB() {
Isolate b1 = new Isolate("TaskB", ....);
b1.start();
}
}
class TaskB {
public static void main(String args[]) {
Isolate b2 = Isolate.currentIsolate();
}
}
synchronized static method uses a different
monitor object inside each task.
Part of the definition of an isolate is its classpath, where the basic classes for the isolate are found. The CLDC runtime searches for classes in three sets of locations:
System and application class paths are specified separately for an isolate when it is created. Classes on system and application class paths have different access rights:
When an isolate requests a class, the class is first looked up the romized system classes, then searched in the isolate system class path, and then searched in the isolate application class path.
User application classes should be put on the application class path, system class path can contain only trusted system classes.
WARNING: UNTRUSTED USER APPLICATION CLASSES MUST NEVER BE PUT ON THE
SYSTEM CLASS PATH, AS IT GRANTS THEM ACCESS TO SYSTEM INTERNALS AND BREAKS
SYSTEM SECURITY.
Object Sharing
The Isolate API in CLDC does not support the sharing of arbitrary
Java object across Isolate boundaries. The only exception is String
objects: String objects may be passed as arguments from a parent
isolate to a child isolate's main() method. Such
Strings are passed by reference instead of by value in order to
conserve resource. Also, interned Strings (such as literal Strings
that appear inside Java source code) may be shared across Isolate
boundaries.
Even though String objects may be shared across isolates, different isolates should not attempt to coordinate their activities by synchronizing on these Strings. Specifically, an interned Strings cannot be synchronized across isolate boundaries because it uses a different monitor object in each Isolate.
Some CLDC/MIDP implementors may be tempted to use native code to
pass shared objects from one isolate to another, and use
traditional Java object-level synchronization to perform
inter-isolate communication. In our experience this could easily
lead to inter-isolate deadlock that could be exploited by
downloaded malicious Midlets. For example, if a shared object is
used to synchronize screen painting, a malicious Midlet may stop
other Midlets from painting by not returning from its
paint() method.
In our experience, with shared objects, it would take significant effort to design a system that can prevent such attacks. In contrast, event queues are much more easily understood to design a safe environment. Thus, we strongly recommend against using shared objects for inter-isolate communication.
The following code is an example of how an isolate can create other isolates:
import com.sun.cldc.isolate.*;
class HelloWorld {
// Usage: cldc_vm -classpath HelloWorld HelloWorld2
public static void main(String [] argv) {
System.out.println("HelloWorld");
for (int i = 0; i < 6; i++) {
try {
// pass i as an argument to the isolate just for fun
String[] isoArgs = {Integer.toString(i)};
Isolate iso = new Isolate(argv[0], isoArgs);
iso.start();
} catch (Exception e) {
System.out.println("caught exception " + e);
e.printStackTrace();
}
System.out.println("HelloWorld: Iso " + i + " started.");
}
}
}
class HelloWorld2 {
static String st = "HelloWorld2[";
public static void main(String [] argv) {
st = st.concat(argv[0]);
st = st.concat("]");
System.out.println("st is " + st);
System.exit(42);
}
}
javax.isolate.IsolateStartupException| Field Summary | |
|---|---|
static int |
MAX_PRIORITY
The maximum priority that an Isolate can have. |
static int |
MIN_PRIORITY
The minimum priority that an Isolate can have. |
static int |
NORM_PRIORITY
The default priority that is assigned to an Isolate. |
| Constructor Summary | |
|---|---|
Isolate(String mainClass,
String[] mainArgs)
Creates a new isolated java application with a default configuration. |
|
Isolate(String mainClass,
String[] mainArgs,
String[] app_classpath)
Creates a new isolated java application with a default configuration. |
|
Isolate(String mainClass,
String[] mainArgs,
String[] app_classpath,
String[] sys_classpath)
Creates a new Isolate with the specified arguments and classpath. |
|
| Method Summary | |
|---|---|
void |
attachDebugger()
|
static Isolate |
currentIsolate()
Returns the Isolate object corresponding to the currently executing task. |
void |
exit(int status)
Requests normal termination of this Isolate. |
int |
exitCode()
Returns the exit code of the isolate. |
String[] |
getClassPath()
Returns the classpath the Isolate was started with. |
static Isolate[] |
getIsolates()
Returns an array of Isolate objects representing
all tasks that have been started but have not terminated. |
int |
getPriority()
Returns the priority of this isolate. |
void |
halt(int status)
Forces termination of this Isolate. |
int |
id()
Returns a small integer ID that uniquely identifies this Isolate among the current set of active Isolates. |
boolean |
isDebuggerConnected()
Indicates if debugger connection is established with the VM. |
boolean |
isSuspended()
Returns if this isolate has been suspended. |
boolean |
isTerminated()
Returns true if this Isolate is terminated. |
int |
reservedMemory()
|
void |
resume()
The opposite of the suspend method. |
void |
setAPIAccess(boolean access)
Sets the access to Isolate API for this Isolate. |
void |
setDebug(boolean mode)
|
void |
setHiddenPackages(String[] package_names)
Sets the packages which will be hidden. |
void |
setMemoryQuota(int reserved)
Sets the object heap memory reserved and maximum limits to the same value. |
void |
setMemoryQuota(int reserved,
int total)
Sets the object heap memory quota for this Isolate. |
void |
setPriority(int new_priority)
Adjust the priority of this Isolate. |
void |
setProfile(String profile)
Sets active profile name for isolate. |
void |
setRestrictedPackages(String[] package_names)
Sets the packages which will be restricted. |
void |
setUseProfiler(boolean useProfiler)
Sets whether isolate should be profiled or not. |
void |
setUseVerifier(boolean verify)
Controls whether or not classes for this isolate need to be verified. |
void |
start()
Start execution of this Isolate. |
void |
suspend()
Suspends all threads in this isolate from execution. |
int |
totalMemory()
|
long |
uniqueId()
Returns a 64-bit ID that uniquely identifies this Isolate. |
int |
usedMemory()
This function returns the approximate amount of object heap memory currently used by this Isolate. |
void |
waitForExit()
Blocks the execution of the calling thread until this Isolate has exited. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MIN_PRIORITY
public static final int NORM_PRIORITY
public static final int MAX_PRIORITY
| Constructor Detail |
|---|
public Isolate(String mainClass,
String[] mainArgs)
throws IsolateStartupException
This constructor has the same effect as invoking
Isolate(String,String[],String[])
and passing null for the app_classpath
and sys_classpath parameters.
See the long constructor documentation for more details.
mainClass - fully qualified name of the main method classmainArgs - the arguments of the main method in the new isolate
IsolateStartupException - if an error occurs in the configuration
or startup of the new isolate before any application code is invoked
public Isolate(String mainClass,
String[] mainArgs,
String[] app_classpath)
throws IsolateStartupException
This constructor has the same effect as invoking
Isolate(String,String[],String[], String[])
and passing null for the sys_classpath
parameter.
See the long constructor documentation for more details.
mainClass - fully qualified name of the main method classmainArgs - the arguments of the main method in the new isolateapp_classpath - the application classpath(s) for the isolate
(see Class path)
IsolateStartupException - if an error occurs in the configuration
or startup of the new isolate before any application code is invoked
public Isolate(String mainClass,
String[] mainArgs,
String[] app_classpath,
String[] sys_classpath)
throws IsolateStartupException
The new isolate will execute the main method of
class mainClass with arguments
mainArgs. The mainClass parameter
must reference a class present in the romized system classes,
or in one of the classpath elements specified by the
sys_classpath and app_classpath parameters.
When the constructor returns, the new isolate is not yet
running. The new isolate does not start execution until the
start method is invoked. The halt
and exit methods will fail if before
start is invoked.
Class resolution and loading are performed in the new task
represented by this new isolate. Any loading exceptions (such as
ClassNotFoundException), including the loading
exception of the specified mainClass, will occur
inside the new task when it is started, not the creator task.
Changes made to any of the constructor's parameters after control returns from this constructor will have no effect on the newly created isolate.
If mainArgs is null, a zero-length
String array will be provided to the main method
of mainClass.
User application classes should be put on app_classpath,
while sys_classpath can contain only trusted system
classes.
WARNING: UNTRUSTED USER APPLICATION CLASSES MUST NEVER BE PUT ON THE SYSTEM CLASS PATH, AS IT GRANTS THEM ACCESS TO SYSTEM INTERNALS AND BREAKS SYSTEM SECURITY.
mainClass - fully qualified name of the main method classmainArgs - the arguments of the main method in the new isolateapp_classpath - the application classpath(s) for the isolatesys_classpath - the system classpath(s) for the isolate
(see Class path)
IsolateStartupException - if an error occurs in the configuration
of the new isolate before any application code is invoked
IllegalArgumentException - if any parameters are found to be
invalid.| Method Detail |
|---|
public void start()
throws IsolateStartupException
Isolate. Any code that belongs
to this Isolate (including static initializers)
is executed only after this method is called.
Control will return from this method when the new isolate's first user level thread starts executing, or if an error occurs during the initialization of the new isolate.
If any exception is thrown by this method, no code in the
Isolate will have executed.
Errors such as the main class being invalid or not visible in the classpath will occur handled within the new isolate.
IsolateStartupException - if an error occurs in the
initialization or configuration of the new isolate
before any application code is invoked, or if this
Isolate was already started or is terminated.
IsolateResourceError - if systems exceeds maximum Isolate count
OutOfMemoryError - if the reserved memory cannot be allocatedpublic void exit(int status)
Isolate.
Invocation of this method is equivalent to causing the isolate
to invoke Runtime.exit(int). If this method
invocation is, in fact, the cause of the isolate's termination,
the status supplied will be the isolate's
termination status.
No exception is thrown if this isolate is already
terminated. Even if isTerminated() returns false prior
to invoking exit, an invocation of exit may
occur after the isolate exits on its own or is terminated by
another isolate. In these cases, the actual exit code reported by
the isolate may be different from status.
If this isolate is not yet started, it will be marked as
already terminated. A subsequent invocation to start() would
result in an IsolateStartupException.
If this isolate is suspended, it will be terminated without being resumed.
status - Termination status. By convention, a nonzero status
code indicates abnormal termination.public void halt(int status)
Isolate.
If this method invocation is in fact the cause of the isolate's
termination, the status supplied will be the
isolate's termination status.
No exception is thrown if this isolate is already
terminated. Even if isTerminated() returns false prior
to invoking halt, an invocation of halt may
occur after the isolate exits on its own or is terminated by
another isolate. In these cases, the actual exit code reported by
the isolate may be different from status.
If this isolate is not yet started, it will be marked as
already terminated. A subsequent invocation to start() would
result in an IsolateStartupException.
If this isolate is suspended, it will be terminated without being resumed.
status - Termination status. By convention, a nonzero status code
indicates abnormal termination.public boolean isTerminated()
Isolate is terminated.
public static Isolate currentIsolate()
This method never returns null.
Isolate object for the current taskpublic static Isolate[] getIsolates()
Isolate objects representing
all tasks that have been started but have not terminated.
New tasks may have been constructed or existing ones
terminated by the time this method returns.
Isolate objects at the time
of the callpublic int id()
public long uniqueId()
public int reservedMemory()
public int totalMemory()
public int usedMemory()
public void setMemoryQuota(int reserved)
reserved - The minimum amount of memory guaranteed to be
available to the isolate at any time. Also the total
amount of memory that the isolate can reserve.
public void setMemoryQuota(int reserved,
int total)
reserved - The minimum amount of memory guaranteed to be
available to the isolate at any time.total - The total amount of memory that the isolate can
reserve.public void setPriority(int new_priority)
new_priority - must be between MIN_PRIORITY
and MAX_PRIORITY, or else this method call will
have no effect.public int getPriority()
public boolean isSuspended()
public void suspend()
public void resume()
suspend method.
This method will resume the isolate only if the isolate is
currently started, suspended and not terminated. Otherwise this
method has no effect.
public int exitCode()
public void waitForExit()
waitForExit() is called on the
current Isolate, the result is undefined.
InterruptedException - (unimplemented yet): if CLDC
Specification 1.1 is enabled, when a thread is blocked
inside this method, it may be interrupted by an
invocation of Thread.interrupt, in which case an
InterruptedException is thrown regardless of the
termination status of this Isolate.public String[] getClassPath()
public void setAPIAccess(boolean access)
false. If the AMS calls this method after the Isolate
has started, it has no effect.In additional, after an Isolate has started, if it has access to the Isolate API, it can call this method to disable it. However, once it loses the access, attempts to call this method would result in a SecurityException.
public void setDebug(boolean mode)
public void attachDebugger()
public boolean isDebuggerConnected()
public void setUseVerifier(boolean verify)
false. This method should be called
before the Isolate is started.
public void setProfile(String profile)
throws IllegalArgumentException,
IllegalIsolateStateException
IllegalIsolateStateException.
The method also determines if profile
is a name of existing profile which is defined in ROM
configuration file. If not, throws runtime
IllegalArgumentException.
profile - The new active profile name.
IllegalArgumentException
IllegalIsolateStateException
public void setHiddenPackages(String[] package_names)
throws IllegalIsolateStateException
IllegalIsolateStateException.
package_name. - The name of package for marking.
IllegalIsolateStateException
public void setRestrictedPackages(String[] package_names)
throws IllegalIsolateStateException
IllegalIsolateStateException.
package_name - The name of package for marking.
IllegalIsolateStateExceptionpublic void setUseProfiler(boolean useProfiler)
|
PenProfile 2.x | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||