Bug 321602 - Eclipse Helios freezes with max CPU utilization in JSP editor
Summary: Eclipse Helios freezes with max CPU utilization in JSP editor
Status: CLOSED DUPLICATE of bug 326332
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: jst.jsp (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 major with 7 votes (vote)
Target Milestone: ---   Edit
Assignee: jst.jsp CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords:
: 327871 335148 335314 335755 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-08-03 10:34 EDT by wolle CLA
Modified: 2011-05-13 15:25 EDT (History)
15 users (show)

See Also:


Attachments
Thread-Dump of Eclipse with max CPU load (35.59 KB, text/plain)
2010-08-03 10:35 EDT, wolle CLA
no flags Details
Patch for the TaglibIndex cache size calculation (1.32 KB, patch)
2010-08-19 03:44 EDT, Tobias Liefke CLA
no flags Details | Diff
Dump of Main-thread each 20 secs during a 5 min JSP loading (151.21 KB, text/plain)
2010-09-24 19:15 EDT, Benjamin Papez CLA
no flags Details
feature patch (581.85 KB, application/x-zip-compressed)
2010-10-06 11:02 EDT, Nick Sandonato CLA
no flags Details
Stack dump when the bug occurs (131.90 KB, text/plain)
2011-05-12 12:11 EDT, David Balažic CLA
no flags Details
taglibindex directory (37.39 KB, application/x-7z-compressed)
2011-05-12 14:29 EDT, David Balažic CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description wolle CLA 2010-08-03 10:34:01 EDT
Build Identifier: 20100617-1415

Environment
-----------
Eclipse: Eclipse Helios for JEE Developers
OS: Ubuntu 10.04 
JDK: Sun JDK 1.6.0_20

When I open a JSP (any JSP) in Eclipse Helios the whole workbench will freeze for at least two minutes with a maximum CPU load on one of my CPUs. This happens on my machine as well as on the machines of some of my colleagues. Sometimes I even have to kill Eclipse since it will not respond anymore.
Looking at Eclipse using "jvisualvm" there seems to be no memory problem, heap and PermGen memory is fine.
I did a few thread dumps and it looks like there is a deadlock. Sometimes the main thread is locked sometimes a worker thread but always with the same stack trace (see "Worker-15" and thread main in attachment).

I also tried to disable all Validators (including JSP) but to no avail.

Reproducible: Always

Steps to Reproduce:
1. Open a JSP in JSP editor
Comment 1 wolle CLA 2010-08-03 10:35:09 EDT
Created attachment 175783 [details]
Thread-Dump of Eclipse with max CPU load

Thread-Dump
Comment 2 Tobias Liefke CLA 2010-08-18 10:15:17 EDT
In my workspace I had the same problem. After debugging i found the following:

org.eclipse.jst.jsp.core.taglib.TaglibIndex#calculateCacheLimit():
"Calculate the maximum number of project descriptions to keep cached.
Calculated as: MINIMUM_LIMIT_FOR_PROJECT_DESCRIPTIONS_CACHE + log(currentWorkspaceProjectCount)"

Where MINIMUM_LIMIT_FOR_PROJECT_DESCRIPTIONS_CACHE is 3.

So suppose you have a workspace with 10 projects, where your main one (that with the JSPs) depend on all others. Then the taglib index is recreating the project descriptions over and over again, as the cache holds only 3 + ln(10) = 5 elements. That results in heavy CPU load as creating a project description is time consuming.

Solution for me was to change the method to:
private int calculateCacheLimit() {
  return MINIMUM_LIMIT_FOR_PROJECT_DESCRIPTIONS_CACHE + ResourcesPlugin.getWorkspace().getRoot().getProjects().length;
}

You could also create ((e^projectCount) - projectCount) empty projects - but for our example of 10 projects that would mean to create ~22000 empty one.
Comment 3 Tobias Liefke CLA 2010-08-19 03:44:10 EDT
Created attachment 176965 [details]
Patch for the TaglibIndex cache size calculation

I added a patch for the proposed quick fix. 

But I would suggest to revise the cache strategy in the TaglibIndex, as the cache is not resized when new projects are added, which will lead to the same CPU load during setup of a workspace from repository.
Comment 4 Benjamin Papez CLA 2010-09-24 19:09:24 EDT
I was seeing the same thread dumps on my installation (I'll attach the stack trace of the main thread taken in an interval of about 20 seconds to the ticket) as I have to wait for about 5 minutes on openeing any JSP in our main dynamic web project. This was very annoing and I already started to edit JSPs in an alternative editor, but after things did not improve on loading Eclipse Helios SR1 today, I decided to debug Eclipse to see what is going on.

Our project is build of multiple Maven modules - it has one main dynamic web project (creating a war) and several important Java projects (creating jars), which I have opened in my workspace. One project is a taglib project (creating a JAR), where the TLDs are under src\resources\META-INF. We have no taglib reference in the web.xml of the main dynamic web project and we also have many dynamic web projects using these taglibs and I have them loaded into the same workspace now and then.

When opening a JSP I can see that the method

org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager.getCMDocument

will start loading the project descriptions over and over again in these method calls:

Object cacheKey = getCacheKey(reference);
...
long lastModified = getModificationStamp(reference);
...
CMDocument document = loadTaglib(reference);
...
entry.modificationStamp = getModificationStamp(reference);

As mentioned previously in this bug report, this is because the cache limit for the project descriptions cache in the TaglibIndex is too small.

1st Suggestion:
Perhaps there could be some logic added that the fProjectDescriptions cache is not plainly evicting the oldest records, but the ones which have the least success ratio when resolving taglibs. This way the projects being able to resolve taglibs will stay longer in memory.

2nd suggestion:
Another possibility to improve things is a slight refactoring in 

org.eclipse.jst.jsp.core.taglib.ProjectDescription.resolve(String, String)

Here we come into the following part:

if (record == null && jspVersion >= 1.2) {
    Map buildPathReferences = new HashMap();
    List projectsProcessed = new ArrayList(fClasspathProjects.size() + 1);
    projectsProcessed.add(fProject);
    addBuildPathReferences(buildPathReferences, projectsProcessed, false);
    record = (ITaglibRecord) buildPathReferences.get(reference);
}

Now the problem is that the addBuildPathreferences will start to go through all dependent projects and call 

TaglibIndex.getInstance().createDescription(buildpathProjects[i]);

more often than the size of the project descriptions cache limit. So it will continously throw out already resolved project descriptions. The odd thing is in our case that actually the reference could be resolved already after creating the second project description and looking into description.fImplicitReferences. So it is overkill to continue loading all the other project descriptions. Perhaps the addBuildPathreferences should get the reference as parameter and if it is not null (same method is used on another place, where really ALL projects should be iterated through, so parameter could be set to null), then as soon as the reference is found stop iterating through the next projects.

Perhaps both suggestions should be implemented and I think they will really help developers, who need to have >8 projects open at a time and work with JSPs and taglibs.
Comment 5 Benjamin Papez CLA 2010-09-24 19:15:56 EDT
Created attachment 179553 [details]
Dump of Main-thread each 20 secs during a 5 min JSP loading
Comment 6 Robert Youdan CLA 2010-09-28 01:33:52 EDT
Note that this bug appears not to be limited to LINUX platform. I have the exact same problem with Helios on Windows 64. The problem does not occur on my most recent Galileo workspaces.

JSPF files do not seem to suffer the same problem: only JSP. This is with all validators disabled.
Comment 7 Robert Youdan CLA 2010-09-28 01:50:35 EDT
Just for kicks I saved a medium sized JSP that was taking about 2 minutes to load, as a JSPF. When I went to open the newly saved JSPF, it too took about 2 minutes at 100% CPU (thank goodness for multi-core CPUs).

Hence, it is not limited to JSP but related to the contents. Our workspace has about 40 projects and this particular file as approx 20 <%@page import= statements, a few <%@ include file= statements, a lot of javascript, many custom tags, and a smattering of scriptlets.

Based on the above, I followed my nose and traced the problem back to a single JSPF file that ONLY contains taglib statements. The file is only 14 lines long and contains 14 <%@ taglib uri= statements. This tiny file takes about 2 minutes at 100% CPU to open.

I hope this helps.
Comment 8 Nitin Dahyabhai CLA 2010-09-28 11:14:57 EDT
Sounds like this is a duplicate of/by bug 326332, then, among other issues being investigated.
Comment 9 Lars Beuster CLA 2010-10-06 09:33:50 EDT
Currently this bug prevents me from editing JSP-pages. Is there a quick (and/or dirty) solution to this bug without recompiling eclipse? Perhaps 
* disable some plugins
* install a snapshot plugin
* replace a classfile in a jar

Or do I have to use another IDE?

Regards
Lars
Comment 10 Nick Sandonato CLA 2010-10-06 11:02:45 EDT
Created attachment 180339 [details]
feature patch

Our first service release has already shipped. In the meantime (Helios SR2 is slated for Feb. 25, 2011), I've created a feature patch that includes the fix from Bug 326332.

To install this feature patch:

1. Close Eclipse
2. Unzip org.eclipse.jst.jsp.core.featurepatch.zip into your eclipse\ directory (e.g., C:\dev\helios\eclipse)
3. You should end up with a new feature in the features\ directory (org.eclipse.jst.jsp.core.featurepatch_1.0.0) and a new plug-in in the plugins\ directory (org.eclipse.jst.jsp.core_1.2.302.v201010061038.jar)
4. Launch Eclipse
5. Double check and make sure that Help > About Eclipse , Installation Details , Plugins has loaded the right version of org.eclipse.jst.jsp.core (1.2.302.v201010061038.jar)

This should clear up the problem for you.
Comment 11 Nick Sandonato CLA 2010-10-06 11:18:50 EDT
This is a duplicate of Bug 326332. We've disabled the limit on the cache size. We're already capable of responding to low-memory events. The limited cache created an additional overhead that was unnecessary.

Thanks for bringing this to our attention. Please see comment 10 for installing the feature patch that contains the fix from Bug 326332 for Helios.

*** This bug has been marked as a duplicate of bug 326332 ***
Comment 12 Nick Sandonato CLA 2010-10-06 11:24:22 EDT
(In reply to comment #10)
> Created an attachment (id=180339) [details]
> feature patch
> 

Just to clarify, this feature patch is against SR1 of Helios.
Comment 13 Lars Beuster CLA 2010-10-06 12:18:46 EDT
Lars(In reply to comment #10)

Hi Nick,
thanks a lot for the quick (and non-dirty;)) workaround. And it works.

Just one question: do I have to revert the change manually if I install SR2 in Feb via the Eclipse update func or is this done automatically?

Thanx and regards
Comment 14 Nick Sandonato CLA 2010-10-06 13:29:42 EDT
(In reply to comment #13)
> Lars(In reply to comment #10)
> 
> Hi Nick,
> thanks a lot for the quick (and non-dirty;)) workaround. And it works.
> 
> Just one question: do I have to revert the change manually if I install SR2 in
> Feb via the Eclipse update func or is this done automatically?
> 
> Thanx and regards

Hi Lars,

You're welcome.

I'm pretty sure that when you update, this feature patch will deactivate since it references the existing feature version of 3.2.2 and the installed feature will have a higher version number in SR2.
Comment 15 Troy CLA 2010-10-06 15:21:05 EDT
The patch works a treat on my Windows Vista machine.
Thanks, much appreciated :).


(In reply to comment #14)
> (In reply to comment #13)
> > Lars(In reply to comment #10)
> > 
> > Hi Nick,
> > thanks a lot for the quick (and non-dirty;)) workaround. And it works.
> > 
> > Just one question: do I have to revert the change manually if I install SR2 in
> > Feb via the Eclipse update func or is this done automatically?
> > 
> > Thanx and regards
> 
> Hi Lars,
> 
> You're welcome.
> 
> I'm pretty sure that when you update, this feature patch will deactivate since
> it references the existing feature version of 3.2.2 and the installed feature
> will have a higher version number in SR2.
Comment 16 shahaf CLA 2010-10-06 20:52:20 EDT
I'm having trouble with the patch from comment #10.

I followed the steps and verified that the feature/plugin artifacts end up in the appropriate directory.

But when I load eclipse and go to Installation Details, I still see the old version of org.eclipse.jst.jsp.core (1.2.300.v201005271731).

And the performance of the JSP editor is still as bad as before.

I tried starting eclipse like this: eclipse.exe -clean
That didn't seem to help.

Is there anything I else I should try?

In case it helps, I'm on 64-bit Win7 but using 32-bit eclipse.
Comment 17 Troy CLA 2010-10-06 21:44:00 EDT
Perhaps I can help...
Are you using the SR1 version of Helios? If not, I think the fix might be specifically targeting SR1 release, not the original release of Helios.
You might want to do a "check for updates" to ensure you're using SR1.

In my Eclipse/plugins directory I have two versions of the jar

org.eclipse.jst.jsp.core_1.2.302.v201008251735.jar (and old one, but not as old as the version you mention).
org.eclipse.jst.jsp.core_1.2.302.v201010061038.jar

Within my features directory I have a folder named 
org.eclipse.jst.jsp.core.featurepatch_1.0.0
which contains a single file called feature.xml.

Hope this is of some assistance.
I'm just glad to having JSP editing back!

Cheers
Troy


(In reply to comment #16)
> I'm having trouble with the patch from comment #10.
> 
> I followed the steps and verified that the feature/plugin artifacts end up in
> the appropriate directory.
> 
> But when I load eclipse and go to Installation Details, I still see the old
> version of org.eclipse.jst.jsp.core (1.2.300.v201005271731).
> 
> And the performance of the JSP editor is still as bad as before.
> 
> I tried starting eclipse like this: eclipse.exe -clean
> That didn't seem to help.
> 
> Is there anything I else I should try?
> 
> In case it helps, I'm on 64-bit Win7 but using 32-bit eclipse.
Comment 18 Nick Sandonato CLA 2010-10-07 09:00:31 EDT
Excellent explanation, Troy. Thanks for helping to clarify so quickly.

Yes, this patch is indeed against Helios SR1 (see comment 12).

(In reply to comment #17)
> Perhaps I can help...
> Are you using the SR1 version of Helios? If not, I think the fix might be
> specifically targeting SR1 release, not the original release of Helios.
> You might want to do a "check for updates" to ensure you're using SR1.
> 
> In my Eclipse/plugins directory I have two versions of the jar
> 
> org.eclipse.jst.jsp.core_1.2.302.v201008251735.jar (and old one, but not as old
> as the version you mention).
> org.eclipse.jst.jsp.core_1.2.302.v201010061038.jar
> 
> Within my features directory I have a folder named 
> org.eclipse.jst.jsp.core.featurepatch_1.0.0
> which contains a single file called feature.xml.
> 
> Hope this is of some assistance.
> I'm just glad to having JSP editing back!
> 
> Cheers
> Troy
> 
> 
> (In reply to comment #16)
> > I'm having trouble with the patch from comment #10.
> > 
> > I followed the steps and verified that the feature/plugin artifacts end up in
> > the appropriate directory.
> > 
> > But when I load eclipse and go to Installation Details, I still see the old
> > version of org.eclipse.jst.jsp.core (1.2.300.v201005271731).
> > 
> > And the performance of the JSP editor is still as bad as before.
> > 
> > I tried starting eclipse like this: eclipse.exe -clean
> > That didn't seem to help.
> > 
> > Is there anything I else I should try?
> > 
> > In case it helps, I'm on 64-bit Win7 but using 32-bit eclipse.
Comment 19 shahaf CLA 2010-10-07 10:18:20 EDT
You're totally right - I thought I was using SR1 but I wasn't.  I have 3 different version of Eclipse side-by-side and evidently I wasn't using the one I thought I was using.

I installed a fresh copy of SR1 and now I see the following in my plugins directory:
...
org.eclipse.jst.jsp.core_1.2.302.v201008251735.jar
org.eclipse.jst.jsp.core_1.2.302.v201010061038.jar
...

And I see the following folder in my features directory:
...
org.eclipse.jst.jsp.core.featurepatch_1.0.0
...
This one is a folder with a single XML file in it.

Still, when I launch Eclipse and open Installation Details, I see this entry:
Eclipse Web Tools Platform - Structured Source JSP Model - 1.2.302.v201008251735 - org.eclipse.jst.jsp.core

I tried the following:
* Check for Updates (none)
* Starting with -clean
* New workspace
* Yet another fresh install of SR1
* Renaming the old jar to something different
None of these things helped.

Can anyone think of anything else I should try?

Thanks
Comment 20 David Williams CLA 2010-10-07 15:11:22 EDT
(In reply to comment #19)

> Can anyone think of anything else I should try?

I have noticed there are sometimes problems with patches being applied, if they are simply unzipped to an install (reported in bug 326735). 

You might try installing the patch with p2. Luckily, since Nick apparently hasn't learn yet how to check the box that says 'generate metadata' :) 
you can still use p2 with the "raw' patch feature and bundle in the zip. 

Unzip that zip file into its own (temporary) directory, say C:\patchdir. Then in your IDE, "install new software", "Add ...", "Local ..." and browse to or paste in your patchdir. 

You'll need to uncheck "show categories" box, but then should see exactly one feature to install 

Perhaps this p2 based code will get it installed properly for you? 

P.S. best not to use -clean any more ... it is less needed than it used to be, and 2) it can mess things up, in theory, by removing some types of init/config data that your package might need (though doubt that's related to your current problems). 

HTH
Comment 21 shahaf CLA 2010-10-14 21:03:05 EDT
David - thanks for your help!

Initially when I tried to follow your suggestion, it didn't work.  I was able to select the patch from c:\temp\patchdir, but when I clicked to install it I got:

"JSP Core Feature Patch" is not applicable to the current configuration and will not be installed.

But eventually I was able to install the patch by doing two more things:
1. Removing the old feature/plugin artifacts that I'd placed manually
2. Running Eclipse as admin (on win7)

After doing these two things and then repeating the patch installation steps, it seemed to work.  Now when I look at Installed Software I see the correct new version.

Hurray!  I don't need to switch to Notepad++ for my JSP files anymore!  :-)

BTW, there might be another bug here were there was (apparently) some kind of permission issue, but the message I got didn't convey this ("not applicable...because of insufficient permission?")
Comment 22 David Williams CLA 2010-10-14 21:25:43 EDT
(In reply to comment #21)

> 2. Running Eclipse as admin (on win7)

I know there's been some issues reported about that (such as bug 320383) ... 
and not sure what the "fix" actually was in Helios SR1; if you simply can do it now, or if on windows 7 you are supposed to first install as Administrator when you install into "Program Files" ... but glad you can use JSP editor again. 

Thanks for letting us know.
Comment 23 Nick Sandonato CLA 2010-10-15 08:48:37 EDT
*** Bug 327871 has been marked as a duplicate of this bug. ***
Comment 24 Nick Sandonato CLA 2011-01-24 10:21:03 EST
*** Bug 335148 has been marked as a duplicate of this bug. ***
Comment 25 cudennec CLA 2011-01-25 09:41:21 EST
*** Bug 335314 has been marked as a duplicate of this bug. ***
Comment 26 Nick Sandonato CLA 2011-01-31 17:04:09 EST
*** Bug 335755 has been marked as a duplicate of this bug. ***
Comment 27 David Balažic CLA 2011-05-12 08:30:14 EDT
Was this fix included in SR-2?

I am running Eclipse Java EE IDE for Web Developers Helios SR-2
and this bug occured twice now.

I open a 200 lines long JSP file and Eclipse freezes for some minutes, using 100% of a CPU core.

I did a find updates yesterday and it reported none.
Comment 28 Nick Sandonato CLA 2011-05-12 09:39:12 EDT
(In reply to comment #27)
> Was this fix included in SR-2?
> 
> I am running Eclipse Java EE IDE for Web Developers Helios SR-2
> and this bug occured twice now.
> 
> I open a 200 lines long JSP file and Eclipse freezes for some minutes, using
> 100% of a CPU core.
> 
> I did a find updates yesterday and it reported none.

Yes. The fix is present in SR2.

What version of org.eclipse.jst.jsp.core is being picked up by your install?
Do you happen to have a stackdump of what was going on at the time of 100% CPU usage?
Comment 29 Nick Sandonato CLA 2011-05-12 11:04:10 EDT
(In reply to comment #28)
> (In reply to comment #27)
> > Was this fix included in SR-2?
> > 
> > I am running Eclipse Java EE IDE for Web Developers Helios SR-2
> > and this bug occured twice now.
> > 
> > I open a 200 lines long JSP file and Eclipse freezes for some minutes, using
> > 100% of a CPU core.
> > 
> > I did a find updates yesterday and it reported none.
> 
> Yes. The fix is present in SR2.
> 
> What version of org.eclipse.jst.jsp.core is being picked up by your install?
> Do you happen to have a stackdump of what was going on at the time of 100% CPU
> usage?

You can get a stackdump in a couple ways. If it's available to you, jstack will output the stack traces. Additionally, you could add the -debug flag when launching eclipse and then press Ctrl+Break in the console. That should output everything to a text file.
Comment 30 David Balažic CLA 2011-05-12 12:11:31 EDT
Created attachment 195505 [details]
Stack dump when the bug occurs
Comment 31 Nitin Dahyabhai CLA 2011-05-12 13:57:26 EDT
Can you attach the (zipped) contents of your workspace's .metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex directory?
Comment 32 David Balažic CLA 2011-05-12 14:29:19 EDT
Created attachment 195521 [details]
taglibindex directory
Comment 33 David Balažic CLA 2011-05-12 14:31:58 EDT
Comment on attachment 195521 [details]
taglibindex directory

7z is much smaller than ZIP...
Comment 34 Nitin Dahyabhai CLA 2011-05-12 14:43:11 EDT
(In reply to comment #33)
> 7z is much smaller than ZIP...

Perhaps, but it's not what I asked for, and I'll have to install something to read it.
Comment 35 Nick Sandonato CLA 2011-05-12 21:03:29 EDT
(In reply to comment #33)
> Comment on attachment 195521 [details]
> taglibindex directory
> 
> 7z is much smaller than ZIP...

Based on the contents of your taglib index, this looks like a different problem. We'll need a new bug for this I think.

You may be able to clear up your performance problem by shutting down your Eclipse instance and deleting the workspace's .metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex directory. Then start up Eclipse again.
Comment 36 Nick Sandonato CLA 2011-05-13 15:25:57 EDT
David, please see Bug 345778, which I've opened to address your issue.