Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / DOMArena.h
blob3f6d3c680ca0f3dc9162c02cfcc3aa5b67c19713
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=2 sw=2 et tw=78:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
7 #ifndef DOM_Arena_h___
8 #define DOM_Arena_h___
9 #include "nsISupportsImpl.h"
10 #include "mozmemory.h"
12 #include "mozilla/mozalloc_oom.h" // for mozalloc_handle_oom
14 #define NS_DECL_DOMARENA_DESTROY void Destroy(void);
16 #define NS_IMPL_DOMARENA_DESTROY(class) \
17 void class ::Destroy(void) { \
18 if (StaticPrefs::dom_arena_allocator_enabled_AtStartup()) { \
19 RefPtr<nsNodeInfoManager> nim = OwnerDoc()->NodeInfoManager(); \
20 RefPtr<DOMArena> arena = \
21 HasFlag(NODE_KEEPS_DOMARENA) \
22 ? nsContentUtils::TakeEntryFromDOMArenaTable(this) \
23 : nullptr; \
24 this->~class(); \
25 MOZ_ASSERT(nim, "nsNodeInfoManager needs to be initialized"); \
26 nim->Free(this); \
27 } else { \
28 delete this; \
29 } \
32 namespace mozilla::dom {
34 class DOMArena {
35 public:
36 friend class DocGroup;
37 DOMArena() {
38 arena_params_t params;
39 params.mMaxDirtyIncreaseOverride = 7;
40 params.mFlags = ARENA_FLAG_THREAD_MAIN_THREAD_ONLY;
41 mArenaId = moz_create_arena_with_params(&params);
44 NS_INLINE_DECL_REFCOUNTING(DOMArena)
46 void* Allocate(size_t aSize) {
47 void* ret = moz_arena_malloc(mArenaId, aSize);
48 if (!ret) {
49 mozalloc_handle_oom(aSize);
51 return ret;
54 private:
55 ~DOMArena() { moz_dispose_arena(mArenaId); }
56 arena_id_t mArenaId;
58 } // namespace mozilla::dom
59 #endif