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 257013 - Introduce callback references in place of activeReferenceQueue
Summary: Introduce callback references in place of activeReferenceQueue
Status: NEW
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 8.2
Hardware: All All
: P2 normal (vote)
Assignee: apireviews
Depends on:
Reported: 2015-12-07 08:55 UTC by Martin Entlicher
Modified: 2015-12-17 13:06 UTC (History)
1 user (show)

See Also:
Exception Reporter:

The proposed CallbackReferences API (38.03 KB, patch)
2015-12-08 09:04 UTC, Martin Entlicher
Details | Diff
New proposed CallbackReferences API (86.05 KB, patch)
2015-12-12 00:17 UTC, Martin Entlicher
Details | Diff
Changed usages from old Utilities.activeReferenceQueue() to new CallbackReferences (80.47 KB, patch)
2015-12-12 00:28 UTC, Martin Entlicher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Entlicher 2015-12-07 08:55:48 UTC
activeReferenceQueue() has a problem described in issue #256943.
I we provide an implementation of references instead of reference queue, we can have more control on it and we can provide implementation that does not need to access the ReferenceQueue internals and that does not suffer from the above problem.
Comment 1 Martin Entlicher 2015-12-08 09:04:19 UTC
Created attachment 157714 [details]
The proposed CallbackReferences API
Comment 2 Martin Entlicher 2015-12-08 09:05:28 UTC
Please review the proposed API change.
Comment 3 Martin Entlicher 2015-12-11 23:58:13 UTC
Unfortunately, the first proposal has some problems.
The use of finalizers is causing troubles, sometimes finalizers are called for objects (instances of Reference) which were placed into the ReferenceQueue and therefore callbacks were discarded before they should be executed.
Also this proposal is increasing memory usage of these "active" callback references.
I'm about to attach a significantly reworked proposal with additional tests.
Comment 4 Martin Entlicher 2015-12-12 00:17:18 UTC
Created attachment 157767 [details]
New proposed CallbackReferences API

I'm attaching the new proposal.
Regarding naming, I was hesitating between CallbackReferences and ActiveReferences, if someone prefers a different name from the proposed one, it's easy to rename.

There are two implementations of the background thread:
1. In NetBeans IDE, it's impossible to occur that at some point in time all callback references would be processed and the thread could be shut down. Therefore the extra memory usage caused by control references checking the GC, is just a waste of memory space. Therefore the IDE sets system property  netbeans.CallbackReferences.delayShutdownOfCallbackThread=infinity which selects the indefinite background thread (old ActiveQueue) and adds no overhead with respect to the original implementation.
2. By default, to keep compatibility, a finishable background thread is used, but it adds an overhead of one extra weak reference having one int field.

Tests are added.
Comment 5 Martin Entlicher 2015-12-12 00:28:24 UTC
Created attachment 157768 [details]
Changed usages from old Utilities.activeReferenceQueue() to new CallbackReferences

Usages changed throughout the NetBeans code base.
Comment 6 Martin Entlicher 2015-12-17 13:06:08 UTC
Since the usages of activeReferenceQueue() are spread throughout the NetBeans codebase, I'll wait with the integration until after all fixes for 8.1 patch 1 are done and merge into the fixes branch, in order not to complicate the backport.