public abstract class Scheduler
extends java.lang.Object
Scheduler
manages Goal
s and runs
Pass
es.
The basic idea is to have the scheduler try to satisfy goals.
To reach a goal, a pass is run. The pass could modify an AST or it
could, for example, initialize the members of a class loaded from a
class file. Passes may be rerun if a goal is not reached. Goals are
processed via a worklist. A goal may have prerequisite
dependencies and corequisite dependencies. All prerequisites
must be reached before the goal is attempted. A corequisite may be
reached while satisfying the goal itself, or vice versa.
Recursive passes are not allowed. If a goal cannot be reached a
SchedulerException (or more usually the subclass
MissingDependencyException) is thrown. The scheduler catches the
exception and adds the goal back onto the worklist and adds the
missing dependency, if any, to the dependency graph. Optionally, a
pass may catch the exception, but it must mark the goal as unreachable
on this run so that it will be added back to the worklist; the pass
must also add any missing dependencies.Modifier and Type | Class and Description |
---|---|
protected static class |
Scheduler.TheEndGoal |
Modifier and Type | Field and Description |
---|---|
protected java.util.Collection<Job> |
commandLineJobs |
protected Pass |
currentPass
The currently running pass, or null if no pass is running.
|
protected static int |
dumpCounter |
protected ExtensionInfo |
extInfo |
protected boolean |
failed
True if any pass has failed.
|
protected java.util.Map<Goal,Goal> |
goals
Map from goals to goals used to intern goals.
|
protected Goal |
infiniteLoopGoal |
protected java.util.Set<Goal> |
inWorklist
Collection of uncompleted goals.
|
protected java.util.Map<Source,Job> |
jobs
A map from
Source s to Job s or to
the COMPLETED_JOB object if the Job previously
existed
but has now finished. |
protected static int |
MAX_RUN_COUNT |
protected java.util.Map<Goal,java.lang.Integer> |
runCount
Map from goals to number of times a pass was run for the goal.
|
protected java.util.LinkedList<Goal> |
worklist |
Constructor and Description |
---|
Scheduler(ExtensionInfo extInfo) |
Modifier and Type | Method and Description |
---|---|
void |
addCorequisiteDependency(Goal goal,
Goal subgoal)
Add a new corequisite
subgoal of the goal . |
void |
addCorequisiteDependencyAndEnqueue(Goal goal,
Goal subgoal) |
void |
addDependencyAndEnqueue(Goal goal,
Goal subgoal,
boolean prerequisite) |
void |
addGoal(Goal goal)
Add
goal to the worklist. |
Job |
addJob(Source source)
Add a new
Job for the Source source . |
Job |
addJob(Source source,
Node ast)
Add a new
Job for the Source source ,
with AST ast . |
void |
addPrerequisiteDependency(Goal goal,
Goal subgoal)
Add a new
subgoal of goal . |
void |
addPrerequisiteDependencyChain(java.util.List<Goal> deps)
Add prerequisite dependencies between adjacent items in a list of goals.
|
boolean |
attemptGoal(Goal goal)
Run a pass until the
goal is attempted. |
protected boolean |
attemptGoal(Goal goal,
java.util.Set<Goal> above) |
abstract Goal |
CodeGenerated(Job job) |
java.util.Collection<Job> |
commandLineJobs() |
protected void |
completeJob(Job job) |
abstract Goal |
ConstantsChecked(Job job) |
abstract Goal |
ConstructorCallsChecked(Job job) |
protected Job |
createSourceJob(Source source,
Node ast)
Create a new
Job for the given source and AST. |
Goal |
currentGoal() |
Job |
currentJob() |
Pass |
currentPass() |
abstract Goal |
Disambiguated(Job job) |
protected void |
dumpDependenceGraph()
Dump the dependence graph to a DOT file.
|
protected void |
dumpDependenceGraph(Goal g)
Dump the dependence graph to a DOT file.
|
protected void |
dumpInFlightDependenceGraph()
Dump the dependence graph to a DOT file.
|
abstract Goal |
ExceptionsChecked(Job job) |
abstract Goal |
ExitPathsChecked(Job job) |
abstract Goal |
FieldConstantsChecked(FieldInstance fi) |
abstract Goal |
ForwardReferencesChecked(Job job) |
abstract Goal |
ImportTableInitialized(Job job) |
boolean |
inInfiniteLoop() |
abstract Goal |
InitializationsChecked(Job job) |
Goal |
internGoal(Goal goal)
Intern the
goal so that there is only one copy of the goal. |
java.util.Collection<Job> |
jobs()
Return all compilation units currently being compiled.
|
Job |
loadSource(FileSource source,
boolean compile)
Load a source file and create a job for it.
|
abstract Goal |
MembersAdded(ParsedClassType ct) |
abstract Goal |
Parsed(Job job) |
boolean |
prerequisiteDependsOn(Goal goal,
Goal subgoal) |
abstract Goal |
ReachabilityChecked(Job job) |
boolean |
reached(Goal g) |
protected boolean |
runGoal(Goal goal) |
protected boolean |
runPass(Pass pass)
Run the pass
pass . |
boolean |
runToCompletion()
Attempt to complete all goals in the worklist (and any subgoals they
have).
|
abstract Goal |
Serialized(Job job) |
void |
setCommandLineJobs(java.util.Collection<Job> c) |
abstract Goal |
SignaturesDisambiguated(Job job) |
abstract Goal |
SignaturesResolved(ParsedClassType ct) |
boolean |
sourceHasJob(Source s) |
protected static java.lang.String |
statusString(boolean okay) |
abstract Goal |
SupertypesDisambiguated(Job job) |
abstract Goal |
SupertypesResolved(ParsedClassType ct) |
java.lang.String |
toString() |
abstract Goal |
TypeChecked(Job job) |
abstract Goal |
TypeExists(java.lang.String name) |
abstract Goal |
TypesInitialized(Job job) |
abstract Goal |
TypesInitializedForCommandLine() |
protected java.util.List<Goal> |
worklist() |
protected ExtensionInfo extInfo
protected java.util.Set<Goal> inWorklist
protected java.util.LinkedList<Goal> worklist
protected java.util.Map<Source,Job> jobs
Source
s to Job
s or to
the COMPLETED_JOB
object if the Job previously
existed
but has now finished. The map contains entries for all
Source
s that have had Job
s added for them.protected java.util.Collection<Job> commandLineJobs
protected java.util.Map<Goal,java.lang.Integer> runCount
protected boolean failed
protected Pass currentPass
protected static int dumpCounter
protected static final int MAX_RUN_COUNT
protected Goal infiniteLoopGoal
public Scheduler(ExtensionInfo extInfo)
public java.util.Collection<Job> commandLineJobs()
public void setCommandLineJobs(java.util.Collection<Job> c)
public void addCorequisiteDependency(Goal goal, Goal subgoal)
subgoal
of the goal
.
subgoal
is a goal on which goal
mutually
depends. The caller must be careful to ensure that all corequisite goals
can be eventually reached.public void addCorequisiteDependencyAndEnqueue(Goal goal, Goal subgoal)
public void addDependencyAndEnqueue(Goal goal, Goal subgoal, boolean prerequisite)
public void addPrerequisiteDependency(Goal goal, Goal subgoal) throws CyclicDependencyException
subgoal
of goal
.
subgoal
must be completed before goal
is
attempted.CyclicDependencyException
- if a prerequisite of subgoal
is
goal
public void addPrerequisiteDependencyChain(java.util.List<Goal> deps) throws CyclicDependencyException
CyclicDependencyException
public Goal internGoal(Goal goal)
goal
so that there is only one copy of the goal.
All goals passed into and returned by scheduler should be interned.goal
- goal
public void addGoal(Goal goal)
goal
to the worklist.public boolean reached(Goal g)
protected void completeJob(Job job)
protected java.util.List<Goal> worklist()
public boolean runToCompletion()
true
if all passes were
successfully run and all goals in the worklist were reached. The worklist
should be empty at return.public Job loadSource(FileSource source, boolean compile)
source
- The source file to load.compile
- True if the compile goal should be added for the new job.public boolean sourceHasJob(Source s)
public Job currentJob()
public Pass currentPass()
public Goal currentGoal()
public boolean attemptGoal(Goal goal)
goal
is attempted. Callers should
check goal.completed() and should be able to handle the goal not being
reached.protected boolean runGoal(Goal goal)
protected boolean runPass(Pass pass)
pass
. All subgoals of the pass's goal
required to start the pass should be satisfied. Running the pass
may not satisfy the goal, forcing it to be retried later with new
subgoals.protected static java.lang.String statusString(boolean okay)
public abstract Goal TypeExists(java.lang.String name)
public abstract Goal MembersAdded(ParsedClassType ct)
public abstract Goal SupertypesResolved(ParsedClassType ct)
public abstract Goal SignaturesResolved(ParsedClassType ct)
public abstract Goal FieldConstantsChecked(FieldInstance fi)
public abstract Goal TypesInitializedForCommandLine()
public java.util.Collection<Job> jobs()
public Job addJob(Source source)
Job
for the Source source
.
A new job will be created if
needed. If the Source source
has already been processed,
and its job discarded to release resources, then null
will be returned.public Job addJob(Source source, Node ast)
Job
for the Source source
,
with AST ast
.
A new job will be created if
needed. If the Source source
has already been processed,
and its job discarded to release resources, then null
will be returned.protected Job createSourceJob(Source source, Node ast)
Job
for the given source and AST.
In general, this method should only be called by addJob
.public java.lang.String toString()
toString
in class java.lang.Object
public boolean inInfiniteLoop()
protected void dumpDependenceGraph()
protected void dumpInFlightDependenceGraph()
protected void dumpDependenceGraph(Goal g)