Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 360855 - JVM crash when trying to JIT compile CPPVisitor.createType
Summary: JVM crash when trying to JIT compile CPPVisitor.createType
Status: RESOLVED NOT_ECLIPSE
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-13 11:53 EDT by Dobrin Alexiev CLA
Modified: 2014-08-05 18:46 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dobrin Alexiev CLA 2011-10-13 11:53:16 EDT
Build Identifier:  I20110613-1736

Sometimes when I change the active build configuration from the project's main menu " Build configuration -> Manage..." I have a JVM crash. 

I tried with different version of Oracle Java and it happens with all JVM version - 1.6.0_14 or higher. 

The messages is in the hs_err*.log file is: 


... 
Current thread (0x34031400):  JavaThread "C1 CompilerThread0" daemon [_thread_in_native, id=6612, stack(0x349e0000,0x34a30000)]
...
Current CompileTask:
C1: 161984 7294             org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor::createType (584 bytes)
...


Looks to me that is it some kind of JVM bug that under certain conditions chokes while compile the method

org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor
	public static IType createType(IASTDeclarator declarator)


The method looks rather long, compared to the other methods of the class so I tried splitting it in three part. 
The experiment worked! The JVM crash doesn't happen if the method is split in few parts. 


I found references to JVM crashes "C1 CompilerThread0" that have been existing in different JVM versions and still exist. 


The JVM crash only happens with specific projects - it looks it is very sensitive on what header files are being parsed. 


Reproducible: Always

Steps to Reproduce:
see details.
Comment 1 Jesper Eskilson CLA 2011-10-13 13:24:49 EDT
I've also reported a bug for this, which was closed with NOT_ECLIPSE. https://bugs.eclipse.org/bugs/show_bug.cgi?id=357757. I also reported a bug with Oracle, which can be found here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7090976

The workaround is to exclude the offending method from compilation, like this:

-XX:CompileCommand=exclude,org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor,createType
Comment 2 Dobrin Alexiev CLA 2011-10-14 09:23:44 EDT
Considering: 

1. that the java bug is not fix yet;
2. whenever it get fixed, customers will still have older version of JRE for years;
3. there is a simple workaround – just make the function shorter by introducing few smaller helper functions 
4. the workaround conform to java practices, not too make functions too long; 

Does it makes sense for a committer to implement the workaround?
Comment 3 Dobrin Alexiev CLA 2011-10-18 16:29:20 EDT
I am able to reproduce the crash only with our custom product: 

It can be downloaded from the site: http://processors.wiki.ti.com/index.php/Download_CCS
Install the 5.1 Release Candidate at the top of the web page. 
Make sure you remove/rename the JRE folder that gets installed inside the Eclipse folder. 
Make sure the default JRE is higher than 1.5.13. 

Start Code Composer. 
In the “CCS Edit” go the main menu “CCS Example Projects”. 
In the edit box on in the top left type “grace”. 
The tree view show projects that are have the specified keyword. 
Start selecting each of the lead nodes and then click on the “Import the example project” on the right pane. 
The JVM crashes after importing for about 7 to 10 project. 

There is something specific in the library header files as well as the timing to get the JVM crash. 


I wander if Jesper Eskilson has a use case that is reproducible in the Open Source?
Comment 4 Dobrin Alexiev CLA 2011-10-18 16:37:57 EDT
In term of submitting a patch I believe the JRE just doesn’t like big functions. 
I tried experimenting with splitting the function in three parts and it worked. 
The problem is that to pass variables between all three part of the split function I created an ugly class to keep those locals. 
I think the real patch should have make meaningful split in functions, than just cutting the function in three with the ax.
Comment 5 Doug Schaefer CLA 2011-10-18 16:50:27 EDT
(In reply to comment #4)
> In term of submitting a patch I believe the JRE just doesn’t like big
> functions. 
> I tried experimenting with splitting the function in three parts and it worked. 
> The problem is that to pass variables between all three part of the split
> function I created an ugly class to keep those locals. 
> I think the real patch should have make meaningful split in functions, than
> just cutting the function in three with the ax.

Then why does it fail in your custom product and nowhere else? I don't see these errors.
Comment 6 Dobrin Alexiev CLA 2011-10-18 17:12:10 EDT
> (In reply to comment #4)
> Then why does it fail in your custom product and nowhere else? I don't see
> these errors.

I think it has to do with the content of the header files as well as timing, when the parsing has to switch from one project/ configuration to another - I need to start another parsing while one parsing is happening. 
I did one very simple experiment – I removed all include statements from the projects files and I don’t have the crash. 
Tracing which statement in which header file get it to crash may be too much. 

I guess at the end of the day we know the CDT fix/workaround - splitting the method in few parts. 
I don’t think we can rely in Java fixing it – for a long time user will have older JREs.
Comment 7 Sergey Prigogin CLA 2011-10-18 17:12:29 EDT
(In reply to comment #5)
> Then why does it fail in your custom product and nowhere else? I don't see
> these errors.

Neither do my 1000+ users.
Comment 8 Sergey Prigogin CLA 2011-10-18 17:30:08 EDT
I've split CPPVisitor.createType(IASTDeclarator) into two methods in cdt_8_0. Please let me know if that helps.
Comment 9 Dobrin Alexiev CLA 2011-10-19 11:57:27 EDT
(In reply to comment #8)
> I've split CPPVisitor.createType(IASTDeclarator) into two methods in cdt_8_0.
> Please let me know if that helps.

Thanks a lot, Sergey. 
The change fixed the JVM crash.
Comment 10 Sergey Prigogin CLA 2011-10-19 13:00:27 EDT
I'm closing this bug since a workaround for the JVM bug has been provided.
Comment 11 Jesper Eskilson CLA 2011-10-21 02:42:36 EDT
I received an email from the responsible engineer assigned to the bug I reported (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7090976):

"This was bug over in the wrong category so it's just now gotten to the right group.  Are you still able to reproduce this?  Can you give a script that would reproduce it?  Intermittent failures are fine and it doesn't have to be minimal, just as long as it crashes.  If not, could you give me a mini dump from a crash using -XX:+CreateMinidumpOnCrash.  Thanks."

I'll try to set up a minimal test case, but haven't been successful so far. If anyone has or can create a test case (or a mini dump), let me know so I can forward it to Oracle.
Comment 12 Dobrin Alexiev CLA 2011-10-21 10:36:08 EDT
I posted a link on the Oracle bug link: 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7090976

to the user case I provided in this bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=360855#c3
Comment 13 Jesper Eskilson CLA 2011-10-21 11:46:36 EDT
(In reply to comment #3)

> I wander if Jesper Eskilson has a use case that is reproducible in the Open
> Source?

Unfortunately not. I'll try to see if I can isolate something, but so far I have been unsuccessful.
Comment 14 Jesper Eskilson CLA 2011-11-09 04:27:31 EST
Another update from Tom Rodriguez at Oracle. He has found and fixed the problem:

"I just updated the bug report.  It's a very old bug with an optimization around invokeinterface.  It's trying to improve the types used in the invoke by looking at the implementors of an interface but picking the wrong types because it's not searching broadly enough.  The code we emit has guards that verify the type so even if we pick the wrong types we can't actually execute wrongly.  What happens here is that as a side effect of the guarding logic we treat an object as two different types and emit loads that happen to have the same offset but different types and one is substituted for the other which is what causes the compiler crash.  So the bug itself can only cause a compiler crash if you get a particular confluence of types and fields and they happen to be at the same offset.  The bug itself should be very reliable.  If a refactoring has caused it to disappear from eclipse then it shouldn't occur again.  It should be fixed in 7u4 and I'll see about getting it back ported to 6 as well.  Thanks for filing the bug."