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 49459 - Missing Mutex.isReadAccess() causing unwanted garbage to be created
Summary: Missing Mutex.isReadAccess() causing unwanted garbage to be created
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 4.x
Hardware: PC Linux
: P3 blocker (vote)
Assignee: Jaroslav Tulach
URL:
Keywords: API_REVIEW_FAST, PERFORMANCE
Depends on:
Blocks:
 
Reported: 2004-09-23 10:06 UTC by Jaroslav Tulach
Modified: 2008-12-22 21:46 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Addition of Mutex.isRead/WriteAccess() with tests (14.08 KB, patch)
2004-09-23 14:48 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2004-09-23 10:06:51 UTC
When I was debugging org.openide.nodes.Children I
found out that often a lot of postWriteAccess
and/or postReadAccess Runnables gets created and
is executed when the
Mutex.Priviledged.exitReadAccess() method is
called. After further investigation it has been
found that those runnables (8 of 10 in my case, so
just two were useful, rest was useless) are there
just to find out whether the code is in read
access section or not. As these Runnables survive
return from a method that creates them, I am
affraid they escape from the young generation in
GC and can live longer then we would like to.

The code pattern in question is:


// we are not in ReadAccess
// Children.MUTEX.isReadAccess, if such call would
// be added to Mutex
class MutexChecker implements Runnable {
  public boolean inReadAccess = true;
  public void run () {
    inReadAccess = false;
  }
}
MutexChecker test = new MutexChecker();
// the code will run either immediatally 
// or after we leave readAccess
// section
Children.MUTEX.postWriteRequest(test);

if (test.inReadAccess) {
  // we are in read access
} else {
  // we are not
}

Such code is used in Children.java and also
FolderChildren.java. I suggest to add new two
methods into Mutex (final class, so no problems
with adding methods) and replace such complex code
above with pure:

MUTEX.isReadAccess() and MUTEX.isWriteAccess()

that is going to perform faster and will be more
easier to use.
Comment 1 Jaroslav Tulach 2004-09-23 10:17:28 UTC
I've just measured that when I open my home directory in Favourites
tab, there is ~800 of such useless runnables created. My directory
contains 136 files.
Comment 2 Antonin Nebuzelsky 2004-09-23 10:19:52 UTC
800?! wow :)
Comment 3 Jaroslav Tulach 2004-09-23 14:48:30 UTC
Created attachment 17837 [details]
Addition of Mutex.isRead/WriteAccess() with tests
Comment 4 Jaroslav Tulach 2004-09-23 14:50:14 UTC
I have added the isReadAccess() and isWriteAccess() methods, cleared
the code in FolderChildren and Children and also clarified behaviour
of write->read->write to notify that this is not the right thing to
do. Ok?
Comment 5 Jesse Glick 2004-09-23 15:49:30 UTC
See also issue #32439 for context.

Don't really care what you do with Mutex; the whole class should die
anyway. Anyway in the future Children should not need it to begin with
- see issue #35833.
Comment 6 Jaroslav Tulach 2004-09-29 09:35:08 UTC
Ok, I'll fix the # of unnecessary allocations tomorrow.
Comment 7 Jaroslav Tulach 2004-09-30 10:15:00 UTC
/cvs/openide/openide-spec-vers.properties,v  <-- 
openide-spec-vers.properties
new revision: 1.158; previous revision: 1.157
done
Processing log script arguments...
More commits to come...
Checking in api/doc/changes/apichanges.xml;
/cvs/openide/api/doc/changes/apichanges.xml,v  <--  apichanges.xml
new revision: 1.220; previous revision: 1.219
done
Processing log script arguments...
More commits to come...
Checking in loaders/nbproject/project.xml;
/cvs/openide/loaders/nbproject/project.xml,v  <--  project.xml
new revision: 1.6; previous revision: 1.5
done
Processing log script arguments...
More commits to come...
Checking in loaders/src/org/openide/loaders/FolderChildren.java;
/cvs/openide/loaders/src/org/openide/loaders/FolderChildren.java,v 
<--  FolderChildren.java
new revision: 1.6; previous revision: 1.5
done
Processing log script arguments...
More commits to come...
Checking in src/org/openide/nodes/Children.java;
/cvs/openide/src/org/openide/nodes/Children.java,v  <--  Children.java
new revision: 1.124; previous revision: 1.123
done
Processing log script arguments...
More commits to come...
Checking in src/org/openide/util/Mutex.java;
/cvs/openide/src/org/openide/util/Mutex.java,v  <--  Mutex.java
new revision: 1.63; previous revision: 1.62
done
Processing log script arguments...
More commits to come...
Checking in test/unit/src/org/openide/util/MutexTest.java;
/cvs/openide/test/unit/src/org/openide/util/MutexTest.java,v  <-- 
MutexTest.java
new revision: 1.12; previous revision: 1.11
Comment 8 Jaromir Uhrik 2005-07-14 16:19:03 UTC
Verified.