JDK-6445579 : /api/java_awt/interactive/ #eventTest0015 & #PMenuTest failing on jck manual with -Xcheck:jni option
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0u8
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-06-30
  • Updated: 2014-02-27
  • Resolved: 2006-08-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u10 b01Fixed
Description
I tested this on the following platforms Windows XP Pro x64, Windows XP Pro x86, Windows 2003 x64. I also tested the following jdks 5.0FCS, 5.0 u5 (FCS), 5.0 u6 (FCS), 5.0u7 (FCS), 5.0u8 B02, 5.0u8 B03. The problem happened on all of the above.

I tried this on Solaris 9 Sparc as well and the issue does not happen there so it is a Windows problem.

This only occurs when the -Xcheck:jni option is used for JCK manual tests. The 2 Tests in questions are:

1: /api/java_awt/interactive/eventTests.html #EventTest0015

When you run this test you are asked to ckick on "Show Frame" and asked within this frame to generate a menu via a right click on your mouse, when you right click here instead of an action performed being generated the test fails.

The following message is given several times (this is in OUT2 option under Test Run Messages pane in Javatest):

Warning: Calling other JNI functions in the scope of Get/Release PrimitiveArrayCritical or Get/ReleaseStringCritical

This is then followed by the following message:
Fatal ERROR in native method: Bad global or local ref passed to JNI
	at sun.awt.windows.WToolkit.eventLoop(Native Method)
	at sun.awt.windows.WToolkit.run(WToolkit.java:269)
	at java.lang.Thread.run(Thread.java:595)

The test exits with the following exit code:
Failed. unexpected exit code: exit code 1

2: /api/java_awt/interactive/PMenuTests.html #PMenuTests

This test asks for you to generate a pop up menu via the right click on a mouse. When you right click instead of a menu pop up the test failes.

The following message is given several times as above in the first test (this is in OUT2 option under Test Run Messages pane in Javatest):

Warning: Calling other JNI functions in the scope of Get/Release PrimitiveArrayCritical or Get/ReleaseStringCritical

This is then followed by the following message:
Fatal ERROR in native method: Bad global or local ref passed to JNI
	at sun.awt.windows.WToolkit.eventLoop(Native Method)
	at sun.awt.windows.WToolkit.run(WToolkit.java:269)
	at java.lang.Thread.run(Thread.java:595)

The test exits with the following exit code as above:
Failed. unexpected exit code: exit code 1

I have also attached and zipped 2 JCK report directories. The first is for Windows XP Pro x64 and the second is for Windows XP Pro x86 (this one just has the 2 tests and nothing else).

The location of the JCK testsuite in Dublin is as follows:
/net/carlow.ireland/export/home4/jck/JCK-runtime-15a
/net/carlow.ireland/export/home4/jck/JCK-compiler-15a

To run the testsuite first map the drive Z:/ to \\carlow\home4 (or your local equivalent). Then copy the interactive file from Z:/jck/utils/tigerTaskFiles/windows . You will need to edit the following fields: PRODUCT (this is you jdks location), WORK_DIRECTORY (this is a local workspace for the testsuite), and OPTIONS (this is where you set -Xcheck:jni).

Once this is done type java -cp Z:/jck/transition/autotest.m/autotest.jar  autotest.mini.Test -t interactive (or the local equivalent of this location). Now just run run.sh script. This will start java test. 

Go to "Configure" and click "Load Configuration" and click on jck.jti. Then click on configure again and go to "Change Configuration" and then "Other Values". Set the option "Test Multi Platfrom JVM" to yes and then set the option "Keywords to "runtime & interactive" and then click done. 

Wait till all 33,547 test load and then run the 2 tests mentioned above by choosing them from the menu on the left hand of Java test harness.

Comments
SUGGESTED FIX --- awt_PopupMenu.cpp 2006-07-06 15:27:27.000000000 +0400 *************** *** 81,87 **** * as the event's target. */ if (env->EnsureLocalCapacity(2) < 0) { ! return; } jobject origin = (env)->GetObjectField(event, AwtEvent::targetID); jobject peerOrigin = GetPeerForTarget(env, origin); --- 81,88 ---- * as the event's target. */ if (env->EnsureLocalCapacity(2) < 0) { ! env->DeleteGlobalRef(event); ! return; } jobject origin = (env)->GetObjectField(event, AwtEvent::targetID); jobject peerOrigin = GetPeerForTarget(env, origin); *************** *** 107,112 **** --- 108,114 ---- done: env->DeleteLocalRef(origin); env->DeleteLocalRef(peerOrigin); + env->DeleteGlobalRef(event); } void AwtPopupMenu::AddItem(AwtMenuItem *item) *************** *** 208,217 **** JNI_CHECK_PEER_RETURN(self); JNI_CHECK_NULL_RETURN(event, "null Event"); // Invoke popup on toolkit thread -- yet another Win32 restriction. AwtPopupMenu* popupMenu = (AwtPopupMenu*)pData; AwtToolkit::GetInstance().SendMessage(WM_AWT_POPUPMENU_SHOW, ! (WPARAM)popupMenu, (LPARAM)event); CATCH_BAD_ALLOC; } --- 210,221 ---- JNI_CHECK_PEER_RETURN(self); JNI_CHECK_NULL_RETURN(event, "null Event"); + jobject gr_event = env->NewGlobalRef(event); // Invoke popup on toolkit thread -- yet another Win32 restriction. AwtPopupMenu* popupMenu = (AwtPopupMenu*)pData; AwtToolkit::GetInstance().SendMessage(WM_AWT_POPUPMENU_SHOW, ! (WPARAM)popupMenu, (LPARAM)gr_event); ! // global ref is deleted in Show() CATCH_BAD_ALLOC; }
07-07-2006

EVALUATION One of possible cause of the problem is that in WPopupMenuPeer._show() we use local ref to event as LPARAM for WM_AWT_POPUPMENU_SHOW message which is processed on another (Toolkit) thread. Most likely creating global ref for event and deleting it in AwtPopupMenu::Show() wil fix the problem.
03-07-2006

EVALUATION The problem is not reproducible with mustang b86.
03-07-2006