harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r636651 - in /harmony/enhanced/jdktools/branches/java6/modules/jpda: make/ src/main/native/jdwp/common/agent/commands/ src/main/native/jdwp/common/agent/core/ src/main/native/jdwp/common/generic/ src/test/java/org/apache/harmony/jpda/tests/...
Date Thu, 13 Mar 2008 07:20:51 GMT
Author: lvjing
Date: Thu Mar 13 00:20:42 2008
New Revision: 636651

URL: http://svn.apache.org/viewvc?rev=636651&view=rev
Log:
Apply patch for HARMONY-5596, [jdktools][jdwp6] Add new command ReferringObjects Command for
Java 6

Added:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsDebuggee.java
  (with props)
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsTest.java
  (with props)
Modified:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.h
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.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/jdwp/JDWPCommands.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=636651&r1=636650&r2=636651&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/make/exclude.common Thu Mar 13 00:20:42
2008
@@ -6,11 +6,12 @@
 #5154
 org/apache/harmony/jpda/tests/jdwp/Events/ClassUnloadTest.java
 #5549
-org/apache/harmony/jpda/tests/jdwp/ReferenceType/ClassFileVersionDebuggee.java
 org/apache/harmony/jpda/tests/jdwp/ReferenceType/ClassFileVersionTest.java
 #5564
 org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java
 #5587
-org/apache/harmony/jpda/tests/jdwp/ReferenceType/ConstantPoolTest
+org/apache/harmony/jpda/tests/jdwp/ReferenceType/ConstantPoolTest.java
 #5591
-org/apache/harmony/jpda/tests/jdwp/VirtualMachine/InstanceCountsTest
+org/apache/harmony/jpda/tests/jdwp/VirtualMachine/InstanceCountsTest.java
+#5596
+org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsTest.java

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp?rev=636651&r1=636650&r2=636651&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
Thu Mar 13 00:20:42 2008
@@ -23,9 +23,11 @@
 #include "ObjectReference.h"
 #include "PacketParser.h"
 #include "ObjectManager.h"
+#include "CallBacks.h"
 
 using namespace jdwp;
 using namespace ObjectReference;
+using namespace CallBacks;
 
 //------------------------------------------------------------------------------
 //ReferenceTypeHandler(1)-------------------------------------------------------
@@ -880,3 +882,89 @@
         }
     }
 }
+
+// New commands for Java 6
+//------------------------------------------------------------------------------
+//ReferringObjectsHandler(10)---------------------------------------------------
+
+void
+ObjectReference::ReferringObjectsHandler::Execute(JNIEnv *jni) throw (AgentException)
+{
+    // Get objectID
+    jobject jvmObject = m_cmdParser->command.ReadObjectID(jni);
+    // Can be: InternalErrorException, OutOfMemoryException, JDWP_ERROR_INVALID_OBJECT
+
+    // Get maximum number of referring objects to return.
+    int maxReferrers = m_cmdParser->command.ReadInt();
+    if(maxReferrers < 0) {
+        throw AgentException(JDWP_ERROR_ILLEGAL_ARGUMENT);
+    }
+
+    // Define tag for referree object
+    jlong targetObjTag = 0xefff;
+    // Set tag for target object
+     jvmtiError err;
+    JVMTI_TRACE(err, GetJvmtiEnv()->SetTag(jvmObject, targetObjTag));
+    if (err != JVMTI_ERROR_NONE) {
+        // Can be: JVMTI_ERROR_MUST_POSSESS_CAPABILITY,  JVMTI_ERROR_INVALID_OBJECT
+        throw AgentException(err);
+    }
+    
+    // Define tag for referrer object
+    jlong referrerObjTag = 0xdfff;
+    jlong tags[2] = {targetObjTag, referrerObjTag};
+
+    // Initial callbacks for jvmtiHeapCallbacks
+    jvmtiHeapCallbacks hcbs;
+    memset(&hcbs, 0, sizeof(hcbs));
+    hcbs.heap_iteration_callback = NULL;
+    hcbs.heap_reference_callback = &HeapReferenceCallback_ReferringObject;
+    hcbs.primitive_field_callback = NULL;
+    hcbs.array_primitive_value_callback = NULL;
+    hcbs.string_primitive_value_callback = NULL;
+
+    //It initiates a traversal over the objects that are directly and indirectly reachable
from the heap roots.
+    JVMTI_TRACE(err, GetJvmtiEnv()->FollowReferences(0, NULL,  NULL,
+         &hcbs, tags));
+    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 referrerTags[1] = {referrerObjTag};
+    jint referringObjectsNum = 0;
+    jobject * pResultObjects = 0;
+    // Return the instances that have been marked expectd tag.
+    JVMTI_TRACE(err, GetJvmtiEnv()->GetObjectsWithTags(1, referrerTags, &referringObjectsNum,
+           &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 returnReferringObjectsNum;
+    //If maxReferrers is zero, all instances are returned.
+    if(0 == maxReferrers) {
+        returnReferringObjectsNum = referringObjectsNum;
+    }
+    else if(maxReferrers < referringObjectsNum) {
+        returnReferringObjectsNum = maxReferrers;
+    }
+    else {
+        returnReferringObjectsNum = referringObjectsNum;
+    }
+
+    // Compose reply package
+    m_cmdParser->reply.WriteInt(returnReferringObjectsNum);
+    JDWP_TRACE_DATA("ReferringObject: return objects number:" << returnReferringObjectsNum
);
+
+    for(int i = 0; i < returnReferringObjectsNum; i++) {
+        m_cmdParser->reply.WriteTaggedObjectID(jni, pResultObjects[i]);
+    }
+    JDWP_TRACE_DATA("ReferringObject: tagged-objectID returned.");
+
+} //ReferringObjectsHandler::Execute()

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.h?rev=636651&r1=636650&r2=636651&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.h
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.h
Thu Mar 13 00:20:42 2008
@@ -212,6 +212,25 @@
 
         };//InvokeMethodHandler
 
+         //New commands for Java 6
+        // =========================================================================
+        /**
+         * The class implements the <code>ReferringObjects (10) </code>
+         * command from the <code>ObjectReference</code> command set.
+         */
+        class ReferringObjectsHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>ReferringObjects</code> JDWP command for the
+             * <code>ObjectReference</code> command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        }; // ReferringObjectsHandler class
+
     } // ObjectReference namespace
 
 } // jdwp namespace

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.cpp?rev=636651&r1=636650&r2=636651&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.cpp
Thu Mar 13 00:20:42 2008
@@ -91,3 +91,33 @@
              *tag_ptr = tag_value;
              return JVMTI_VISIT_OBJECTS;
      }
+     
+//-----------------------------------------------------------------------------
+// Heap callbacks, used in ReferringObject command
+//-----------------------------------------------------------------------------
+
+     /**
+      * Describes a reference from an object or the VM (the referrer) 
+      * to another object (the referree) or a heap root to a referree. It 
+      * will be invoked by ReferringObject command.
+      */
+     jint JNICALL CallBacks::HeapReferenceCallback_ReferringObject
+        (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) {
+             jlong targetObjTag = *(static_cast<jlong *>(user_data));
+             jlong *ptr = static_cast<jlong *>(user_data);
+             ptr++;
+             jlong referrerObjTag = *ptr;
+             if(*tag_ptr == targetObjTag && referrer_tag_ptr != NULL) {
+                *referrer_tag_ptr = referrerObjTag;
+             }
+            return JVMTI_VISIT_OBJECTS;
+     }
+ 

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.h?rev=636651&r1=636650&r2=636651&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.h
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/CallBacks.h
Thu Mar 13 00:20:42 2008
@@ -24,7 +24,7 @@
 
 namespace jdwp {
 
-     //-----------------------------------------------------------------------------
+   //-----------------------------------------------------------------------------
    // Heap callbacks, used in Instances, InstanceCounts command
    //-----------------------------------------------------------------------------
     namespace CallBacks {
@@ -78,6 +78,26 @@
          const jchar* value, 
          jint value_length, 
          void* user_data);
+         
+        //-----------------------------------------------------------------------------
+        // Heap callbacks, used in ReferringObject command
+        //-----------------------------------------------------------------------------
+        /**
+         * Describes a reference from an object or the VM (the referrer) 
+         * to another object (the referree) or a heap root to a referree. It 
+         * will be invoked by ReferringObject command.
+         */
+        jint JNICALL HeapReferenceCallback_ReferringObject
+        (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);
+
     } //CallBacks namespace
 } // jdwp namesoace
 #endif//_CALL_BACKS_H_

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=636651&r1=636650&r2=636651&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
Thu Mar 13 00:20:42 2008
@@ -311,6 +311,10 @@
         case JDWP_COMMAND_OR_IS_COLLECTED:
             return new ObjectReference::IsCollectedHandler();
 
+         // New commands for Java 6
+        case JDWP_COMMAND_OR_REFERRING_OBJECTS:
+            return new ObjectReference::ReferringObjectsHandler(); 
+
         }
         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=636651&r1=636650&r2=636651&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
Thu Mar 13 00:20:42 2008
@@ -132,6 +132,8 @@
     JDWP_COMMAND_OR_DISABLE_COLLECTION = 7,
     JDWP_COMMAND_OR_ENABLE_COLLECTION = 8,
     JDWP_COMMAND_OR_IS_COLLECTED = 9,
+    // New commands for Java 6
+    JDWP_COMMAND_OR_REFERRING_OBJECTS = 10,
 
     /* Commands StringReference */
     JDWP_COMMAND_SR_VALUE = 1,

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=636651&r1=636650&r2=636651&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
Thu Mar 13 00:20:42 2008
@@ -78,6 +78,7 @@
 
         public static final byte AllClassesWithGenericCommand = 20;
         
+        //New commands for Java 6
         public static final byte InstanceCountsCommand = 21;
     }
 
@@ -207,6 +208,9 @@
         public static final byte EnableCollectionCommand = 8;
 
         public static final byte IsCollectedCommand = 9;
+        
+        //New commands for Java 6
+        public static final byte ReferringObjectsCommand = 10;
     }
 
     /**

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsDebuggee.java?rev=636651&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsDebuggee.java
(added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsDebuggee.java
Thu Mar 13 00:20:42 2008
@@ -0,0 +1,88 @@
+/*
+ * 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.ObjectReference;
+
+
+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 ReferringObjectsDebuggee extends SyncDebuggee {
+
+    static final int maxNum = 17;
+    
+    static int referringObjNum;
+    
+    static int nonreferringObjNum;
+    
+    static {
+        referringObjNum = new Random().nextInt(maxNum) + 2;
+        nonreferringObjNum = new Random().nextInt(maxNum) + 2;
+    }
+
+    @Override
+    public void run() {
+        ReferringObjectsReferree001 referree = new ReferringObjectsReferree001();
+        //Referrer objects which contain reference of referree object       
+        ArrayList<ReferringObjectsReferrer001> referringObjs = new ArrayList<ReferringObjectsReferrer001>();
+        
+        for(int i = 0; i < referringObjNum; i++) {
+            referringObjs.add(new ReferringObjectsReferrer001(referree));
+        }
+        
+        //Referrer objects which contain reference which is null 
+        ArrayList<ReferringObjectsReferrer001> nonreferringObjs = new ArrayList<ReferringObjectsReferrer001>();
+        
+        for(int i = 0; i < nonreferringObjNum; i++) {
+            nonreferringObjs.add(new ReferringObjectsReferrer001(null));
+        }
+        
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+        logWriter.println("--> Debuggee: ReferringObjectsDebuggee...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+    }
+
+    public static void main(String[] args) {
+        runDebuggee(ReferringObjectsDebuggee.class);
+    }
+
+}
+
+class ReferringObjectsReferree001 {
+    
+}
+
+class ReferringObjectsReferrer001 {
+    private boolean isReferrer;
+    private ReferringObjectsReferree001 reference;
+    
+    ReferringObjectsReferrer001(ReferringObjectsReferree001 reference) {
+        if(null != reference) {
+            isReferrer = true;
+        }
+        else {
+            isReferrer = false;
+        }
+        this.reference = reference;
+    }
+}
+
+

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

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsTest.java?rev=636651&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsTest.java
(added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsTest.java
Thu Mar 13 00:20:42 2008
@@ -0,0 +1,260 @@
+/*
+ * 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.ObjectReference;
+
+import java.util.Random;
+
+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 ReferringObjectsTest extends JDWPSyncTestCase {
+
+    static final int testStatusPassed = 0;
+
+    static final int testStatusFailed = -1;
+    
+    static int maxReferrers;
+
+    static final String thisCommandName = "ObjectReference.ReferringObjects command";
+
+    static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsDebuggee;";
+   
+    static final String referreeObjSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsReferree001;";
+    
+    static final String referrerObjSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferringObjectsReferrer001;";
+    
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.ReferringObjectsDebuggee";
+    }
+
+    // ReferringObjects need canGetInstanceInfo VM capability support
+    private boolean isCapability() {
+        // check capability, relevant for this test
+        logWriter.println("=> Check capability: canGetInstanceInfo");
+        debuggeeWrapper.vmMirror.capabilities();
+        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetInstanceInfo;
+        return isCapability;
+    }
+    
+    /**
+     * This testcase exercises ObjectReference.ReferringObjects command.
+     * <BR>The test starts ReferringObjectsDebuggee class, requests referree objectID,

+     * for this class by ReferenceType.Instances command, then performs ObjectReference.ReferringObjects

+     * command and checks that returned instances are equal to the expected referrer objects.
Since maxReferrers
+     * equals zero, all instances are returned.
+     */
+    public void testReferringObjects_MaxReferrersIsZero() {
+        maxReferrers = 0;
+        DoTestReferringObjects();
+    }
+    
+    /**
+     * This testcase exercises ObjectReference.ReferringObjects command.
+     * <BR>The test starts ReferringObjectsDebuggee class, requests referree objectID,

+     * for this class by ReferenceType.Instances command, then performs ObjectReference.ReferringObjects

+     * command and checks that returned instances are equal to the expected referrer objects.
Since maxReferrers
+     * is more than the number of referrer objects, all instances are returned.
+     */
+    public void testReferringObjects_MaxReferrersIsLarge() {
+        maxReferrers = 20;
+        DoTestReferringObjects();
+    }
+    
+    /**
+     * This testcase exercises ObjectReference.ReferringObjects command.
+     * <BR>The test starts ReferringObjectsDebuggee class, requests referree objectID,

+     * for this class by ReferenceType.Instances command, then performs ObjectReference.ReferringObjects

+     * command and checks that returned instances are equal to the expected referrer objects.
Since maxReferrers
+     * is less than the number of referrer objects, the number of instances returned is equal
to maxReferrers.
+     */
+    public void testReferringObjects_MaxReferrersIsSmall() {
+        maxReferrers = 1;
+        DoTestReferringObjects();
+    }
+    
+    /**
+     * This is the real body of the testcase which exercises ObjectReference.ReferringObjects
command.
+     * <BR>The test starts ReferringObjectsDebuggee class, requests referree objectID,

+     * for this class by ReferenceType.Instances command, then performs ObjectReference.ReferringObjects

+     * command and checks that returned instances are equal to the expected referrer objects.
+     */
+    public void DoTestReferringObjects() {
+        String thisTestName = "testReferringObjects_Normal";
+        
+        if (!isCapability()) {
+            logWriter.println("##WARNING: this VM dosn't possess capability: canGetInstanceInfo");
+            return;
+        }
+        
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        // Get the number of referrer objects in ReferringObjectsDebugee
+        long debuggeeRefTypeID = getClassIDBySignature(debuggeeSignature);
+        long referringObjNumID = debuggeeWrapper.vmMirror.getFieldID(
+                debuggeeRefTypeID, "referringObjNum");
+        long[] fieldIDs = new long[1];
+        fieldIDs[0] = referringObjNumID;
+        Value[] values = debuggeeWrapper.vmMirror.getReferenceTypeValues(
+                debuggeeRefTypeID, fieldIDs);
+        int expectedReferringObjNum = values[0].getIntValue();
+        
+        logWriter.println("=> ReferringObjNum in debuggee is: " + expectedReferringObjNum);
+
+        if(maxReferrers > 0) {
+            expectedReferringObjNum = (maxReferrers > expectedReferringObjNum) ? expectedReferringObjNum
: maxReferrers;
+        }
+        
+        // Compose Instances command to get referree objectID
+        CommandPacket InstancesCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.InstancesCommand);
+        
+        long referreeObjTypeID = getClassIDBySignature(referreeObjSignature);
+        InstancesCommand.setNextValueAsReferenceTypeID(referreeObjTypeID);
+        InstancesCommand.setNextValueAsInt(1);
+        
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(InstancesCommand);
+        InstancesCommand = null;
+        
+        // Get the number of instances that returned. 
+        int objNum = checkedReply.getNextValueAsInt();
+        // Get the tagged-objectID
+        byte tag = checkedReply.getNextValueAsByte();
+        long objectID = checkedReply.getNextValueAsObjectID();
+        
+        // Compose ReferringObjects commnad
+        CommandPacket ReferringObjectsCommand = new CommandPacket(
+                JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
+                JDWPCommands.ObjectReferenceCommandSet.ReferringObjectsCommand);
+        
+        ReferringObjectsCommand.setNextValueAsObjectID(objectID);
+        ReferringObjectsCommand.setNextValueAsInt(maxReferrers);
+        
+        // Perform ReferringObjects command and attain reply package
+        checkedReply = debuggeeWrapper.vmMirror
+                .performCommand(ReferringObjectsCommand);
+        ReferringObjectsCommand = null;
+        
+        // Get referrer objects numbers
+        int referringObjects = checkedReply.getNextValueAsInt();
+        assertEquals(thisCommandName + "returned instances number is wrong.", expectedReferringObjNum,
referringObjects,null,null);
+   
+        long referrerTypeID = getClassIDBySignature(referrerObjSignature);
+        long referrerFieldID = debuggeeWrapper.vmMirror.getFieldID(
+                referrerTypeID, "isReferrer");
+        
+        // Check the returned objects are referrer objects
+        for (int i = 0; i < referringObjects; i++) {
+            //Get the tagged-objectID
+            tag = checkedReply.getNextValueAsByte();
+            assertEquals(thisCommandName
+                    + "returned object tag is invalid.", 'L', tag, null, null);
+            
+            objectID = checkedReply.getNextValueAsObjectID();
+            logWriter.println("=> ObjectID is: " + objectID);
+            values = debuggeeWrapper.vmMirror.getObjectReferenceValues(
+                    objectID, new long[] { referrerFieldID });
+            boolean isReferrer = values[0].getBooleanValue();
+            if (!isReferrer) {
+                printErrorAndFail(thisCommandName
+                        + "returned object is not a referrer which references this object.");
+            }
+        }
+        logWriter.println("=> CHECK: PASSED: expected instances are returned:");
+        logWriter.println("=> Returned referringObjects number is" + referringObjects);
+        
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH");
+        assertAllDataRead(checkedReply);
+    }
+    
+    /**
+     * This testcase exercises ObjectReference.ReferringObjects command. <BR>
+     * Compose a ReferringObjects command with negative maxReferrers
+     * The vm should throw a ILLEGAL_ARGUMENT exception.
+     */
+    public void testReferringObjects_IllegalArgument() {
+        String thisTestName = "testReferringObjects_IllegalArgument";
+        
+        if (!isCapability()) {
+            logWriter.println("##WARNING: this VM dosn't possess capability: canGetInstanceInfo");
+            return;
+        }
+        
+        int maxReferrers = -1;
+        
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        // Compose Instances command to get referree objectID
+        CommandPacket InstancesCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.InstancesCommand);
+        
+        long referreeObjTypeID = getClassIDBySignature(referreeObjSignature);
+        InstancesCommand.setNextValueAsReferenceTypeID(referreeObjTypeID);
+        InstancesCommand.setNextValueAsInt(1);
+        
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(InstancesCommand);
+        InstancesCommand = null;
+        
+        // Get the number of instances that returned. 
+        int objNum = checkedReply.getNextValueAsInt();
+        // Get the tagged-objectID
+        byte tag = checkedReply.getNextValueAsByte();
+        long objectID = checkedReply.getNextValueAsObjectID();
+        
+        // Compose ReferringObjects commnad
+        CommandPacket ReferringObjectsCommand = new CommandPacket(
+                JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
+                JDWPCommands.ObjectReferenceCommandSet.ReferringObjectsCommand);
+        
+        ReferringObjectsCommand.setNextValueAsObjectID(objectID);
+        ReferringObjectsCommand.setNextValueAsInt(maxReferrers);
+        
+        // Perform ReferringObjects command and attain reply package
+        checkedReply = debuggeeWrapper.vmMirror
+                .performCommand(ReferringObjectsCommand);
+        ReferringObjectsCommand = 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;
+            }
+        }
+        printErrorAndFail(thisCommandName + " should throw ILLEGAL_ARGUMENT exception when
maxReferrers is negative.");
+    }
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(ReferringObjectsTest.class);
+    }
+
+}

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



Mime
View raw message