You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by lv...@apache.org on 2008/03/04 07:06:19 UTC

svn commit: r633366 - in /harmony/enhanced/jdktools/branches/java6/modules/jpda/src: main/native/jdwp/common/agent/commands/ main/native/jdwp/common/agent/core/ test/java/org/apache/harmony/jpda/tests/framework/jdwp/ test/java/org/apache/harmony/jpda/t...

Author: lvjing
Date: Mon Mar  3 22:06:15 2008
New Revision: 633366

URL: http://svn.apache.org/viewvc?rev=633366&view=rev
Log:
Apply patch for HARMONY-5562 ([jdktools][jdwp6] Add new jdwp command "Instances" for jdwp 6)

Added:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesDebuggee.java   (with props)
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java   (with props)
Modified:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.h
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp
    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/agent/core/jdwpTypes.h
    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/VmMirror.java

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.cpp?rev=633366&r1=633365&r2=633366&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.cpp Mon Mar  3 22:06:15 2008
@@ -851,6 +851,86 @@
 // New commands for Java 6
 
 //------------------------------------------------------------------------------
+// InstancesHandler(16)-----------------------------------------------
+
+void
+ReferenceType::InstancesHandler::Execute(JNIEnv *jni)
+        throw (AgentException)
+{
+    jclass jvmClass = m_cmdParser->command.ReadReferenceTypeID(jni);
+    // Can be: InternalErrorException, OutOfMemoryException,
+    // JDWP_ERROR_INVALID_CLASS, JDWP_ERROR_INVALID_OBJECT
+#ifndef NDEBUG
+    if (JDWP_TRACE_ENABLED(LOG_KIND_DATA)) {
+        jvmtiError err;
+        char* signature = 0;
+        JVMTI_TRACE(err, GetJvmtiEnv()->GetClassSignature(jvmClass, &signature, 0));
+        JvmtiAutoFree afcs(signature);
+        JDWP_TRACE_DATA("SourceDebugExtension: received: refTypeID=" << jvmClass
+            << ", classSignature=" << JDWP_CHECK_NULL(signature));
+    }
+#endif
+    jint maxInstances = m_cmdParser->command.ReadInt();
+    if(maxInstances < 0) {
+        throw AgentException(JDWP_ERROR_ILLEGAL_ARGUMENT);
+    }
+
+    jvmtiHeapCallbacks hcbs;
+    memset(&hcbs, 0, sizeof(hcbs));
+    hcbs.heap_iteration_callback = NULL;
+    hcbs.heap_reference_callback = &HeapReferenceCallback;
+    hcbs.primitive_field_callback = &PrimitiveFieldCallback;
+    hcbs.array_primitive_value_callback = &ArrayPrimitiveValueCallback;
+    hcbs.string_primitive_value_callback = &StringPrimitiveValueCallback;
+
+    jvmtiError err;
+    //It initiates a traversal over the objects that are directly and indirectly reachable from the heap roots.
+    JVMTI_TRACE(err, GetJvmtiEnv()->FollowReferences(0, jvmClass,  NULL,
+         &hcbs, NULL));
+     if (err != JVMTI_ERROR_NONE) {
+        // Can be: JVMTI_ERROR_MUST_POSSESS_CAPABILITY, JVMTI_ERROR_INVALID_CLASS
+        // JVMTI_ERROR_INVALID_OBJECT, JVMTI_ERROR_NULL_POINTER 
+        throw AgentException(err);
+     }
+
+     const jlong tags[1] = {EXPECTED_INSTANCE_TAG};
+     int reachableInstancesNum = 0;
+     jobject * pResultObjects = 0;
+     // Return the instances that have been marked EXPECTED_INSTANCE_TAG tag.
+     JVMTI_TRACE(err, GetJvmtiEnv()->GetObjectsWithTags(1, tags, &reachableInstancesNum,
+            &pResultObjects, NULL));
+     JvmtiAutoFree afResultObjects(pResultObjects);
+
+     if (err != JVMTI_ERROR_NONE) {
+        // Can be: JVMTI_ERROR_MUST_POSSESS_CAPABILITY, JVMTI_ERROR_ILLEGAL_ARGUMENT 
+        // JVMTI_ERROR_ILLEGAL_ARGUMENT, JVMTI_ERROR_NULL_POINTER  
+        throw AgentException(err);
+     }
+
+     jint returnInstancesNum;
+     //If maxInstances is zero, all instances are returned.
+     if(0 == maxInstances) {
+        returnInstancesNum = reachableInstancesNum;
+     }
+     else if(maxInstances < reachableInstancesNum) {
+        returnInstancesNum = maxInstances;
+     }
+     else {
+        returnInstancesNum = reachableInstancesNum;
+     }
+
+     // Compose reply package
+     m_cmdParser->reply.WriteInt(returnInstancesNum);
+     JDWP_TRACE_DATA("Instances: return instances number:" << returnInstancesNum);
+
+     for(int i = 0; i < returnInstancesNum; i++) {
+          m_cmdParser->reply.WriteTaggedObjectID(jni, pResultObjects[i]);
+     }
+     JDWP_TRACE_DATA("Instances: tagged-objectID returned.");
+
+}
+
+//------------------------------------------------------------------------------
 // ClassFileVersionHandler(17)-----------------------------------------------
 
 void
@@ -883,11 +963,78 @@
     }
 
     m_cmdParser->reply.WriteInt(majorVersion);
-     JDWP_TRACE_DATA("ClassFileVersion: send: majorVersion=" 
+    JDWP_TRACE_DATA("ClassFileVersion: send: majorVersion=" 
         << majorVersion);
      
-     m_cmdParser->reply.WriteInt(minorVersion);
+    m_cmdParser->reply.WriteInt(minorVersion);
     JDWP_TRACE_DATA("ClassFileVersion: send: minorVersion=" 
         << minorVersion);
     
 }
+
+//-----------------------------------------------------------------------------
+// Heap callbacks, used in Instances command
+//-----------------------------------------------------------------------------
+
+     /**
+     * Describes a reference from an object or the VM (the referrer) 
+     * to another object (the referree) or a heap root to a referree. 
+     */
+     jint JNICALL ReferenceType::HeapReferenceCallback
+        (jvmtiHeapReferenceKind reference_kind, 
+         const jvmtiHeapReferenceInfo* reference_info, 
+         jlong class_tag, 
+         jlong referrer_class_tag, 
+         jlong size, 
+         jlong* tag_ptr, 
+         jlong* referrer_tag_ptr, 
+         jint length, 
+         void* user_data) {
+            *tag_ptr = EXPECTED_INSTANCE_TAG;
+            return JVMTI_VISIT_OBJECTS;
+     }
+
+    /**
+     * This callback will describe a static field if the object is a class, 
+     * and otherwise will describe an instance field. 
+     */
+     jint JNICALL ReferenceType::PrimitiveFieldCallback
+        (jvmtiHeapReferenceKind kind, 
+         const jvmtiHeapReferenceInfo* info, 
+         jlong object_class_tag, 
+         jlong* object_tag_ptr, 
+         jvalue value, 
+         jvmtiPrimitiveType value_type, 
+         void* user_data) {
+              *object_tag_ptr = EXPECTED_INSTANCE_TAG;
+              return JVMTI_VISIT_OBJECTS;
+     }
+     
+    /**
+     * Describes the values in an array of a primitive type.
+     */
+     jint JNICALL ReferenceType::ArrayPrimitiveValueCallback
+        (jlong class_tag, 
+         jlong size, 
+         jlong* tag_ptr, 
+         jint element_count, 
+         jvmtiPrimitiveType element_type, 
+         const void* elements, 
+         void* user_data) {
+             *tag_ptr = EXPECTED_INSTANCE_TAG;
+             return JVMTI_VISIT_OBJECTS;
+     }
+     
+    /**
+     * Describes the value of a java.lang.String. 
+     */ 
+     jint JNICALL ReferenceType::StringPrimitiveValueCallback
+        (jlong class_tag, 
+         jlong size, 
+         jlong* tag_ptr, 
+         const jchar* value, 
+         jint value_length, 
+         void* user_data) {
+             *tag_ptr = EXPECTED_INSTANCE_TAG;
+             return JVMTI_VISIT_OBJECTS;
+     }

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.h?rev=633366&r1=633365&r2=633366&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ReferenceType.h Mon Mar  3 22:06:15 2008
@@ -33,6 +33,10 @@
 #include "AgentException.h"
 #include "CommandHandler.h"
 
+//This tag is used to mark instance that is reachable for garbage collection purpose
+//It will be used in Instances command
+#define   EXPECTED_INSTANCE_TAG  0xfffff
+
 namespace jdwp {
 
     /**
@@ -347,6 +351,22 @@
         }; // MethodsWithGenericHandler class
 
     //New commands for Java 6
+   // =========================================================================
+        /**
+        * The class implements the <code> Instances(16)</code>
+         * command from the <code>ReferenceType</code> command set.
+         */
+        class InstancesHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>Instances</code> JDWP command for the
+             * <code>ReferenceType</code> command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+        };// InstancesHandler class
 
     // =========================================================================
         /**
@@ -365,7 +385,62 @@
             virtual void Execute(JNIEnv *jni) throw(AgentException);
         };// ClassFileVersionHandler class
 
+
    // =========================================================================
+   //-----------------------------------------------------------------------------
+   // Heap callbacks, used in Instances command
+   //-----------------------------------------------------------------------------
+    /**
+     * Describes a reference from an object or the VM (the referrer) 
+     * to another object (the referree) or a heap root to a referree. 
+     */
+     jint JNICALL HeapReferenceCallback
+        (jvmtiHeapReferenceKind reference_kind, 
+         const jvmtiHeapReferenceInfo* reference_info, 
+         jlong class_tag, 
+         jlong referrer_class_tag, 
+         jlong size, 
+         jlong* tag_ptr, 
+         jlong* referrer_tag_ptr, 
+         jint length, 
+         void* user_data) ;
+
+    /**
+     * This callback will describe a static field if the object is a class, 
+     * and otherwise will describe an instance field. 
+     */
+     jint JNICALL PrimitiveFieldCallback
+        (jvmtiHeapReferenceKind kind, 
+         const jvmtiHeapReferenceInfo* info, 
+         jlong object_class_tag, 
+         jlong* object_tag_ptr, 
+         jvalue value, 
+         jvmtiPrimitiveType value_type, 
+         void* user_data);
+     
+    /**
+     * Describes the values in an array of a primitive type.
+     */
+     jint JNICALL ArrayPrimitiveValueCallback
+        (jlong class_tag, 
+         jlong size, 
+         jlong* tag_ptr, 
+         jint element_count, 
+         jvmtiPrimitiveType element_type, 
+         const void* elements, 
+         void* user_data);
+     
+    /**
+     * Describes the value of a java.lang.String. 
+     */ 
+     jint JNICALL StringPrimitiveValueCallback
+        (jlong class_tag, 
+         jlong size, 
+         jlong* tag_ptr, 
+         const jchar* value, 
+         jint value_length, 
+         void* user_data);
+
     } // ReferenceType namespace
 
 } // jdwp namesoace

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp?rev=633366&r1=633365&r2=633366&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp Mon Mar  3 22:06:15 2008
@@ -612,8 +612,17 @@
     m_cmdParser->reply.WriteBoolean(IsAdded(caps.canRequestVMDeathEvent));
     m_cmdParser->reply.WriteBoolean(IsAdded(caps.canSetDefaultStratum));
 
-    for (int i = 0; i < 17; i++)
+    // New capabilities for Java 6
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetInstanceInfo));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canRequestMonitorEvents));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetMonitorFrameInfo));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canUseSourceNameFilters));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetConstantPool ));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canForceEarlyReturn));
+
+    for (int i = 0; i < 11; i++){
         m_cmdParser->reply.WriteBoolean(JNI_FALSE);
+    }
 }
 
 //-----------------------------------------------------------------------------

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp?rev=633366&r1=633365&r2=633366&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp Mon Mar  3 22:06:15 2008
@@ -375,6 +375,17 @@
         env.caps.canRequestVMDeathEvent = 1;
         env.caps.canSetDefaultStratum = 0;
 
+        //New capabilities for Java 6
+        env.caps.canGetInstanceInfo = 1;
+        env.caps.canRequestMonitorEvents = 1;
+        env.caps.canGetMonitorFrameInfo = 1;
+        env.caps.canUseSourceNameFilters = 1;
+        env.caps.canGetConstantPool = 
+            caps.can_get_constant_pool;
+        env.caps.canForceEarlyReturn =
+            caps.can_force_early_return;
+        caps.can_tag_objects = 1;
+
         // these caps should be added for full agent functionality
         // caps.can_suspend = 1;
         // caps.can_signal_thread = 1;
@@ -390,7 +401,6 @@
         // caps.can_redefine_any_class = 1;
 
         // these caps look unnecessary for JDWP agent
-        caps.can_tag_objects = 0;
         caps.can_maintain_original_method_order = 0;
         caps.can_redefine_any_class = 0;
         caps.can_get_current_thread_cpu_time = 0;

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=633366&r1=633365&r2=633366&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 Mon Mar  3 22:06:15 2008
@@ -251,6 +251,9 @@
             return new ReferenceType::MethodsWithGenericHandler();
         
         //New commands for Java 6
+        case JDWP_COMMAND_RT_INSTANCES:
+            return new ReferenceType::InstancesHandler();
+
         case JDWP_COMMAND_RT_CLASS_FILE_VERSION:
             return new ReferenceType::ClassFileVersionHandler();
 

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/jdwpTypes.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/jdwpTypes.h?rev=633366&r1=633365&r2=633366&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/jdwpTypes.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/jdwpTypes.h Mon Mar  3 22:06:15 2008
@@ -81,7 +81,14 @@
         unsigned int canGetSourceDebugExtension : 1;
         unsigned int canRequestVMDeathEvent : 1;
         unsigned int canSetDefaultStratum : 1;
-        unsigned int : 17;
+        unsigned int canGetInstanceInfo : 1; 
+        unsigned int canRequestMonitorEvents : 1;  
+        unsigned int canGetMonitorFrameInfo : 1;   
+        unsigned int canUseSourceNameFilters : 1; 
+        unsigned int canGetConstantPool : 1;
+        unsigned int canForceEarlyReturn : 1;
+
+        unsigned int : 11;
     };
 
     /**

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=633366&r1=633365&r2=633366&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 Mon Mar  3 22:06:15 2008
@@ -61,7 +61,7 @@
 
     public boolean canSetDefaultStratum             = false;
 
-    public boolean reserved16                       = false;
+    public boolean canGetInstanceInfo               = false;
 
     public boolean reserved17                       = false;
 

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=633366&r1=633365&r2=633366&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 Mon Mar  3 22:06:15 2008
@@ -410,7 +410,8 @@
                 .getNextValueAsBoolean();
         targetVMCapabilities.canSetDefaultStratum = replyPacket
                 .getNextValueAsBoolean();
-        targetVMCapabilities.reserved16 = replyPacket.getNextValueAsBoolean();
+        targetVMCapabilities.canGetInstanceInfo = replyPacket
+                .getNextValueAsBoolean();
         targetVMCapabilities.reserved17 = replyPacket.getNextValueAsBoolean();
         targetVMCapabilities.reserved18 = replyPacket.getNextValueAsBoolean();
         targetVMCapabilities.reserved19 = replyPacket.getNextValueAsBoolean();

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesDebuggee.java?rev=633366&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesDebuggee.java (added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesDebuggee.java Mon Mar  3 22:06:15 2008
@@ -0,0 +1,72 @@
+/*
+ * 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.ReferenceType;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+public class InstancesDebuggee extends SyncDebuggee {
+
+	static final int maxNum = 17;
+	
+	static int reachableObjNum;
+	
+	static int unreachableObjNum;
+	
+	static {
+		reachableObjNum = new Random().nextInt(maxNum) + 2;
+		unreachableObjNum = new Random().nextInt(maxNum) + 2;
+	}
+
+	@Override
+	public void run() {
+		//Objects reachable for garbage collection purpose
+		
+		ArrayList<MockClass> reachableObjs = new ArrayList<MockClass>();
+        
+		for(int i = 0; i < reachableObjNum; i++) {
+			reachableObjs.add(new MockClass(true));
+		}
+       
+		//Objects unreachable
+		for(int i = 0; i < unreachableObjNum; i++) {
+			new MockClass(false);
+		}
+		synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+        logWriter.println("--> Debuggee: InstancesDebuggee...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+	}
+
+	public static void main(String[] args) {
+		runDebuggee(InstancesDebuggee.class);
+	}
+
+}
+
+class MockClass {
+	private boolean isReachable;
+	MockClass(boolean isReachable){
+		this.isReachable = isReachable;
+	}
+}
+
+

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

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java?rev=633366&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java (added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java Mon Mar  3 22:06:15 2008
@@ -0,0 +1,209 @@
+/*
+ * 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.ReferenceType;
+
+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.Value;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+public class InstancesTest extends JDWPSyncTestCase {
+
+    static final int testStatusPassed = 0;
+
+    static final int testStatusFailed = -1;
+    
+    static int maxInstances;
+
+    static final String thisCommandName = "ReferenceType.Instances command";
+
+    static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesDebuggee;";
+
+    static final String mockClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/MockClass;";
+
+    @Override
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.InstancesDebuggee";
+    }
+
+    /**
+     * All test cases is based on this process. <BR>
+     * It starts InstancesDebuggee class, requests referenceTypeId for
+     * MockClass class by VirtualMachine.ClassesBySignature command, then performs
+     * ReferenceType.Instances command and checks that returned reachable
+     * objects are expected ones.
+     */
+    private void runTestInstances() {
+        String thisTestName = "testInstances001";
+
+        // check capability, relevant for this test
+        logWriter.println("=> Check capability: canGetInstanceInfo");
+        debuggeeWrapper.vmMirror.capabilities();
+        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetInstanceInfo;
+        if (!isCapability) {
+            logWriter
+                    .println("##WARNING: this VM dosn't possess capability: canGetInstanceInfo");
+            return;
+        }
+
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName
+                + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        long mockClassRefTypeID = getClassIDBySignature(mockClassSignature);
+        long debuggeeRefTypeID = getClassIDBySignature(debuggeeSignature);
+
+        //Get the number of reachable objects in debuggee class
+        long reachableObjNumID = debuggeeWrapper.vmMirror.getFieldID(
+                debuggeeRefTypeID, "reachableObjNum");
+        long[] fieldIDs = new long[1];
+        fieldIDs[0] = reachableObjNumID;
+
+        Value[] values = debuggeeWrapper.vmMirror.getReferenceTypeValues(
+                debuggeeRefTypeID, fieldIDs);
+        int expectedReachableObjNum = values[0].getIntValue();
+        
+        logWriter.println("=> ReachableObjNum in debuggee is: " + expectedReachableObjNum);
+        
+        //maxInstances is maximum number of instances to return. 
+        //So expectedReachableObjNum should be less than maxInstances
+        if (expectedReachableObjNum > maxInstances && maxInstances > 0) {
+            expectedReachableObjNum = maxInstances;
+        }
+
+        logWriter.println("=> CHECK: send " + thisCommandName
+                + " and check reply for ERROR...");
+
+        CommandPacket InstancesCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.InstancesCommand);
+        InstancesCommand.setNextValueAsReferenceTypeID(mockClassRefTypeID);
+        InstancesCommand.setNextValueAsInt(maxInstances);
+
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror
+                .performCommand(InstancesCommand);
+        InstancesCommand = null;
+
+        short errorCode = checkedReply.getErrorCode();
+        if (errorCode != JDWPConstants.Error.NONE) {
+            if (errorCode == JDWPConstants.Error.NOT_IMPLEMENTED) {
+                logWriter
+                        .println("=> CHECK PASSED: Expected error (NOT_IMPLEMENTED) is returned");
+                return;
+            }
+            else if(errorCode == JDWPConstants.Error.ILLEGAL_ARGUMENT) {
+                logWriter
+                        .println("=> CHECK PASSED: Expected error (ILLEGAL_ARGUMENT) is returned");
+                return;
+            }
+
+        }
+
+        //Get the number of instances that returned. 
+        int reachableInstancesNum = checkedReply.getNextValueAsInt();
+        assertEquals(thisCommandName + "returned instances number is wrong.",
+                expectedReachableObjNum, reachableInstancesNum, null, null);
+
+        long mockClassFieldID = debuggeeWrapper.vmMirror.getFieldID(
+                mockClassRefTypeID, "isReachable");
+        for (int i = 0; i < reachableInstancesNum; i++) {
+            //Get the tagged-objectID
+            byte tag = checkedReply.getNextValueAsByte();
+            assertEquals(thisCommandName
+                    + "returned object tag is invalid.", 'L', tag, null, null);
+            
+            long objectID = checkedReply.getNextValueAsObjectID();
+            logWriter.println("=> ObjectID is: " + objectID);
+            values = debuggeeWrapper.vmMirror.getObjectReferenceValues(
+                    objectID, new long[] { mockClassFieldID });
+            boolean isReachable = values[0].getBooleanValue();
+            if (!isReachable) {
+                printErrorAndFail(thisCommandName
+                        + "returned object is not reachable.");
+            }
+        }
+        logWriter.println("=> CHECK: PASSED: expected instances are returned:");
+        logWriter.println("=> Returned reachable instances number is" + expectedReachableObjNum);
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH");
+        assertAllDataRead(checkedReply);
+
+    }
+    
+    /**
+     * This testcase exercises ReferenceType.Instances command. <BR>
+     * The test starts InstancesDebuggee class, requests referenceTypeId for
+     * MockClass class by VirtualMachine.ClassesBySignature command, then performs
+     * ReferenceType.Instances command and checks that returned reachable
+     * objects are expected ones. Maximum number of instances is zero, so all instances 
+     * are returned.
+     */
+    public void testInstances001() {
+        maxInstances = 0;
+        runTestInstances();
+    }
+    
+    /**
+     * This testcase exercises ReferenceType.Instances command. <BR>
+     * The test starts InstancesDebuggee class, requests referenceTypeId for
+     * MockClass class by VirtualMachine.ClassesBySignature command, then performs
+     * ReferenceType.Instances command. Since maximum number of instances is negtive, so  
+     * ILLEGAL_ARGUMENT exception are replied.
+     */
+    public void testInstances002() {
+        maxInstances = -1;
+        runTestInstances();
+    }
+    
+    /**
+     * This testcase exercises ReferenceType.Instances command. <BR>
+     * The test starts InstancesDebuggee class, requests referenceTypeId for
+     * MockClass class by VirtualMachine.ClassesBySignature command, then performs
+     * ReferenceType.Instances command and checks that returned reachable
+     * objects are expected ones. Maximum number of instances is more than the reachable
+     * objects of this reference type, so all instances are returned.
+     */
+    public void testInstances003() {
+        maxInstances = 20;
+        runTestInstances();
+    }
+    
+    /**
+     * This testcase exercises ReferenceType.Instances command. <BR>
+     * The test starts InstancesDebuggee class, requests referenceTypeId for
+     * MockClass class by VirtualMachine.ClassesBySignature command, then performs
+     * ReferenceType.Instances command and checks that returned reachable
+     * objects are expected ones. Maximum number of instances is less than the reachable
+     * objects of this reference type, so maximum number of instances are returned.
+     */
+    public void testInstances004() {
+        maxInstances = 1;
+        runTestInstances();
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(InstancesTest.class);
+
+    }
+
+}

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