Class cornell.slk.jkernel.core.Task
Source code
java.lang.Object
|
+----cornell.slk.jkernel.core.Task
- public final class Task
- extends java.lang.Object
A J-Kernel Task is a collection of classes, objects, and
thread segments, clearly separated from other tasks.A task keeps track of all child tasks spawned by the
task, as well as all capabilities generated by the
task, so that when the task is terminated, all the
task's children are terminated, and all the task's
capabilities are revoked. This prevents capabilities
from being garbage collected (and thus prevents the
target objects pointed to by the capabilities from
being garbage collected) until the capabilities are
explicitly revoked.
Field Summary
|
java.util.Vector
|
capabilities
|
java.util.Vector
|
children
|
RefSetCache
|
classCheckTable
The fast copy routines, like the serialization routines,
only work if the task that an object is copied to can
find the object's class (this was a deliberate design
choice to prevent one task from injecting malicious code
into another task).
|
boolean
|
dead
|
java.io.PrintStream
|
errStream
|
int
|
id
|
boolean
|
nativeCodeEnabled
|
TaskClassNodeLoader
|
nodeLoader
A task's nodeLoader is responsible for managing
all the classes defined or used by this task.
|
Task
|
parent
|
boolean
|
seeded
|
java.lang.Object
|
taskStateLock
The task state lock must be acquired to create a capability,
create a thread, spawn a subtask, or terminate the task.
|
Constructor Summary
|
Task(Resolver resolver,
Task parent)
|
Task(Resolver resolver)
This creates a new task, which is a subtask of the
current task.
The resolver maps class names to bytecode in cases where
the system loader cannot find a class with a given name.
When a task is first created, it contains no objects, no
classes, and and no threads.
|
Methods inherited from class java.lang.Object
|
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
parent
Task parent
children
java.util.Vector children
capabilities
java.util.Vector capabilities
id
int id
nodeLoader
TaskClassNodeLoader nodeLoader
- A task's nodeLoader is responsible for managing
all the classes defined or used by this task.
classCheckTable
RefSetCache classCheckTable
- The fast copy routines, like the serialization routines,
only work if the task that an object is copied to can
find the object's class (this was a deliberate design
choice to prevent one task from injecting malicious code
into another task). This hash table serves as a
cache to see whether a class has already been
found in this task.
seeded
boolean seeded
nativeCodeEnabled
boolean nativeCodeEnabled
taskStateLock
java.lang.Object taskStateLock
- The task state lock must be acquired to create a capability,
create a thread, spawn a subtask, or terminate the task.
dead
boolean dead
errStream
java.io.PrintStream errStream
Task
Task(Resolver resolver,
Task parent)
Task
public Task(Resolver resolver)
- This creates a new task, which is a subtask of the
current task.
The resolver maps class names to bytecode in cases where
the system loader cannot find a class with a given name.
When a task is first created, it contains no objects, no
classes, and and no threads. The task must be seeded with
an object in order for any objects to exist in the
task, and the seed object must be invoked in order
for control to pass into the task.
enableNativeCode
public void enableNativeCode() throws java.lang.SecurityException
- Enable a new task to load native code. This method
should be called immediately after a new task is
created, before the new task is seeded. This method
will only work if the current task also has the
right to load native code. Otherwise, a SecurityException
is thrown
seed
public Capability seed(java.lang.String className) throws RemoteException
- Creates an object in a new task, and returns a Capability
to that object.
When a task is first created, it contains no objects
and no threads. The new task must be seeded with
an object in order for any objects to exist in the
new task, and the seed object must be invoked in order
for control to pass into the new task.
The seed method creates a new object of the class
given by the fully qualified class name "className" in the new task
(this name is resolved in to a Class object in
the new task). This class must be public, it must implement
a remote interface, and it must have a public constructor
taking no arguments. The seed method creates a
capability for the new object and returns this
capability.
The seed method can only be called once for each task.
Any calls to seed after the first call will result
in a SecurityException.
currentTask
public static Task currentTask()
- Returns the current task.
terminate
public void terminate() throws java.lang.SecurityException
- Shut down a task. When a task is terminated, all of
its child tasks are revoked, all of its capabilities
are revoked, and all of its thread segments are killed.
terminateInternal
void terminateInternal()
getRepository
public static Repository getRepository()
- Return the system repository. The repository is shared
among all tasks, and is used to export capabilities from
one task to another.
The following are standard entries in the repository:
- /system/standardResolver - This is a Resolver
that loads bytecode from the classpath specified as
an argument to Main.main when the VM was started.
setRepository
public static void setRepository(Repository r) throws java.lang.SecurityException
getClass
public static java.lang.Class getClass(java.lang.String className) throws java.lang.ClassNotFoundException
- Returns the Class object associated with a name in the
current task. In each task, a class name can
be mapped to at most one Class object. If getClass
does not have a Class object for a certain name,
it will query the task's resolvers to find bytecode
for the name, or to find an existing shared class.
If it finds the bytecode, it will create
a new Class object based on the bytecode and return it.
If it finds a shared class, it will use the shared class.
Otherwise, getClass throws a ClassNotFoundException
"className" must be a fully qualified class name.
shareClass
public static SharedClass shareClass(java.lang.String className) throws java.lang.ClassNotFoundException
- Creates a SharedClass object for a class so that
other tasks can share the class. For any class
in the current task, calling shareClass with the
name of the class creates a SharedClass object that
can be passed to other tasks. Other tasks'
resolvers can use the SharedClass object to use
the class.
Shared class cannot have static
fields. In addition, any class referred to by a
shared class must also be shared.
Shared classes generally fall into one of two
categories:
- Small, simple, serializable or fast-copy classes whose objects
can be passed by copy in remote invocations.
- Remote interface classes that serve as front
ends for more complicated services.
"className" must be a fully qualified class name.
addResolver
public static void addResolver(Resolver resolver)
- addResolver appends a resolver to the current task's
list of resolvers. When a task is looking
for bytecode for a class name, it queries each
of its resolvers in its list of resolvers, in
order, until one of the resolvers returns
bytecode for the given name. addResolver puts
a new resolver at the end of this list, which means
the new resolver only gets a chance to resolve
a name if the previous resolvers could not find
bytecode for the name.
getDebugStream
public static java.io.PrintStream getDebugStream()
- For debugging purposes only. This method may be
eliminated eventually.
setErrorStream
public static void setErrorStream(java.io.PrintStream errStream)
- Set the stream that errors generated by J-Kernel
get dumped to. By default, this is set to
the system's System.out.
toString
public java.lang.String toString()
- Overrides:
- toString in class java.lang.Object
addCapability
int addCapability(Capability c)
removeCapability
void removeCapability(int id)
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException