webengine/osswebengine/MemoryManager/Src/MemoryPool.cpp
changeset 65 5bfc169077b2
parent 42 d39add9822e2
child 68 92a765b5b3e7
equal deleted inserted replaced
42:d39add9822e2 65:5bfc169077b2
    26 #include "StopScheduler.h"
    26 #include "StopScheduler.h"
    27 #include "fast_malloc.h"
    27 #include "fast_malloc.h"
    28 #include "SymbianDlHeap.h"
    28 #include "SymbianDlHeap.h"
    29 #include <OOMMonitorSession.h>
    29 #include <OOMMonitorSession.h>
    30 #include <hal.h>
    30 #include <hal.h>
    31 #include <avkon.hrh>
       
    32 #include <avkon.rsg>
       
    33 #include <StringLoader.h>
       
    34 #include <WebKit.rsg>
       
    35 
    31 
    36 // CONSTANTS
    32 // CONSTANTS
    37 
    33 
    38 // CLASS DECLARATIONS
    34 // CLASS DECLARATIONS
    39 
    35 
   463 //-----------------------------------------------------------------------------
   459 //-----------------------------------------------------------------------------
   464 // CNewSymbianHeapPool::DoAlloc
   460 // CNewSymbianHeapPool::DoAlloc
   465 //-----------------------------------------------------------------------------
   461 //-----------------------------------------------------------------------------
   466 TAny* CNewSymbianHeapPool::DoAlloc( TUint aSize )
   462 TAny* CNewSymbianHeapPool::DoAlloc( TUint aSize )
   467     {
   463     {
   468     TAny *p = iAlloc->Alloc( aSize );
   464     return iAlloc->Alloc( aSize );
   469     if (!p)
       
   470         ShowOOMDialog();
       
   471     return p;
       
   472     }
   465     }
   473 
   466 
   474 //-----------------------------------------------------------------------------
   467 //-----------------------------------------------------------------------------
   475 // CNewSymbianHeapPool::ReAllocate
   468 // CNewSymbianHeapPool::ReAllocate
   476 //-----------------------------------------------------------------------------
   469 //-----------------------------------------------------------------------------
   482     TAny* p = iAlloc->ReAlloc( aPtr, aSize );
   475     TAny* p = iAlloc->ReAlloc( aPtr, aSize );
   483     
   476     
   484     // check memory manager status
   477     // check memory manager status
   485     if( !p || iMemStatus & ERescueOOM )
   478     if( !p || iMemStatus & ERescueOOM )
   486         {
   479         {
   487         ShowOOMDialog();
       
   488         if( !iIsCollecting )
   480         if( !iIsCollecting )
   489             {
   481             {
   490             CollectMemory();
   482             CollectMemory();
   491             }
   483             }
   492 
   484 
   557 	req = freeSpace + systemFreeMemory - aTotalSize;	
   549 	req = freeSpace + systemFreeMemory - aTotalSize;	
   558 	
   550 	
   559 	if(req > 0)
   551 	if(req > 0)
   560 		return ETrue;
   552 		return ETrue;
   561 	
   553 	
   562     // We haven't got the required amount free yet, pop an OOM dialog and then try the browser heap.
   554 	// We haven't got the required amount free yet, try the browser heap.
   563     ShowOOMDialog();
       
   564 	CollectMemory(aTotalSize);
   555 	CollectMemory(aTotalSize);
   565 	// ask the system how much is free now...
   556 	// ask the system how much is free now...
   566 	HAL::Get(HALData::EMemoryRAMFree, systemFreeMemory);
   557 	HAL::Get(HALData::EMemoryRAMFree, systemFreeMemory);
   567 	req = freeSpace + systemFreeMemory - aTotalSize;	
   558 	req = freeSpace + systemFreeMemory - aTotalSize;	
   568 	
   559 	
   617     //alloc_rescue_buffer();
   608     //alloc_rescue_buffer();
   618     }
   609     }
   619 
   610 
   620 CNewSymbianHeapPool::CNewSymbianHeapPool() : CMemoryPool()
   611 CNewSymbianHeapPool::CNewSymbianHeapPool() : CMemoryPool()
   621 	{
   612 	{
   622     isInitted = EFalse;
       
   623     iOOMErrorDialog = 0;
       
   624     iOOMMessage = 0;
       
   625 	}
   613 	}
   626 
   614 
   627 CNewSymbianHeapPool::~CNewSymbianHeapPool()
   615 CNewSymbianHeapPool::~CNewSymbianHeapPool()
   628 	{
   616 	{
   629 //	iAlloc->Close();	// TODO: Need to clean up here, but it's not implemented in the allocator yet.
   617 //	iAlloc->Close();	// TODO: Need to clean up here, but it's not implemented in the allocator yet.
   631 						// be deleting this object when we're closing the allocator - which we never do
   619 						// be deleting this object when we're closing the allocator - which we never do
   632 						// except at process end.
   620 						// except at process end.
   633 	}
   621 	}
   634 
   622 
   635 #ifdef __WINSCW__
   623 #ifdef __WINSCW__
   636 const TInt KMaxHeapSize = 0x1000000; // 32MB, on emulator
   624 const TInt KMaxHeapSize = 0x2000000; // 32MB, on emulator
   637 #else
   625 #else
   638 const TInt KMaxHeapSize = 0x4000000; // 64MB, on hardware
   626 const TInt KMaxHeapSize = 0x4000000; // 64MB, on hardware
   639 #endif
   627 #endif
   640 
   628 
   641 const TInt KHeapGrowSize = 0x10000;  // 64KB
   629 const TInt KHeapGrowSize = 0x10000;  // 64KB
   673 		return EFalse;
   661 		return EFalse;
   674 	
   662 	
   675 	return CMemoryPool::Create();
   663 	return CMemoryPool::Create();
   676 	}
   664 	}
   677 
   665 
   678 /*
       
   679  * Initialize the OOM dialog and localized message resource
       
   680  * This should be called as soon in the startup process as possible
       
   681  * (unfortunately it can't be called until resources are already loaded)
       
   682  * Note: apps are responsible for showing their own oom dialog; there
       
   683  * is no system one AFAIK; at least we can re-use the oom localized
       
   684  * resource message from elsewhere
       
   685  */
       
   686 void CNewSymbianHeapPool::InitOOMDialog()
       
   687     {
       
   688     if (!isInitted)
       
   689         {
       
   690         isInitted = ETrue;
       
   691         iOOMErrorDialog = CAknGlobalNote::NewL();
       
   692         iOOMErrorDialog->SetSoftkeys(R_AVKON_SOFTKEYS_OK_EMPTY);
       
   693         iOOMMessage = StringLoader::LoadL(R_QTN_BROWSER_DIALOG_OOM);
       
   694         iOOMDisplayed = EFalse;
       
   695         }
       
   696     }
       
   697 
       
   698 void CNewSymbianHeapPool::ShowOOMDialog()
       
   699     {
       
   700     // Don't show it if we did once already
       
   701     if (iOOMDisplayed)
       
   702         return;
       
   703 
       
   704     // If we got OOM, show a dialog (if the dialog was initted properly to begin with)
       
   705     if (iOOMErrorDialog)
       
   706         {
       
   707         // If we couldn't load the message resource when we first initted, 
       
   708         // try again now; this shouldn't ever happen
       
   709         if (!iOOMMessage)
       
   710             {
       
   711             iOOMMessage = StringLoader::LoadL(R_QTN_BROWSER_DIALOG_OOM);
       
   712             }
       
   713         // If we have no dialog or message we unfortunately cannot display it!
       
   714         if (iOOMMessage) 
       
   715             {
       
   716             iOOMErrorDialog->ShowNoteL(EAknGlobalWarningNote,iOOMMessage->Des());
       
   717             iOOMDisplayed = ETrue;
       
   718             }
       
   719         }
       
   720     }
       
   721 
       
   722 void CNewSymbianHeapPool::ResetOOMDialogDisplayed()
       
   723     {
       
   724     iOOMDisplayed = EFalse;
       
   725     }
       
   726 
       
   727 #ifdef OOM_LOGGING   
   666 #ifdef OOM_LOGGING   
   728 void CNewSymbianHeapPool::DumpHeapLogs()
   667 void CNewSymbianHeapPool::DumpHeapLogs()
   729     {
   668     {
   730     iAlloc->dump_heap_logs(0);
   669     iAlloc->dump_heap_logs(0);
   731     iAlloc->dump_dl_free_chunks();
   670     iAlloc->dump_dl_free_chunks();