You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directmemory.apache.org by "Prashant Sharma (JIRA)" <ji...@apache.org> on 2012/12/14 15:38:12 UTC

[jira] [Comment Edited] (DIRECTMEMORY-118) MemoryManager crashes on allocation of more than 300Mb or memory

    [ https://issues.apache.org/jira/browse/DIRECTMEMORY-118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13532341#comment-13532341 ] 

Prashant Sharma edited comment on DIRECTMEMORY-118 at 12/14/12 2:37 PM:
------------------------------------------------------------------------

Please see the following diff that fixes the problem.

{noformat}
Index: directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java
===================================================================
--- directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java	(revision 1421100)
+++ directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java	(working copy)
@@ -136,12 +136,12 @@
     {
         List<Integer> sizes = new ArrayList<Integer>();
 
-        for ( int i = minSizeThreshold; i <= totalSize; i *= 8 )
+        for ( Long i = Integer.valueOf(minSizeThreshold).longValue(); i <= totalSize.longValue(); i *= 8 )
         {
-            sizes.add( Integer.valueOf( i ) );
+            sizes.add( i.intValue() );
         }
 
-        // If totalSize < minSizeThreshold or totalSize is not a multiple of minSizeThreshold 
+        // If totalSize < minSizeThreshold or totalSize is not a multiple of minSizeThreshold
         // we force adding an element to the map
         if ( sizes.isEmpty() || !sizes.contains( totalSize ) )
         {
{noformat}

without the above fix Integer overflows and leads to infinite loop. 
                
      was (Author: prashant_):
    Please see the following diff that fixes the problem.

{noformat}
Index: directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java
===================================================================
--- directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java	(revision 1421100)
+++ directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java	(working copy)
@@ -136,12 +136,12 @@
     {
         List<Integer> sizes = new ArrayList<Integer>();
 
-        for ( int i = minSizeThreshold; i <= totalSize; i *= 8 )
+        for ( Long i = Integer.valueOf(minSizeThreshold).longValue(); i <= totalSize.longValue(); i *= 8 )
         {
-            sizes.add( Integer.valueOf( i ) );
+            sizes.add( i.intValue() );
         }
 
-        // If totalSize < minSizeThreshold or totalSize is not a multiple of minSizeThreshold 
+        // If totalSize < minSizeThreshold or totalSize is not a multiple of minSizeThreshold
         // we force adding an element to the map
         if ( sizes.isEmpty() || !sizes.contains( totalSize ) )
         {
{noformat}
                  
> MemoryManager crashes on allocation of more than 300Mb or memory
> ----------------------------------------------------------------
>
>                 Key: DIRECTMEMORY-118
>                 URL: https://issues.apache.org/jira/browse/DIRECTMEMORY-118
>             Project: Apache DirectMemory
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 0.2
>            Reporter: Prashant Sharma
>             Fix For: 0.2
>
>
> Following code reproduces the bug.
> val cacheService =  new DirectMemory[String, ArrayBuffer[Any]]()
>     .setNumberOfBuffers(1)
>     .setInitialCapacity(1)
>     .setMemoryManager(new MemoryManagerServiceImpl(true))
>     .setSize(300 *(1024*1024))
>     .setConcurrencyLevel(1)
>     .newCacheService();

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira