harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gregory Shimansky (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-3866) [drlvm][jvmti] GetOwnedMonitorInfo returns information about 1 monitor even if there are no monitors owned by the specified thread
Date Sat, 09 Jun 2007 08:14:26 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-3866?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12503033
] 

Gregory Shimansky commented on HARMONY-3866:
--------------------------------------------

I can also explain why in this test sometimes the number of owned monitors is 2 (I cannot
explain how it can report 0 monitors though). The method Thread.start actually acquires 2
monitors, 1st one is "this" (the thread object) because method start is synchronized, as I've
written previously, the 2nd one is "lock" which is used for managing thread java state.

But later thread that started a thread performs lock.wait(), which exits the monitor for the
time while this thread is waiting. So if the ThreadStart event for the newly started thread
happens while starter thread is not waiting on lock.wait, then the number of owned monitors
should be 2, otherwise when starter thread is executing wait, the number of owned monitors
should be 1.

Removing synchronized keyword on Thread.start method won't solve the race condition in the
test. Its results still won't be consistent because the number of reported monitors will be
either 0 or 1.

> [drlvm][jvmti] GetOwnedMonitorInfo returns information about 1 monitor even if there
are no monitors owned by the specified thread
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3866
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3866
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>         Environment: Windows and Linux
>            Reporter: Vera Petrashkova
>            Assignee: Gregory Shimansky
>            Priority: Minor
>         Attachments: GOMI.zip
>
>
> According to J2SE JVMTI specification  method 
> GetOwnedMonitorInfo jvmtiEnv* env,
>             jthread thread,
>             jint* owned_monitor_count_ptr,
>             jobject** owned_monitors_ptr)
> returns  information about the monitors owned by the specified thread. 
> It saves the number of monitors to owned_monitor_count_ptr.
> The following test demonstrates that on  DRLVM returns information about 1 monitor even
if there are no monitors owned by the specified thread.
> In this case on RI returned value of  owned_monitor_count_ptr parameter equals 0.
> --------------------GOMI.java-------------------
> public class GOMI {
>     public static boolean all_threads_can_start = false;
>     public final static Object sync0 = new Object();
>     public final static Object sync1 = new Object();
>     
>     public static void main(String[] args) {
> 	GOMI_thread tr = new GOMI_thread("Owner");
>         tr.start();        
>     }
> }
> class GOMI_ag extends Thread {
>     public GOMI_ag(String s) {
>        super(s);
>     }
>     public void run() {
>         return;
>     }
> }
> class GOMI_thread extends Thread {
>     GOMI_thread(String name) {
>         super(name);
>     }
>     public void run() {
>         try {
>             Thread.sleep(5000);
>         } catch (Throwable e) {
>             e.printStackTrace();
>         }
>         try {
>             GOMI_ag ag = new GOMI_ag("agent");
>             ag.start();
>             ag.join();
>         } catch (Throwable te) {
>             te.printStackTrace();
>         }
>         try {
>             Thread.sleep(5000);
>         } catch (Throwable e) {
>             e.printStackTrace();
>         }
>     }
> } 
> ----------------GOMI.cpp------------------------
> #include "evnts.h"
> static bool flag = false;
> static bool flag_res = false;
> void GOMI()
> {
> }
> JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
> {
>     Callbacks CB;
>     CB.cbThreadStart = (jvmtiEventThreadStart)callbackThreadStart;
>     CB.cbVMDeath = (jvmtiEventVMDeath)callbackVMDeath;
>     AGENT_FOR_EVENTS_TESTS_PART_I; /* evnts.h */
>     jvmtiEvent events[] = { JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
>     AGENT_FOR_EVENTS_TESTS_PART_II; /* evnts.h */
>     fprintf(stderr, "\n-----------test GOMI started--------------\n");
>     fflush(stderr);
>     return JNI_OK;
> }
> /* *********************************************************************** */
> void JNICALL callbackThreadStart(prms_THRD_START)
> {
>     if (flag) return;
>     jvmtiPhase phase;
>     jvmtiThreadInfo tinfo;
>     jvmtiError result;
>     jint tcount = 0;
>     jthread* threads;
>     jthread my_thread = NULL;
>     jint owned_monitor_count;
>     jobject* owned_monitors;
>     result = jvmti_env->GetPhase(&phase);
>     if ((result != JVMTI_ERROR_NONE) || (phase != JVMTI_PHASE_LIVE)) return;
>     result = jvmti_env->GetThreadInfo(thread, &tinfo);
>     if (result != JVMTI_ERROR_NONE) return;
> 	fprintf(stderr, "\tnative: current started thread name is %s  \n", tinfo.name);
>     if (strcmp(tinfo.name, "agent")) return;
>     fprintf(stderr, "\tnative: test started\n");
>     result = jvmti_env->GetAllThreads(&tcount, &threads);
>     if (result != JVMTI_ERROR_NONE) return;
>     for ( int i = 0; i < tcount; i++ ) {
>         result = jvmti_env->GetThreadInfo(threads[i], &tinfo);
>         fprintf(stderr, "\tnative: current thread %d name is %s  \n", i, tinfo.name);
>         if (result != JVMTI_ERROR_NONE) continue;
>         if (strcmp(tinfo.name, "Owner")) continue;
>         my_thread = threads[i];
>         fprintf(stderr, "\tnative: tested thread was found = %p %s %d\n", my_thread,
tinfo.name, i);
>     }
>     result = jvmti_env->GetOwnedMonitorInfo(my_thread,
>                 &owned_monitor_count, &owned_monitors);
> 	flag = true;
>     fprintf(stderr, "\tnative: GetOwnedMonitorInfo result = %d (must be zero) \n", result);
>     fprintf(stderr, "\n\tnative: number of owned monitors is %d (must be 0)\n",
>          owned_monitor_count );
>     if ((result == JVMTI_ERROR_NONE) && (owned_monitor_count == 0)) {
>         flag_res = true;
>         return;
>     }
> }
> void JNICALL callbackVMDeath(prms_VMDEATH)
> {
>     fprintf(stderr, "\n\tTest GOMI: ");
>     if (flag && flag_res)
>         fprintf(stderr, " passed \n");
>     else
>         fprintf(stderr, " failed \n");
>     fprintf(stderr, "\n} /* test GOMI finished */ \n");
>     fflush(stderr);
> }
> ------------------------------------------------
> Attachment contains additional source code files and GOMI.dll
> Output on DRLVM:
> ================
> Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or
its l
> icensors, as applicable.
> java version "1.5.0"
> pre-alpha : not complete or compatible
> svn = r537729, (May 14 2007), Windows/ia32/msvc 1310, release build
> http://incubator.apache.org/harmony
> -----------test GOMI started--------------
>         native: current started thread name is main
>         native: current started thread name is Owner
>         native: current started thread name is agent
>         native: test started
>         native: current thread 0 name is agent
>         native: current thread 1 name is Owner
>         native: tested thread was found = 0218FFFC Owner 1
>         native: current thread 2 name is ref handler
>         native: current thread 3 name is finalizer
>         native: current thread 4 name is finalizer
>         native: current thread 5 name is main
>         native: GetOwnedMonitorInfo result = 0 (must be zero)
>         native: number of owned monitors is 1 (must be 0)
>         Test GOMI:  failed
> } /* test GOMI is finished */
> Output on RI:
> ===========
> -----------test GOMI started--------------
>         native: current started thread name is Signal Dispatcher
>         native: current started thread name is main
> java version "1.5.0_06"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
> Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
>         native: current started thread name is Owner
>         native: current started thread name is DestroyJavaVM
>         native: current started thread name is agent
>         native: test started
>         native: current thread 0 name is agent
>         native: current thread 1 name is DestroyJavaVM
>         native: current thread 2 name is Owner
>         native: tested thread was found = 00A877F4 Owner 2
>         native: current thread 3 name is Signal Dispatcher
>         native: current thread 4 name is Finalizer
>         native: current thread 5 name is Reference Handler
>         native: GetOwnedMonitorInfo result = 0 (must be zero)
>         native: number of owned monitors is 0 (must be 0)
>         Test GOMI:  passed
> } /* test GOMI is finished */
> This bug causes the failure of the test
>      vm.jvmti.funcs.GetOwnedMonitorInfo.GetOwnedMonitorInfo0101.GetOwnedMonitorInfo0101
> from DRLVM Validation test suite (http://issues.apache.org/jira/browse/HARMONY-3206)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message