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

Bug 370407

Summary: JPA hangs eclipse during refactoring
Product: [WebTools] Dali JPA Tools Reporter: Jesper Skov <jskov>
Component: JPAAssignee: Karen Butzke <karenfbutzke>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: karenfbutzke, neil.hauge
Version: unspecified   
Target Milestone: 3.2 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 377039    
Bug Blocks:    
Attachments:
Description Flags
Thread dump made when Eclipse is hung.
none
CPU profiling snapshot of slow refactoring operation
none
Clean-build with validation enabled
none
CPU profiling snapshot of validation operation
none
Clean+build with I20120419070008 updated WTP.
none
Refactoring with I20120419070008 updated WTP.
none
Clean+build with I20120425070315 updated WTP
none
Refactoring with I20120425070315 updated WTP none

Description Jesper Skov CLA 2012-02-02 04:34:01 EST
Build Identifier: Version: Indigo Service Release 1 Build id: 20110916-0149

One of our projects using JPA causes refactoring to hang Eclipse for 30-50 seconds.

This happens almost consistently when renaming some of the classes, while other classes in the same package does not trigger the hang.

Specifically, a particular class needs to renamed 1-3 times in a row, then it will happen for sure.

I have disabled JPA validation because that also takes a long time for some of the classes in the project.


Reproducible: Sometimes

Steps to Reproduce:
(private project that I cannot give you access to, but I am willing to test):
1. Check out jb.it.jess, let build settle
2. Find class Address and rename it (sometimes 2-3 times).
3. Eclipse hangs with non-responsive GUI. Progress bar at 50%.
Comment 1 Jesper Skov CLA 2012-02-02 04:35:18 EST
Created attachment 210433 [details]
Thread dump made when Eclipse is hung.
Comment 2 Karen Butzke CLA 2012-04-12 15:56:20 EDT
A couple of questions for you. That thread dump doesn't have any obvious deadlocks in it. Is this a deadlock scenario, or does it just hang for a while and eventually finish?

Is your project all Java annotations or do you also have orm.xml mapping files?

I am doing some performance profiling and improvements right now in Juno and would be interested to get more information. Could you try this out in the Juno M6 build to see if the problems are still there? We have made some fairly significant changes that *might* help the problem, but hard to tell.

Also, if you want to spend the time to do some performance profiling of the JPA validation, I could attempt to use your results in my work to improve performance. I've had success using the Java VisualVM using jdk1.6.0_31. I set the profiler CPU settings to 'Start profiling from classes:' org.eclipse.jpt.**, uncheck 'Profile new Runnables', and 'Profile only classes:' org.eclipse.jpt.*. Then you could run validation on the project and attach the resulting snapshot to the bug.
Comment 3 Jesper Skov CLA 2012-04-13 01:18:52 EDT
Eclipse just hangs for up to a minute, but then resumes. No deadlock.

There is no orm.xml in play, just annotations.

I will try Juno and let you know what I find. I might even try the visualvm profiling if I get time today.
Comment 4 Jesper Skov CLA 2012-04-13 02:54:48 EDT
Ah, uphill battle: JBoss Tools is not yet available for JunoM6, so I have a hard time getting anything working.

But I'll keep an eye out for JBossTools builds and update this issue with more information as soon as I have it.
Comment 5 Jesper Skov CLA 2012-04-13 05:38:23 EDT
I fumbled the JBossTools issue; got it working and am using JunoM6 now.

First observation is this:

'JPA Project Change Event Handler' still runs for a minute on refactoring.

But it runs in the background, which is a big improvement.

If I make two refactoring operations immediately after another, I get the "User Operation is Waiting" modal dialog.



I'll look into generating some profiling data.
Comment 6 Jesper Skov CLA 2012-04-13 07:29:57 EDT
Not entirely sure what is going on now...

When I look in Project->Properties->JPA there are no defined platforms, and I get this error:

An internal error occurred during: "JPA Facet File Change Event Handler".
Project does not have a recognized JPA platform.


I have not been able to reproduce the JPA lags I saw after the first time I started Eclips4.2.

I tried installing the Dali JPA Support and EclipseLink JPA Support plugins, but to no avail.



If I use Eclipse 3.7 on the workspace, and then later start Eclipse 4.2 on the same workspace, it will allow the JPA event handlers to run - I see them in the progress view. But I have not been able to reproduce the 1+-minute runtimes again.


If you could provide me with hints for how to get the JPA platform defined, I will provide the CPU profiling data.
Comment 7 Karen Butzke CLA 2012-04-13 09:35:45 EDT
What happens if you create a new JPA project, are you able to choose the JPA platform you want?

For your existing project, in the file system check the .settings folder for org.eclipse.jpt.core.prefs and what is the defined platform in that file? It should be org.eclipse.jpt.core.platform=<platform>. It looks like you have hit an upgrade bug, but not sure if it's Dali or JBoss tools causing the issue. Also you could check the Error Log view and attach the stack trace of the error when opening the project properties.
Comment 8 Jesper Skov CLA 2012-04-16 04:13:08 EDT
Manually editing org.eclipse.jpt.core.prefs made the JPA system happy again.

I'll attach a CPU profiling snaphot. I hope it is of some use to you.
Comment 9 Jesper Skov CLA 2012-04-16 04:14:40 EDT
Created attachment 214036 [details]
CPU profiling snapshot of slow refactoring operation

This is the profiling following the renaming of a class.
Comment 10 Karen Butzke CLA 2012-04-17 11:10:58 EDT
Thanks so much for doing the profiling, the results were definitely helpful. I had some assumptions about the particular slow performance code only being an issue during project loading, so this makes it a bigger reason to fix it. I'm not promising miracles, but am making an attempt to fix some of these issues in Juno M7.

I am also interested in what causes your validation to take so long. I know of 1 issue (bug 376595), but there could potentially be other issues slowing it down. I would appreciate your attaching a profiling snapshot of a project validation run with JPA validation turned back on.
Comment 11 Jesper Skov CLA 2012-04-18 04:06:31 EDT
Created attachment 214164 [details]
Clean-build with validation enabled

No problem; glad to help.

Our developers are majorly unhappy about the current performance, as they waste a lot of time on it. So I am happy to help you with profiling - also if you have any pre-milestone builds you want tested. Let me know.

Attached is a clean-build with validation enabled.

I assume this is what you asked for?
Comment 12 Karen Butzke CLA 2012-04-18 08:18:55 EDT
(In reply to comment #11)
> Created attachment 214164 [details]
> Clean-build with validation enabled
> 
> No problem; glad to help.
> 
> Our developers are majorly unhappy about the current performance, as they waste
> a lot of time on it. So I am happy to help you with profiling - also if you
> have any pre-milestone builds you want tested. Let me know.
> 
> Attached is a clean-build with validation enabled.
> 
> I assume this is what you asked for?

That is definitely helpful in showing the building of a JPA project, but it looks like you stopped to early to see the actual validation job running. I assume you're stopping the profiling early since otherwise it would probably take an hour to run? The changes I've made so far should have greatly improved the building time. I'll let you know when there's an i-build that you could verify that in.

Could you right-click on the project and choose 'Validate' and send a profiling snapshot of that process?
Comment 13 Jesper Skov CLA 2012-04-18 09:08:22 EDT
Actually, I thought Validation was run as part of the build process?

When I right-click the projects and run Validate, it completes in a jiffie.


Anyway, I'll make you a profiling snapshot, and maybe you can spot if I am simply missing something.
Comment 14 Jesper Skov CLA 2012-04-18 09:18:48 EDT
Created attachment 214179 [details]
CPU profiling snapshot of validation operation

As you can see, it completes in <1s.

As far as I can tell, JPA validation is enabled. But you may be able to reason otherwise from the snapshot.
Comment 15 Karen Butzke CLA 2012-04-18 09:29:40 EDT
(In reply to comment #14)
> Created attachment 214179 [details]
> CPU profiling snapshot of validation operation
> 
> As you can see, it completes in <1s.
> 
> As far as I can tell, JPA validation is enabled. But you may be able to reason
> otherwise from the snapshot.

The JPA project build time is taking so long in the clean-build that it hasn't even gotten to the validation.

In the profiling snapshot of a 'Validation' operation it is only validating 1 java entity. Does this project have class-refs listed in the persistence.xml? I'm confused as to what is going on here. Are there any errors in the error log? Do you see your entities in the Project Explorer view under the JPA Content node?
Comment 16 Jesper Skov CLA 2012-04-18 09:42:41 EDT
This is the persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
	<persistence-unit name="jb.it.jess.ejb">
	  <provider>org.hibernate.ejb.HibernatePersistence</provider> 
	  <jta-data-source>java:/jdbc/jb.it.jess.ds</jta-data-source>
	  <class>dk.jyskebank.service.domain.AuditEntry</class>
	  	<properties>
     		<property name="hibernate.hbm2ddl.auto" value="create-drop" />
	    	<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
	    	<property name="hibernate.show_sql" value="true" />
		</properties>
	</persistence-unit>
</persistence>

And only that class is listed under the JPA Content node.

Not sure why it looks like that. I can try to remove it, if it makes a difference.


There are also project build errors. I didn't notice because I was focusing on the refactoring problems :(    I'll see if I can get it fixed.
Comment 17 Jesper Skov CLA 2012-04-18 09:58:33 EDT
I fixed the build errors.

Commenting the persistence.xml class reference out did not make a difference - still only the one class listed in the JPA Content.

I'm afraid I know too little of JPA to amend it myself, but I'm happy to follow any input you may have.
Comment 18 Karen Butzke CLA 2012-04-18 11:14:59 EDT
It sounds like this project only has 1 class in it that is annotated with @Entity. Is that the case? Are there other projects with JPA entities in them? I'm not completely sure how to help you without more info about your model. In the JPA project properties you can set 'Discover annotated classes automically' or 'Annotated classes must be listed in persistence.xml'. What do you have that set to?
Comment 19 Karen Butzke CLA 2012-04-18 12:03:19 EDT
In your original comment you said:

> I have disabled JPA validation because that also takes a long time for some of
> the classes in the project.

Could I get you to clarify this statement? I made some assumptions about what you meant here and I may have been wrong. In the project properties did you remove the JPA facet on the 'Project Facets' page or did you uncheck 'JPA Validator' on the 'Validation' page? And what steps are you taking when you say that the validation takes a long time for some of the classes?

Maybe some of the confusion is because Dali project building and validation are 2 separate processes, unlike how one would think of JDT where building and validation are inseparable. So during a project clean the Dali JPA project gets rebuilt first and then it gets validated.
Comment 20 Jesper Skov CLA 2012-04-19 04:08:56 EDT
Looking through the sources, there is only that one @Entity annotated class.

The comment about slow Validation was just a hasty assumption, it seems.
It may well be one of the other validators taking a long time, and I just disabled them all. Didn't intend to mislead ;)

So I guess the - JPA - performance problems are only related to build and refactoring.
Comment 21 Karen Butzke CLA 2012-04-20 09:04:05 EDT
The latest WTP i-build (http://download.eclipse.org/webtools/downloads/drops/R3.4.0/I-3.4.0-20120419070008) has the changes I've made so far that should help with your issues. If you could try it out on the refactoring or cleaning operations and attach another profiling snapshot, that'd be great!
Comment 22 Jesper Skov CLA 2012-04-23 03:57:38 EDT
Created attachment 214369 [details]
Clean+build with I20120419070008 updated WTP.
Comment 23 Jesper Skov CLA 2012-04-23 03:58:05 EDT
Created attachment 214370 [details]
Refactoring with I20120419070008 updated WTP.
Comment 24 Jesper Skov CLA 2012-04-23 04:00:16 EDT
I've added profiling snapshots for clean+build and a class renaming.

Class renaming took 17 seconds, which is a marked improvement.
Obviously, if you can find further ways to improve it, our developers would love it :)
Comment 25 Karen Butzke CLA 2012-04-25 08:58:07 EDT
A few more changes became apparent with your latest snapshots. Those changes are in build http://build.eclipse.org/webtools/committers/wtp4x-R3.4.0-I/20120425070315/I-3.4.0-20120425070315/ if you could try it out once more.

This will probably be as good as it gets in Juno (M7 is wrapping up soon), but it's a big improvement from completely hanging the UI for up to a minute down to showing progress for 17 seconds! We're planning to continue making performance improvements in the next release.
Comment 26 Jesper Skov CLA 2012-04-26 04:05:06 EDT
Created attachment 214583 [details]
Clean+build with I20120425070315 updated WTP
Comment 27 Jesper Skov CLA 2012-04-26 04:05:29 EDT
Created attachment 214584 [details]
Refactoring with I20120425070315 updated WTP
Comment 28 Jesper Skov CLA 2012-04-26 04:07:45 EDT
Truly awesome!

The refactoring operation now clocks at 7-9 seconds. Definitely acceptable.

Thanks a lot for your work. We're looking forward to the M7 release in May.

I'll close the issue (if I can).
Comment 29 Jesper Skov CLA 2012-04-26 04:09:09 EDT
Uh, don't know if you use the bug status for tracking, so I'll let you close it in whatever way is appropriate...
Comment 30 Karen Butzke CLA 2012-04-26 07:57:20 EDT
Thanks, glad to help!