Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/js/src/gc/DeletePolicy.h
Line
Count
Source (jump to first uncovered line)
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 "js/TracingAPI.h"
11
12
#ifdef ENABLE_BIGINT
13
namespace JS {
14
class BigInt;
15
} // namespace JS
16
#endif
17
18
namespace js {
19
namespace gc {
20
21
struct ClearEdgesTracer : public JS::CallbackTracer
22
{
23
    ClearEdgesTracer();
24
25
#ifdef DEBUG
26
    TracerKind getTracerKind() const override { return TracerKind::ClearEdges; }
27
#endif
28
29
    template <typename T>
30
    inline void clearEdge(T** thingp);
31
32
    void onObjectEdge(JSObject** objp) override;
33
    void onStringEdge(JSString** strp) override;
34
    void onSymbolEdge(JS::Symbol** symp) override;
35
#ifdef ENABLE_BIGINT
36
    void onBigIntEdge(JS::BigInt** bip) override;
37
#endif
38
    void onScriptEdge(JSScript** scriptp) override;
39
    void onShapeEdge(js::Shape** shapep) override;
40
    void onObjectGroupEdge(js::ObjectGroup** groupp) override;
41
    void onBaseShapeEdge(js::BaseShape** basep) override;
42
    void onJitCodeEdge(js::jit::JitCode** codep) override;
43
    void onLazyScriptEdge(js::LazyScript** lazyp) override;
44
    void onScopeEdge(js::Scope** scopep) override;
45
    void onRegExpSharedEdge(js::RegExpShared** sharedp) override;
46
    void onChild(const JS::GCCellPtr& thing) override;
47
};
48
49
#ifdef DEBUG
50
inline bool
51
IsClearEdgesTracer(JSTracer *trc)
52
{
53
    return trc->isCallbackTracer() &&
54
           trc->asCallbackTracer()->getTracerKind() == JS::CallbackTracer::TracerKind::ClearEdges;
55
}
56
#endif
57
58
} // namespace gc
59
60
/*
61
 * Provides a delete policy that can be used for objects which have their
62
 * lifetime managed by the GC so they can be safely destroyed outside of GC.
63
 *
64
 * This is necessary for example when initializing such an object may fail after
65
 * the initial allocation. The partially-initialized object must be destroyed,
66
 * but it may not be safe to do so at the current time as the store buffer may
67
 * contain pointers into it.
68
 *
69
 * This policy traces GC pointers in the object and clears them, making sure to
70
 * trigger barriers while doing so. This will remove any store buffer pointers
71
 * into the object and make it safe to delete.
72
 */
73
template <typename T>
74
struct GCManagedDeletePolicy
75
{
76
0
    void operator()(const T* constPtr) {
77
0
        if (constPtr) {
78
0
            auto ptr = const_cast<T*>(constPtr);
79
0
            gc::ClearEdgesTracer trc;
80
0
            ptr->trace(&trc);
81
0
            js_delete(ptr);
82
0
        }
83
0
    }
Unexecuted instantiation: js::GCManagedDeletePolicy<js::UnboxedLayout>::operator()(js::UnboxedLayout const*)
Unexecuted instantiation: js::GCManagedDeletePolicy<js::ObjectValueMap>::operator()(js::ObjectValueMap const*)
Unexecuted instantiation: js::GCManagedDeletePolicy<js::Debugger>::operator()(js::Debugger const*)
Unexecuted instantiation: js::GCManagedDeletePolicy<js::FunctionScope::Data>::operator()(js::FunctionScope::Data const*)
Unexecuted instantiation: js::GCManagedDeletePolicy<js::ModuleScope::Data>::operator()(js::ModuleScope::Data const*)
Unexecuted instantiation: js::GCManagedDeletePolicy<js::WasmInstanceScope::Data>::operator()(js::WasmInstanceScope::Data const*)
84
};
85
86
} // namespace js
87
88
#endif // gc_DeletePolicy_h