harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r603228 - /harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_class.cpp
Date Tue, 11 Dec 2007 12:49:14 GMT
Author: gshimansky
Date: Tue Dec 11 04:49:13 2007
New Revision: 603228

URL: http://svn.apache.org/viewvc?rev=603228&view=rev
Log:
Fixed bug HARMONY-5287
[drlvm][jvmti] Lack of synchronization in GetLoadedClasses and GetClassLoaderClasses may cause
VM to crash

Patch adds synchronization to lock all classloaders until the table of
reported classes is filled up.


Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_class.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_class.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_class.cpp?rev=603228&r1=603227&r2=603228&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_class.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_class.cpp Tue Dec 11 04:49:13 2007
@@ -101,6 +101,7 @@
     unsigned int cl_count;
     jvmtiError errorCode;
     ClassLoader* classloader;
+    ClassLoader *bootstrap;
 
     /*
      * Check given env & current phase.
@@ -114,11 +115,13 @@
         return JVMTI_ERROR_NULL_POINTER;
     }
 
+    ClassLoader::LockLoadersTable();
     /**
      * Get the number of loaded classes by bootstrap loader
      */
-    ClassTable* tbl =
-        VM_Global_State::loader_env->bootstrap_class_loader->GetLoadedClasses();
+    bootstrap = VM_Global_State::loader_env->bootstrap_class_loader;
+    bootstrap->Lock();
+    ClassTable* tbl = bootstrap->GetLoadedClasses();
     count = tbl->GetItemCount();
 
     /**
@@ -128,6 +131,7 @@
     for( index = 0; index < cl_count; index++ )
     {
         classloader = (ClassLoader::GetClassLoaderTable())[index];
+        classloader->Lock();
         tbl = classloader->GetLoadedClasses();
         ClassTable::iterator it;
         for(it = tbl->begin(); it != tbl->end(); it++)
@@ -146,6 +150,14 @@
      */
     if (!count)
     {
+        for(index = 0; index < cl_count; index++)
+        {
+            classloader = (ClassLoader::GetClassLoaderTable())[index];
+            classloader->Unlock();
+        }
+        bootstrap->Unlock();
+        ClassLoader::UnlockLoadersTable();
+
         *classes = NULL;
         *classes_num = 0;
         return JVMTI_ERROR_NONE;
@@ -156,6 +168,13 @@
      */
     errorCode = _allocate( (sizeof(jclass) * count), (unsigned char**) classes );
     if (errorCode != JVMTI_ERROR_NONE) {
+        for(index = 0; index < cl_count; index++)
+        {
+            classloader = (ClassLoader::GetClassLoaderTable())[index];
+            classloader->Unlock();
+        }
+        bootstrap->Unlock();
+        ClassLoader::UnlockLoadersTable();
         return errorCode;
     }
 
@@ -187,6 +206,7 @@
             (*classes)[number++] = (jclass)new_handle;
         }
 
+        classloader->Unlock();
         /**
          * Get next class loader
          */
@@ -198,6 +218,7 @@
     } while( true );
     assert( number == count );
 
+    ClassLoader::UnlockLoadersTable();
     /**
      * Set class number
      */
@@ -246,11 +267,13 @@
         classloader = ClassLoader::FindByObject((((ObjectHandle)initiating_loader)->object));
     }
 
+    classloader->Lock();
     /**
      * Get the number of loaded classes
      */
     tbl = classloader->GetInitiatedClasses();
     if( !(count = tbl->GetItemCount()) ) {
+        classloader->Unlock();
         // no loaded classes
         *classes_ptr = NULL;
         *class_count_ptr = 0;
@@ -262,6 +285,7 @@
      */
     errorCode = _allocate( (sizeof(jclass) * count), (unsigned char**)classes_ptr );
     if (errorCode != JVMTI_ERROR_NONE) {
+        classloader->Unlock();
         return errorCode;
     }
 
@@ -281,6 +305,7 @@
     }
     assert( index == count );
 
+    classloader->Unlock();
     /**
      * Set class number
      */



Mime
View raw message