From f72b1098090228d5b18d176198bb6850c74bc929 Mon Sep 17 00:00:00 2001 From: prrace Date: Tue, 15 Jul 2025 12:52:33 -0700 Subject: [PATCH 1/4] 8362289 --- .../classes/apple/laf/JRSUIControl.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java index cfe3b916161fa..db69204a58838 100644 --- a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java +++ b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java @@ -27,6 +27,8 @@ import java.nio.*; import java.util.*; +import sun.java2d.Disposer; +import sun.java2d.DisposerRecord; import apple.laf.JRSUIConstants.*; @@ -92,6 +94,7 @@ private static ThreadLocalByteBuffer getThreadLocalBuffer() { private final HashMap nativeMap; private final HashMap changes; private long cfDictionaryPtr; + private Object disposerReferent = new Object(); private long priorEncodedProperties; private long currentEncodedProperties; @@ -101,6 +104,7 @@ public JRSUIControl(final boolean flipped){ this.flipped = flipped; cfDictionaryPtr = getCFDictionary(flipped); if (cfDictionaryPtr == 0) throw new RuntimeException("Unable to create native representation"); + Disposer.addRecord(disposerReferent, new JRSUIControlDisposerRecord(cfDictionaryPtr)); nativeMap = new HashMap(); changes = new HashMap(); } @@ -109,16 +113,29 @@ public JRSUIControl(final boolean flipped){ flipped = other.flipped; cfDictionaryPtr = getCFDictionary(flipped); if (cfDictionaryPtr == 0) throw new RuntimeException("Unable to create native representation"); + Disposer.addRecord(disposerReferent, new JRSUIControlDisposerRecord(cfDictionaryPtr)); nativeMap = new HashMap(); changes = new HashMap(other.nativeMap); changes.putAll(other.changes); } - @SuppressWarnings("removal") - protected synchronized void finalize() throws Throwable { - if (cfDictionaryPtr == 0) return; - disposeCFDictionary(cfDictionaryPtr); - cfDictionaryPtr = 0; + private static class JRSUIControlDisposerRecord implements DisposerRecord { + + private long cfDictionaryPtr; + JRSUIControlDisposerRecord(long ptr) { + cfDictionaryPtr = ptr; + } + + public synchronized void dispose() { + if (cfDictionaryPtr == 0) { + return; + } + try { + disposeCFDictionary(cfDictionaryPtr); + } catch (Throwable t) { + } + cfDictionaryPtr = 0; + } } From 130fdc5ea70bdfaf3658082e6f0621be3ffedd58 Mon Sep 17 00:00:00 2001 From: prrace Date: Tue, 15 Jul 2025 13:04:23 -0700 Subject: [PATCH 2/4] 8362289 --- src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java index db69204a58838..738db6bfaaeb5 100644 --- a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java +++ b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java @@ -124,7 +124,7 @@ private static class JRSUIControlDisposerRecord implements DisposerRecord { private long cfDictionaryPtr; JRSUIControlDisposerRecord(long ptr) { cfDictionaryPtr = ptr; - } + } public synchronized void dispose() { if (cfDictionaryPtr == 0) { From 2c5617380f600fd7e97f0717760c01f8e6b26caa Mon Sep 17 00:00:00 2001 From: prrace Date: Wed, 16 Jul 2025 13:55:38 -0700 Subject: [PATCH 3/4] 8362289 --- src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java index 738db6bfaaeb5..467559eba30bd 100644 --- a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java +++ b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java @@ -126,10 +126,7 @@ private static class JRSUIControlDisposerRecord implements DisposerRecord { cfDictionaryPtr = ptr; } - public synchronized void dispose() { - if (cfDictionaryPtr == 0) { - return; - } + public void dispose() { try { disposeCFDictionary(cfDictionaryPtr); } catch (Throwable t) { From 3b4556cf9041ab2b203a8513016cd0c6631ab470 Mon Sep 17 00:00:00 2001 From: prrace Date: Wed, 16 Jul 2025 15:39:38 -0700 Subject: [PATCH 4/4] JRSUIControl.java --- .../macosx/classes/apple/laf/JRSUIControl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java index 0d9373963c528..f28e05d1877de 100644 --- a/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java +++ b/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java @@ -93,8 +93,8 @@ private static ThreadLocalByteBuffer getThreadLocalBuffer() { private final HashMap nativeMap; private final HashMap changes; - private long cfDictionaryPtr; - private Object disposerReferent = new Object(); + private final long cfDictionaryPtr; + private final Object disposerReferent = new Object(); private long priorEncodedProperties; private long currentEncodedProperties; @@ -121,7 +121,7 @@ public JRSUIControl(final boolean flipped){ private static class JRSUIControlDisposerRecord implements DisposerRecord { - private long cfDictionaryPtr; + private final long cfDictionaryPtr; JRSUIControlDisposerRecord(long ptr) { cfDictionaryPtr = ptr; } @@ -131,7 +131,6 @@ public void dispose() { disposeCFDictionary(cfDictionaryPtr); } catch (Throwable t) { } - cfDictionaryPtr = 0; } }