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

Bug 342217

Summary: Opening a corrupted workspace causes CDT parser to use up all java heap
Product: [Tools] CDT Reporter: Martin Swiezawski <marcin.swiezawski>
Component: cdt-parserAssignee: Project Inbox <cdt-parser-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: normal    
Priority: P3 CC: cdtdoug, yevshif
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Martin Swiezawski CLA 2011-04-07 16:07:11 EDT
Build Identifier: Helios SR1

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=149121 for background information. 
I have a workspace that exhibits bug described in above bugzilla, I have tried the workaround described in comment #50. This in turn causes the issue where the parser seems to get into a loop and uses up entire java heap, which then triggers a message asking user to exit the workbench. Thus if 149121 is fixed with workaround described in comment #50, then CDT could trigger this issue. I am not sure if this is project specific or not. 


Workspace .log file contains this call stack. I have also attached the workspace that exhibits this issue. 

!ENTRY org.eclipse.core.jobs 4 2 2011-04-07 14:35:17.078
!MESSAGE An internal error occurred during: "Computing Macro Expansion".
!STACK 0
java.lang.OutOfMemoryError: Java heap space
	at java.util.ArrayList.ensureCapacity(Unknown Source)
	at java.util.ArrayList.add(Unknown Source)
	at org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.getMacros(PDOMFile.java:580)
	at org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider.collectFileContent(IndexBasedFileContentProvider.java:174)
	at org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider.getContentForInclusion(IndexBasedFileContentProvider.java:125)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor$1.checkFile(CPreprocessor.java:103)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor$1.checkFile(CPreprocessor.java:1)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.findInclusion(CPreprocessor.java:935)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.executeInclude(CPreprocessor.java:1251)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.executeDirective(CPreprocessor.java:1067)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.internalFetchToken(CPreprocessor.java:726)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.fetchToken(CPreprocessor.java:469)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.nextToken(CPreprocessor.java:563)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.fetchToken(AbstractGNUSourceCodeParser.java:260)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.nextToken(AbstractGNUSourceCodeParser.java:284)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.acceptInactiveCodeBoundary(AbstractGNUSourceCodeParser.java:345)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.declarationList(AbstractGNUSourceCodeParser.java:1283)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parseTranslationUnit(AbstractGNUSourceCodeParser.java:1253)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.translationUnit(AbstractGNUSourceCodeParser.java:1248)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parse(AbstractGNUSourceCodeParser.java:645)
	at org.eclipse.cdt.core.dom.parser.AbstractCLikeLanguage.getASTTranslationUnit(AbstractCLikeLanguage.java:143)
	at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:806)
	at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:770)
	at org.eclipse.cdt.internal.core.model.ASTCache$1.run(ASTCache.java:295)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.cdt.internal.core.model.ASTCache.createAST(ASTCache.java:289)
	at org.eclipse.cdt.internal.core.model.ASTCache.getAST(ASTCache.java:168)
	at org.eclipse.cdt.internal.core.model.ASTCache.runOnAST(ASTCache.java:215)
	at org.eclipse.cdt.internal.ui.editor.ASTProvider.runOnAST(ASTProvider.java:344)
	at org.eclipse.cdt.internal.ui.text.c.hover.CMacroExpansionInput$1.run(CMacroExpansionInput.java:276)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

!ENTRY org.eclipse.cdt.ui 4 4 2011-04-07 14:35:26.069
!MESSAGE Error
!STACK 0
java.lang.OutOfMemoryError: Java heap space
	at java.util.ArrayList.ensureCapacity(Unknown Source)
	at java.util.ArrayList.add(Unknown Source)
	at org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.getMacros(PDOMFile.java:580)
	at org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider.collectFileContent(IndexBasedFileContentProvider.java:174)
	at org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider.getContentForInclusion(IndexBasedFileContentProvider.java:125)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor$1.checkFile(CPreprocessor.java:103)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor$1.checkFile(CPreprocessor.java:1)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.findInclusion(CPreprocessor.java:935)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.executeInclude(CPreprocessor.java:1251)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.executeDirective(CPreprocessor.java:1067)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.internalFetchToken(CPreprocessor.java:726)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.fetchToken(CPreprocessor.java:469)
	at org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor.nextToken(CPreprocessor.java:563)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.fetchToken(AbstractGNUSourceCodeParser.java:260)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.nextToken(AbstractGNUSourceCodeParser.java:284)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.acceptInactiveCodeBoundary(AbstractGNUSourceCodeParser.java:345)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.declarationList(AbstractGNUSourceCodeParser.java:1283)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parseTranslationUnit(AbstractGNUSourceCodeParser.java:1253)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.translationUnit(AbstractGNUSourceCodeParser.java:1248)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parse(AbstractGNUSourceCodeParser.java:645)
	at org.eclipse.cdt.core.dom.parser.AbstractCLikeLanguage.getASTTranslationUnit(AbstractCLikeLanguage.java:143)
	at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:806)
	at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:770)
	at org.eclipse.cdt.internal.core.model.ASTCache$1.run(ASTCache.java:295)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.cdt.internal.core.model.ASTCache.createAST(ASTCache.java:289)
	at org.eclipse.cdt.internal.core.model.ASTCache.getAST(ASTCache.java:168)
	at org.eclipse.cdt.internal.core.model.ASTCache.runOnAST(ASTCache.java:215)
	at org.eclipse.cdt.internal.ui.editor.ASTProvider.runOnAST(ASTProvider.java:344)
	at org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover$1.run(CSourceHover.java:734)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)





Reproducible: Always

Steps to Reproduce:
1. unzip workspace 
2. Use eclipse to open this workspace (it should fail)
3. Apply workaround described at the end of comment #50 from 149121
4. Start eclipse again. 

This workspace is based on an custom product that uses unmodified EPP CDT Helios SR1 package as baseline, but also includes a number of other plugins.
Comment 1 Martin Swiezawski CLA 2011-04-07 16:10:06 EDT
Actually I can't attach a large .zip, I can send it separately.
Comment 2 Markus Schorn CLA 2011-04-08 05:26:00 EDT
What is the maximum heap size you are using when running into this issue?
Comment 3 Martin Swiezawski CLA 2011-04-08 08:47:37 EDT
I was using the default setting of 384. I enabled the display of java heap display and if I am quick enough when I hit recycle bin to garbage collect, then heap goes down a lot and then sits there for 2-3 seconds, then whatever process kicks of parsing starts again and java heap gets used up very quickly. The project is not large maybe 15-20 source files and it takes about 15-20 seconds for the heap to get used up once the process starts.
Comment 4 Markus Schorn CLA 2011-04-08 08:59:43 EDT
Can you try to delete <workspace>/.metadata/.plugins/org.eclipse.cdt.core ?
Comment 5 Martin Swiezawski CLA 2011-04-08 11:04:02 EDT
That worked around this issue. Heap is steady and no messages asking to exit.
Comment 6 Markus Schorn CLA 2011-04-08 11:27:29 EDT
I assume that the files had been parsed using a wrong character encoding. This would lead to a lot of useless information in the index. When loading this information, the OutOfMemoryError can occur.
Comment 7 Martin Swiezawski CLA 2011-04-08 13:46:43 EDT
I would be very surprised if encoding was changed from defaults. I checked with the customer and their response was "what encoding". Would workspace .metadata help? or project itself? I think I should be able to attach both if I separate them out.