tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GCContext-inl.h (1243B)


      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_GCContext_inl_h
      8 #define gc_GCContext_inl_h
      9 
     10 #include "gc/GCContext.h"
     11 
     12 #include "gc/ZoneAllocator.h"
     13 
     14 inline void JS::GCContext::free_(Cell* cell, void* p, size_t nbytes,
     15                                 MemoryUse use) {
     16  if (p) {
     17    removeCellMemory(cell, nbytes, use);
     18    js_free(p);
     19  }
     20 }
     21 
     22 template <class T>
     23 inline void JS::GCContext::release(Cell* cell, T* p, size_t nbytes,
     24                                   MemoryUse use) {
     25  if (p) {
     26    removeCellMemory(cell, nbytes, use);
     27    p->Release();
     28  }
     29 }
     30 
     31 inline void JS::GCContext::removeCellMemory(Cell* cell, size_t nbytes,
     32                                            MemoryUse use) {
     33  // This may or may not be called as part of GC.
     34  if (nbytes && cell->isTenured()) {
     35    auto zone = js::ZoneAllocator::from(cell->asTenured().zoneFromAnyThread());
     36    zone->removeCellMemory(cell, nbytes, use, isFinalizing());
     37  }
     38 }
     39 
     40 #endif  // gc_GCContext_inl_h