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.
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.
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.
800?! wow :)
Created attachment 17837 [details] Addition of Mutex.isRead/WriteAccess() with tests
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?
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.
Ok, I'll fix the # of unnecessary allocations tomorrow.
/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
Verified.