This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 40026 - Early assigning of document to text component
Summary: Early assigning of document to text component
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker (vote)
Assignee: Petr Nejedly
URL:
Keywords: THREAD
: 40047 40070 40072 40073 40074 40100 40148 41503 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-02-12 15:22 UTC by Miloslav Metelka
Modified: 2008-12-22 15:47 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Deadlock of AWT against document loading RP (12.49 KB, text/plain)
2004-02-12 15:24 UTC, Miloslav Metelka
Details
Possible fix for the problem (1.05 KB, patch)
2004-02-12 15:25 UTC, Miloslav Metelka
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Miloslav Metelka 2004-02-12 15:22:36 UTC
Petre yesterday I was trying to resolve issue
39944 and issue 39783 by calling the fold
maintainers directly instead of posting to RP
(when pane.setDocument() is called and the view
hierarchy is being constructed which in turn
triggers the fold hierarchy to be created).

It looked well until Mato hit a dedlok (attached).
I guess that happened when the IDE was shutdown
with few editors opened and Mato restarted the IDE
and "scrolled" through opened components by
Alt+Right key.
 That deadlock unveils an interesting case that
makes me think about the assigning of the document
to the text component.

In the current state the situation may be like this:
1) document gets created in CES.
2) document loading gets scheduled into RP.
3) before doc-loading RP write-locks the doc the
AWT thread constructs the editor pane and calls
CES.getDocumentHack() and assigns the doc into
pane by pane.setDocument().
4) setDocument() triggers various listeners (e.g.
in TextUI) that service the doc change - e.g. view
hierarchy gets created etc. Those operations
typically run under read/write lock being held on
the document to make sure there is no modification
done to the doc during e.g. view hierarchy
construction.
5) If any code involved would call
CES.openDocument() when under read/write lock
there is a deadlock because CES will put this
thread to sleep but as the thread still holds
read/write lock on the doc the doc-loading RP
cannot acquire the doc write lock and the loading
will never proceed. In the attached dedlok the
JavaParserGlue calls the CES.openDocument().

I was wondering whether it's necessary to assign
the document to text component prior it gets fully
loaded and I think it does not help much because
even if the document gets assigned to the
component the loading will write-lock it until
it's fully loaded so the user will see the content
_after_ the loading ends anyway (the repainting of
the editor acquires read-lock so it will block
until write-lock of loading RP gets released).
 I propose to change the current
CloneableEditor.initialize() to call
CES.openDocument() instead of
CES.getDocumentHack(). Although by openDocument()
we may block AWT for a while the user IMHO is
waiting for the document to be opened and she
would not do any useful work in the meantime anyway.

I've prepared a patch that I have tested and there
seem to be no problems with it. If you agree that
this would be useful change please approve it or
integrate it directly. Thanks.
Comment 1 Miloslav Metelka 2004-02-12 15:24:50 UTC
Created attachment 13393 [details]
Deadlock of AWT against document loading RP
Comment 2 Miloslav Metelka 2004-02-12 15:25:35 UTC
Created attachment 13394 [details]
Possible fix for the problem
Comment 3 Petr Nejedly 2004-02-12 17:10:04 UTC
I'd go even further and also simplify the code around (e.g. setting
caret).
I'll try it...
Comment 4 Martin Roskanin 2004-02-13 09:55:48 UTC
*** Issue 40047 has been marked as a duplicate of this issue. ***
Comment 5 Petr Nejedly 2004-02-13 10:21:11 UTC
Fixed (different patch).
openide/src/org/openide/text/CloneableEditor.java,v1.69
Comment 6 pzajac 2004-02-13 10:57:52 UTC
*** Issue 40070 has been marked as a duplicate of this issue. ***
Comment 7 Petr Nejedly 2004-02-13 11:51:18 UTC
*** Issue 40073 has been marked as a duplicate of this issue. ***
Comment 8 pzajac 2004-02-13 12:19:52 UTC
*** Issue 40074 has been marked as a duplicate of this issue. ***
Comment 9 Miloslav Metelka 2004-02-13 15:02:22 UTC
*** Issue 40072 has been marked as a duplicate of this issue. ***
Comment 10 Martin Roskanin 2004-02-15 08:41:38 UTC
*** Issue 40100 has been marked as a duplicate of this issue. ***
Comment 11 Miloslav Metelka 2004-02-17 14:46:34 UTC
*** Issue 40148 has been marked as a duplicate of this issue. ***
Comment 12 Marian Mirilovic 2004-02-19 08:29:53 UTC
I think it works fine now - verified
Comment 13 Petr Nejedly 2004-03-31 09:18:42 UTC
*** Issue 41503 has been marked as a duplicate of this issue. ***