Bug 86541 - Investigate if we can avoid computing bindings when creating breakpoints
Summary: Investigate if we can avoid computing bindings when creating breakpoints
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Luc Bourlier CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2005-02-24 14:40 EST by DJ Houghton CLA
Modified: 2005-04-13 14:54 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description DJ Houghton CLA 2005-02-24 14:40:46 EST
build i0222

- start Eclipse with an empty workspace
- switch to the Java perspective
- Open Type...
- nothing is in the list
- Window -> Show View -> Other -> PDE -> Plug-ins
- org.eclipse.core.resources
- use context menu to Add to Java Search
- OK
- Open Type...
- choose "Workspace" class
- pick a method, any method
- double-click to add a breakpoint

Note that:
- the break point appears and then immediately disappears
- break point is moved to be the last line (closing brace) of the method

When setting a breakpoint in the breakpoint location validator, it was
determined from the AST that the super-class (PlatformObject) could not be
resolved so that's why the breakpoint was moved. 

Is it necessary to have to resolve the class in order to set a breakpoint?
Comment 1 Olivier Thomann CLA 2005-02-24 14:43:52 EST
If the code needs to be resolved, the proper context should be provided.
Otherwise it is likely that the resolution will fail.
Comment 2 DJ Houghton CLA 2005-02-24 15:04:54 EST
See also bug 86542.
Comment 3 Luc Bourlier CLA 2005-02-24 17:39:50 EST
Resolving the class is not required to set a breakpoint, but is usefull for one
specific case.
With some code :

1: int i= 2
2:      + 3;

if you try to add a breakpoint line 2, the breakpoint will be move line 1,
because we know the compiler doesn't generate code for line 2, the constant
value is resolve at compile time.

We are currently doing this optimisation if we think the compiler will be able
to resolve the bindings. The current implementation is, if we have a Java
project, we can ask and will get the bindings. It's obviously wrong in this case
(and others).

But, that shouldn't be a real problem, we can check if bindings were resolved
after the fact.

The real problem is the fact that the compiler doesn't return the complete AST
of the type in this case, the method nodes are empty.
It looks like because we asked for the bindings to be resolved and the
superclass is not available, the compiler does not complete the parsing.
I would have excepted to get the complete AST, with no bindings.

Olivier, is this the normal behavior (incomplete AST if problems with the
bindings) ? I don't see anything in javadoc about it.
Comment 4 Olivier Thomann CLA 2005-02-24 22:20:55 EST
This looks like a bug. When the hierarchy cannot be built, the compilation
aborts. At this moment the methods inside the compilation unit have no body.
I take the bug back and I will investigate a fix.
Comment 5 Olivier Thomann CLA 2005-02-25 10:12:30 EST
Luc,

You found a bug in the AST. When the bindings cannot be resolved, we should not
abort and give a complete tree. However you should not request the bindings just
to support the case you describe. Requesting the bindings cost in memory and
speed. It would be must faster to create the tree without the bindings.
So I suggest that you set up the creation of the tree without the bindings.
We will fix this issue in our code.
Comment 6 Olivier Thomann CLA 2005-02-25 12:04:21 EST
Fix is released for JDT/Core. Regression test added.
You should still investigate the necessity to get bindings in this case. I don't
believe you should resolve the bindings.
Comment 7 Darin Wright CLA 2005-04-13 12:41:02 EDT
Fixed in BreakpointLocationVerifierJob and ValidBreakpointLocationLocator. 
Modified the job to run first without bindings, and determine if bindings 
would have been helpful. If so, and binding info is available (i.e. we hava a 
Java model context), the job is re-run with bindings.
Comment 8 Darin Wright CLA 2005-04-13 12:44:43 EDT
Please verify, Luc.

Luc, I have one question about the code in ValidBreakpointLocationLocator#visit
(Assignemnt). It only checks the right hand side of the assignment if the left 
hand side is a local or a static fields. Why does it exclude non-static fields?
Comment 9 Luc Bourlier CLA 2005-04-13 14:54:24 EDT
Verified.

For your question, the test case is (bug 75599) :

1:  
2:  foo
3:      =
4:        <expression>;

if the user ask to set a breakpoint on line 1 and 'foo' is a local variable or a
static field, the breakpoint is set on line 4.

The idea is, when the user ask to set a breakpoint on a empty line before the
assigment, he wants the vm/thread to suspend on the first intruction to be
executed after line 1.

If 'foo' is a local variable or a static field, the code generated by the
compiler is something like:
- code for <expression>
- store result in 'foo'
The expression is executed first

if 'foo' is an non-static field, the generated code is looks like:
- push 'this' on the stack
- code for <expression>
- store result in this.foo
The first instruction is the push of 'this', this instruction is associated with
the line of the 'foo' identifier.

If the user ask for a breakpoint on line 2, it is set on line 2.