Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 334651

Summary: Deadlock reported during startup of cdt.debug.ui
Product: [Tools] CDT Reporter: Anton Leherbauer <aleherb+eclipse>
Component: cdt-debugAssignee: Patrick Chuong <pchuong>
Status: RESOLVED FIXED QA Contact: Ken Ryall <ken.ryall>
Severity: major    
Priority: P3 CC: cdtdoug, marc.khouzam, pawel.1.piech, pchuong
Version: 8.0   
Target Milestone: 8.0   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
fix
pchuong: iplog-, pchuong: review?
Fix #2 aleherb+eclipse: iplog-

Description Anton Leherbauer CLA 2011-01-18 09:48:12 EST
While loading class "org.eclipse.cdt.debug.internal.ui.pinclone.PinCloneUtils", thread "Thread[main,6,main]" timed out waiting (5000ms) for thread "Thread[Worker-2,5,main]" to finish starting bundle "org.eclipse.cdt.debug.ui_7.1.0.qualifier [39]". To avoid deadlock, thread "Thread[main,6,main]" is proceeding but "org.eclipse.cdt.debug.internal.ui.pinclone.PinCloneUtils" may not be fully initialized.

Root exception:
org.eclipse.osgi.framework.internal.core.AbstractBundle$BundleStatusException
at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1075)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:285)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:268)
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:106)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:453)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:476)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.eclipse.cdt.debug.internal.ui.pinclone.ViewIDCounterManager$1.runInUIThread(ViewIDCounterManager.java:79)
at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:95)
[...]


This is a known problem with the Sun/Oracle JVM during startup when one thread is activating a bundle and another thread tries to load classes from that bundle.
See e.g. bug 36358, bug 86713 and bug 209920.
The usual solution is to schedule all background jobs/threads at the very end of the start() method in the Activator.
Comment 1 Marc Khouzam CLA 2011-01-18 09:51:24 EST
Awesome, Patrick and I were just looking into that.

Toni, how did you see this problem?  We saw it when trying to run the DSF-GDB JUnit tests.  See bug 334650.
Comment 2 Anton Leherbauer CLA 2011-01-18 10:23:22 EST
(In reply to comment #1)
> Awesome, Patrick and I were just looking into that.
> 
> Toni, how did you see this problem?  We saw it when trying to run the DSF-GDB
> JUnit tests.  See bug 334650.

Nice coincidence.
I saw it during normal startup from the workspace, but only once so far.  It depends on the timing and which views are open, I'd guess.
Comment 3 Anton Leherbauer CLA 2011-01-18 10:35:16 EST
When I launch into the Debug perspective and the Breakpoints view is open with a few C/C++ Breakpoints and no C/C++ Editor, I can reproduce it about every other time.  At least this activates the cdt.debug.ui on a worker thread instead of the UI thread.
Comment 4 Patrick Chuong CLA 2011-01-18 10:44:53 EST
Created attachment 187008 [details]
fix

Toni, Marc, can you test this patch when you have a chance? Thanks.
Comment 5 Anton Leherbauer CLA 2011-01-18 10:52:21 EST
(In reply to comment #4)
> Created attachment 187008 [details]
> fix
> 
> Toni, Marc, can you test this patch when you have a chance? Thanks.

Thanks Patrick, I did not try your patch, but I assume it would work.  I think the synchronized (fInitialized) is problematic, though, because fInitialized changes.
I have a patch ready for CDebugUIPlugin which leaves ViewIDCounterManager unchanged and also makes sure all other background initialization is done safely.
Comment 6 Anton Leherbauer CLA 2011-01-18 10:55:20 EST
Created attachment 187012 [details]
Fix #2

I'd suggest this solution.
Comment 7 Patrick Chuong CLA 2011-01-18 11:02:52 EST
I was thinking of doing the same, but try to minimized the number of changes. I have committed your fix to HEAD. Thanks for the patch.
Comment 8 CDT Genie CLA 2011-01-18 11:23:05 EST
*** cdt cvs genie on behalf of pchuong ***
Bug 334651 - Deadlock reported during startup of cdt.debug.ui

[*] CDebugUIPlugin.java 1.72 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java?root=Tools_Project&r1=1.71&r2=1.72