1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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 gc_FreeOp_inl_h
8 #define gc_FreeOp_inl_h
9
10 #include "gc/FreeOp.h"
11
12 #include "gc/ZoneAllocator.h"
13 #include "js/RefCounted.h"
14
free_(Cell * cell,void * p,size_t nbytes,MemoryUse use)15 inline void JSFreeOp::free_(Cell* cell, void* p, size_t nbytes, MemoryUse use) {
16 if (p) {
17 removeCellMemory(cell, nbytes, use);
18 js_free(p);
19 }
20 }
21
freeLater(Cell * cell,void * p,size_t nbytes,MemoryUse use)22 inline void JSFreeOp::freeLater(Cell* cell, void* p, size_t nbytes,
23 MemoryUse use) {
24 if (p) {
25 removeCellMemory(cell, nbytes, use);
26 queueForFreeLater(p);
27 }
28 }
29
queueForFreeLater(void * p)30 inline void JSFreeOp::queueForFreeLater(void* p) {
31 // Default JSFreeOps are not constructed on the stack, and will hold onto the
32 // pointers to free indefinitely.
33 MOZ_ASSERT(!isDefaultFreeOp());
34
35 // It's not safe to free this allocation immediately, so we must crash if we
36 // can't append to the list.
37 js::AutoEnterOOMUnsafeRegion oomUnsafe;
38 if (!freeLaterList.append(p)) {
39 oomUnsafe.crash("JSFreeOp::freeLater");
40 }
41 }
42
43 template <class T>
release(Cell * cell,T * p,size_t nbytes,MemoryUse use)44 inline void JSFreeOp::release(Cell* cell, T* p, size_t nbytes, MemoryUse use) {
45 if (p) {
46 removeCellMemory(cell, nbytes, use);
47 p->Release();
48 }
49 }
50
removeCellMemory(Cell * cell,size_t nbytes,MemoryUse use)51 inline void JSFreeOp::removeCellMemory(Cell* cell, size_t nbytes,
52 MemoryUse use) {
53 RemoveCellMemory(cell, nbytes, use, isCollecting());
54 }
55
56 #endif // gc_JSFreeOp_inl_h
57