Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318704 - [Editor] Zero lenght sematically highlighted positions cause endless loop
Summary: [Editor] Zero lenght sematically highlighted positions cause endless loop
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 1.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: SR1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-02 08:35 EDT by Sven Efftinge CLA
Modified: 2017-09-19 17:46 EDT (History)
3 users (show)

See Also:
sebastian.zarnekow: helios+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Efftinge CLA 2010-07-02 08:35:15 EDT
I am running into a deadlock situation. I seems like Highlighting and Outline are deadlocking.

I have let the IDE run for a bit and then paused, when repeating it is stuck in the same two places... (See stack tracess below)

The problem can be replicated - I always get the problem when in a particular position in the source text.

If I remove my semantic highlighting, it does not hang, and I get an error marker instead (because of a syntax error - which is expected).

Do I need to protect the highlighting in a UnitOfWork some way, or should it work without this? I read this: "Please refer to DefaultContentOutlineNodeFactory.getEObjectHandle(EObject, IStateAccess<XtextResource>) to learn more about IEObjectHandles. ", and I have seen that I may not work directly with the model.

And I looked at the mentioned code, but I just don't get it...
What I am doing now is like this...

    public void provideHighlightingFor2(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
        if(resource == null)
            return;
        EList<EObject> contents = resource.getContents();
        if(contents == null || contents.size() == 0)
            return; // nothing there at all - probably an empty file
        BeeModel model = (BeeModel) contents.get(0);
        // BuildUnit bu = model.getBody();
        TreeIterator<EObject> all = model.eAllContents();
        while(all.hasNext()) {
            EObject o = all.next();
            // TODO: OPTIMIZE the if-then-else below using an EMF switch
            if(o instanceof BuildUnit)
                highlightBuildUnit((BuildUnit) o, acceptor);

            // handle literals
            else if(o instanceof BLiteralExpression) {
                Object val = ((BLiteralExpression) o).getValue();
                // handle real numbers (INT and HEX are handled by terminal rules)
                if(val instanceof Float || val instanceof Double)
                    highlightObject(o, BeeLangHighlightConfiguration.REAL_ID, acceptor);
            }
            else if(o instanceof PathVector)
                highlightPaths((PathVector) o, acceptor);
    // etc. etc...

Where the the various highlightObject, highlightPaths, use a variant of finding "firstFeature" as I seen used by others...

Am I doing something wrong?
If I should use "readOnly" and "IUnitOfWork", how to I get to the model from the XtextResource passed in in the call to provideHighlightingFor ?

(The version on b3's HEAD has the semantic highlighting disabled since I am working on a proposal provider for the position where this issue occurs...)
        // provideHighlightingFor2(resource, acceptor);

Regards
- henrik


Daemon Thread [Thread-0] (Suspended)   
    Unsafe.park(boolean, long) line: not available [native method]   
    LockSupport.park(Object) line: 158   
    ReentrantReadWriteLock$NonfairSync(AbstractQueuedSynchronizer).parkAndCheckInterrupt() line: 747   
    ReentrantReadWriteLock$NonfairSync(AbstractQueuedSynchronizer).doAcquireShared(int) line: 877   
    ReentrantReadWriteLock$NonfairSync(AbstractQueuedSynchronizer).acquireShared(int) line: 1197   
    ReentrantReadWriteLock$ReadLock.lock() line: 594   
    XtextDocument$XtextDocumentLocker(IStateAccess$AbstractImpl<P>).readOnly(IUnitOfWork<T,P>) line: 36   
    XtextDocument.readOnly(IUnitOfWork<T,XtextResource>) line: 58   
    XtextContentOutlinePage.synchronizeOutlinePage() line: 312   
    EditorSelectionChangedListener.selectionChanged(SelectionChangedEvent) line: 31   
    XtextSourceViewer(TextViewer).firePostSelectionChanged(SelectionChangedEvent) line: 2745   
    XtextSourceViewer(TextViewer).firePostSelectionChanged(int, int) line: 2693   
    TextViewer$5.run() line: 2672   
    Display.runTimers() line: 3742   
    Display.readAndDispatch() line: 3256   
    Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2624   
    Workbench.runUI() line: 2588   
    Workbench.access$4(Workbench) line: 2422   
    Workbench$7.run() line: 670   
    Realm.runWithDefault(Realm, Runnable) line: 332   
    Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 663   
    PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149   
    IDEApplication.start(IApplicationContext) line: 115   
    EclipseAppHandle.run(Object) line: 196   
    EclipseAppLauncher.runApplication(Object) line: 110   
    EclipseAppLauncher.start(Object) line: 79   
    EclipseStarter.run(Object) line: 369   
    EclipseStarter.run(String[], Runnable) line: 179   
    NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]   
    NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39   
    DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25   
    Method.invoke(Object, Object...) line: 597   
    Main.invokeFramework(String[], URL[]) line: 619   
    Main.basicRun(String[]) line: 574   
    Main.run(String[]) line: 1407   
    Main.main(String[]) line: 1383   


AND
Thread [Worker-3] (Suspended)   
    MergingHighlightedPositionAcceptor.mergePositions(int, int, int, LightweightPosition$IntToStringArray[]) line: 88   
    MergingHighlightedPositionAcceptor.mergePositions() line: 71   
    MergingHighlightedPositionAcceptor.provideHighlightingFor(XtextResource, IHighlightedPositionAcceptor) line: 47   
    HighlightingReconciler.reconcilePositions(XtextResource) line: 87   
    HighlightingReconciler.modelChanged(XtextResource) line: 275   
    XtextDocument.notifyModelListeners(XtextResource) line: 90   
    XtextDocument$XtextDocumentLocker.afterModify(XtextResource, Object, IUnitOfWork<?,XtextResource>) line: 142   
    XtextDocument$XtextDocumentLocker.afterModify(Object, Object, IUnitOfWork) line: 1   
    XtextDocument$XtextDocumentLocker(IStateAccess$AbstractImpl<P>).modify(IUnitOfWork<T,P>) line: 58   
    XtextDocument$XtextDocumentLocker.modify(IUnitOfWork<T,XtextResource>) line: 149   
    XtextDocument.modify(IUnitOfWork<T,XtextResource>) line: 62   
    XtextDocumentReconcileStrategy.reconcile(IRegion) line: 27   
    XtextReconciler.run(IProgressMonitor) line: 179   
    Worker.run() line: 54
Comment 1 Sven Efftinge CLA 2010-07-02 08:35:50 EDT
Copied from a forum message by Henrik (news://news.eclipse.org:119/i0jmvv$f4f$1@build.eclipse.org)
Comment 2 Henrik Lindberg CLA 2010-07-03 10:22:55 EDT
Sebastian wrote
>can you confirm that it's an endless loop in MergedHighlightingPositionAcceptor.mergePositions?

So far, I have only paused the execution and looked at where the different threads were executing - did not look at exact positions, but "mergePositions" was always on the call stack (afaict).

How can I provide more info?

To replicate:
If you update your b3 workspace remove the o.e.b3.backend.[edit, editor and test] projects (obsolete generated stuff).

Then uncomment line 145 in /org.eclipse.b3.beelang.ui/src/org/eclipse/b3/coloring/BeeLangSemanticHighlightingCalculator.java
which says:
// provideHighlightingFor2(resource, acceptor);

And with a b3 file like this:
unit HelloDeadlock version | {
}

Place the marker at | (if you get that far after typing 'version'), try typing a version '1.0.0', or invoke proposals.
Comment 3 Sebastian Zarnekow CLA 2010-07-03 13:12:38 EDT
I'ld guess that the problem does not disappear if you close the outline before you perform the necessary steps to reproduce the locked ui.

A list of offset / lengths / ids that are passed to the HighlightedPositionAcceptor would be great, e.g something like

1, 5, 'myId'
3, 5, 'myIdOverlay', 'anotherId'
4, 6, ..
Comment 4 Henrik Lindberg CLA 2010-07-03 19:49:54 EDT
(In reply to comment #3)
> I'ld guess that the problem does not disappear if you close the outline before
> you perform the necessary steps to reproduce the locked ui.
> 
> A list of offset / lengths / ids that are passed to the
> HighlightedPositionAcceptor would be great, e.g something like
> 
> 1, 5, 'myId'
> 3, 5, 'myIdOverlay', 'anotherId'
> 4, 6, ..

Does not help to close the outline (tried that).
Will see what I can generate in terms of data...
Comment 5 Henrik Lindberg CLA 2010-07-03 20:30:10 EDT
I wrote a wrapper to record what was called.

For this input:
unit a version  {
}
unit b { }

This is the positions and styles
5, 1, default
25, 1, default
14, 0, version

And the last output gave me a clue to the cause.
So, I filtered out requests to highlight something of zero length - and guess what... Now it does not hang anymore.
Comment 6 Sebastian Zarnekow CLA 2010-07-04 04:39:19 EDT
Thanks Henrik.

I changed the subject of this bugzilla and scheduled it for SR1.
Comment 7 Sebastian Zarnekow CLA 2010-07-20 08:57:11 EDT
Fixed in HEAD.
Comment 8 Alexis Drogoul CLA 2012-02-13 10:58:42 EST
I've run into this bug again in XText v2.2.0 Filtering the nodes of length 0, suggested here, did not help. Debugging shows that mergePositions() of MergingHighlightedPositionAcceptor is stuck into an endless while() loop, but only for certain files, but I've yet to understand the pattern. I'll post more information as soon as I have significant test cases.
Comment 9 Karsten Thoms CLA 2017-09-19 17:35:45 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 10 Karsten Thoms CLA 2017-09-19 17:46:42 EDT
Closing all bugs that were set to RESOLVED before Neon.0