Skip to content

Commit 8e44856

Browse files
committed
8365180: Remove sun.awt.windows.WInputMethod.finalize()
Reviewed-by: serb, azvegint
1 parent 558d063 commit 8e44856

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import sun.awt.AWTAccessor;
4545
import sun.awt.AWTAccessor.ComponentAccessor;
4646
import sun.awt.im.InputMethodAdapter;
47+
import sun.java2d.Disposer;
48+
import sun.java2d.DisposerRecord;
4749

4850
final class WInputMethod extends InputMethodAdapter
4951
{
@@ -124,6 +126,8 @@ final class WInputMethod extends InputMethodAdapter
124126
public WInputMethod()
125127
{
126128
context = createNativeContext();
129+
disposerRecord = new ContextDisposerRecord(context);
130+
Disposer.addRecord(this, disposerRecord);
127131
cmode = getConversionStatus(context);
128132
open = getOpenStatus(context);
129133
currentLocale = getNativeLocale();
@@ -132,16 +136,23 @@ public WInputMethod()
132136
}
133137
}
134138

135-
@Override
136-
@SuppressWarnings("removal")
137-
protected void finalize() throws Throwable
138-
{
139-
// Release the resources used by the native input context.
140-
if (context!=0) {
141-
destroyNativeContext(context);
142-
context=0;
139+
private final ContextDisposerRecord disposerRecord;
140+
141+
private static final class ContextDisposerRecord implements DisposerRecord {
142+
143+
private final int context;
144+
private volatile boolean disposed;
145+
146+
ContextDisposerRecord(int c) {
147+
context = c;
148+
}
149+
150+
public synchronized void dispose() {
151+
if (!disposed) {
152+
destroyNativeContext(context);
153+
}
154+
disposed = true;
143155
}
144-
super.finalize();
145156
}
146157

147158
@Override
@@ -151,9 +162,7 @@ public synchronized void setInputMethodContext(InputMethodContext context) {
151162

152163
@Override
153164
public void dispose() {
154-
// Due to a memory management problem in Windows 98, we should retain
155-
// the native input context until this object is finalized. So do
156-
// nothing here.
165+
disposerRecord.dispose();
157166
}
158167

159168
/**
@@ -448,6 +457,7 @@ public void hideWindows() {
448457
@Override
449458
public void removeNotify() {
450459
endCompositionNative(context, DISCARD_INPUT);
460+
disableNativeIME(awtFocussedComponentPeer);
451461
awtFocussedComponent = null;
452462
awtFocussedComponentPeer = null;
453463
}
@@ -658,8 +668,8 @@ private WComponentPeer getNearestNativePeer(Component comp)
658668

659669
}
660670

661-
private native int createNativeContext();
662-
private native void destroyNativeContext(int context);
671+
private static native int createNativeContext();
672+
private static native void destroyNativeContext(int context);
663673
private native void enableNativeIME(WComponentPeer peer, int context, boolean useNativeCompWindow);
664674
private native void disableNativeIME(WComponentPeer peer);
665675
private native void handleNativeIMEEvent(WComponentPeer peer, AWTEvent e);

src/java.desktop/windows/native/libawt/windows/awt_InputMethod.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern BOOL g_bUserHasChangedInputLang;
5252
* Signature: ()I
5353
*/
5454
JNIEXPORT jint JNICALL
55-
Java_sun_awt_windows_WInputMethod_createNativeContext(JNIEnv *env, jobject self)
55+
Java_sun_awt_windows_WInputMethod_createNativeContext(JNIEnv *env, jclass cls)
5656
{
5757
TRY;
5858

@@ -69,7 +69,7 @@ Java_sun_awt_windows_WInputMethod_createNativeContext(JNIEnv *env, jobject self)
6969
* Signature: (I)V
7070
*/
7171
JNIEXPORT void JNICALL
72-
Java_sun_awt_windows_WInputMethod_destroyNativeContext(JNIEnv *env, jobject self, jint context)
72+
Java_sun_awt_windows_WInputMethod_destroyNativeContext(JNIEnv *env, jclass cls, jint context)
7373
{
7474
TRY_NO_VERIFY;
7575

0 commit comments

Comments
 (0)