Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 296343 - OOME error caused by java indexing referencing classloader from threadLocal
Summary: OOME error caused by java indexing referencing classloader from threadLocal
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.5.2   Edit
Assignee: Satyam Kandula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 299051 299053 299054
  Show dependency tree
 
Reported: 2009-11-27 09:49 EST by Brian Young CLA
Modified: 2011-09-14 11:35 EDT (History)
5 users (show)

See Also:
Olivier_Thomann: review+


Attachments
Image of Memory Analyzer result (102.12 KB, image/jpeg)
2009-11-30 10:26 EST, Satyam Kandula CLA
no flags Details
Probable code changes that could help (3.2 Maintenance branch) (995 bytes, patch)
2009-12-01 10:54 EST, Satyam Kandula CLA
no flags Details | Diff
Proposed patch for 3.2 maintenance stream (5.11 KB, patch)
2010-01-07 01:22 EST, Satyam Kandula CLA
Olivier_Thomann: iplog+
Olivier_Thomann: review+
Details | Diff
Proposed patch for 3.5.2 (5.15 KB, patch)
2010-01-07 04:46 EST, Satyam Kandula CLA
Olivier_Thomann: iplog+
Details | Diff
Proposed patch for 3.6 (4.70 KB, patch)
2010-01-07 04:51 EST, Satyam Kandula CLA
Olivier_Thomann: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Young CLA 2009-11-27 09:49:00 EST
User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 1.1.4322; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Build Identifier: 3.2.0.v_671 (version info on JDT jar file)

Main issue of this case is OutOfMemory issue. We identified that         
application classloader i.e. compoundClassLoader is  not freeing up even 
after application has been stopped. 

The reason we believe is thread named "java indexing" owned by Eclipse JDT component is referencing this compound classloader from it's threadLocal. And as we know threadLocal object has native reference and never been destroyed

The belief is that if compound classloader from Thread Local is not referenced the OOM will not occur

Reproducible: Always

Steps to Reproduce:
Our defect scenario can be reproduced as follows: 
- deploy a web application with JSPs to WAS 
- visit the JSPs via your browser. This will trigger JSP compilation. We suspect that the compilation uses some JDT features which then spawn the indexer thread referencing the web applications classloader
Comment 1 Olivier Thomann CLA 2009-11-27 11:27:26 EST
Satyam, please investigate.
Comment 2 Satyam Kandula CLA 2009-11-30 10:26:55 EST
Created attachment 153348 [details]
Image of Memory Analyzer result
Comment 3 Satyam Kandula CLA 2009-11-30 11:09:27 EST
The attached image seems to indicate that the compound class loader is the parent of the Indexing thread's context class loader. Thus the context class loader is probably holding up some memory, but as there will be only one index thread, it is unlikely that the memory should grow indefinitely for each application start and stop. 
I couldn't try out much with WAS server yet -- should do that and update my comments.
Comment 4 Satyam Kandula CLA 2009-12-01 10:54:53 EST
Created attachment 153477 [details]
Probable code changes that could help (3.2 Maintenance branch)

This is not a proper patch that could be applied as yet. However, I just want to propose the probable fix that could help. 

In this patch, the thread context class loader for the internal threads is being set to the class's class loader. By doing this the Indexing thread should not reference the compound class loader. 

I will generate a plugin based on this patch, which could be tried over.
Comment 5 Dani Megert CLA 2009-12-02 10:44:35 EST
It would be good to have a test case for this. Once scenario you could try to build is having a huge workspace, delete the index, start and wait until the indexer starts. Then exit. I would expect that the indexer aborts immediately and all goes well. Hence I can not quite understand why we would run into OOME due to the Java indexer.
Comment 6 Satyam Kandula CLA 2009-12-03 00:42:39 EST
(In reply to comment #5)
> Hence I can not quite understand why we would run into OOME
> due to the Java indexer.
The "Java Indexing" thread is having a reference to the context class loader, because of which that class loader and those classes are not getting garbage collected. 
WAS 6.2 seems to be using only the compiler part of the JDT Core and not really doing any indexing! It is just that the indexing thread gets created at the JDT Core plugin activation time, but I dont think it is really getting used!
Comment 7 Dani Megert CLA 2009-12-03 01:45:26 EST
>The "Java Indexing" thread is having a reference to the context class loader,
>because of which that class loader and those classes are not getting garbage
>collected. 
Sure, but the indexer gets stopped/disposed on shutdown. Why should this cause an OOME? Please explain.
Comment 8 Satyam Kandula CLA 2009-12-03 03:29:09 EST
(In reply to comment #7)
> >The "Java Indexing" thread is having a reference to the context class loader,
> >because of which that class loader and those classes are not getting garbage
> >collected. 
> Sure, but the indexer gets stopped/disposed on shutdown. Why should this cause
> an OOME? Please explain.
The JDT plugin does not seem to be getting stopped. It is not getting loaded on the application context. All the applications loaded on WAS does seem to be using the same JDT plugin.  Hence, when one application gets stopped it doesn't stop the JDT plugin and hence the indexer is still running.
Comment 9 Dani Megert CLA 2009-12-03 03:44:48 EST
OK, so is that the scenario: the server continues to run after the app is closed and JDT Core stays in memory and then *something* causes an OOME?

If that's the case then I suspect that your fix will not do the trick because JDT Core will not know that the app is closed and will therefore keep holding on to the types that are cached in its model.
Comment 10 Satyam Kandula CLA 2009-12-03 04:43:11 EST
I don't think the model is being used at all. It looks like the compiler is the only one that is being used by the server. Well, I have to say -- I am not sure!

Yes, you are right there could be some significant JDT memory that is being still hold and as the server and the Eclipse version that is being used are pretty old, I am being conservative and trying to address only the problem that is stated. 

BTW, I have given the plugin patch to the customer and waiting for the feedback - I was having problem accessing bugzilla and hence just send it directly.
Comment 11 Dani Megert CLA 2009-12-03 04:52:05 EST
>BTW, I have given the plugin patch to the customer and waiting for the feedback
>- I was having problem accessing bugzilla and hence just send it directly.
Yes, I saw it. Let's wait for their feedback before spending more time on this.
Comment 12 Satyam Kandula CLA 2010-01-07 01:22:45 EST
Created attachment 155475 [details]
Proposed patch for 3.2 maintenance stream
Comment 13 Satyam Kandula CLA 2010-01-07 04:46:19 EST
Created attachment 155478 [details]
Proposed patch for 3.5.2
Comment 14 Satyam Kandula CLA 2010-01-07 04:51:25 EST
Created attachment 155479 [details]
Proposed patch for 3.6
Comment 15 Olivier Thomann CLA 2010-01-07 09:01:30 EST
Patch looks good.
Comment 16 Olivier Thomann CLA 2010-01-07 09:42:51 EST
Released for 3.6M5.
Comment 17 Olivier Thomann CLA 2010-01-07 10:58:40 EST
Released for 3.5.2.
Added regression test:
org.eclipse.jdt.core.tests.model.JavaSearchBugsTests#testBug296343
Comment 18 Olivier Thomann CLA 2010-01-07 11:33:21 EST
Bug cloned for 3.4.2+ release (bug 299051)
Bug cloned for 3.3.2+ release (bug 299053)
Bug cloned for 3.2.2+ release (bug 299054)
Comment 19 Srikanth Sankaran CLA 2010-01-21 06:25:32 EST
Verified for 3.5.2 RC2 by code inspection.
Comment 20 Olivier Thomann CLA 2011-09-14 11:35:05 EDT
Verified for 3.8M2 by code inspection.