1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef _MDB_
7 #  include "mdb.h"
8 #endif
9 
10 #ifndef _MORK_
11 #  include "mork.h"
12 #endif
13 
14 #ifndef _ORKINHEAP_
15 #  include "orkinHeap.h"
16 #endif
17 
18 #ifndef _MORKENV_
19 #  include "morkEnv.h"
20 #endif
21 
22 #include "nsIMemoryReporter.h"
23 
24 #include <stdlib.h>
25 
26 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
27 
orkinHeap()28 orkinHeap::orkinHeap()  // does nothing
29     : mUsedSize(0) {}
30 
31 /*virtual*/
~orkinHeap()32 orkinHeap::~orkinHeap()  // does nothing
33 {}
34 
35 MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MorkSizeOfOnAlloc)
MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MorkSizeOfOnFree)36 MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MorkSizeOfOnFree)
37 
38 // { ===== begin nsIMdbHeap methods =====
39 /*virtual*/ nsresult orkinHeap::Alloc(
40     nsIMdbEnv* mev,   // allocate a piece of memory
41     mdb_size inSize,  // requested size of new memory block
42     void** outBlock)  // memory block of inSize bytes, or nil
43 {
44   MORK_USED_1(mev);
45   nsresult outErr = NS_OK;
46   void* block = malloc(inSize);
47   if (!block)
48     outErr = morkEnv_kOutOfMemoryError;
49   else
50     mUsedSize += MorkSizeOfOnAlloc(block);
51 
52   MORK_ASSERT(outBlock);
53   if (outBlock) *outBlock = block;
54   return outErr;
55 }
56 
Free(nsIMdbEnv * mev,void * inBlock)57 /*virtual*/ nsresult orkinHeap::Free(
58     nsIMdbEnv* mev,  // free block allocated earlier by Alloc()
59     void* inBlock) {
60   MORK_USED_1(mev);
61   MORK_ASSERT(inBlock);
62   if (inBlock) {
63     mUsedSize -= MorkSizeOfOnFree(inBlock);
64     free(inBlock);
65   }
66   return NS_OK;
67 }
68 
GetUsedSize()69 size_t orkinHeap::GetUsedSize() { return mUsedSize; }
70 // } ===== end nsIMdbHeap methods =====
71 
72 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
73