8365180: Remove sun.awt.windows.WInputMethod.finalize()

Reviewed-by: serb, azvegint
This commit is contained in:
Phil Race 2025-08-22 04:28:56 +00:00
parent 558d06399c
commit 8e44856992
2 changed files with 26 additions and 16 deletions

View File

@ -44,6 +44,8 @@ import java.util.Map;
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 @@ final class WInputMethod extends InputMethodAdapter
}
}
@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 @@ final class WInputMethod extends InputMethodAdapter
@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();
}
/**
@ -448,6 +457,7 @@ final class WInputMethod extends InputMethodAdapter
@Override
public void removeNotify() {
endCompositionNative(context, DISCARD_INPUT);
disableNativeIME(awtFocussedComponentPeer);
awtFocussedComponent = null;
awtFocussedComponentPeer = null;
}
@ -658,8 +668,8 @@ final class WInputMethod extends InputMethodAdapter
}
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);

View File

@ -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;