polyglot.frontend
Class Scheduler

java.lang.Object
  extended by polyglot.frontend.Scheduler
Direct Known Subclasses:
JLScheduler

public abstract class Scheduler
extends java.lang.Object

The Scheduler manages Goals and runs Passes. 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.

Author:
nystrom

Nested Class Summary
protected static class Scheduler.TheEndGoal
           
 
Field Summary
protected  java.util.Collection commandLineJobs
           
protected static java.lang.Object COMPLETED_JOB
           
protected  Pass currentPass
          The currently running pass, or null if no pass is running.
protected static int dumpCounter
           
protected  ExtensionInfo extInfo
           
protected  java.util.Map goals
          Map from goals to goals used to intern goals.
protected  Goal infiniteLoopGoal
           
protected  java.util.Set inWorklist
          Collection of uncompleted goals.
protected  java.util.Map jobs
          A map from Sources to Jobs 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 runCount
          Map from goals to number of times a pass was run for the goal.
protected  java.util.LinkedList worklist
           
 
Constructor Summary
Scheduler(ExtensionInfo extInfo)
           
 
Method Summary
 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 deps)
          Add prerequisite dependencies between adjacent items in a list of goals.
 boolean attemptGoal(Goal goal)
          Run a passes until the goal is attempted.
protected  boolean attemptGoal(Goal goal, java.util.Set above)
           
abstract  Goal CodeGenerated(Job job)
           
 java.util.Collection 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 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 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 worklist()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

extInfo

protected ExtensionInfo extInfo

inWorklist

protected java.util.Set inWorklist
Collection of uncompleted goals.


worklist

protected java.util.LinkedList worklist

jobs

protected java.util.Map jobs
A map from Sources to Jobs or to the COMPLETED_JOB object if the Job previously existed but has now finished. The map contains entries for all Sources that have had Jobs added for them.


commandLineJobs

protected java.util.Collection commandLineJobs

goals

protected java.util.Map goals
Map from goals to goals used to intern goals.


runCount

protected java.util.Map runCount
Map from goals to number of times a pass was run for the goal.


COMPLETED_JOB

protected static final java.lang.Object COMPLETED_JOB

currentPass

protected Pass currentPass
The currently running pass, or null if no pass is running.


dumpCounter

protected static int dumpCounter

MAX_RUN_COUNT

protected static final int MAX_RUN_COUNT
See Also:
Constant Field Values

infiniteLoopGoal

protected Goal infiniteLoopGoal
Constructor Detail

Scheduler

public Scheduler(ExtensionInfo extInfo)
Method Detail

commandLineJobs

public java.util.Collection commandLineJobs()

setCommandLineJobs

public void setCommandLineJobs(java.util.Collection c)

prerequisiteDependsOn

public boolean prerequisiteDependsOn(Goal goal,
                                     Goal subgoal)

addCorequisiteDependency

public void addCorequisiteDependency(Goal goal,
                                     Goal subgoal)
Add a new corequisite 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.


addCorequisiteDependencyAndEnqueue

public void addCorequisiteDependencyAndEnqueue(Goal goal,
                                               Goal subgoal)

addDependencyAndEnqueue

public void addDependencyAndEnqueue(Goal goal,
                                    Goal subgoal,
                                    boolean prerequisite)

addPrerequisiteDependency

public void addPrerequisiteDependency(Goal goal,
                                      Goal subgoal)
                               throws CyclicDependencyException
Add a new subgoal of goal. subgoal must be completed before goal is attempted.

Throws:
CyclicDependencyException - if a prerequisite of subgoal is goal

addPrerequisiteDependencyChain

public void addPrerequisiteDependencyChain(java.util.List deps)
                                    throws CyclicDependencyException
Add prerequisite dependencies between adjacent items in a list of goals.

Throws:
CyclicDependencyException

internGoal

public Goal internGoal(Goal goal)
Intern the goal so that there is only one copy of the goal. All goals passed into and returned by scheduler should be interned.

Parameters:
goal -
Returns:
the interned copy of goal

addGoal

public void addGoal(Goal goal)
Add goal to the worklist.


reached

public boolean reached(Goal g)

completeJob

protected void completeJob(Job job)

worklist

protected java.util.List worklist()

runToCompletion

public boolean runToCompletion()
Attempt to complete all goals in the worklist (and any subgoals they have). This method returns true if all passes were successfully run and all goals in the worklist were reached. The worklist should be empty at return.


loadSource

public Job loadSource(FileSource source,
                      boolean compile)
Load a source file and create a job for it. Optionally add a goal to compile the job to Java.

Parameters:
source - The source file to load.
compile - True if the compile goal should be added for the new job.
Returns:
The new job or null if the job has already completed.

sourceHasJob

public boolean sourceHasJob(Source s)

currentJob

public Job currentJob()

currentPass

public Pass currentPass()

currentGoal

public Goal currentGoal()

attemptGoal

public boolean attemptGoal(Goal goal)
Run a passes until the goal is attempted. Callers should check goal.completed() and should be able to handle the goal not being reached.

Returns:
false if there was an error trying to reach the goal; true if there was no error, even if the goal was not reached.

attemptGoal

protected boolean attemptGoal(Goal goal,
                              java.util.Set above)

runGoal

protected boolean runGoal(Goal goal)

runPass

protected boolean runPass(Pass pass)
Run the 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.


statusString

protected static java.lang.String statusString(boolean okay)

TypeExists

public abstract Goal TypeExists(java.lang.String name)

MembersAdded

public abstract Goal MembersAdded(ParsedClassType ct)

SupertypesResolved

public abstract Goal SupertypesResolved(ParsedClassType ct)

SignaturesResolved

public abstract Goal SignaturesResolved(ParsedClassType ct)

FieldConstantsChecked

public abstract Goal FieldConstantsChecked(FieldInstance fi)

Parsed

public abstract Goal Parsed(Job job)

TypesInitialized

public abstract Goal TypesInitialized(Job job)

TypesInitializedForCommandLine

public abstract Goal TypesInitializedForCommandLine()

ImportTableInitialized

public abstract Goal ImportTableInitialized(Job job)

SignaturesDisambiguated

public abstract Goal SignaturesDisambiguated(Job job)

SupertypesDisambiguated

public abstract Goal SupertypesDisambiguated(Job job)

Disambiguated

public abstract Goal Disambiguated(Job job)

TypeChecked

public abstract Goal TypeChecked(Job job)

ConstantsChecked

public abstract Goal ConstantsChecked(Job job)

ReachabilityChecked

public abstract Goal ReachabilityChecked(Job job)

ExceptionsChecked

public abstract Goal ExceptionsChecked(Job job)

ExitPathsChecked

public abstract Goal ExitPathsChecked(Job job)

InitializationsChecked

public abstract Goal InitializationsChecked(Job job)

ConstructorCallsChecked

public abstract Goal ConstructorCallsChecked(Job job)

ForwardReferencesChecked

public abstract Goal ForwardReferencesChecked(Job job)

Serialized

public abstract Goal Serialized(Job job)

CodeGenerated

public abstract Goal CodeGenerated(Job job)

jobs

public java.util.Collection jobs()
Return all compilation units currently being compiled.


addJob

public Job addJob(Source source)
Add a new 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.


addJob

public Job addJob(Source source,
                  Node ast)
Add a new 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.


createSourceJob

protected Job createSourceJob(Source source,
                              Node ast)
Create a new Job for the given source and AST. In general, this method should only be called by addJob.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

inInfiniteLoop

public boolean inInfiniteLoop()

dumpDependenceGraph

protected void dumpDependenceGraph()
Dump the dependence graph to a DOT file.


dumpInFlightDependenceGraph

protected void dumpInFlightDependenceGraph()
Dump the dependence graph to a DOT file.


dumpDependenceGraph

protected void dumpDependenceGraph(Goal g)
Dump the dependence graph to a DOT file.