Skip to content

Commit 4510d7d

Browse files
committed
Improve tracing options in JobManager and DeadlockDetector
Add the following to the .options file so that one can choose to trace these events via the preferences (General > Tracing): - jobs/yielding - jobs/yielding/detailed - jobs/blockedunblocked Do not log to sysout for the preference "jobs/locks", use the same method as other tracers. Show the name of system jobs that block other jobs in JobManager.reportBlocked(...)
1 parent 86c0357 commit 4510d7d

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

runtime/bundles/org.eclipse.core.jobs/.options

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Debugging options for the org.eclipse.core.jobs bundle
22

33
# NOTE: There is a deadlock risk when using these debug flags in a workspace
4-
# launched from Eclipse due to interaction with a lock in the debugger console.
4+
# launched from Eclipse due to interaction with a lock in the debugger console.
55
# For details: https://bugs.eclipse.org/bugs/show_bug.cgi?id=93968
66

77
# Prints debug information on running background jobs
@@ -14,4 +14,10 @@ org.eclipse.core.jobs/jobs/locks=false
1414
org.eclipse.core.jobs/jobs/errorondeadlock=false
1515
# Debug shutdown behaviour
1616
org.eclipse.core.jobs/jobs/shutdown=false
17+
# Debug jobs yielding execution so that other (blocked) jobs are given a chance to execute
18+
org.eclipse.core.jobs/jobs/yielding=false
19+
org.eclipse.core.jobs/jobs/yielding/detailed=false
20+
# Debug when jobs are blocked (by other jobs) and unblocked
21+
org.eclipse.core.jobs/jobs/blockedunblocked=false
22+
1723

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/DeadlockDetector.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ private Thread[] getThreadsOwningLock(ISchedulingRule rule) {
245245
}
246246
}
247247
if ((blocking.isEmpty()) && (JobManager.DEBUG_LOCKS)) {
248-
System.out.println("Lock " + rule + " is involved in deadlock but is not owned by any thread."); //$NON-NLS-1$ //$NON-NLS-2$
248+
JobManager.debug("Lock " + rule + " is involved in deadlock but is not owned by any thread."); //$NON-NLS-1$ //$NON-NLS-2$
249249
}
250250
if ((blocking.size() > 1) && (rule instanceof ILock) && (JobManager.DEBUG_LOCKS)) {
251-
System.out.println("Lock " + rule + " is owned by more than 1 thread, but it is not a rule."); //$NON-NLS-1$ //$NON-NLS-2$
251+
JobManager.debug("Lock " + rule + " is owned by more than 1 thread, but it is not a rule."); //$NON-NLS-1$ //$NON-NLS-2$
252252
}
253253
return blocking.toArray(new Thread[blocking.size()]);
254254
}
@@ -354,13 +354,13 @@ void lockReleased(Thread owner, ISchedulingRule lock) {
354354
//make sure the lock and thread exist in the graph
355355
if (threadIndex < 0) {
356356
if (JobManager.DEBUG_LOCKS) {
357-
System.out.println("[lockReleased] Lock " + lock + " was already released by thread " + owner.getName()); //$NON-NLS-1$ //$NON-NLS-2$
357+
JobManager.debug("[lockReleased] Lock " + lock + " was already released by thread " + owner.getName()); //$NON-NLS-1$ //$NON-NLS-2$
358358
}
359359
return;
360360
}
361361
if (lockIndex < 0) {
362362
if (JobManager.DEBUG_LOCKS) {
363-
System.out.println("[lockReleased] Thread " + owner.getName() + " already released lock " + lock); //$NON-NLS-1$ //$NON-NLS-2$
363+
JobManager.debug("[lockReleased] Thread " + owner.getName() + " already released lock " + lock); //$NON-NLS-1$ //$NON-NLS-2$
364364
}
365365
return;
366366
}
@@ -376,7 +376,8 @@ void lockReleased(Thread owner, ISchedulingRule lock) {
376376
|| lock.isConflicting(locks.get(j)))) {
377377
if (graph[threadIndex][j] == NO_STATE) {
378378
if (JobManager.DEBUG_LOCKS) {
379-
System.out.println("[lockReleased] More releases than acquires for thread " + owner.getName() + " and lock " + lock); //$NON-NLS-1$ //$NON-NLS-2$
379+
JobManager.debug("[lockReleased] More releases than acquires for thread " + owner.getName() //$NON-NLS-1$
380+
+ " and lock " + lock); //$NON-NLS-1$
380381
}
381382
} else {
382383
graph[threadIndex][j]--;
@@ -399,13 +400,15 @@ void lockReleasedCompletely(Thread owner, ISchedulingRule rule) {
399400
//need to make sure that the given thread and rule were not already removed from the graph
400401
if (threadIndex < 0) {
401402
if (JobManager.DEBUG_LOCKS) {
402-
System.out.println("[lockReleasedCompletely] Lock " + rule + " was already released by thread " + owner.getName()); //$NON-NLS-1$ //$NON-NLS-2$
403+
JobManager.debug(
404+
"[lockReleasedCompletely] Lock " + rule + " was already released by thread " + owner.getName()); //$NON-NLS-1$ //$NON-NLS-2$
403405
}
404406
return;
405407
}
406408
if (ruleIndex < 0) {
407409
if (JobManager.DEBUG_LOCKS) {
408-
System.out.println("[lockReleasedCompletely] Thread " + owner.getName() + " already released lock " + rule); //$NON-NLS-1$ //$NON-NLS-2$
410+
JobManager
411+
.debug("[lockReleasedCompletely] Thread " + owner.getName() + " already released lock " + rule); //$NON-NLS-1$ //$NON-NLS-2$
409412
}
410413
return;
411414
}
@@ -464,20 +467,20 @@ void lockWaitStop(Thread owner, ISchedulingRule lock) {
464467
//make sure the thread and lock exist in the graph
465468
if (threadIndex < 0) {
466469
if (JobManager.DEBUG_LOCKS) {
467-
System.out.println("Thread " + owner.getName() + " was already removed."); //$NON-NLS-1$ //$NON-NLS-2$
470+
JobManager.debug("Thread " + owner.getName() + " was already removed."); //$NON-NLS-1$ //$NON-NLS-2$
468471
}
469472
return;
470473
}
471474
if (lockIndex < 0) {
472475
if (JobManager.DEBUG_LOCKS) {
473-
System.out.println("Lock " + lock + " was already removed."); //$NON-NLS-1$ //$NON-NLS-2$
476+
JobManager.debug("Lock " + lock + " was already removed."); //$NON-NLS-1$ //$NON-NLS-2$
474477
}
475478
return;
476479
}
477480
if (graph[threadIndex][lockIndex] != WAITING_FOR_LOCK) {
478481
// Lock has already been granted, nothing to do...
479482
if (JobManager.DEBUG_LOCKS) {
480-
System.out.println("Lock " + lock + " already granted to depth: " + graph[threadIndex][lockIndex]); //$NON-NLS-1$ //$NON-NLS-2$
483+
JobManager.debug("Lock " + lock + " already granted to depth: " + graph[threadIndex][lockIndex]); //$NON-NLS-1$ //$NON-NLS-2$
481484
}
482485
return;
483486
}

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ final void reportBlocked(IProgressMonitor monitor, Collection<InternalJob> block
13951395
IStatus reason;
13961396
InternalJob blockingJob = blockingJobs.stream().sorted(Comparator.comparing(InternalJob::isSystem)).findFirst()
13971397
.orElse(null);
1398-
if (blockingJob == null || blockingJob instanceof ThreadJob || blockingJob.isSystem()) {
1398+
if (blockingJob == null || blockingJob instanceof ThreadJob) {
13991399
reason = new Status(IStatus.INFO, JobManager.PI_JOBS, 1, JobMessages.jobs_blocked0, null);
14001400
} else {
14011401
String msg = NLS.bind(JobMessages.jobs_blocked1, blockingJob.getName());

0 commit comments

Comments
 (0)