LCOV - code coverage report
Current view: top level - js/src/gc - Nursery-inl.h (source / functions) Hit Total Coverage
Test: output.info Lines: 25 27 92.6 %
Date: 2017-07-14 16:53:18 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2             :  * vim: set ts=4 sw=4 et tw=79 ft=cpp:
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       7             : 
       8             : #ifndef gc_Nursery_inl_h
       9             : #define gc_Nursery_inl_h
      10             : 
      11             : #include "gc/Nursery.h"
      12             : 
      13             : #include "jscntxt.h"
      14             : 
      15             : #include "gc/Heap.h"
      16             : #include "gc/Zone.h"
      17             : #include "js/TracingAPI.h"
      18             : #include "vm/Runtime.h"
      19             : 
      20             : MOZ_ALWAYS_INLINE /* static */ bool
      21       35464 : js::Nursery::getForwardedPointer(JSObject** ref)
      22             : {
      23       35464 :     MOZ_ASSERT(ref);
      24       35464 :     MOZ_ASSERT(IsInsideNursery(*ref));
      25       35464 :     const gc::RelocationOverlay* overlay = reinterpret_cast<const gc::RelocationOverlay*>(*ref);
      26       35464 :     if (!overlay->isForwarded())
      27       23668 :         return false;
      28       11796 :     *ref = static_cast<JSObject*>(overlay->forwardingAddress());
      29       11796 :     return true;
      30             : }
      31             : 
      32             : namespace js {
      33             : 
      34             : // The allocation methods below will not run the garbage collector. If the
      35             : // nursery cannot accomodate the allocation, the malloc heap will be used
      36             : // instead.
      37             : 
      38             : template <typename T>
      39             : static inline T*
      40             : AllocateObjectBuffer(JSContext* cx, uint32_t count)
      41             : {
      42             :     size_t nbytes = JS_ROUNDUP(count * sizeof(T), sizeof(Value));
      43             :     T* buffer = static_cast<T*>(cx->nursery().allocateBuffer(cx->zone(), nbytes));
      44             :     if (!buffer)
      45             :         ReportOutOfMemory(cx);
      46             :     return buffer;
      47             : }
      48             : 
      49             : template <typename T>
      50             : static inline T*
      51       10687 : AllocateObjectBuffer(JSContext* cx, JSObject* obj, uint32_t count)
      52             : {
      53       10687 :     if (cx->helperThread())
      54          93 :         return cx->zone()->pod_malloc<T>(count);
      55       10594 :     size_t nbytes = JS_ROUNDUP(count * sizeof(T), sizeof(Value));
      56       10594 :     T* buffer = static_cast<T*>(cx->nursery().allocateBuffer(obj, nbytes));
      57       10594 :     if (!buffer)
      58           0 :         ReportOutOfMemory(cx);
      59       10594 :     return buffer;
      60             : }
      61             : 
      62             : // If this returns null then the old buffer will be left alone.
      63             : template <typename T>
      64             : static inline T*
      65        6054 : ReallocateObjectBuffer(JSContext* cx, JSObject* obj, T* oldBuffer,
      66             :                        uint32_t oldCount, uint32_t newCount)
      67             : {
      68        6054 :     if (cx->helperThread())
      69          17 :         return obj->zone()->pod_realloc<T>(oldBuffer, oldCount, newCount);
      70        6037 :     T* buffer =  static_cast<T*>(cx->nursery().reallocateBuffer(obj, oldBuffer,
      71             :                                                                 oldCount * sizeof(T),
      72        6037 :                                                                 newCount * sizeof(T)));
      73        6037 :     if (!buffer)
      74           0 :         ReportOutOfMemory(cx);
      75        6037 :     return buffer;
      76             : }
      77             : 
      78             : static inline void
      79           3 : EvictAllNurseries(JSRuntime* rt, JS::gcreason::Reason reason = JS::gcreason::EVICT_NURSERY)
      80             : {
      81           3 :     rt->gc.evictNursery(reason);
      82           3 : }
      83             : 
      84             : } // namespace js
      85             : 
      86             : #endif /* gc_Nursery_inl_h */

Generated by: LCOV version 1.13