Skip to content

Commit

Permalink
Remove recycling of ThreadJob in ImplicitJobs eclipse-platform#724
Browse files Browse the repository at this point in the history
The JobManager uses the ImplicitJobs implementation to spawn internal
jobs for the execution on a specific ISchedulingRule within an executed
job. This implementation creates instances of ThreadJob. These instances
are reused, such that the same ThreadJob instance is reused for
different rules and potentially different jobs. This is achieved by a
recycle functionality, which caches a ThreadJob for reuse once it is not
used anymore. This functionality results in the same job occurring with
different rules at different places and points in time. This is both
unexpected and error prone.

Since this reuse functionality only seems to be a performance
improvement whose value does nowadays not outweigh the added complexity
and risk of error, this change removes the recycling functionality.

Fixes eclipse-platform#724.
  • Loading branch information
HeikoKlare committed Sep 30, 2023
1 parent 823a56b commit 5f450df
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
*/
class ImplicitJobs {

/**
* Cached unused instance that can be reused
* @GuardedBy("this")
*/
private ThreadJob jobCache = null;
protected JobManager manager;

/**
Expand Down Expand Up @@ -77,9 +72,9 @@ void begin(ISchedulingRule rule, IProgressMonitor monitor, boolean suspend) {
//create a thread job for this thread, use the rule from the real job if it has one
Job realJob = manager.currentJob();
if (realJob != null && realJob.getRule() != null)
threadJob = newThreadJob(realJob.getRule());
threadJob = new ThreadJob(realJob.getRule());
else {
threadJob = newThreadJob(rule);
threadJob = new ThreadJob(rule);
threadJob.acquireRule = true;
}
//don't acquire rule if it is a suspended rule
Expand Down Expand Up @@ -172,7 +167,6 @@ private void endThreadJob(ThreadJob threadJob, boolean resume, boolean worker) {
//if the job was started, we need to notify job manager to end it
if (threadJob.isRunning())
manager.endJob(threadJob, Status.OK_STATUS, false, worker);
recycle(threadJob);
}

/**
Expand All @@ -188,25 +182,6 @@ private boolean isSuspended(ISchedulingRule rule) {
return false;
}

/**
* Returns a new or reused ThreadJob instance.
* @GuardedBy("this")
*/
private ThreadJob newThreadJob(ISchedulingRule rule) {
if (jobCache != null) {
ThreadJob job = jobCache;
// calling setRule will try to acquire JobManager.lock, breaking
// lock acquisition protocol. Since we managing this special job
// ourselves we can call internalSetRule
((InternalJob) job).internalSetRule(rule);
job.acquireRule = job.isRunning = false;
job.realJob = null;
jobCache = null;
return job;
}
return new ThreadJob(rule);
}

/**
* A job has just finished that was holding a scheduling rule, and the
* scheduling rule is now free. Wake any blocked thread jobs so they can
Expand All @@ -218,15 +193,6 @@ void notifyWaitingThreadJobs(InternalJob job) {
}
}

/**
* Indicates that a thread job is no longer in use and can be reused.
* @GuardedBy("this")
*/
private void recycle(ThreadJob job) {
if (jobCache == null && job.recycle())
jobCache = job;
}

/**
* Implements IJobManager#resume(ISchedulingRule)
* @param rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,30 +417,6 @@ void push(final ISchedulingRule rule) {
}
}

/**
* Reset all of this job's fields so it can be reused. Returns false if
* reuse is not possible
* @GuardedBy("JobManager.implicitJobs")
*/
boolean recycle() {
//don't recycle if still running for any reason
if (getState() != Job.NONE) {
return false;
}
//clear and reset all fields
acquireRule = isRunning = isBlocked = false;
realJob = null;
setRule(null);
setThread(null);
if (ruleStack.length != 2) {
ruleStack = new ISchedulingRule[2];
} else {
ruleStack[0] = ruleStack[1] = null;
}
top = -1;
return true;
}

@Override
public IStatus run(IProgressMonitor monitor) {
synchronized (this) {
Expand Down

0 comments on commit 5f450df

Please sign in to comment.