webengine/osswebengine/MemoryManager/Src/MemoryPool.cpp
branchRCL_3
changeset 46 30342f40acbf
parent 35 1f3c3f2f5b0a
child 47 e1bea15f9a39
equal deleted inserted replaced
44:800203832575 46:30342f40acbf
    30 #include <hal.h>
    30 #include <hal.h>
    31 #include <avkon.hrh>
    31 #include <avkon.hrh>
    32 #include <avkon.rsg>
    32 #include <avkon.rsg>
    33 #include <StringLoader.h>
    33 #include <StringLoader.h>
    34 #include <WebKit.rsg>
    34 #include <WebKit.rsg>
       
    35 #include "MemoryLogger.h"
    35 
    36 
    36 // CONSTANTS
    37 // CONSTANTS
    37 
    38 
    38 // CLASS DECLARATIONS
    39 // CLASS DECLARATIONS
    39 
    40 
   130 //-----------------------------------------------------------------------------
   131 //-----------------------------------------------------------------------------
   131 // CMemoryPool::CollectMemory
   132 // CMemoryPool::CollectMemory
   132 //-----------------------------------------------------------------------------
   133 //-----------------------------------------------------------------------------
   133 void CMemoryPool::CollectMemory(TUint aSize)
   134 void CMemoryPool::CollectMemory(TUint aSize)
   134     {
   135     {
       
   136     MEM_LOG("CMemoryPool::CollectMemory - run");
   135     if( iIsCollecting ) return;
   137     if( iIsCollecting ) return;
   136 
   138 
   137     iIsCollecting = ETrue;
   139     iIsCollecting = ETrue;
   138     for( TInt i=0; i<iCollectors.Count(); ++i )
   140     for( TInt i=0; i<iCollectors.Count(); ++i )
   139       {
   141       {
   140         iCollectors[i]->Collect(aSize);
   142         iCollectors[i]->Collect(aSize);
   141       }
   143       }
   142 
       
   143     User::CompressAllHeaps();
       
   144     iIsCollecting = EFalse;
   144     iIsCollecting = EFalse;
   145 	
   145 	
   146 	if (iStopScheduler)
   146 	if (iStopScheduler && !iIsStopping )
   147 		iStopScheduler->Start( CStopScheduler::ECheckMemory, aSize );
   147 		iStopScheduler->Start( CStopScheduler::ECheckMemory, aSize );
   148     }
   148     }
   149 
   149 
   150 //-----------------------------------------------------------------------------
   150 //-----------------------------------------------------------------------------
   151 // CMemoryPool::RestoreCollectors
   151 // CMemoryPool::RestoreCollectors
   465 
   465 
   466 #ifdef __NEW_ALLOCATOR__
   466 #ifdef __NEW_ALLOCATOR__
   467 //-----------------------------------------------------------------------------
   467 //-----------------------------------------------------------------------------
   468 // CNewSymbianHeapPool::FreeMemory
   468 // CNewSymbianHeapPool::FreeMemory
   469 //-----------------------------------------------------------------------------
   469 //-----------------------------------------------------------------------------
   470 TUint CNewSymbianHeapPool::FreeMemory(TFreeMem& /*aFree*/ )
   470 TUint CNewSymbianHeapPool::FreeMemory(TFreeMem& aFree )
   471     {
   471     {
   472     // TODO: implement free_memory
   472     // TODO: implement free_memory
   473     return KMaxTUint;
   473     aFree.iPool = 0;
   474 //    return free_memory( aFree.iPool, aFree.iHeap, aFree.iHal );
   474     aFree.iHeap = 0;
       
   475     
       
   476     TInt freeRAM; 
       
   477     if(HAL::Get(HALData::EMemoryRAMFree, freeRAM) == KErrNone) 
       
   478         aFree.iHal = freeRAM;
       
   479     else
       
   480         aFree.iHal = 0;
       
   481     
       
   482     return KMaxTUint; // not fully implemented
   475     }
   483     }
   476 
   484 
   477 //-----------------------------------------------------------------------------
   485 //-----------------------------------------------------------------------------
   478 // CNewSymbianHeapPool::DoAlloc
   486 // CNewSymbianHeapPool::DoAlloc
   479 //-----------------------------------------------------------------------------
   487 //-----------------------------------------------------------------------------
   480 TAny* CNewSymbianHeapPool::DoAlloc( TUint aSize )
   488 TAny* CNewSymbianHeapPool::DoAlloc( TUint aSize )
   481     {
   489     {
   482     TAny *p = iAlloc->Alloc( aSize );
   490     TAny *p = iAlloc->Alloc( aSize );
   483     if (!p)
   491     if(iAlloc->isLowSystemMemory && p) // use this a pre OOM indicator
       
   492         {
       
   493         iStopScheduler->Start( CStopScheduler::ECheckMemory, 0 );                
       
   494         iAlloc->isLowSystemMemory = 0; // reset so that we don't check before next request for RAM
       
   495         }
       
   496         
       
   497     if (!p) {
   484         ShowOOMDialog();
   498         ShowOOMDialog();
       
   499         MEM_LOG("CNewSymbianHeapPool::DoAlloc - failed");
       
   500     }
   485     return p;
   501     return p;
   486     }
   502     }
   487 
   503 
   488 //-----------------------------------------------------------------------------
   504 //-----------------------------------------------------------------------------
   489 // CNewSymbianHeapPool::ReAllocate
   505 // CNewSymbianHeapPool::ReAllocate
   492     {
   508     {
   493     // reset the status for next allocation
   509     // reset the status for next allocation
   494     iMemStatus &= ~ERescueOOM;
   510     iMemStatus &= ~ERescueOOM;
   495 
   511 
   496     TAny* p = iAlloc->ReAlloc( aPtr, aSize );
   512     TAny* p = iAlloc->ReAlloc( aPtr, aSize );
   497     
   513     if(iAlloc->isLowSystemMemory && p) // use this a pre OOM indicator
       
   514         {
       
   515         iStopScheduler->Start( CStopScheduler::ECheckMemory, 0 );                
       
   516         iAlloc->isLowSystemMemory = 0; // reset so that we don't check before next request for RAM
       
   517         }
       
   518 
   498     // check memory manager status
   519     // check memory manager status
   499     if( !p || iMemStatus & ERescueOOM )
   520     if( !p || iMemStatus & ERescueOOM )
   500         {
   521         {
   501         ShowOOMDialog();
   522         ShowOOMDialog();
   502         if( !iIsCollecting )
   523         if( !iIsCollecting )
   507         if( !p )
   528         if( !p )
   508 			p = iAlloc->ReAlloc( aPtr, aSize );
   529 			p = iAlloc->ReAlloc( aPtr, aSize );
   509 
   530 
   510         NotifyAndStop();
   531         NotifyAndStop();
   511         }
   532         }
       
   533 
       
   534 #ifdef OOM_LOGGING    
       
   535     if(!p)
       
   536         MEM_LOG("CNewSymbianHeapPool::ReAllocate - failed");
       
   537 #endif
   512 
   538 
   513     return p;
   539     return p;
   514     }
   540     }
   515 
   541 
   516 //-----------------------------------------------------------------------------
   542 //-----------------------------------------------------------------------------
   583 	// if we still haven't got enough RAM, we should stop the browser from going any further just yet.
   609 	// if we still haven't got enough RAM, we should stop the browser from going any further just yet.
   584 	if (req < 0)
   610 	if (req < 0)
   585 		{
   611 		{
   586 		iMemStatus |= ECheckOOM;
   612 		iMemStatus |= ECheckOOM;
   587 		NotifyAndStop();
   613 		NotifyAndStop();
       
   614 
       
   615 #ifdef OOM_LOGGING		
       
   616 		MEM_LOG("CNewSymbianHeapPool::PreCheck - failed !!");
       
   617 		DumpHeapLogs(aTotalSize);
       
   618 #endif		
   588 		return EFalse;
   619 		return EFalse;
   589 		}
   620 		}
   590 	
   621 	
   591 	return ETrue;
   622 	return ETrue;
   592 	}
   623 	}
   709         }
   740         }
   710     }
   741     }
   711 
   742 
   712 void CNewSymbianHeapPool::ShowOOMDialog()
   743 void CNewSymbianHeapPool::ShowOOMDialog()
   713     {
   744     {
       
   745     MEM_LOG("CNewSymbianHeapPool::ShowOOMDialog - called");
       
   746     
   714     // Don't show it if we did once already
   747     // Don't show it if we did once already
   715     if (iOOMDisplayed)
   748     if (iOOMDisplayed)
   716         return;
   749         return;
   717 
   750 
   718     // If we got OOM, show a dialog (if the dialog was initted properly to begin with)
   751     // If we got OOM, show a dialog (if the dialog was initted properly to begin with)
   737     {
   770     {
   738     iOOMDisplayed = EFalse;
   771     iOOMDisplayed = EFalse;
   739     }
   772     }
   740 
   773 
   741 #ifdef OOM_LOGGING   
   774 #ifdef OOM_LOGGING   
   742 void CNewSymbianHeapPool::DumpHeapLogs()
   775 void CNewSymbianHeapPool::DumpHeapLogs(TInt aFailSize)
   743     {
   776     {
   744     iAlloc->dump_heap_logs(0);
   777     iAlloc->dump_heap_logs(aFailSize);
   745     iAlloc->dump_dl_free_chunks();
   778     iAlloc->dump_dl_free_chunks();
   746     }
   779     }
   747 #endif
   780 #endif
   748 #endif
   781 #endif
   749 // END OF FILE
   782 // END OF FILE