Bug 403552 - [implementation] Use a thread pool or jobs for short-life threads
Summary: [implementation] Use a thread pool or jobs for short-life threads
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.2.2   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-16 14:03 EDT by Nathan Reynolds CLA
Modified: 2013-03-18 11:33 EDT (History)
3 users (show)

See Also:


Attachments
Thread.start() Call Stack Tree (1005.33 KB, text/plain)
2013-03-16 14:03 EDT, Nathan Reynolds CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Reynolds CLA 2013-03-16 14:03:09 EDT
I noticed that Eclipse IDE will create a lot of short-lived threads.  If this happens too quickly, then Eclipse will report out of native memory and can not create a new thread.  From there, the IDE's health degrades quickly and becomes unusable.  It eventually has to be killed.

The problem is that each time a thread is created, the address range for its stack is allocated.  When the thread dies, the stack space is not cleaned up immediately by the JVM.  Instead, the stack space won't be cleaned up until the next full GC.  These dead stacks accumulate and cause the above error.  Unfortunately, the JVM won't trigger a full GC if it can't find space for a new thread's stack.

The solution is to use thread pools for short-lived threads.  This will not only prevent the error, but it will also improve performance since a thread can immediately begin executing the task.

I used BTrace to record the call stack each time Thread.start() is called.  I then aggregated these call stacks into a tree (attached).  The numbers in () tell how many threads were created on that branch of the tree.  The BTrace script detected 1562 threads started!  66% of the threads are being created in org.eclipse.jface.text.source.projection.ProjectionSummary$Summarizer.<init>.

Here's a list of the top offenders.  I am not sure which areas these belong to.  Please file a separate bug for each one.  I suspect some of these could be grouped together.

(1027) org.eclipse.jface.text.source.projection.ProjectionSummary$Summarizer.<init>
(114) org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView.computeAndDoSetInput
(103) org.eclipse.jface.text.contentassist.ContentAssistant$AutoAssistListener.start
(97) org.eclipse.jface.text.contentassist.AdditionalInfoController$Timer.<init>
(43) java.util.Timer.<init>
(36) org.eclipse.jface.text.TextViewerHoverManager.computeInformation
(30) java.lang.ref.Finalizer$1.run
(23) org.eclipse.core.internal.jobs.WorkerPool.jobQueued
(21) org.eclipse.jface.text.reconciler.AbstractReconciler.startReconciling
(15) org.eclipse.jdt.internal.compiler.ProcessTaskManager.<init>
(9) org.eclipse.jface.text.source.AnnotationModel.cleanup
Comment 1 Nathan Reynolds CLA 2013-03-16 14:03:51 EDT
Created attachment 228532 [details]
Thread.start() Call Stack Tree
Comment 2 Jay Arthanareeswaran CLA 2013-03-17 12:57:06 EDT
Since most of the listed ones concern the UI, I am moving this to JDT/UI and requesting Markus to take a call on this.