1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2006
21 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
43 #include "AvmDebug.h" // for AvmAssert
44 #include "SymbianHeap.h"
46 size_t VMPI_getVMPageSize()
49 HAL::Get(HAL::EMemoryPageSize
, pageSize
);
53 bool VMPI_canMergeContiguousRegions()
58 bool VMPI_canCommitAlreadyCommittedMemory()
63 bool VMPI_useVirtualMemory()
68 bool VMPI_areNewPagesDirty()
73 static SymbianHeap
* symbianHeapListRoot
= 0;
75 void* VMPI_reserveMemoryRegion(void* address
, size_t size
)
77 // After reading the RChunk API it looks like we can not allocate contiguous memory.
78 // Create a new heap when address is null. Otherwise return null which MMgc should handle.
80 // Open question is could we instead just create one SymbianHeap instance and always allocate
81 // from there and ignore reserverMemoryRegion and releaseMemoryRegion. However as each region
82 // should be contiguous it's maybe easier just to create multiple regions = heaps.
86 SymbianHeap
* newHeap
= new SymbianHeap(size
);
87 if(newHeap
&& newHeap
->GetStart())
89 newHeap
->m_next
= symbianHeapListRoot
;
90 symbianHeapListRoot
= newHeap
;
91 ptr
= (void*)newHeap
->GetStart();
100 bool VMPI_releaseMemoryRegion(void* address
, size_t size
)
102 SymbianHeap
* heap
= SymbianHeap::FindHeap((TUint
)address
, symbianHeapListRoot
);
106 SymbianHeap
* list
= symbianHeapListRoot
;
107 SymbianHeap
* prev
= NULL
;
114 prev
->m_next
= heap
->m_next
;
117 symbianHeapListRoot
= heap
->m_next
;
130 bool VMPI_commitMemory(void* address
, size_t size
)
133 SymbianHeap
* heap
= SymbianHeap::FindHeap((TUint
)address
, symbianHeapListRoot
);
136 result
= heap
->Commit((TUint
)address
, size
);
137 // FIXME https://bugzilla.mozilla.org/show_bug.cgi?id=571407
138 // This needs to be investigated, rather than a simple band-aid applied.
139 // TEMPORARY FIX: MMgc should zero initialize the memory, but it does not seem to do it in all cases.
142 memset(address
, 0, size
);
145 VMPI_debugLog("Failed to allocate normal memory.\n");
151 bool VMPI_decommitMemory(char *address
, size_t size
)
154 SymbianHeap
* heap
= SymbianHeap::FindHeap((TUint
)address
, symbianHeapListRoot
);
157 result
= heap
->Decommit((TUint
)address
, size
);
163 void* VMPI_allocateAlignedMemory(size_t size
)
165 char *ptr
, *ptr2
, *aligned_ptr
;
166 size_t align_size
= VMPI_getVMPageSize();
167 size_t align_mask
= align_size
- 1;
169 size_t alloc_size
= size
+ align_size
+ sizeof(int);
170 ptr
= (char *)malloc(alloc_size
);
172 if(ptr
==NULL
) return(NULL
);
174 ptr2
= ptr
+ sizeof(int);
175 aligned_ptr
= ptr2
+ (align_size
- ((size_t)ptr2
& align_mask
));
177 ptr2
= aligned_ptr
- sizeof(int);
178 *((int *)ptr2
)=(int)(aligned_ptr
- ptr
);
183 void VMPI_releaseAlignedMemory(void* address
)
185 int *ptr2
=(int *)address
- 1;
186 char *unaligned_ptr
= (char*) address
- *ptr2
;
191 void VMPI_releaseAlignedMemory(void* address
)
195 void* VMPI_allocateAlignedMemory(size_t)
200 size_t VMPI_getPrivateResidentPageCount()
202 size_t pageSize
= VMPI_getVMPageSize();
206 HAL::Get(HAL::EMemoryRAMFree
, freeRAM
);
207 return freeRAM
/pageSize
;
214 uint64_t VMPI_getPerformanceFrequency()
217 HAL::Get(HALData::EFastCounterFrequency
, tickPeriod
);
218 return (uint64_t)tickPeriod
;
221 uint64_t VMPI_getPerformanceCounter()
227 TInt64 lt = t.Int64 ();
228 return (uint64_t) (lt & 0x7FFFFFFF);
230 TUint32 counter
= User::FastCounter();
234 void VMPI_cleanStack(size_t amt
)
236 // TODO - According to Tommy it does not kill if we don't implement on Symbian.
237 // It could be possible to implement using ARM assembler.
240 void VMPI_setupPCResolution()
245 void VMPI_desetupPCResolution()
250 uintptr_t VMPI_getThreadStackBase()
252 TThreadStackInfo info
;
254 mythread
.StackInfo(info
);
255 return uintptr_t(info
.iBase
);
258 // Defined in SymbianPortUtils.cpp to prevent them from being inlined below
259 extern void CallWithRegistersSaved2(void (*fn
)(void* stackPointer
, void* arg
), void* arg
, void* buf
);
260 extern void CallWithRegistersSaved3(void (*fn
)(void* stackPointer
, void* arg
), void* arg
, void* buf
);
262 void VMPI_callWithRegistersSaved(void (*fn
)(void* stackPointer
, void* arg
), void* arg
)
265 VMPI_setjmpNoUnwind(buf
); // Save registers
266 CallWithRegistersSaved2(fn
, arg
, &buf
); // Computes the stack pointer, calls fn
267 CallWithRegistersSaved3(fn
, &arg
, &buf
); // Probably prevents the previous call from being a tail call
270 #ifdef MMGC_MEMORY_PROFILER
272 bool VMPI_captureStackTrace(uintptr_t* buffer
, size_t bufferSize
, uint32_t framesToSkip
)
280 bool VMPI_getFunctionNameFromPC(uintptr_t pc
, char *buffer
, size_t bufferSize
)
288 bool VMPI_getFileAndLineInfoFromPC(uintptr_t /*pc*/, char */
*buffer*/
, size_t /*bufferSize*/, uint32_t* /*lineNumber*/)
293 #endif //MEMORY_PROFILER