Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down