1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1999
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Mike McCabe <mccabe@netscape.com>
24 : * John Bandhauer <jband@netscape.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or 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.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : /* Implementation of xptiWorkingSet. */
41 :
42 : #include "xptiprivate.h"
43 : #include "nsString.h"
44 : #include "nsIMemoryReporter.h"
45 :
46 : using namespace mozilla;
47 :
48 0 : NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(XPTMallocSizeOf, "xpti-working-set")
49 :
50 0 : static PRInt64 GetXPTArenaSize()
51 : {
52 0 : return XPT_SizeOfArena(gXPTIStructArena, XPTMallocSizeOf);
53 : }
54 :
55 1428 : NS_MEMORY_REPORTER_IMPLEMENT(xptiWorkingSet,
56 : "explicit/xpti-working-set",
57 : KIND_HEAP,
58 : UNITS_BYTES,
59 : GetXPTArenaSize,
60 4323 : "Memory used by the XPCOM typelib system.")
61 :
62 : #define XPTI_STRUCT_ARENA_BLOCK_SIZE (1024 * 1)
63 : #define XPTI_HASHTABLE_SIZE 2048
64 :
65 1419 : xptiWorkingSet::xptiWorkingSet()
66 1419 : : mTableReentrantMonitor("xptiWorkingSet::mTableReentrantMonitor")
67 : {
68 1419 : MOZ_COUNT_CTOR(xptiWorkingSet);
69 :
70 1419 : mIIDTable.Init(XPTI_HASHTABLE_SIZE);
71 1419 : mNameTable.Init(XPTI_HASHTABLE_SIZE);
72 :
73 : gXPTIStructArena = XPT_NewArena(XPTI_STRUCT_ARENA_BLOCK_SIZE, sizeof(double),
74 1419 : "xptiWorkingSet structs");
75 :
76 1419 : NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(xptiWorkingSet));
77 1419 : }
78 :
79 : static PLDHashOperator
80 2144498 : xpti_Invalidator(const char* keyname, xptiInterfaceEntry* entry, void* arg)
81 : {
82 2144498 : entry->LockedInvalidateInterfaceInfo();
83 2144498 : return PL_DHASH_NEXT;
84 : }
85 :
86 : void
87 1409 : xptiWorkingSet::InvalidateInterfaceInfos()
88 : {
89 2818 : ReentrantMonitorAutoEnter monitor(mTableReentrantMonitor);
90 1409 : mNameTable.EnumerateRead(xpti_Invalidator, NULL);
91 1409 : }
92 :
93 2818 : xptiWorkingSet::~xptiWorkingSet()
94 : {
95 1409 : MOZ_COUNT_DTOR(xptiWorkingSet);
96 :
97 : // Only destroy the arena if we're doing leak stats. Why waste shutdown
98 : // time touching pages if we don't have to?
99 : #ifdef NS_FREE_PERMANENT_DATA
100 1409 : XPT_DestroyArena(gXPTIStructArena);
101 : #endif
102 1409 : }
103 :
104 : XPTArena* gXPTIStructArena;
|