Bug 133141 - Must JavaCore.create(IFile) always do full checks?
Summary: Must JavaCore.create(IFile) always do full checks?
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2006-03-24 07:22 EST by Dani Megert CLA
Modified: 2007-05-25 09:02 EDT (History)
1 user (show)

See Also:
frederic_fusier: review+


Attachments
Proposed fix and performance test (4.42 KB, patch)
2007-05-16 10:52 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2006-03-24 07:22:28 EST
I20060315-1200

I found this while digging into bug 133025. In 3.2 Debug added some code that requests the Java element adapter for an IFile (that's OK). This results in a call to JavaCore.create(IFile). Even though the CU is in the model all checks are made before the CU is returned and the Scanner is consulted, see the stack trace below.

NOTE: this is the same behavior as in 3.1 (and maybe before) and not a regression in JDT Core but since many clients are either using JavaCore.create(IFile) or IFile.getAdapter(IJavaElement.class) it could be a good performance benefit if this could be avoided.

Thread [main] (Suspended (breakpoint at line 834 in Scanner))
	owns: Class<T> (org.eclipse.jdt.core.JavaConventions) (id=270)
	owns: RunnableLock  (id=310)
	Scanner.getNextToken() line: 834
	JavaConventions.scannedIdentifier(String) line: 89
	JavaConventions.validateIdentifier(String) line: 232
	Util.isValidFolderNameForPackage(String) line: 1320
	Util.packageName(IPath) line: 1474
	JavaModelManager.determineIfOnClasspath(IResource, IJavaProject) line: 830
	JavaModelManager.createCompilationUnitFrom(IFile, IJavaProject) line: 749
	JavaModelManager.create(IFile, IJavaProject) line: 660
	JavaModelManager.create(IResource, IJavaProject) line: 624
	JavaCore.create(IResource) line: 1378
	ResourceAdapterFactory.getAdapter(Object, Class) line: 38
	AdapterFactoryProxy.getAdapter(Object, Class) line: 63
	AdapterManager.getAdapter(Object, Class) line: 253
	File(PlatformObject).getAdapter(Class) line: 65
	FileEditorInput.getAdapter(Class) line: 87
	ToggleBreakpointAdapter.isRemote(IWorkbenchPart, ISelection) line: 422
	ToggleBreakpointAdapter.canToggleWatchpoints(IWorkbenchPart, ISelection) line: 810
	RetargetWatchpointAction.canPerformAction(Object, ISelection, IWorkbenchPart) line: 36
	RetargetAction$1.run() line: 204
	RunnableLock.run() line: 35
	UISynchronizer(Synchronizer).runAsyncMessages(boolean) line: 123
Comment 1 Philipe Mulet CLA 2006-03-27 02:00:36 EST
This API can be invoked with arbitrary resources, and thus it may not be part of the model.
Comment 2 Dani Megert CLA 2006-03-27 03:57:43 EST
I know, but thought you could do this:
1. check if it is already in the model
2. if so, return the CU else go through current code path
Comment 3 Philipe Mulet CLA 2006-03-27 05:47:40 EST
In order to be acknowledged to be part of the model, it needs to find it based on its handle; which is precisely what is occurring there.
Might be improved, but not an immediate change.

Also being in the model cache is not guaranteed, we first need to understand if the same IFile is used all the time; and if so, why aren't clients keeping the handle ?

Alternatively, the factory could remember recent handles... 
Comment 4 Jerome Lanneluc CLA 2006-05-03 07:35:35 EDT
Post 3.2
Comment 5 Dani Megert CLA 2006-06-16 08:46:26 EDT
Can this now be reopened for 3.3.?
Comment 6 Jerome Lanneluc CLA 2006-06-16 08:50:25 EDT
Reopening to consider in 3.3
Comment 7 Jerome Lanneluc CLA 2007-04-02 12:11:27 EDT
To be investigated during 3.3 M7
Comment 8 Dani Megert CLA 2007-05-04 07:39:51 EDT
>To be investigated during 3.3 M7
OK. So the result was that it doesn't pay off? What about looking into this during RC1?
Comment 9 Jerome Lanneluc CLA 2007-05-04 09:19:22 EDT
(In reply to comment #8)
> >To be investigated during 3.3 M7
> OK. So the result was that it doesn't pay off? What about looking into this
> during RC1?
> 
Sorry I didn't have time to look at this during M7. I'll try to look at it during RC1.
Comment 10 Jerome Lanneluc CLA 2007-05-16 10:52:33 EDT
Created attachment 67417 [details]
Proposed fix and performance test

The fix consists in using the project's cache if it is available. 
Note the project cache is available only if at least one NameLookup has been created for the project (e.g. for a reconcile, or if IJavaProject#findType(...) has been used) since last time the classpath was updated.

Running locally, the test is about 20% faster with the fix.
Comment 11 Frederic Fusier CLA 2007-05-16 12:07:57 EDT
Fix is OK for me.

Just one cosmetic remark on perf test, set-up may be more simple as we already created and stored a working copy on the big project:

	// setup (force the project cache to be created)
	IFile file = (IFile) WORKING_COPY.getResource();
	getNameLookup(BIG_PROJECT);
Comment 12 Jerome Lanneluc CLA 2007-05-16 13:11:48 EDT
Thanks Frederic. Made the change to the test.

Fix and test released for 3.3RC1 in HEAD.
Comment 13 Olivier Thomann CLA 2007-05-17 10:37:39 EDT
There is no background data for this perf test.
See performance.FullSourceWorkspaceModelTests#testCreateJavaElement() in last perf results.
So this needs to be verified later.
Comment 14 Frederic Fusier CLA 2007-05-25 09:02:55 EDT
Verified for 3.3 RC1 using performance results of test performance.FullSourceWorkspaceModelTests#testCreateJavaElement() in page http://fullmoon.ottawa.ibm.com/downloads/drops/I20070524-0010/performance/org.eclipse.jdt.core.php?