diff --git a/src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java b/src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java index e893a58f9edfb..ff790d725b7bc 100644 --- a/src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java +++ b/src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java @@ -44,6 +44,8 @@ import sun.awt.AWTAccessor; import sun.awt.AWTAccessor.ComponentAccessor; import sun.awt.im.InputMethodAdapter; +import sun.java2d.Disposer; +import sun.java2d.DisposerRecord; final class WInputMethod extends InputMethodAdapter { @@ -124,6 +126,8 @@ final class WInputMethod extends InputMethodAdapter public WInputMethod() { context = createNativeContext(); + disposerRecord = new ContextDisposerRecord(context); + Disposer.addRecord(this, disposerRecord); cmode = getConversionStatus(context); open = getOpenStatus(context); currentLocale = getNativeLocale(); @@ -132,16 +136,23 @@ public WInputMethod() } } - @Override - @SuppressWarnings("removal") - protected void finalize() throws Throwable - { - // Release the resources used by the native input context. - if (context!=0) { - destroyNativeContext(context); - context=0; + private final ContextDisposerRecord disposerRecord; + + private static final class ContextDisposerRecord implements DisposerRecord { + + private final int context; + private volatile boolean disposed; + + ContextDisposerRecord(int c) { + context = c; + } + + public synchronized void dispose() { + if (!disposed) { + destroyNativeContext(context); + } + disposed = true; } - super.finalize(); } @Override @@ -151,9 +162,7 @@ public synchronized void setInputMethodContext(InputMethodContext context) { @Override public void dispose() { - // Due to a memory management problem in Windows 98, we should retain - // the native input context until this object is finalized. So do - // nothing here. + disposerRecord.dispose(); } /** @@ -658,8 +667,8 @@ private WComponentPeer getNearestNativePeer(Component comp) } - private native int createNativeContext(); - private native void destroyNativeContext(int context); + private static native int createNativeContext(); + private static native void destroyNativeContext(int context); private native void enableNativeIME(WComponentPeer peer, int context, boolean useNativeCompWindow); private native void disableNativeIME(WComponentPeer peer); private native void handleNativeIMEEvent(WComponentPeer peer, AWTEvent e); diff --git a/src/java.desktop/windows/native/libawt/windows/awt_InputMethod.cpp b/src/java.desktop/windows/native/libawt/windows/awt_InputMethod.cpp index fcc6e4c2cb872..87087870b5d70 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_InputMethod.cpp +++ b/src/java.desktop/windows/native/libawt/windows/awt_InputMethod.cpp @@ -52,7 +52,7 @@ extern BOOL g_bUserHasChangedInputLang; * Signature: ()I */ JNIEXPORT jint JNICALL -Java_sun_awt_windows_WInputMethod_createNativeContext(JNIEnv *env, jobject self) +Java_sun_awt_windows_WInputMethod_createNativeContext(JNIEnv *env, jclass cls) { TRY; @@ -69,7 +69,7 @@ Java_sun_awt_windows_WInputMethod_createNativeContext(JNIEnv *env, jobject self) * Signature: (I)V */ JNIEXPORT void JNICALL -Java_sun_awt_windows_WInputMethod_destroyNativeContext(JNIEnv *env, jobject self, jint context) +Java_sun_awt_windows_WInputMethod_destroyNativeContext(JNIEnv *env, jclass cls, jint context) { TRY_NO_VERIFY;