LCOV - code coverage report
Current view: top level - js/src/gc - DeletePolicy.h (source / functions) Hit Total Coverage
Test: output.info Lines: 2 9 22.2 %
Date: 2018-08-07 16:42:27 Functions: 0 0 -
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=8 sts=4 et sw=4 tw=99:
       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_DeletePolicy_h
       8             : #define gc_DeletePolicy_h
       9             : 
      10             : #include "gc/Barrier.h"
      11             : #include "js/TracingAPI.h"
      12             : #ifdef ENABLE_BIGINT
      13             : #include "vm/BigIntType.h"
      14             : #endif
      15             : 
      16             : namespace js {
      17             : namespace gc {
      18             : 
      19             : struct ClearEdgesTracer : public JS::CallbackTracer
      20             : {
      21             :     ClearEdgesTracer();
      22             : 
      23             : #ifdef DEBUG
      24           0 :     TracerKind getTracerKind() const override { return TracerKind::ClearEdges; }
      25             : #endif
      26             : 
      27             :     template <typename T>
      28             :     inline void clearEdge(T** thingp);
      29             : 
      30             :     void onObjectEdge(JSObject** objp) override;
      31             :     void onStringEdge(JSString** strp) override;
      32             :     void onSymbolEdge(JS::Symbol** symp) override;
      33             : #ifdef ENABLE_BIGINT
      34             :     void onBigIntEdge(JS::BigInt** bip) override;
      35             : #endif
      36             :     void onScriptEdge(JSScript** scriptp) override;
      37             :     void onShapeEdge(js::Shape** shapep) override;
      38             :     void onObjectGroupEdge(js::ObjectGroup** groupp) override;
      39             :     void onBaseShapeEdge(js::BaseShape** basep) override;
      40             :     void onJitCodeEdge(js::jit::JitCode** codep) override;
      41             :     void onLazyScriptEdge(js::LazyScript** lazyp) override;
      42             :     void onScopeEdge(js::Scope** scopep) override;
      43             :     void onRegExpSharedEdge(js::RegExpShared** sharedp) override;
      44             :     void onChild(const JS::GCCellPtr& thing) override;
      45             : };
      46             : 
      47             : #ifdef DEBUG
      48             : inline bool
      49          72 : IsClearEdgesTracer(JSTracer *trc)
      50             : {
      51           0 :     return trc->isCallbackTracer() &&
      52         144 :            trc->asCallbackTracer()->getTracerKind() == JS::CallbackTracer::TracerKind::ClearEdges;
      53             : }
      54             : #endif
      55             : 
      56             : } // namespace gc
      57             : 
      58             : /*
      59             :  * Provides a delete policy that can be used for objects which have their
      60             :  * lifetime managed by the GC so they can be safely destroyed outside of GC.
      61             :  *
      62             :  * This is necessary for example when initializing such an object may fail after
      63             :  * the initial allocation. The partially-initialized object must be destroyed,
      64             :  * but it may not be safe to do so at the current time as the store buffer may
      65             :  * contain pointers into it.
      66             :  *
      67             :  * This policy traces GC pointers in the object and clears them, making sure to
      68             :  * trigger barriers while doing so. This will remove any store buffer pointers
      69             :  * into the object and make it safe to delete.
      70             :  */
      71             : template <typename T>
      72             : struct GCManagedDeletePolicy
      73             : {
      74           0 :     void operator()(const T* constPtr) {
      75           0 :         if (constPtr) {
      76           0 :             auto ptr = const_cast<T*>(constPtr);
      77           0 :             if (JS::RuntimeHeapIsCollecting()) {
      78           0 :                 MOZ_ASSERT(js::CurrentThreadIsGCSweeping());
      79             :                 // Do not attempt to clear out storebuffer edges.
      80             :             } else {
      81             :                 gc::ClearEdgesTracer trc;
      82             :                 ptr->trace(&trc);
      83             :             }
      84             :             js_delete(ptr);
      85             :         }
      86             :     }
      87             : };
      88             : 
      89             : } // namespace js
      90             : 
      91             : #endif // gc_DeletePolicy_h

Generated by: LCOV version 1.13-14-ga5dd952