Bug 604553: Enable expectedfail for tests that use .out files (r=cpeyer)
[tamarin-stm.git] / VMPI / MMgcPortSymbian.cpp
blob907418956341a94ffeda4ffb2f2b445053d7f029
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
14 * License.
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.
23 * Contributor(s):
24 * Adobe AS3 Team
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 ***** */
40 #include <e32std.h>
41 #include <hal.h>
42 #include "MMgc.h"
43 #include "AvmDebug.h" // for AvmAssert
44 #include "SymbianHeap.h"
46 size_t VMPI_getVMPageSize()
48 TInt pageSize;
49 HAL::Get(HAL::EMemoryPageSize, pageSize);
50 return pageSize;
53 bool VMPI_canMergeContiguousRegions()
55 return false;
58 bool VMPI_canCommitAlreadyCommittedMemory()
60 return false;
63 bool VMPI_useVirtualMemory()
65 return true;
68 bool VMPI_areNewPagesDirty()
70 return true;
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.
83 void* ptr = 0;
84 if(address == NULL)
86 SymbianHeap* newHeap = new SymbianHeap(size);
87 if(newHeap && newHeap->GetStart())
89 newHeap->m_next = symbianHeapListRoot;
90 symbianHeapListRoot = newHeap;
91 ptr = (void*)newHeap->GetStart();
92 } else
94 delete newHeap;
97 return ptr;
100 bool VMPI_releaseMemoryRegion(void* address, size_t size)
102 SymbianHeap* heap = SymbianHeap::FindHeap((TUint)address, symbianHeapListRoot);
103 if(heap)
105 // remove from list
106 SymbianHeap* list = symbianHeapListRoot;
107 SymbianHeap* prev = NULL;
108 while(list)
110 if(list == heap)
112 if(prev)
114 prev->m_next = heap->m_next;
115 } else
117 symbianHeapListRoot = heap->m_next;
119 delete heap;
120 break;
122 prev = list;
123 list = list->m_next;
125 return true;
127 return false;
130 bool VMPI_commitMemory(void* address, size_t size)
132 bool result = false;
133 SymbianHeap* heap = SymbianHeap::FindHeap((TUint)address, symbianHeapListRoot);
134 if(heap)
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.
140 if(result)
142 memset(address, 0, size);
143 } else
145 VMPI_debugLog("Failed to allocate normal memory.\n");
148 return result;
151 bool VMPI_decommitMemory(char *address, size_t size)
153 bool result = false;
154 SymbianHeap* heap = SymbianHeap::FindHeap((TUint)address, symbianHeapListRoot);
155 if(heap)
157 result = heap->Decommit((TUint)address, size);
159 return result;
162 #if 0
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);
180 return(aligned_ptr);
183 void VMPI_releaseAlignedMemory(void* address)
185 int *ptr2=(int *)address - 1;
186 char *unaligned_ptr = (char*) address - *ptr2;
187 free(unaligned_ptr);
189 #endif // 0
191 void VMPI_releaseAlignedMemory(void* address)
195 void* VMPI_allocateAlignedMemory(size_t)
197 return 0;
200 size_t VMPI_getPrivateResidentPageCount()
202 size_t pageSize = VMPI_getVMPageSize();
203 if(pageSize > 0)
205 TInt freeRAM;
206 HAL::Get(HAL::EMemoryRAMFree, freeRAM);
207 return freeRAM/pageSize;
208 } else
210 return 0;
214 uint64_t VMPI_getPerformanceFrequency()
216 TInt tickPeriod;
217 HAL::Get(HALData::EFastCounterFrequency, tickPeriod);
218 return (uint64_t)tickPeriod;
221 uint64_t VMPI_getPerformanceCounter()
223 // Alternative way:
225 TTime t;
226 t.UniversalTime ();
227 TInt64 lt = t.Int64 ();
228 return (uint64_t) (lt & 0x7FFFFFFF);
230 TUint32 counter = User::FastCounter();
231 return counter;
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()
242 // TODO
245 void VMPI_desetupPCResolution()
247 // TODO
250 uintptr_t VMPI_getThreadStackBase()
252 TThreadStackInfo info;
253 RThread mythread;
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)
264 jmp_buf buf;
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)
274 (void) buffer;
275 (void) bufferSize;
276 (void) framesToSkip;
277 return false;
280 bool VMPI_getFunctionNameFromPC(uintptr_t pc, char *buffer, size_t bufferSize)
282 (void)pc;
283 (void)buffer;
284 (void)bufferSize;
285 return false;
288 bool VMPI_getFileAndLineInfoFromPC(uintptr_t /*pc*/, char */*buffer*/, size_t /*bufferSize*/, uint32_t* /*lineNumber*/)
290 return false;
293 #endif //MEMORY_PROFILER