harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r639566 - in /harmony/enhanced/jdktools/branches/java6/modules/jpda: make/ src/main/native/include/ src/main/native/jdwp/common/agent/commands/ src/main/native/jdwp/common/agent/core/ src/main/native/jdwp/common/generic/ src/test/java/org/a...
Date Fri, 21 Mar 2008 08:29:04 GMT
Author: lvjing
Date: Fri Mar 21 01:28:53 2008
New Revision: 639566

URL: http://svn.apache.org/viewvc?rev=639566&view=rev
Log:
Apply patch for HARMONY-5613 [jdktools][jdwp6]Add new command OwnedMonitorsStackDepthInfo
Command for Java6

Added:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoDebuggee.java
  (with props)
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoTest.java
  (with props)
Modified:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti.h
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti_types.h
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.h
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CommandDispatcher.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/TestOptions.java
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/Capabilities.java
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/JDWPCommands.java
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/VmMirror.java

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common Fri Mar 21 01:28:53
2008
@@ -15,3 +15,5 @@
 org/apache/harmony/jpda/tests/jdwp/VirtualMachine/InstanceCountsTest.java
 #5596
 org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsTest.java
+#5613
+org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoTest.java

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti.h?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti.h
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti.h
Fri Mar 21 01:28:53 2008
@@ -681,7 +681,9 @@
 
     void *reserved152;
 
-    void *reserved153;
+    jvmtiError (JNICALL * GetOwnedMonitorStackDepthInfo)(jvmtiEnv* env, 
+        jthread thread, jint* monitor_info_count_ptr, 
+        jvmtiMonitorStackDepthInfo** monitor_info_ptr);
 
     jvmtiError (JNICALL * GetObjectSize) (jvmtiEnv * env,
         jobject object, jlong * size_ptr);
@@ -1110,6 +1112,12 @@
         const jvmtiClassDefinition * class_definitions)
     {
         return funcs->RedefineClasses (this, class_count, class_definitions);
+    }
+
+    jvmtiError GetOwnedMonitorStackDepthInfo (jthread thread, jint* monitor_info_count_ptr,

+        jvmtiMonitorStackDepthInfo** monitor_info_ptr) 
+    { 
+        return funcs->GetOwnedMonitorStackDepthInfo(this, thread, monitor_info_count_ptr,
monitor_info_ptr); 
     }
 
     jvmtiError GetObjectSize (jobject object, jlong * size_ptr)

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti_types.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti_types.h?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti_types.h
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/include/jvmti_types.h
Fri Mar 21 01:28:53 2008
@@ -873,6 +873,13 @@
         jlong reserved2;
     } jvmtiTimerInfo;
 
+    typedef struct
+    {
+        jobject monitor;
+        jint stack_depth;
+    } jvmtiMonitorStackDepthInfo;
+
+
     typedef enum
     {
         JVMTI_PHASE_ONLOAD = 1,

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.cpp?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.cpp
Fri Mar 21 01:28:53 2008
@@ -372,3 +372,48 @@
 }
 
 //-----------------------------------------------------------------------------
+//OwnedMonitorsStackDepthInfoHandler-------------------------------------------
+void
+ThreadReference::OwnedMonitorsStackDepthInfoHandler::Execute(JNIEnv *jni)
+    throw (AgentException)
+{
+    // Read thread id from OwnedMonitorsStackDepthInfoHandler command
+    jthread thrd = m_cmdParser->command.ReadThreadID(jni);
+    JDWP_TRACE_DATA("OwnedMonitorsStackDepthInfo: received: threadID=" << thrd);
+
+    // If the thread is not suspended, throw exception
+    if (!GetThreadManager().IsSuspended(thrd))
+        throw AgentException(JVMTI_ERROR_THREAD_NOT_SUSPENDED);
+
+    // Invoke jvmti function to attain the expected monitor data
+    jvmtiError err;
+    jint count;
+    jvmtiMonitorStackDepthInfo* pMonitorInfos;
+    JVMTI_TRACE(err, GetJvmtiEnv()->GetOwnedMonitorStackDepthInfo(thrd, &count, &pMonitorInfos));
+    if (err != JVMTI_ERROR_NONE) {
+        // Can be: JVMTI_ERROR_MUST_POSSESS_CAPABILITY, JVMTI_ERROR_INVALID_THREAD
+        // JVMTI_ERROR_THREAD_NOT_ALIVE, JVMTI_ERROR_NULL_POINTER 
+        throw AgentException(err);
+    }
+    
+    // Must release memeory manually
+    JvmtiAutoFree af(pMonitorInfos);
+
+    // Write monitor count to reply package
+    JDWP_TRACE_DATA("OwnedMonitorsStackDepthInfo: received: monitor count=" << count);
+    m_cmdParser->reply.WriteInt(count);
+    
+    // Write each monitor and its stack depth to reply package 
+    for (int i =0; i < count; i++){
+        // Attain monitor and its stack depth from returned data.
+        jobject monitor = pMonitorInfos[i].monitor;
+        m_cmdParser->reply.WriteTaggedObjectID(jni, monitor);
+        JDWP_TRACE_DATA("OwnedMonitorsStackDepthInfo: received: monitor object=" <<
monitor);
+        
+        jint stack_depth = pMonitorInfos[i].stack_depth;
+        JDWP_TRACE_DATA("OwnedMonitorsStackDepthInfo: received: monitor stack depth=" <<
stack_depth);
+        m_cmdParser->reply.WriteInt(stack_depth);
+    }
+}
+
+//-----------------------------------------------------------------------------

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.h?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.h
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ThreadReference.h
Fri Mar 21 01:28:53 2008
@@ -245,6 +245,24 @@
 
         };//SuspendCountHandler
 
+        // New command for Java 6
+        /**
+         * The class implements the <code>OwnedMonitorsStackDepthInfo</code>
command from the
+         * ThreadReference command set.
+         */
+        class OwnedMonitorsStackDepthInfoHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>OwnedMonitorsStackDepthInfo</code> JDWP command
for the
+             * ThreadReference command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//OwnedMonitorsStackDepthInfoHandler
+
     }//ThreadReference
 
 }//jdwp

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CommandDispatcher.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CommandDispatcher.cpp?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CommandDispatcher.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CommandDispatcher.cpp
Fri Mar 21 01:28:53 2008
@@ -358,6 +358,10 @@
         case JDWP_COMMAND_TR_SUSPEND_COUNT:
             return new ThreadReference::SuspendCountHandler();
 
+        // New command for Java 6
+        case JDWP_COMMAND_TR_OWNED_MONITORS_STACK_DEPTH:
+            return new ThreadReference::OwnedMonitorsStackDepthInfoHandler();
+
         }//JDWP_COMMAND_SET_THREAD_REFERENCE
         break;
 

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h
Fri Mar 21 01:28:53 2008
@@ -151,6 +151,8 @@
     JDWP_COMMAND_TR_STOP = 10,
     JDWP_COMMAND_TR_INTERRUPT = 11,
     JDWP_COMMAND_TR_SUSPEND_COUNT = 12,
+    // New command for Java 6
+    JDWP_COMMAND_TR_OWNED_MONITORS_STACK_DEPTH = 13,
 
     /* Commands ThreadGroupReference */
     JDWP_COMMAND_TGR_NAME = 1,

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/TestOptions.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/TestOptions.java?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/TestOptions.java
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/TestOptions.java
Fri Mar 21 01:28:53 2008
@@ -216,7 +216,7 @@
 
         return getProperty("jpda.settings.debuggeeAgentOptions",
                 "transport=dt_socket,address=" + address + ",server=" + serv
-                + ",suspend=" + getDebuggeeSuspend() + agentExtraOptions + ",trace=all");
+                + ",suspend=" + getDebuggeeSuspend() + agentExtraOptions);
     }
 
     /**

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/Capabilities.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/Capabilities.java?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/Capabilities.java
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/Capabilities.java
Fri Mar 21 01:28:53 2008
@@ -65,7 +65,7 @@
 
     public boolean reserved17                       = false;
 
-    public boolean reserved18                       = false;
+    public boolean canGetMonitorFrameInfo           = false;
 
     public boolean reserved19                       = false;
 

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/JDWPCommands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/JDWPCommands.java?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/JDWPCommands.java
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/JDWPCommands.java
Fri Mar 21 01:28:53 2008
@@ -253,6 +253,9 @@
         public static final byte InterruptCommand = 11;
 
         public static final byte SuspendCountCommand = 12;
+
+        //New command for Java 6
+        public static final byte OwnedMonitorsStackDepthInfoCommand = 13;
     }
 
     /**

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/VmMirror.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/VmMirror.java?rev=639566&r1=639565&r2=639566&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/VmMirror.java
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/framework/jdwp/VmMirror.java
Fri Mar 21 01:28:53 2008
@@ -413,7 +413,7 @@
         targetVMCapabilities.canGetInstanceInfo = replyPacket
                 .getNextValueAsBoolean();
         targetVMCapabilities.reserved17 = replyPacket.getNextValueAsBoolean();
-        targetVMCapabilities.reserved18 = replyPacket.getNextValueAsBoolean();
+        targetVMCapabilities.canGetMonitorFrameInfo = replyPacket.getNextValueAsBoolean();
         targetVMCapabilities.reserved19 = replyPacket.getNextValueAsBoolean();
         targetVMCapabilities.canGetConstantPool = replyPacket
                 .getNextValueAsBoolean();

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoDebuggee.java?rev=639566&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoDebuggee.java
(added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoDebuggee.java
Fri Mar 21 01:28:53 2008
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+
+/**
+ * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.OwnedMonitorsStackDepthInfoTest</code>.
+ * This debuggee starts the tested thread <code>TESTED_THREAD</code> which
+ * synchronized with test via the <code>SGNL_READY</code> and
+ * <code>SGNL_CONTINUE</code> signals.
+ */
+public class OwnedMonitorsStackDepthInfoDebuggee extends SyncDebuggee {
+
+    public static final String TESTED_THREAD = "TestedThread";
+    
+    // These two objects are used 
+    static Object waitForStart = new Object();
+    static Object waitForFinish = new Object();
+    
+    public void run() {
+        DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
+                logWriter, synchronizer); 
+        
+        synchronized(waitForStart){
+            thrd.start();
+            try {
+                waitForStart.wait();
+            } catch (InterruptedException e) {
+
+            }
+        }
+
+        synchronized(waitForFinish){
+            logWriter.println("thread is finished");
+        }
+    }
+
+    class DebuggeeThread extends Thread {
+
+        LogWriter logWriter;
+        DebuggeeSynchronizer synchronizer;
+
+        public DebuggeeThread(String name, LogWriter logWriter,
+                DebuggeeSynchronizer synchronizer) {
+            super(name);
+            this.logWriter = logWriter;
+            this.synchronizer = synchronizer;
+        }
+
+        public void run() {
+
+            synchronized(OwnedMonitorsStackDepthInfoDebuggee.waitForFinish){
+
+                synchronized(OwnedMonitorsStackDepthInfoDebuggee.waitForStart){
+
+                    OwnedMonitorsStackDepthInfoDebuggee.waitForStart.notifyAll();
+
+                    logWriter.println(getName() +  ": started");
+                    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+                    logWriter.println(getName() +  ": wait for SGNL_CONTINUE");
+                    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+                    logWriter.println(getName() +  ": finished");
+                }
+            }
+        }
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(OwnedMonitorsStackDepthInfoDebuggee.class);
+    }
+}

Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoDebuggee.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoTest.java?rev=639566&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoTest.java
(added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoTest.java
Fri Mar 21 01:28:53 2008
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
+import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+/**
+ * JDWP Unit test for ThreadReference.OwnedMonitorsStackDepthInfo command.
+ */
+public class OwnedMonitorsStackDepthInfoTest extends JDWPSyncTestCase {
+
+    static final String thisCommandName = "ThreadReference.OwnedMonitorsStackDepthInfo command
";
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.OwnedMonitorsStackDepthInfoDebuggee";
+    }
+    
+    // OwnedMonitorsStackDepthInfo needs canGetMonitorFrameInfo VM capability support
+    private boolean isCapability() {
+        // check capability, relevant for this test
+        logWriter.println("=> Check capability: canGetMonitorFrameInfo");
+        debuggeeWrapper.vmMirror.capabilities();
+        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetMonitorFrameInfo;
+        return isCapability;
+    }
+
+    /**
+     * This testcase exercises ThreadReference.OwnedMonitorsStackDepthInfo
+     * command. <BR>
+     * At first the test starts OwnedMonitorsStackDepthInfoDebuggee which runs
+     * the tested thread 'TESTED_THREAD'. <BR>
+     * Then the test performs the ThreadReference.OwnedMonitorsStackDepthInfo
+     * command for the tested thread and gets list of monitor objects.
+     * The returned monitor objects are equal to expected count and their stack depth are
+     *  equal to expected depth. This test will perform MonitorInfo to guarrantee that returend
+     *  monitors do belong to the test thread.
+     */
+    public void testOwnedMonitorsStackDepthInfo() {
+        String thisTestName = "testOwnedMonitorsStackDepthInfo";
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        if (!isCapability()) {
+            logWriter.println("##WARNING: this VM dosn't possess capability: canGetInstanceInfo");
+            return;
+        }
+
+        // Getting ID of the tested thread
+        logWriter.println("==> testedThreadName = "
+                + OwnedMonitorsStackDepthInfoDebuggee.TESTED_THREAD);
+        logWriter.println("==> Get testedThreadID...");
+        long testedThreadID = debuggeeWrapper.vmMirror
+                .getThreadID(OwnedMonitorsStackDepthInfoDebuggee.TESTED_THREAD);
+
+        // Compose the OwnedMonitorsStackDepthInfo command
+        CommandPacket stackDepthPacket = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.OwnedMonitorsStackDepthInfoCommand);
+        stackDepthPacket.setNextValueAsThreadID(testedThreadID);
+
+        // Suspend the VM before perform command
+        logWriter.println("==> testedThreadID = " + testedThreadID);
+        logWriter.println("==> suspend testedThread...");
+        debuggeeWrapper.vmMirror.suspendThread(testedThreadID);
+        
+        // Perform the command and attain the reply package
+        ReplyPacket stackDepthReply = debuggeeWrapper.vmMirror
+                .performCommand(stackDepthPacket);
+        checkReplyPacket(stackDepthReply,
+                "ThreadReference::OwnedMonitorsStackDepthInfo command");
+
+        // Expected return values, these values is attained from RI behavior
+        int expectedMonitorCount = 3;
+        int[] expectedStackDepth = new int[] { 6, 7, 7 };
+
+        // Analyze the reply package
+        int owned = stackDepthReply.getNextValueAsInt();
+        assertEquals(thisCommandName
+                + "returned number of owned monitors is not equal to expected number.",
+                expectedMonitorCount, owned, null, null);
+        logWriter
+                .println("==> CHECK: PASSED: returned owned monitors have the same counts
as expected");
+        logWriter.println("==> Owned monitors: " + owned);
+
+        for (int i = 0; i < owned; i++) {
+            // Attain monitor object ID
+            TaggedObject monitorObject = stackDepthReply
+                    .getNextValueAsTaggedObject();
+            
+            // Attain monitor stack depth
+            int returnedDepthInfo = stackDepthReply.getNextValueAsInt();
+            assertEquals(thisCommandName
+                    + "returned monitor is not owned by test thread",
+                    expectedStackDepth[i], returnedDepthInfo, null, null);
+            logWriter.println("==> CHECK: PASSED: returned owned monitor has the expected
stack depth");
+            logWriter.println("==> Stack depth: " + returnedDepthInfo);
+
+            /*
+             *  Test the returned monitor object does belong to the test thread by MonitorInfo
Command 
+             */
+            // Compose the MonitorInfo Command
+            CommandPacket monitorInfoPacket = new CommandPacket(
+                    JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ObjectReferenceCommandSet.MonitorInfoCommand);
+            monitorInfoPacket.setNextValueAsObjectID(monitorObject.objectID);
+
+            // Perform the command and attain the reply package
+            ReplyPacket monitorInfoReply = debuggeeWrapper.vmMirror
+                    .performCommand(monitorInfoPacket);
+            checkReplyPacket(monitorInfoReply,
+                    "ObjectReference::MonitorInfo command");
+
+            // Attain thread id from monitor info
+            long ownerThreadID = monitorInfoReply.getNextValueAsThreadID();
+            assertEquals(thisCommandName + "returned monitor is not owned by test thread",
ownerThreadID, testedThreadID, null, null);
+            
+            logWriter.println("==> CHECK: PASSED: returned monitor does belong to the
test thread.");
+            logWriter.println("==> Monitor owner thread ID: " + ownerThreadID);
+
+        }
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        assertAllDataRead(stackDepthReply); 
+    }
+
+    
+    public void testOwnedMonitorsStackDepthInfo_Unsuspended() {
+        String thisTestName = "testOwnedMonitorsStackDepthInfo";
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName
+                + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        if (!isCapability()) {
+            logWriter
+                    .println("##WARNING: this VM dosn't possess capability: OwnedMonitorsStackDepthInfo");
+            return;
+        }
+
+        // Getting ID of the tested thread
+        logWriter.println("==> testedThreadName = "
+                + OwnedMonitorsStackDepthInfoDebuggee.TESTED_THREAD);
+        logWriter.println("==> Get testedThreadID...");
+        long testedThreadID = debuggeeWrapper.vmMirror
+                .getThreadID(OwnedMonitorsStackDepthInfoDebuggee.TESTED_THREAD);
+
+        // Compose the OwnedMonitorsStackDepthInfo command
+        CommandPacket stackDepthPacket = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.OwnedMonitorsStackDepthInfoCommand);
+        stackDepthPacket.setNextValueAsThreadID(testedThreadID);
+
+        // Perform the command and attain the reply package
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror
+                .performCommand(stackDepthPacket);
+        short errorCode = checkedReply.getErrorCode();
+        if (errorCode != JDWPConstants.Error.NONE) {
+            if (errorCode == JDWPConstants.Error.THREAD_NOT_SUSPENDED) {
+                logWriter.println("=> CHECK PASSED: Expected error (THREAD_NOT_SUSPENDED)
is returned");
+                return;
+            }
+        }
+        printErrorAndFail(thisCommandName + " should throw exception when VM is not suspended.");
+    }    
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(OwnedMonitorsStackDepthInfoTest.class);
+    }
+}

Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/OwnedMonitorsStackDepthInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message