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

Bug 448231

Summary: Java heap space error in UI on refactoring of Javascript variable.
Product: [WebTools] JSDT Reporter: Vadim Yusanenko <usanenko.vadim>
Component: GeneralAssignee: Project Inbox <jsdt.javascript-inbox>
Status: RESOLVED DUPLICATE QA Contact: Victor Rubezhny <vrubezhny>
Severity: major    
Priority: P3 CC: daniel.rolka, shr31223, thatnitind
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
Minimal sample to cause heap space exception in WTP on refactor of var none

Description Vadim Yusanenko CLA 2014-10-22 04:32:29 EDT
Hi Eclipse folks!

Background:
1) Created PyDev project
2) Configure -> Convert to Javascript 
3) DIsabled Javascript builder as NullPointer exception pops up every 5 seconds or so (separate issue)
3) Opened .js file -> select refactor on var XXX inside function (refactor on function name work though)
4) java.lang.OutOfMemoryError: Java heap space
Able to reproduce every time. Makes using WTP impossible.

Stack trace:
eclipse.buildId=4.4.1.M20140925-0400
java.version=1.8.0_25
java.vendor=Oracle Corporation
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.standard.product -keyring /Users/vadimyusanenko/.eclipse_keyring -showlocation
Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.standard.product -keyring /Users/vadimyusanenko/.eclipse_keyring -showlocation

org.eclipse.ui
Error
Tue Oct 21 23:29:26 EEST 2014
Unhandled event loop exception

java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Arrays.java:3181)
	at java.util.ArrayList.grow(ArrayList.java:261)
	at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235)
	at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227)
	at java.util.ArrayList.add(ArrayList.java:458)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.CompilationUnitScope.mergeWithSuperBinding(CompilationUnitScope.java:676)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.CompilationUnitScope.buildSuperType(CompilationUnitScope.java:549)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:409)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:343)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:327)
	at org.eclipse.wst.jsdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:754)
	at org.eclipse.wst.jsdt.internal.core.Openable.codeSelect(Openable.java:167)
	at org.eclipse.wst.jsdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:330)
	at org.eclipse.wst.jsdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:324)
	at org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:213)
	at org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection.resolveElementAtOffset(JavaTextSelection.java:77)
	at org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectionChanged(RenameJavaElementAction.java:108)
	at org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction.selectionChanged(SelectionDispatchAction.java:166)
	at org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged(SelectionDispatchAction.java:235)
	at org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction.update(SelectionDispatchAction.java:137)
	at org.eclipse.wst.jsdt.ui.actions.RenameAction.update(RenameAction.java:87)
	at org.eclipse.wst.jsdt.ui.actions.RefactorActionGroup.refactorMenuShown(RefactorActionGroup.java:614)
	at org.eclipse.wst.jsdt.ui.actions.RefactorActionGroup.access$1(RefactorActionGroup.java:599)
	at org.eclipse.wst.jsdt.ui.actions.RefactorActionGroup$1.menuAboutToShow(RefactorActionGroup.java:537)
	at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:352)
	at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:492)
	at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:487)
	at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:519)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:255)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4188)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1467)

Thanks and hope this will make platform better.

-- Configuration Details --
Product: Eclipse 4.4.1.20140925-1820 (org.eclipse.epp.package.standard.product)
Installed Features:
 org.eclipse.platform 4.4.0.v20140925-0400
Comment 1 Daniel Rolka CLA 2014-10-22 05:14:43 EDT
You can increase the JVM heap size by proper options in the 'eclipse.ini' confiruration file (-Xms and -Xmx). You can also play a bit with different gc types in order to additionally tune your JVM. For Oracle JVM you can try to use the G1 one (-XX:+UseG1GC)

Daniel
Comment 2 Vadim Yusanenko CLA 2014-10-22 05:23:42 EDT
Did it already:
-Xss2m
-Xms1G
-Xmx1G

It is not OK, when with such configuration I am out of heap space, it is definitely a bug.

Regarding: -XX:+UseG1GC - grateful, make come in handy later, thanks.
Comment 3 Vadim Yusanenko CLA 2014-10-22 05:45:19 EDT
I will try to provide minimal sample project with this. I understand it is hard to debug with comments only. But maybe there is already a known limitation here, that you are aware of.
Comment 4 Vadim Yusanenko CLA 2014-10-22 07:30:56 EDT
Created attachment 248089 [details]
Minimal sample to cause heap space exception in WTP on refactor of var

1. Eclipse 4.4.1 and install WTP (JsDT is of interest here)
2. Unzip
3. Import as project
4. Configure as javascript project (if required)
5. Open "static/js/functions.js"
6. Right click on "current_row_iterator" variable and select refactor
Comment 5 Vadim Yusanenko CLA 2014-10-22 07:40:57 EDT
I like Open Source movement and think Eclipse is a tool made with a good intent in mind. But let's be honest - to make it better - it is important to criticize it as well. Even the most loyal to Eclipse people (they are suffering but understand what it costs to create open source IDE and that it requires time and efforts :) ) agree that Web development in Eclipse is very poor at this moment.
The sample I've attached is only 1/4 of all JS code we have, and if it can not handle this - it is not a production grade web IDE - it is only suitable for university homework. Sorry for such harsh words.

A few thoughts (though I am a back-end developer, so may be wrong - sorry)
- I declared variable in local scope (var XYZ) - is it really necessary to use all available memory to check whether this change will affect anything? It seems the only thing that may be affected is my function scope. Sorry if this question is dumb.
- Once again - this is only a small part of all JS code available, if it can not handle this with MaxPermSize=1G, then something is really really bad in my opinion.

Thanks for working on WTP and thanks for all criticism you are hearing. I do believe WTP will become better over time. Lot's of work here, I understand.
Comment 6 Victor Rubezhny CLA 2015-05-20 12:52:12 EDT
Vadim,

Your issue duplicates Bug #433515 which was fixed in Mars stream. There was a Feature Patch created due to address the issue in WTP Luna SR2 (See Bug #461160). 

You need to upgrade your Eclipse and WTP to be at least Luna SR2 and then install JSDT Feature patch for WTP SR2 from the repository: http://download.eclipse.org/webtools/repository/luna/

Thanks for your patience!

*** This bug has been marked as a duplicate of bug 433515 ***