Integrated: 8301684: Fix test code to not get finalizer deprecation warnings
Afshin Zafari
duke at openjdk.org
Fri Mar 17 13:25:14 UTC 2023
On Fri, 10 Mar 2023 08:23:45 GMT, Afshin Zafari <duke at openjdk.org> wrote:
> To replace the finalizer use in the code, the `Cleaner` approach is used as stated in [Oracle doc on deprecated finalize() method](https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#finalize()).
> Briefly:
> 1. An instance of `Cleaner` (`java.lang.ref`) is created.
> 2. Using the `Cleaner`, an object is registered with a `Runnable` callback that is notified when the object is no longer reachable (GC'ed).
> 3. Write code in the callback to do other cleanings.
>
>
> Cleaner c = new Cleaner();
> Cleanable cleanable = c.register(an_obj, a_runnable);
> ...
> //JVM notifies by calling the
> a_runnable.run() {...}
>
> ### Tests
> local:
> vmTestbase/nsk/monitoring/stress/classload
> vmTestbase/nsk/jvmti/AttachOnDemand
> vmTestbase/nsk/jdi/ObjectReference/referringObjects
> vmTestbase/nsk/sysdict
> mach5: tier 1-5
This pull request has now been integrated.
Changeset: 6dd6c15e
Author: Afshin Zafari <Afshin.zafari at oracle.com>
Committer: Coleen Phillimore <coleenp at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/6dd6c15ed4b2a563989e97c5a75634c3e0e7e915
Stats: 116 lines in 2 files changed: 9 ins; 85 del; 22 mod
8301684: Fix test code to not get finalizer deprecation warnings
Reviewed-by: coleenp, dholmes
-------------
PR: https://git.openjdk.org/jdk/pull/12968
More information about the hotspot-runtime-dev
mailing list