/hg/icedtea6: Profiled memory usage and implemented proper clean...

dbhole at icedtea.classpath.org dbhole at icedtea.classpath.org
Tue Apr 6 11:17:11 PDT 2010


changeset 601db47e5a01 in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=601db47e5a01
author: Deepak Bhole <dbhole at redhat.com>
date: Tue Apr 06 14:17:02 2010 -0400

	Profiled memory usage and implemented proper cleanup for C++ side.


diffstat:

7 files changed, 212 insertions(+), 151 deletions(-)
ChangeLog                                         |   42 ++++++
plugin/icedteanp/IcedTeaJavaRequestProcessor.cc   |   97 +++++++--------
plugin/icedteanp/IcedTeaPluginRequestProcessor.cc |  135 +++++++++------------
plugin/icedteanp/IcedTeaPluginRequestProcessor.h  |   16 +-
plugin/icedteanp/IcedTeaPluginUtils.cc            |   59 ++++++---
plugin/icedteanp/IcedTeaPluginUtils.h             |    7 -
plugin/icedteanp/IcedTeaScriptablePluginObject.cc |    7 -

diffs (truncated from 865 to 500 lines):

diff -r 8089180753c9 -r 601db47e5a01 ChangeLog
--- a/ChangeLog	Mon Apr 05 00:21:56 2010 +0200
+++ b/ChangeLog	Tue Apr 06 14:17:02 2010 -0400
@@ -1,3 +1,45 @@ 2010-04-04  Nobuhiro Iwamatsu <iwamatsu@
+2010-04-06  Deepak Bhole <dbhole at redhat.com>
+
+	* plugin/icedteanp/IcedTeaJavaRequestProcessor.cc
+	(newMessageOnBus): Update to used string pointer vector (form strSplit)
+	instead of a string vector. Correctly free memory.
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc: Initialize
+	message_queue to be a string pointer vector vector instead of a string
+	vector vector.
+	(newMessageOnBus): Update to used string pointer vector (form strSplit) 
+	instead of a string vector. Correctly free memory.
+	(sendWindow): Deal with string pointers instead of strings for message
+	parts.
+	(eval): Same.
+	(call): Same.
+	(sendString): Same.
+	(setMember): Same.
+	(sendMember): Same.
+	(finalize): Same.
+	(queue_processor): Same. Also, free message part memory after processing.
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.h: Change method
+	signatures to deal with string pointer vectors instead of string vectors.
+	* plugin/icedteanp/IcedTeaPluginUtils.cc
+	(stringToJSID): Added another signature that receives a string pointer.
+	(strSplit): Return string pointer vector instead of string vector.
+	(getUTF8String): Change signature to receive string pointer vector instead
+	of string vector. Update function accordingly.
+	(getUTF16LEString): Same. 
+	(subscribe): Make subscription atomic.
+	(unSubscribe): Make unsubscription atomic, bound to same lock as
+	subscribe().
+	(post): Make list iteration and processing atomic, bound to same lock as
+	subscribe and unSubscribe.
+	* plugin/icedteanp/IcedTeaPluginUtils.h: Added new signature for
+	stringToJSID and updated signatures for strSplit, getUTF8String and
+	getUTF16LEString.
+	* plugin/icedteanp/IcedTeaScriptablePluginObject.cc
+	(IcedTeaScriptableJavaPackageObject::deAllocate): Implemented method.
+	(IcedTeaScriptableJavaPackageObject::invalidate): Same.
+	(IcedTeaScriptableJavaObject::deAllocate): Same.
+	(IcedTeaScriptableJavaObject::invalidate): Same.
+
+
 2010-04-04  Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
 
 	* acinclude.m4 (IT_SET_ARCH_SETTINGS): Fix Hitachi SH settings.
diff -r 8089180753c9 -r 601db47e5a01 plugin/icedteanp/IcedTeaJavaRequestProcessor.cc
--- a/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Mon Apr 05 00:21:56 2010 +0200
+++ b/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Tue Apr 06 14:17:02 2010 -0400
@@ -60,21 +60,21 @@ JavaRequestProcessor::newMessageOnBus(co
 {
 
 	// Anything we are waiting for _MUST_ have and instance id and reference #
-	std::vector<std::string>* message_parts = IcedTeaPluginUtilities::strSplit(message, " ");
+	std::vector<std::string*>* message_parts = IcedTeaPluginUtilities::strSplit(message, " ");
 
-	IcedTeaPluginUtilities::printStringVector("JavaRequest::newMessageOnBus:", message_parts);
+	IcedTeaPluginUtilities::printStringPtrVector("JavaRequest::newMessageOnBus:", message_parts);
 
-	if (message_parts->at(0) == "context" && message_parts->at(2) == "reference")
-		if (atoi(message_parts->at(1).c_str()) == this->instance && atoi(message_parts->at(3).c_str()) == this->reference)
+	if (*(message_parts->at(0)) == "context" && *(message_parts->at(2)) == "reference")
+		if (atoi(message_parts->at(1)->c_str()) == this->instance && atoi(message_parts->at(3)->c_str()) == this->reference)
 		{
 			// Gather the results
 
 			// Let's get errors out of the way first
-			if (message_parts->at(4).find("Error") == 0)
+			if (!message_parts->at(4)->find("Error"))
 			{
 				for (int i=5; i < message_parts->size(); i++)
 				{
-					result->error_msg->append(message_parts->at(i));
+					result->error_msg->append(*(message_parts->at(i)));
 					result->error_msg->append(" ");
 				}
 
@@ -83,78 +83,78 @@ JavaRequestProcessor::newMessageOnBus(co
 				result->error_occurred = true;
 				result_ready = true;
 			}
-			else if (message_parts->at(4) == "GetStringUTFChars" ||
-			         message_parts->at(4) == "GetToStringValue")
+			else if (!message_parts->at(4)->find("GetStringUTFChars") ||
+			         !message_parts->at(4)->find("GetToStringValue"))
 			{
 				// first item is length, and it is radix 10
-				int length = strtol(message_parts->at(5).c_str(), NULL, 10);
+				int length = strtol(message_parts->at(5)->c_str(), NULL, 10);
 
 				IcedTeaPluginUtilities::getUTF8String(length, 6 /* start at */, message_parts, result->return_string);
 				result_ready = true;
 			}
-			else if (message_parts->at(4) == "GetStringChars") // GetStringChars (UTF-16LE/UCS-2)
+			else if (!message_parts->at(4)->find("GetStringChars")) // GetStringChars (UTF-16LE/UCS-2)
 			{
 				// first item is length, and it is radix 10
-				int length = strtol(message_parts->at(5).c_str(), NULL, 10);
+				int length = strtol(message_parts->at(5)->c_str(), NULL, 10);
 
 				IcedTeaPluginUtilities::getUTF16LEString(length, 6 /* start at */, message_parts, result->return_wstring);
 				result_ready = true;
-			} else if ((message_parts->at(4) == "FindClass") ||
-			        (message_parts->at(4) == "GetClassName") ||
-			        (message_parts->at(4) == "GetClassID") ||
-			        (message_parts->at(4) == "GetMethodID") ||
-			        (message_parts->at(4) == "GetStaticMethodID") ||
-			        (message_parts->at(4) == "GetObjectClass") ||
-                    (message_parts->at(4) == "NewObject") ||
-                    (message_parts->at(4) == "NewStringUTF") ||
-                    (message_parts->at(4) == "HasPackage") ||
-                    (message_parts->at(4) == "HasMethod") ||
-                    (message_parts->at(4) == "HasField") ||
-                    (message_parts->at(4) == "GetStaticFieldID") ||
-                    (message_parts->at(4) == "GetFieldID") ||
-                    (message_parts->at(4) == "GetJavaObject") ||
-                    (message_parts->at(4) == "IsInstanceOf") ||
-                    (message_parts->at(4) == "NewArray"))
+			} else if (!message_parts->at(4)->find("FindClass") ||
+			           !message_parts->at(4)->find("GetClassName") ||
+			           !message_parts->at(4)->find("GetClassID") ||
+			           !message_parts->at(4)->find("GetMethodID") ||
+			           !message_parts->at(4)->find("GetStaticMethodID") ||
+			           !message_parts->at(4)->find("GetObjectClass") ||
+			           !message_parts->at(4)->find("NewObject") ||
+			           !message_parts->at(4)->find("NewStringUTF") ||
+			           !message_parts->at(4)->find("HasPackage") ||
+			           !message_parts->at(4)->find("HasMethod") ||
+			           !message_parts->at(4)->find("HasField") ||
+			           !message_parts->at(4)->find("GetStaticFieldID") ||
+			           !message_parts->at(4)->find("GetFieldID") ||
+			           !message_parts->at(4)->find("GetJavaObject") ||
+			           !message_parts->at(4)->find("IsInstanceOf") ||
+			           !message_parts->at(4)->find("NewArray"))
 			{
-				result->return_identifier = atoi(message_parts->at(5).c_str());
-				result->return_string->append(message_parts->at(5)); // store it as a string as well, for easy access
+				result->return_identifier = atoi(message_parts->at(5)->c_str());
+				result->return_string->append(*(message_parts->at(5))); // store it as a string as well, for easy access
 				result_ready = true;
-			}  else if ((message_parts->at(4) == "DeleteLocalRef") ||
-		                (message_parts->at(4) == "NewGlobalRef"))
+			}  else if (!message_parts->at(4)->find("DeleteLocalRef") ||
+			            !message_parts->at(4)->find("NewGlobalRef"))
 			{
 			    result_ready = true; // nothing else to do
-			} else if ((message_parts->at(4) == "CallMethod") ||
-					   (message_parts->at(4) == "CallStaticMethod") ||
-					   (message_parts->at(4) == "GetField") ||
-					   (message_parts->at(4) == "GetStaticField") ||
-					   (message_parts->at(4) == "GetValue") ||
-	                   (message_parts->at(4) == "GetObjectArrayElement"))
+			} else if (!message_parts->at(4)->find("CallMethod") ||
+			           !message_parts->at(4)->find("CallStaticMethod") ||
+			           !message_parts->at(4)->find("GetField") ||
+			           !message_parts->at(4)->find("GetStaticField") ||
+			           !message_parts->at(4)->find("GetValue") ||
+			           !message_parts->at(4)->find("GetObjectArrayElement"))
 			{
 
-			    if (message_parts->at(5) == "literalreturn")
+			    if (!message_parts->at(5)->find("literalreturn"))
                 {
 			        // literal returns don't have a corresponding jni id
 			        result->return_identifier = 0;
-			        result->return_string->append(message_parts->at(5));
+			        result->return_string->append(*(message_parts->at(5)));
 			        result->return_string->append(" ");
-			        result->return_string->append(message_parts->at(6));
+			        result->return_string->append(*(message_parts->at(6)));
 
                 } else
 			    {
                     // Else it is a complex object
 
-			        result->return_identifier = atoi(message_parts->at(5).c_str());
-			        result->return_string->append(message_parts->at(5)); // store it as a string as well, for easy access
+			        result->return_identifier = atoi(message_parts->at(5)->c_str());
+			        result->return_string->append(*(message_parts->at(5))); // store it as a string as well, for easy access
 			    }
 
 				result_ready = true;
-			} else if ((message_parts->at(4) == "GetArrayLength"))
+			} else if (!message_parts->at(4)->find("GetArrayLength"))
             {
 			    result->return_identifier = 0; // length is not an "identifier"
-			    result->return_string->append(message_parts->at(5));
+			    result->return_string->append(*(message_parts->at(5)));
 			    result_ready = true;
-            } else if ((message_parts->at(4) == "SetField") ||
-                       (message_parts->at(4) == "SetObjectArrayElement"))
+            } else if (!message_parts->at(4)->find("SetField") ||
+                       !message_parts->at(4)->find("SetObjectArrayElement"))
             {
 
                 // nothing to do
@@ -163,13 +163,12 @@ JavaRequestProcessor::newMessageOnBus(co
                 result_ready = true;
             }
 
-			delete message_parts;
+            IcedTeaPluginUtilities::freeStringPtrVector(message_parts);
 			return true;
 		}
 
-	delete message_parts;
+    IcedTeaPluginUtilities::freeStringPtrVector(message_parts);
 	return false;
-
 }
 
 /**
diff -r 8089180753c9 -r 601db47e5a01 plugin/icedteanp/IcedTeaPluginRequestProcessor.cc
--- a/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc	Mon Apr 05 00:21:56 2010 +0200
+++ b/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc	Tue Apr 06 14:17:02 2010 -0400
@@ -50,7 +50,7 @@ exception statement from your version. *
 // Initialize static members used by the queue processing framework
 pthread_mutex_t message_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t syn_write_mutex = PTHREAD_MUTEX_INITIALIZER;
-std::vector< std::vector<std::string>* >* message_queue = new std::vector< std::vector<std::string>* >();
+std::vector< std::vector<std::string*>* >* message_queue = new std::vector< std::vector<std::string*>* >();
 
 /**
  * PluginRequestProcessor constructor.
@@ -91,36 +91,36 @@ PluginRequestProcessor::newMessageOnBus(
 {
     PLUGIN_DEBUG_1ARG("PluginRequestProcessor processing %s\n", message);
 
-    std::string type;
-    std::string command;
+    std::string* type;
+    std::string* command;
     int counter = 0;
 
-    std::vector<std::string>* message_parts = IcedTeaPluginUtilities::strSplit(message, " ");
+    std::vector<std::string*>* message_parts = IcedTeaPluginUtilities::strSplit(message, " ");
 
-    std::vector<std::string>::iterator the_iterator;
+    std::vector<std::string*>::iterator the_iterator;
     the_iterator = message_parts->begin();
 
-    IcedTeaPluginUtilities::printStringVector("PluginRequestProcessor::newMessageOnBus:", message_parts);
+    IcedTeaPluginUtilities::printStringPtrVector("PluginRequestProcessor::newMessageOnBus:", message_parts);
 
     type = message_parts->at(0);
     command = message_parts->at(4);
 
-    if (type == "instance")
+    if (!type->find("instance"))
     {
-        if (command == "GetWindow")
+        if (!command->find("GetWindow"))
         {
             // Window can be queried from the main thread only. And this call
             // returns immediately, so we do it in the same thread.
             this->sendWindow(message_parts);
             return true;
-        } else if (command == "GetMember" ||
-                   command == "SetMember" ||
-                   command == "ToString"  ||
-                   command == "Call"      ||
-                   command == "GetSlot"   ||
-                   command == "SetSlot"   ||
-                   command == "Eval"      ||
-                   command == "Finalize")
+        } else if (!command->find("GetMember") ||
+                   !command->find("SetMember") ||
+                   !command->find("ToString") ||
+                   !command->find("Call") ||
+                   !command->find("GetSlot") ||
+                   !command->find("SetSlot") ||
+                   !command->find("Eval") ||
+                   !command->find("Finalize"))
         {
 
             // Update queue synchronously
@@ -136,7 +136,7 @@ PluginRequestProcessor::newMessageOnBus(
 
     }
 
-    delete message_parts;
+    IcedTeaPluginUtilities::freeStringPtrVector(message_parts);
 
     // If we got here, it means we couldn't process the message. Let the caller know.
     return false;
@@ -149,10 +149,10 @@ PluginRequestProcessor::newMessageOnBus(
  */
 
 void
-PluginRequestProcessor::sendWindow(std::vector<std::string>* message_parts)
+PluginRequestProcessor::sendWindow(std::vector<std::string*>* message_parts)
 {
-    std::string type;
-    std::string command;
+    std::string* type;
+    std::string* command;
     int reference;
     std::string response = std::string();
     std::string window_ptr_str = std::string();
@@ -161,8 +161,8 @@ PluginRequestProcessor::sendWindow(std::
     int id;
 
     type = message_parts->at(0);
-    id = atoi(message_parts->at(1).c_str());
-    reference = atoi(message_parts->at(3).c_str());
+    id = atoi(message_parts->at(1)->c_str());
+    reference = atoi(message_parts->at(3)->c_str());
     command = message_parts->at(4);
 
     NPP instance;
@@ -182,8 +182,6 @@ PluginRequestProcessor::sendWindow(std::
 
     plugin_to_java_bus->post(response.c_str());
 
-    delete message_parts;
-
     // store the instance pointer for future reference
     IcedTeaPluginUtilities::storeInstanceID(variant, instance);
 }
@@ -195,7 +193,7 @@ PluginRequestProcessor::sendWindow(std::
  */
 
 void
-PluginRequestProcessor::eval(std::vector<std::string>* message_parts)
+PluginRequestProcessor::eval(std::vector<std::string*>* message_parts)
 {
     JavaRequestProcessor request_processor = JavaRequestProcessor();
     JavaResultData* java_result;
@@ -209,11 +207,11 @@ PluginRequestProcessor::eval(std::vector
     std::string return_type = std::string();
     int id;
 
-    reference = atoi(message_parts->at(3).c_str());
+    reference = atoi(message_parts->at(3)->c_str());
     window_ptr = (NPVariant*) IcedTeaPluginUtilities::stringToJSID(message_parts->at(5));
     instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(window_ptr);
 
-    java_result = request_processor.getString(message_parts->at(6));
+    java_result = request_processor.getString(*(message_parts->at(6)));
     CHECK_JAVA_RESULT(java_result);
     script.append(*(java_result->return_string));
 
@@ -250,9 +248,6 @@ PluginRequestProcessor::eval(std::vector
     response += result_variant_jniid;
 
     plugin_to_java_bus->post(response.c_str());
-
-    delete message_parts;
-
 }
 
 /**
@@ -262,10 +257,10 @@ PluginRequestProcessor::eval(std::vector
  */
 
 void
-PluginRequestProcessor::call(std::vector<std::string>* message_parts)
+PluginRequestProcessor::call(std::vector<std::string*>* message_parts)
 {
     NPP instance;
-    std::string window_ptr_str;
+    std::string* window_ptr_str;
     NPVariant* window_ptr;
     int reference;
     std::string window_function_name;
@@ -276,7 +271,7 @@ PluginRequestProcessor::call(std::vector
     JavaRequestProcessor java_request = JavaRequestProcessor();
     JavaResultData* java_result;
 
-    reference = atoi(message_parts->at(3).c_str());
+    reference = atoi(message_parts->at(3)->c_str());
 
     // window
     window_ptr_str = message_parts->at(5);
@@ -286,14 +281,14 @@ PluginRequestProcessor::call(std::vector
     instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(window_ptr);
 
     // function name
-    java_result = java_request.getString(message_parts->at(6));
+    java_result = java_request.getString(*(message_parts->at(6)));
     CHECK_JAVA_RESULT(java_result);
     window_function_name.append(*(java_result->return_string));
 
     // arguments
     for (int i=7; i < message_parts->size(); i++)
     {
-        arg_ids.push_back(message_parts->at(i));
+        arg_ids.push_back(*(message_parts->at(i)));
     }
 
     // determine arguments
@@ -366,7 +361,7 @@ PluginRequestProcessor::call(std::vector
  * @param message_parts The request message.
  */
 void
-PluginRequestProcessor::sendString(std::vector<std::string>* message_parts)
+PluginRequestProcessor::sendString(std::vector<std::string*>* message_parts)
 {
     std::string variant_ptr;
     NPVariant* variant;
@@ -375,8 +370,8 @@ PluginRequestProcessor::sendString(std::
     int reference;
     std::string response = std::string();
 
-    reference = atoi(message_parts->at(3).c_str());
-    variant_ptr = message_parts->at(5);
+    reference = atoi(message_parts->at(3)->c_str());
+    variant_ptr = *(message_parts->at(5));
 
     variant = (NPVariant*) IcedTeaPluginUtilities::stringToJSID(variant_ptr);
     AsyncCallThreadData thread_data = AsyncCallThreadData();
@@ -410,7 +405,6 @@ PluginRequestProcessor::sendString(std::
     plugin_to_java_bus->post(response.c_str());
 
     cleanup:
-    delete message_parts;
 
     pthread_mutex_lock(&tc_mutex);
     thread_count--;
@@ -424,7 +418,7 @@ PluginRequestProcessor::sendString(std::
  */
 
 void
-PluginRequestProcessor::setMember(std::vector<std::string>* message_parts)
+PluginRequestProcessor::setMember(std::vector<std::string*>* message_parts)
 {
     std::string propertyNameID;
     std::string value = std::string();
@@ -438,28 +432,28 @@ PluginRequestProcessor::setMember(std::v
     JavaRequestProcessor java_request = JavaRequestProcessor();
     JavaResultData* java_result;
 
-    IcedTeaPluginUtilities::printStringVector("PluginRequestProcessor::_setMember - ", message_parts);
+    IcedTeaPluginUtilities::printStringPtrVector("PluginRequestProcessor::_setMember - ", message_parts);
 
-    reference = atoi(message_parts->at(3).c_str());
+    reference = atoi(message_parts->at(3)->c_str());
 
-    member = (NPVariant*) (IcedTeaPluginUtilities::stringToJSID(message_parts->at(5)));
-    propertyNameID = message_parts->at(6);
+    member = (NPVariant*) (IcedTeaPluginUtilities::stringToJSID(*(message_parts->at(5))));
+    propertyNameID = *(message_parts->at(6));
 
-    if (message_parts->at(7) == "literalreturn")
+    if (*(message_parts->at(7)) == "literalreturn")
     {
-        value.append(message_parts->at(7));
+        value.append(*(message_parts->at(7)));
         value.append(" ");
-        value.append(message_parts->at(8));
+        value.append(*(message_parts->at(8)));
     } else
     {
-        value.append(message_parts->at(7));
+        value.append(*(message_parts->at(7)));
     }
 
     instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(member);
 
-    if (message_parts->at(4) == "SetSlot")
+    if (*(message_parts->at(4)) == "SetSlot")
     {
-        property_identifier = browser_functions.getintidentifier(atoi(message_parts->at(6).c_str()));
+        property_identifier = browser_functions.getintidentifier(atoi(message_parts->at(6)->c_str()));
     } else
     {
         java_result = java_request.getString(propertyNameID);
@@ -504,7 +498,6 @@ PluginRequestProcessor::setMember(std::v
     plugin_to_java_bus->post(response.c_str());
 
     cleanup:
-    delete message_parts;
 
     // property_name, type and value are deleted by _setMember
     pthread_mutex_lock(&tc_mutex);
@@ -524,7 +517,7 @@ PluginRequestProcessor::setMember(std::v
  */
 
 void
-PluginRequestProcessor::sendMember(std::vector<std::string>* message_parts)
+PluginRequestProcessor::sendMember(std::vector<std::string*>* message_parts)
 {
     // member initialization
     std::vector<std::string> args;
@@ -545,17 +538,17 @@ PluginRequestProcessor::sendMember(std::
     int reference;
 
     // debug printout of parent thread data
-    IcedTeaPluginUtilities::printStringVector("PluginRequestProcessor::getMember:", message_parts);
+    IcedTeaPluginUtilities::printStringPtrVector("PluginRequestProcessor::getMember:", message_parts);
 
-    reference = atoi(message_parts->at(3).c_str());
+    reference = atoi(message_parts->at(3)->c_str());
 
     // store info in local variables for easy access
-    instance_id = atoi(message_parts->at(1).c_str());
+    instance_id = atoi(message_parts->at(1)->c_str());



More information about the distro-pkg-dev mailing list