harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r558746 - in /harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent: commands/VirtualMachine.cpp commands/VirtualMachine.h core/PacketParser.cpp core/PacketParser.h
Date Mon, 23 Jul 2007 14:38:53 GMT
Author: gshimansky
Date: Mon Jul 23 07:38:51 2007
New Revision: 558746

URL: http://svn.apache.org/viewvc?view=rev&rev=558746
Log:
Applied patch from HARMONY-4323
[jdktools][jpda] JDWP commands VirtualMachine.AllClasses returns not prepared classes


Modified:
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.h
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.h

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp?view=diff&rev=558746&r1=558745&r2=558746
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.cpp
Mon Jul 23 07:38:51 2007
@@ -117,15 +117,14 @@
             count++;
         }
     }
+    size_t classCountPos = m_cmdParser->reply.GetPosition();
     m_cmdParser->reply.WriteInt(count);
     JDWP_TRACE_DATA("ClassesBySignature: classes=" << count);
     
+    int notIncludedClasses = 0;
     for (i = 0; i < count; i++)
     {
         jdwpTypeTag refTypeTag = GetClassManager().GetJdwpTypeTag(classes[i]);
-        m_cmdParser->reply.WriteByte(refTypeTag);
-
-        m_cmdParser->reply.WriteReferenceTypeID(jni, classes[i]);
 
         jint status;
         JVMTI_TRACE(err, jvmti->GetClassStatus(classes[i], &status));
@@ -137,8 +136,16 @@
         } else {
             if ( status == JVMTI_CLASS_STATUS_PRIMITIVE ) {
                 status = 0;
+            } else {
+                if ( (status & JVMTI_CLASS_STATUS_PREPARED) == 0 ) {
+                    // Given class is not prepared - don't return such class
+                    notIncludedClasses++;
+                    continue;
+                }
             }
         }
+        m_cmdParser->reply.WriteByte(refTypeTag);
+        m_cmdParser->reply.WriteReferenceTypeID(jni, classes[i]);
         m_cmdParser->reply.WriteInt(status);
 #ifndef NDEBUG
         if (JDWP_TRACE_ENABLED(LOG_KIND_DATA)) {    
@@ -153,6 +160,15 @@
         }
 #endif
     }
+
+    if ( notIncludedClasses != 0 ) {
+        size_t currentPos = m_cmdParser->reply.GetPosition();
+        jint currentLength = m_cmdParser->reply.GetLength();
+        m_cmdParser->reply.SetPosition(classCountPos);
+        m_cmdParser->reply.WriteInt(count - notIncludedClasses);
+        m_cmdParser->reply.SetPosition(currentPos);
+        m_cmdParser->reply.SetLength(currentLength);
+    }
 }
 
 bool
@@ -191,25 +207,33 @@
         throw AgentException(err);
 
     JDWP_TRACE_DATA("AllClasses: classes=" << classCount);
+    size_t classCountPos = m_cmdParser->reply.GetPosition();
     m_cmdParser->reply.WriteInt(classCount);
 
     // don't trace signatures of all classes
+    int notIncludedClasses = 0;
     for (int i = 0; i < classCount; i++) {
-        Compose41Class(jni, jvmti, classes[i]);
+        notIncludedClasses += Compose41Class(jni, jvmti, classes[i]);
+    }
+
+    if (notIncludedClasses > 0) {
+        size_t currentPos = m_cmdParser->reply.GetPosition();
+        jint currentLength = m_cmdParser->reply.GetLength();
+        m_cmdParser->reply.SetPosition(classCountPos);
+        m_cmdParser->reply.WriteInt(classCount - notIncludedClasses);
+        m_cmdParser->reply.SetPosition(currentPos);
+        m_cmdParser->reply.SetLength(currentLength);
     }
 }
 
 //-----------------------------------------------------------------------------
 
-void
+int
 VirtualMachine::AllClassesHandler::Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti,
         jclass klass) throw (AgentException)
 {
     jdwpTypeTag refTypeTag = GetClassManager().GetJdwpTypeTag(klass);
 
-    m_cmdParser->reply.WriteByte(refTypeTag);
-    m_cmdParser->reply.WriteReferenceTypeID(jni, klass);
-
     char* signature = 0;
 
     jvmtiError err;
@@ -220,25 +244,25 @@
     if (err != JVMTI_ERROR_NONE)
         throw AgentException(err);
 
-    m_cmdParser->reply.WriteString(signature);
-
     jint status;
     JVMTI_TRACE(err, jvmti->GetClassStatus(klass, &status));
     if (err != JVMTI_ERROR_NONE)
         throw AgentException(err);
 
     // According to JVMTI spec ClassStatus flag for arrays and primitive classes must be
zero
-    if (status == JVMTI_CLASS_STATUS_ARRAY) {
+    if (status == JVMTI_CLASS_STATUS_ARRAY || status == JVMTI_CLASS_STATUS_PRIMITIVE) {
         status = 0;
-    } else {
-        if (status == JVMTI_CLASS_STATUS_PRIMITIVE) {
-            JDWP_INFO("WARNING: GetLoadedClasses() returned primitive type with signature:
" 
-                << JDWP_CHECK_NULL(signature));
-            status = 0;
-        }
+    } else if ( (status & JVMTI_CLASS_STATUS_PREPARED) == 0 ) {
+        // Given class is not prepared - don't return such class
+        return 1;
     }
 
+    m_cmdParser->reply.WriteByte(refTypeTag);
+    m_cmdParser->reply.WriteReferenceTypeID(jni, klass);
+    m_cmdParser->reply.WriteString(signature);
     m_cmdParser->reply.WriteInt(status);
+
+    return 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -687,15 +711,12 @@
 //-----------------------------------------------------------------------------
 //AllClassesWithGenericHandler-------------------------------------------------
 
-void
+int
 VirtualMachine::AllClassesWithGenericHandler::Compose41Class(JNIEnv *jni_env,
             jvmtiEnv* jvmti, jclass klass) throw (AgentException)
 {
     jdwpTypeTag refTypeTag = GetClassManager().GetJdwpTypeTag(klass);
 
-    m_cmdParser->reply.WriteByte(refTypeTag);
-    m_cmdParser->reply.WriteReferenceTypeID(jni_env, klass);
-
     char* signature = 0;
     char* generic = 0;
 
@@ -708,31 +729,34 @@
     if (err != JVMTI_ERROR_NONE)
         throw AgentException(err);
 
-    m_cmdParser->reply.WriteString(signature);
-
-    if (generic != 0)
-        m_cmdParser->reply.WriteString(generic);
-    else
-        m_cmdParser->reply.WriteString("");
-
     jint status;
     JVMTI_TRACE(err, jvmti->GetClassStatus(klass, &status));
     if (err != JVMTI_ERROR_NONE)
         throw AgentException(err);
 
     // According to JVMTI spec ClassStatus flag for arrays and primitive classes must be
zero
-    if (status == JVMTI_CLASS_STATUS_ARRAY) {
+    if (status == JVMTI_CLASS_STATUS_ARRAY || status == JVMTI_CLASS_STATUS_PRIMITIVE) {
         status = 0;
-    } else {
-        if ( status == JVMTI_CLASS_STATUS_PRIMITIVE ) {
-            status = 0;
-        }
+    } else if ( (status & JVMTI_CLASS_STATUS_PREPARED) == 0 ) {
+        // Given class is not prepared - don't return such class
+        return 1;
     }
 
+    m_cmdParser->reply.WriteByte(refTypeTag);
+    m_cmdParser->reply.WriteReferenceTypeID(jni_env, klass);
+    m_cmdParser->reply.WriteString(signature);
+
+    if (generic != 0)
+        m_cmdParser->reply.WriteString(generic);
+    else
+        m_cmdParser->reply.WriteString("");
+
     m_cmdParser->reply.WriteInt(status);
     JDWP_TRACE_DATA("AllClassesWithGeneric: typeTag=" << refTypeTag << ", refTypeID="
          << klass << ", signature=" << JDWP_CHECK_NULL(signature) <<
", generic=" 
          << JDWP_CHECK_NULL(generic) << ", status=" << status);
+
+    return 0;
 }
 
 //-----------------------------------------------------------------------------

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.h?view=diff&rev=558746&r1=558745&r2=558746
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.h
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/commands/VirtualMachine.h
Mon Jul 23 07:38:51 2007
@@ -95,14 +95,21 @@
             virtual void Execute(JNIEnv *jni) throw(AgentException);
 
             /**
-             * Writes class-type tag, reference ID, signature and status
-             * to the reply packet.
+             * If the passed class (klass parameter) has status
+             * JVMTI_CLASS_STATUS_PREPARED then writes class type tag,
+             * reference id, signature and status
+             * to the reply packet and reutrn 0 - success sign.
+             * Otherwise (class not prepared) doesn't write class info
+             * to the reply packet and reutrn 1 - unsuccess sign.
              *
              * @param jni   - the JNI interface pointer
              * @param jvmti - the JVMTI interface pointer
              * @param klass - the Java class
+             *
+             * @return 0 on success,
+             *         1 otherwise.
              */
-            virtual void Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti, jclass klass)
+            virtual int Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti, jclass klass)
                                             throw (AgentException);
 
         };//AllClassesHandler
@@ -391,14 +398,21 @@
         protected:
 
             /**
-             * Writes a class-type tag, reference ID, signature, generic signature and status
-             * to the reply packet.
+             * If the passed class (klass parameter) has status
+             * JVMTI_CLASS_STATUS_PREPARED then writes class type tag,
+             * reference id, signature, generic signature and status
+             * to the reply packet and reutrn 0 - success sign.
+             * Otherwise (class not prepared) doesn't write class info
+             * to the reply packet and reutrn 1 - unsuccess sign.
              *
              * @param jni   - the JNI interface pointer
              * @param jvmti - the JVMTI interface pointer
              * @param klass - Java class
+             *
+             * @return 0 on success,
+             *         1 otherwise.
              */
-            virtual void Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti, jclass klass)
+            virtual int Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti, jclass klass)
                                             throw (AgentException);
 
         };//AllClassesWithGenericHandler

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp?view=diff&rev=558746&r1=558745&r2=558746
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp
Mon Jul 23 07:38:51 2007
@@ -500,6 +500,13 @@
     }
 }
 
+size_t OutputPacketComposer::GetPosition() {
+    return m_position;
+}
+
+void OutputPacketComposer::SetPosition(size_t newPosition) {
+    m_position = newPosition;
+}
 
 void OutputPacketComposer::WriteRawData(const void* data, int length) throw (OutOfMemoryException)
{
     AllocateMemoryForData(length);

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.h?view=diff&rev=558746&r1=558745&r2=558746
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.h
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.h
Mon Jul 23 07:38:51 2007
@@ -642,6 +642,52 @@
 
     public:
 
+        /** 
+         * Gets current position in reply packet,
+         * to which next data will be written.
+         * 
+         * @return the current position in reply packet.
+         */
+        size_t GetPosition();
+
+        /** 
+         * Sets current position in reply packet
+         * to the newPosition, passed as parameter.
+         * Next data will be written in reply packet
+         * starting with the newPosition.
+         * This function is intended to rewrite some written
+         * data with new value and should be used carefully.
+         * Exemplary scenario is the following:
+         * - currentPosition = GetPosition();
+         * - currentLength = GetLength();
+         * - SetPosition(newPosition);
+         * - Rewriting data to the newPosition;
+         * - SetPosition(currentPosition);
+         * - SetLength(currentLength);
+         * 
+         * @param newPosition - new position in reply packet.
+         */
+        void SetPosition(size_t newPosition);
+
+        /** 
+         * Sets current length of jdwp packet
+         * to the new value, passed as parameter.
+         * This function can be used to restore length 
+         * of reply packet to the right value after
+         * rewriting some data in packet and,
+         * in this case, it should be used carefully.
+         * Exemplary scenario is the following:
+         * - currentPosition = GetPosition();
+         * - currentLength = GetLength();
+         * - SetPosition(newPosition);
+         * - Rewriting data to the newPosition;
+         * - SetPosition(currentPosition);
+         * - SetLength(currentLength);
+         * 
+         * @param newLength - new length of reply packet.
+         */
+        void SetLength(jint newLength) { m_packet.type.cmd.len = newLength; }
+
         /**
          * Creates an empty instance of OutputPacketComposer .
          */
@@ -938,7 +984,6 @@
         void MoveData(JNIEnv *jni, OutputPacketComposer* to);
 
     protected:
-        void SetLength(jint length) { m_packet.type.cmd.len = length; }
         void SetId(jint id) { m_packet.type.cmd.id = id; }
         void SetFlags(jbyte flags) { m_packet.type.cmd.flags = flags; }
         void SetCommandSet(jdwpCommandSet cmdSet) { m_packet.type.cmd.cmdSet = cmdSet; }



Mime
View raw message