harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcfi...@apache.org
Subject svn commit: r643447 - in /harmony/enhanced/drlvm/trunk/vm/vmcore: include/environment.h include/mem_alloc.h src/class_support/Environment.cpp src/class_support/classloader.cpp src/util/mem_alloc.cpp
Date Tue, 01 Apr 2008 15:26:05 GMT
Author: mcfirst
Date: Tue Apr  1 08:26:00 2008
New Revision: 643447

URL: http://svn.apache.org/viewvc?rev=643447&view=rev
Log:
Applying the patch from HARMONY-5047 [drlvm][jdwp] stress test org.apache.harmony.test.stress.jpda.jdwp.scenario.MEMORY003.MemoryTest003
crashes

Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/environment.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/mem_alloc.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Environment.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/mem_alloc.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/environment.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/environment.h?rev=643447&r1=643446&r2=643447&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/environment.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/environment.h Tue Apr  1 08:26:00 2008
@@ -37,6 +37,20 @@
 typedef struct DynamicCode DynamicCode;
 typedef struct Assertion_Registry Assertion_Registry;
 
+#ifdef USE_COMPRESSED_VTABLE_POINTERS
+
+typedef VirtualMemoryPool VTablePool;
+// used for compressed VTable pointers
+#define DEFAULT_VTABLE_POOL_SIZE                    1*GBYTE
+
+#else //USE_COMPRESSED_VTABLE_POINTERS
+
+typedef PoolManager VTablePool;
+// used for uncompressed VTable pointers
+#define DEFAULT_VTABLE_POOL_SIZE                    256*KBYTE
+
+#endif //USE_COMPRESSED_VTABLE_POINTERS
+
 struct Global_Env {
   public:
      // Global VM states.
@@ -54,7 +68,7 @@
     DynamicCode*              dcList;
     Assertion_Registry*       assert_reg;
     PoolManager*              GlobalCodeMemoryManager;
-    PoolManager*              VTableMemoryManager;
+    VTablePool*               VTableMemoryManager;
 
     hythread_library_t        hythread_lib;
     String_Pool               string_pool;  // string table

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/mem_alloc.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/mem_alloc.h?rev=643447&r1=643446&r2=643447&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/mem_alloc.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/mem_alloc.h Tue Apr  1 08:26:00 2008
@@ -31,10 +31,6 @@
 
 // pool is used for common stub code
 #define DEFAULT_JIT_CODE_POOL_SIZE                  256*KBYTE
-// used for compressed VTable pointers
-#define DEFAULT_VTABLE_POOL_SIZE_NO_RESIZE          8*MBYTE
-// used for uncompressed VTable pointers
-#define DEFAULT_VTABLE_POOL_SIZE                    256*KBYTE
 // used for compiled code of a user class loader
 #define DEFAULT_CLASSLOADER_JIT_CODE_POOL_SIZE      256*KBYTE
 // used for compiled code of the bootstrap class loader
@@ -60,36 +56,58 @@
 // if PoolDescriptors is filled less than (MEMORY_UTILIZATION_LIMIT)% of its size then it
is considered to be passive,
 // otherwise it is active (allows further memory allocations from it)
 
-class PoolManager {
+class BasePoolManager {
 public:
-    PoolManager(size_t initial_size, size_t page_size, bool use_large_pages, bool is_code,
bool is_resize_allowed);
-    virtual ~PoolManager();
+    BasePoolManager(size_t initial_size, bool use_large_pages, bool is_code);
+    virtual ~BasePoolManager();
     
-    // alloc is synchronized inside the class
-    void* alloc(size_t size, size_t alignment, Code_Allocation_Action action);
-    inline Byte* get_pool_base();
-
 protected:
-    PoolDescriptor*   _active_pool;
-    PoolDescriptor*   _passive_pool;
     size_t            _page_size;
     bool              _use_large_pages;
     size_t            _default_pool_size;
     bool              _is_code;
-    bool              _is_resize_allowed;
 
     apr_pool_t* aux_pool;
     apr_thread_mutex_t* aux_mutex;
 
-    Byte   *vtable_pool_start; // for compressed vtable pointers support only!
-
 protected:
-    inline PoolDescriptor* allocate_pool_storage(size_t size); // allocate memory for new
PoolDescriptor
-    inline size_t round_up_to_page_size_multiple(size_t size);
     inline void _lock();
     inline void _unlock();
+    inline size_t round_up_to_page_size_multiple(size_t size);
 };
 
+class PoolManager : public BasePoolManager {
+public:
+    PoolManager(size_t initial_size, bool use_large_pages, bool is_code = false);
+    virtual ~PoolManager();
 
-#endif //_MEM_ALLOC_H_
+    // alloc is synchronized inside the class
+    void* alloc(size_t size, size_t alignment, Code_Allocation_Action action);
 
+protected:
+    PoolDescriptor*   _active_pool;
+    PoolDescriptor*   _passive_pool;
+
+protected:
+    inline PoolDescriptor* allocate_pool_storage(size_t size); // allocate memory for new
PoolDescriptor
+};
+
+
+class VirtualMemoryPool : public BasePoolManager {
+public:
+    VirtualMemoryPool(size_t initial_size, bool use_large_pages, bool is_code = false);
+    virtual ~VirtualMemoryPool();
+
+    // alloc is synchronized inside the class
+    void* alloc(size_t size, size_t alignment, Code_Allocation_Action action);
+    Byte* get_base();
+
+protected:
+    Byte* _base;
+    size_t _reserved;
+    size_t _committed;
+    size_t _allocated;
+    port_vmem_t* _vmem;
+};
+
+#endif //_MEM_ALLOC_H_

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Environment.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Environment.cpp?rev=643447&r1=643446&r2=643447&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Environment.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Environment.cpp Tue Apr  1 08:26:00
2008
@@ -327,15 +327,12 @@
 
     pool_size = parse_size_prop("vm.code_pool_size.stubs", DEFAULT_JIT_CODE_POOL_SIZE);
     assert(pool_size);
-    GlobalCodeMemoryManager = new PoolManager(pool_size, system_page_size, use_large_pages,

-        true/*is_code*/, true/*is_resize_allowed*/);
+    GlobalCodeMemoryManager = new PoolManager(pool_size, use_large_pages,
+        true/*is_code*/);
 
-    bool compress_vtables = vm_vtable_pointers_are_compressed();
-    pool_size = parse_size_prop("vm.vtable_pool_size",
-        compress_vtables?DEFAULT_VTABLE_POOL_SIZE_NO_RESIZE : DEFAULT_VTABLE_POOL_SIZE);
+    pool_size = parse_size_prop("vm.vtable_pool_size", DEFAULT_VTABLE_POOL_SIZE);
     assert(pool_size);
-    VTableMemoryManager = new PoolManager(pool_size, system_page_size, use_large_pages, 
-        false/*is_code*/, !compress_vtables/*is_resize_allowed*/);
+    VTableMemoryManager = new VTablePool(pool_size, use_large_pages);
 
     bootstrap_code_pool_size = pool_size = parse_size_prop("vm.code_pool_size.bootstrap_loader",
         DEFAULT_BOOTSTRAP_JIT_CODE_POOL_SIZE);
@@ -345,3 +342,16 @@
     assert(pool_size);
 }
 
+POINTER_SIZE_INT vm_get_vtable_base()
+{
+    assert (VM_Global_State::loader_env->VTableMemoryManager);
+
+#ifdef USE_COMPRESSED_VTABLE_POINTERS
+    assert (VM_Global_State::loader_env->VTableMemoryManager->get_base());
+    // Subtract a small number (like 1) from the real base so that
+    // no valid vtable offsets will ever be 0.
+    return (POINTER_SIZE_INT) (VM_Global_State::loader_env->VTableMemoryManager->get_base()
- 8);
+#else
+    return 0;
+#endif
+} //vm_get_vtable_base

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp?rev=643447&r1=643446&r2=643447&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp Tue Apr  1 08:26:00
2008
@@ -97,7 +97,7 @@
         ? env->bootstrap_code_pool_size
         : env->user_code_pool_size;
 
-    CodeMemoryManager = new PoolManager(code_pool_size, env->system_page_size, env->use_large_pages,
true/*is_code*/, true/*is_resize_allowed*/);
+    CodeMemoryManager = new PoolManager(code_pool_size, env->use_large_pages, true/*is_code*/);
     if(!CodeMemoryManager) return false;
 
     return true;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/mem_alloc.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/mem_alloc.cpp?rev=643447&r1=643446&r2=643447&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/mem_alloc.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/mem_alloc.cpp Tue Apr  1 08:26:00 2008
@@ -18,10 +18,10 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/** 
+/**
  * @author Intel, Aleksey Ignatenko, Alexei Fedotov
  * @version $Revision: 1.1.2.1.4.3 $
- */  
+ */
 
 
 #define LOG_DOMAIN "vm.core"
@@ -50,104 +50,119 @@
 //////////////////////MemoryManager ////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
 
-Byte* PoolManager::get_pool_base() 
+BasePoolManager::BasePoolManager(size_t initial_size,
+                                 bool use_large_pages,
+                                 bool is_code) :
+        _use_large_pages(use_large_pages),
+        _default_pool_size(initial_size),
+        _is_code(is_code)
 {
-    return vtable_pool_start; 
+    size_t* ps = port_vmem_page_sizes();
+
+    _page_size = ps[0];
+
+    if (_use_large_pages && ps[1] != 0)
+        _page_size = ps[1];
+
+    VERIFY(APR_SUCCESS == apr_pool_create(&aux_pool, 0), \
+        "Cannot initialize a memory pool");
+    VERIFY(APR_SUCCESS == apr_thread_mutex_create(&aux_mutex, APR_THREAD_MUTEX_NESTED,
aux_pool), \
+        "Cannot initialize pool reallocation mutex");
+
+#ifdef VM_STATS
+    VM_Statistics::get_vm_stats().number_memorymanager_created++;
+#endif
 }
 
-size_t PoolManager::round_up_to_page_size_multiple(size_t size)
+BasePoolManager::~BasePoolManager()
 {
-    return ((size + _page_size - 1) / _page_size) * _page_size;
+    VERIFY(APR_SUCCESS == apr_thread_mutex_destroy(aux_mutex), \
+        "Cannot destroy the mutex");
+    apr_pool_destroy(aux_pool);
 }
 
-void PoolManager::_lock()
+void BasePoolManager::_lock()
 {
     VERIFY(APR_SUCCESS == apr_thread_mutex_lock(aux_mutex), \
         "Cannot lock the pool's mutex");
 }
- 
-void PoolManager::_unlock()
+
+void BasePoolManager::_unlock()
 {
     VERIFY(APR_SUCCESS == apr_thread_mutex_unlock(aux_mutex), \
         "Cannot unlock the pool's mutex");
 }
 
-PoolManager::PoolManager(size_t initial_size, size_t page_size, bool use_large_pages, bool
is_code, bool is_resize_allowed) : 
-_page_size(page_size), _use_large_pages(use_large_pages), _default_pool_size(initial_size),
_is_code(is_code), _is_resize_allowed(is_resize_allowed)
- {
-    VERIFY(APR_SUCCESS == apr_pool_create(&aux_pool, 0), \
-        "Cannot initialize a memory pool");
-    VERIFY(APR_SUCCESS == apr_thread_mutex_create(&aux_mutex, APR_THREAD_MUTEX_NESTED,
aux_pool), \
-        "Cannot initialize pool reallocation mutex");
- 
+size_t BasePoolManager::round_up_to_page_size_multiple(size_t size)
+{
+    return ((size + _page_size - 1) / _page_size) * _page_size;
+}
+
+PoolManager::PoolManager(size_t initial_size,
+                         bool use_large_pages,
+                         bool is_code) :
+        BasePoolManager(initial_size, use_large_pages, is_code)
+{
     _active_pool = allocate_pool_storage(_default_pool_size);
     _passive_pool = NULL;
-    vtable_pool_start = _active_pool->_begin;
- 
-#ifdef VM_STATS
-    VM_Statistics::get_vm_stats().number_memorymanager_created++;
-#endif
 }
 
 PoolManager::~PoolManager()
 {
     PoolDescriptor* pDesc = NULL;
-    
+
     while (_passive_pool)
     {
         pDesc = _passive_pool;
         port_vmem_release(pDesc->_descriptor);
         _passive_pool = _passive_pool->_next;
     }
-    
+
     while (_active_pool)
     {
         pDesc = _active_pool;
         port_vmem_release(pDesc->_descriptor);
         _active_pool = _active_pool->_next;
     }
-
-    VERIFY(APR_SUCCESS == apr_thread_mutex_destroy(aux_mutex), \
-        "Cannot destroy the mutex");
-    apr_pool_destroy(aux_pool);
 }
 
 PoolDescriptor* PoolManager::allocate_pool_storage(size_t size)
 {
     PoolDescriptor* pDesc = (PoolDescriptor*) apr_palloc(aux_pool, sizeof(PoolDescriptor));
     memset(pDesc, 0, sizeof(PoolDescriptor));
- 
+
     void *pool_storage = NULL;
     size = round_up_to_page_size_multiple(size);
     pDesc->_size = size;
      unsigned int mem_protection = PORT_VMEM_MODE_READ | PORT_VMEM_MODE_WRITE;
     if (_is_code) {
          mem_protection |= PORT_VMEM_MODE_EXECUTE;
-     }
-    size_t ps = (!_is_code && _use_large_pages) ? 
+    }
+
+    size_t ps = (!_is_code && _use_large_pages) ?
          PORT_VMEM_PAGESIZE_LARGE : PORT_VMEM_PAGESIZE_DEFAULT;
-     
-    apr_status_t status = port_vmem_reserve(&pDesc->_descriptor, &pool_storage,

+
+    apr_status_t status = port_vmem_reserve(&pDesc->_descriptor, &pool_storage,
          size, mem_protection, ps, aux_pool);
     if (status != APR_SUCCESS)  {
          LDIE(27, "Cannot allocate pool storage: {0} bytes of virtual memory for code or
data.\n"
              "Error code = {1}" << (void *)size << status);
      }
- 
+
     status = port_vmem_commit(&pool_storage, size, pDesc->_descriptor);
     if (status != APR_SUCCESS || pool_storage == NULL)  {
          LDIE(27, "Cannot allocate pool storage: {0} bytes of virtual memory for code or
data.\n"
              "Error code = {1}" << (void *)size << status);
      }
- 
+
 #ifdef VM_STATS
     VM_Statistics::get_vm_stats().number_memoryblock_allocations++;
     VM_Statistics::get_vm_stats().total_memory_allocated += size;
 #endif
- 
+
     pDesc->_begin  = (Byte*)pool_storage;
     pDesc->_end = ((Byte*)(pool_storage) + size);
- 
+
     return pDesc;
 }
 
@@ -168,42 +183,36 @@
 
     assert(_active_pool);
     Byte *pool_start = _active_pool->_begin;
-     pool_start = (Byte *) ((POINTER_SIZE_INT)(pool_start + mask) & ~(POINTER_SIZE_INT)mask);
+    pool_start = (Byte *) ((POINTER_SIZE_INT)(pool_start + mask) & ~(POINTER_SIZE_INT)mask);
     Byte *pool_end = _active_pool->_end;
- 
-     size_t mem_left_in_pool = (pool_end - pool_start);
+
+    size_t mem_left_in_pool = (pool_end - pool_start);
     while (size > mem_left_in_pool) {
-        if (!_is_resize_allowed) {
-            LDIE(28, "Error: VTable pool overflow, resize is not allowed. Please, extand
VTable pool size.\n");
-            // TODO: add functionality to commit additional part of memory if reserved enough:
-            // need for (is_resize_allowed = false) case - commit every time by little pieces

-         }
- 
         // memory utilization logic
-        // check that required size less than MEMORY_UTILIZATION_LIMIT % of active memory
block size - all active memory 
+        // check that required size less than MEMORY_UTILIZATION_LIMIT % of active memory
block size - all active memory
         // blocks have size more than MEMORY_UTILIZATION_LIMIT % of active memory block size
         PoolDescriptor* pDesc = _active_pool->_next;
         if (pDesc)
         {
-            if ((size + mask)*MEMORY_UTILIZATION_LIMIT < (POINTER_SIZE_INT)(pDesc->_size))

+            if ((size + mask)*MEMORY_UTILIZATION_LIMIT < (POINTER_SIZE_INT)(pDesc->_size))
             {
                 _active_pool->_next = _passive_pool;
                 _passive_pool = _active_pool;
                 _active_pool = pDesc;
- 
+
                 pool_start = _active_pool->_begin;
                 pool_start = (Byte *) ((POINTER_SIZE_INT)(pool_start + mask) & ~(POINTER_SIZE_INT)mask);
- 
+
                 break;
             }
         }
- 
+
         assert(_default_pool_size);
         size_t new_pool_size = ((size > _default_pool_size)? size : _default_pool_size);
         new_pool_size += mask;
         PoolDescriptor* p_pool = allocate_pool_storage(new_pool_size);
         assert (p_pool);
-        
+
         // memory utilization logic
         // left size of pool more than MEMORY_UTILIZATION_LIMIT % of the pool's size
         if ((mem_left_in_pool * MEMORY_UTILIZATION_LIMIT) > _active_pool->_size) //put
pool in _active_pool list
@@ -218,30 +227,110 @@
             _passive_pool = _active_pool;
             _active_pool = p_pool;
         }
-        
+
         pool_start = p_pool->_begin;
         pool_start = (Byte *) ((POINTER_SIZE_INT)(pool_start + mask) & ~(POINTER_SIZE_INT)mask);
         break;
      }
     void *p = pool_start;
     _active_pool->_begin += size;
- 
+
     _unlock();
- 
+
  #ifdef VM_STATS
     UNSAFE_REGION_START
     VM_Statistics::get_vm_stats().total_memory_used += size;
     UNSAFE_REGION_END
 #endif
- 
+
     return p;
  }
- 
-POINTER_SIZE_INT vm_get_vtable_base()
+
+VirtualMemoryPool::VirtualMemoryPool(size_t initial_size,
+                                     bool use_large_pages,
+                                     bool is_code) :
+        BasePoolManager(initial_size, use_large_pages, is_code),
+        _base(NULL),
+        _reserved(0),
+        _committed(0),
+        _allocated(0)
+{
+    void *pool_storage = NULL;
+    _reserved = round_up_to_page_size_multiple(initial_size);
+
+    unsigned int mem_protection = PORT_VMEM_MODE_READ | PORT_VMEM_MODE_WRITE;
+    if (_is_code)
+         mem_protection |= PORT_VMEM_MODE_EXECUTE;
+
+    size_t ps = (!_is_code && _use_large_pages) ?
+         PORT_VMEM_PAGESIZE_LARGE : PORT_VMEM_PAGESIZE_DEFAULT;
+
+    apr_status_t status = port_vmem_reserve(&_vmem, (void**) &_base, _reserved,
+            mem_protection, ps, aux_pool);
+    if (status != APR_SUCCESS)  {
+         LDIE(27, "Cannot allocate pool storage: {0} bytes of virtual memory for code or
data.\n"
+             "Error code = {1}" << (void *)_reserved << status);
+    }
+
+	assert(_vmem);
+}
+
+VirtualMemoryPool::~VirtualMemoryPool()
+{
+    port_vmem_release(_vmem);
+}
+
+void* VirtualMemoryPool::alloc(size_t size, size_t alignment, Code_Allocation_Action action)
+{
+    // Make sure alignment is a power of 2.
+    assert((alignment & (alignment-1)) == 0);
+    size_t mask = alignment - 1;
+
+    // align the requested size
+    size = (size + mask) & ~mask;
+
+    // CAA_Simulate functionality support
+    if (action == CAA_Simulate)
+        size = 0;
+
+    _lock();
+
+    assert(_base);
+    assert(_reserved);
+    assert(_committed <= _reserved);
+    assert(_allocated <= _committed);
+
+    size_t new_allocated = _allocated + size;
+
+    if (new_allocated > _committed) {
+        apr_status_t status = APR_ENOMEM;
+
+        size_t new_committed = round_up_to_page_size_multiple(new_allocated);
+
+        if (new_committed <= _reserved) {
+            Byte* commit_start = _base + _committed;
+            status = port_vmem_commit((void**) &commit_start, new_committed - _committed,
_vmem);
+        }
+
+        if (status != APR_SUCCESS)  {
+             LDIE(27, "Cannot allocate pool storage: {0} bytes of virtual memory for code
or data.\n"
+                 "Error code = {1}" << (void *)size << status);
+        }
+
+        _committed = new_committed;
+
+    }
+
+    Byte* result = _base + _allocated;
+    _allocated = new_allocated;
+
+    _unlock();
+
+    return result;
+ }
+
+Byte* VirtualMemoryPool::get_base()
 {
-    // Subtract a small number (like 1) from the real base so that
-    // no valid vtable offsets will ever be 0.
-    assert (VM_Global_State::loader_env->VTableMemoryManager);
-    assert (VM_Global_State::loader_env->VTableMemoryManager->get_pool_base());
-    return (POINTER_SIZE_INT) (VM_Global_State::loader_env->VTableMemoryManager->get_pool_base()
- 8);
-} //vm_get_vtable_base
+    assert(_base);
+    return _base;
+}



Mime
View raw message