2013-01-28 00:35:12 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2013-04-17 00:47:10 +04:00
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2013-06-20 04:59:09 +04:00
|
|
|
#ifndef js_GCAPI_h
|
|
|
|
#define js_GCAPI_h
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2013-09-19 23:24:53 +04:00
|
|
|
#include "mozilla/NullPtr.h"
|
2013-09-26 02:19:08 +04:00
|
|
|
|
2013-06-28 04:37:29 +04:00
|
|
|
#include "js/HeapAPI.h"
|
2013-08-09 03:07:22 +04:00
|
|
|
#include "js/RootingAPI.h"
|
2013-08-18 02:50:18 +04:00
|
|
|
#include "js/Value.h"
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2014-05-19 14:09:55 +04:00
|
|
|
namespace js {
|
|
|
|
namespace gc {
|
|
|
|
class GCRuntime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-17 03:26:33 +04:00
|
|
|
typedef enum JSGCMode {
|
|
|
|
/* Perform only global GCs. */
|
|
|
|
JSGC_MODE_GLOBAL = 0,
|
|
|
|
|
|
|
|
/* Perform per-compartment GCs until too much garbage has accumulated. */
|
|
|
|
JSGC_MODE_COMPARTMENT = 1,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect in short time slices rather than all at once. Implies
|
|
|
|
* JSGC_MODE_COMPARTMENT.
|
|
|
|
*/
|
|
|
|
JSGC_MODE_INCREMENTAL = 2
|
|
|
|
} JSGCMode;
|
|
|
|
|
2013-01-28 00:35:12 +04:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
#define GCREASONS(D) \
|
|
|
|
/* Reasons internal to the JS engine */ \
|
|
|
|
D(API) \
|
|
|
|
D(MAYBEGC) \
|
2013-09-17 20:46:32 +04:00
|
|
|
D(DESTROY_RUNTIME) \
|
2013-01-28 00:35:12 +04:00
|
|
|
D(DESTROY_CONTEXT) \
|
|
|
|
D(LAST_DITCH) \
|
|
|
|
D(TOO_MUCH_MALLOC) \
|
|
|
|
D(ALLOC_TRIGGER) \
|
|
|
|
D(DEBUG_GC) \
|
|
|
|
D(TRANSPLANT) \
|
|
|
|
D(RESET) \
|
2013-03-14 21:26:06 +04:00
|
|
|
D(OUT_OF_NURSERY) \
|
|
|
|
D(EVICT_NURSERY) \
|
|
|
|
D(FULL_STORE_BUFFER) \
|
|
|
|
\
|
|
|
|
/* These are reserved for future use. */ \
|
|
|
|
D(RESERVED0) \
|
|
|
|
D(RESERVED1) \
|
|
|
|
D(RESERVED2) \
|
|
|
|
D(RESERVED3) \
|
|
|
|
D(RESERVED4) \
|
|
|
|
D(RESERVED5) \
|
|
|
|
D(RESERVED6) \
|
|
|
|
D(RESERVED7) \
|
|
|
|
D(RESERVED8) \
|
|
|
|
D(RESERVED9) \
|
|
|
|
D(RESERVED10) \
|
|
|
|
D(RESERVED11) \
|
|
|
|
D(RESERVED12) \
|
|
|
|
D(RESERVED13) \
|
|
|
|
D(RESERVED14) \
|
|
|
|
D(RESERVED15) \
|
|
|
|
D(RESERVED16) \
|
|
|
|
D(RESERVED17) \
|
|
|
|
D(RESERVED18) \
|
|
|
|
D(RESERVED19) \
|
2013-01-28 00:35:12 +04:00
|
|
|
\
|
|
|
|
/* Reasons from Firefox */ \
|
|
|
|
D(DOM_WINDOW_UTILS) \
|
|
|
|
D(COMPONENT_UTILS) \
|
|
|
|
D(MEM_PRESSURE) \
|
|
|
|
D(CC_WAITING) \
|
|
|
|
D(CC_FORCED) \
|
|
|
|
D(LOAD_END) \
|
|
|
|
D(POST_COMPARTMENT) \
|
|
|
|
D(PAGE_HIDE) \
|
|
|
|
D(NSJSCONTEXT_DESTROY) \
|
|
|
|
D(SET_NEW_DOCUMENT) \
|
|
|
|
D(SET_DOC_SHELL) \
|
|
|
|
D(DOM_UTILS) \
|
|
|
|
D(DOM_IPC) \
|
|
|
|
D(DOM_WORKER) \
|
|
|
|
D(INTER_SLICE_GC) \
|
|
|
|
D(REFRESH_FRAME) \
|
|
|
|
D(FULL_GC_TIMER) \
|
2013-03-19 04:37:24 +04:00
|
|
|
D(SHUTDOWN_CC) \
|
|
|
|
D(FINISH_LARGE_EVALUTE)
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
namespace gcreason {
|
|
|
|
|
|
|
|
/* GCReasons will end up looking like JSGC_MAYBEGC */
|
|
|
|
enum Reason {
|
|
|
|
#define MAKE_REASON(name) name,
|
|
|
|
GCREASONS(MAKE_REASON)
|
|
|
|
#undef MAKE_REASON
|
|
|
|
NO_REASON,
|
|
|
|
NUM_REASONS,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For telemetry, we want to keep a fixed max bucket size over time so we
|
|
|
|
* don't have to switch histograms. 100 is conservative; as of this writing
|
|
|
|
* there are 26. But the cost of extra buckets seems to be low while the
|
|
|
|
* cost of switching histograms is high.
|
|
|
|
*/
|
|
|
|
NUM_TELEMETRY_REASONS = 100
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace gcreason */
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Zone GC:
|
|
|
|
*
|
|
|
|
* SpiderMonkey's GC is capable of performing a collection on an arbitrary
|
|
|
|
* subset of the zones in the system. This allows an embedding to minimize
|
|
|
|
* collection time by only collecting zones that have run code recently,
|
|
|
|
* ignoring the parts of the heap that are unlikely to have changed.
|
|
|
|
*
|
|
|
|
* When triggering a GC using one of the functions below, it is first necessary
|
|
|
|
* to select the zones to be collected. To do this, you can call
|
|
|
|
* PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select
|
|
|
|
* all zones. Failing to select any zone is an error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Schedule the given zone to be collected as part of the next GC.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
2013-01-28 01:51:35 +04:00
|
|
|
PrepareZoneForGC(Zone *zone);
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Schedule all zones to be collected in the next GC.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
PrepareForFullGC(JSRuntime *rt);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* When performing an incremental GC, the zones that were selected for the
|
|
|
|
* previous incremental slice must be selected in subsequent slices as well.
|
|
|
|
* This function selects those slices automatically.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
PrepareForIncrementalGC(JSRuntime *rt);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Returns true if any zone in the system has been scheduled for GC with one of
|
|
|
|
* the functions above or by the JS engine.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsGCScheduled(JSRuntime *rt);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Undoes the effect of the Prepare methods above. The given zone will not be
|
|
|
|
* collected in the next GC.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
2013-01-28 01:51:35 +04:00
|
|
|
SkipZoneForGC(Zone *zone);
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
/*
|
2014-01-23 23:47:11 +04:00
|
|
|
* Non-Incremental GC:
|
|
|
|
*
|
|
|
|
* The following functions perform a non-incremental GC.
|
2013-01-28 00:35:12 +04:00
|
|
|
*/
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Performs a non-incremental collection of all selected zones. Some objects
|
|
|
|
* that are unreachable from the program may still be alive afterwards because
|
|
|
|
* of internal references.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
GCForReason(JSRuntime *rt, gcreason::Reason reason);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Perform a non-incremental collection after clearing caches and other
|
|
|
|
* temporary references to objects. This will remove all unreferenced objects
|
|
|
|
* in the system.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
ShrinkingGC(JSRuntime *rt, gcreason::Reason reason);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Incremental GC:
|
|
|
|
*
|
|
|
|
* Incremental GC divides the full mark-and-sweep collection into multiple
|
|
|
|
* slices, allowing client JavaScript code to run between each slice. This
|
|
|
|
* allows interactive apps to avoid long collection pauses. Incremental GC does
|
|
|
|
* not make collection take less time, it merely spreads that time out so that
|
|
|
|
* the pauses are less noticable.
|
|
|
|
*
|
|
|
|
* For a collection to be carried out incrementally the following conditions
|
|
|
|
* must be met:
|
|
|
|
* - The collection must be run by calling JS::IncrementalGC() rather than
|
|
|
|
* JS_GC().
|
|
|
|
* - The GC mode must have been set to JSGC_MODE_INCREMENTAL with
|
|
|
|
* JS_SetGCParameter().
|
|
|
|
* - All native objects that have their own trace hook must indicate that they
|
|
|
|
* implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS
|
|
|
|
* flag.
|
|
|
|
*
|
|
|
|
* Note: Even if incremental GC is enabled and working correctly,
|
|
|
|
* non-incremental collections can still happen when low on memory.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Begin an incremental collection and perform one slice worth of work or
|
|
|
|
* perform a slice of an ongoing incremental collection. When this function
|
|
|
|
* returns, the collection is not complete. This function must be called
|
|
|
|
* repeatedly until !IsIncrementalGCInProgress(rt).
|
|
|
|
*
|
|
|
|
* Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or
|
|
|
|
* shorter than the requested interval.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection
|
|
|
|
* by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt),
|
|
|
|
* this is equivalent to GCForReason. When this function returns,
|
|
|
|
* IsIncrementalGCInProgress(rt) will always be false.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason);
|
|
|
|
|
|
|
|
enum GCProgress {
|
|
|
|
/*
|
|
|
|
* During non-incremental GC, the GC is bracketed by JSGC_CYCLE_BEGIN/END
|
|
|
|
* callbacks. During an incremental GC, the sequence of callbacks is as
|
|
|
|
* follows:
|
|
|
|
* JSGC_CYCLE_BEGIN, JSGC_SLICE_END (first slice)
|
|
|
|
* JSGC_SLICE_BEGIN, JSGC_SLICE_END (second slice)
|
|
|
|
* ...
|
|
|
|
* JSGC_SLICE_BEGIN, JSGC_CYCLE_END (last slice)
|
|
|
|
*/
|
|
|
|
|
|
|
|
GC_CYCLE_BEGIN,
|
|
|
|
GC_SLICE_BEGIN,
|
|
|
|
GC_SLICE_END,
|
|
|
|
GC_CYCLE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
struct JS_FRIEND_API(GCDescription) {
|
2013-02-18 10:56:32 +04:00
|
|
|
bool isCompartment_;
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
GCDescription(bool isCompartment)
|
2013-02-18 10:56:32 +04:00
|
|
|
: isCompartment_(isCompartment) {}
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
jschar *formatMessage(JSRuntime *rt) const;
|
|
|
|
jschar *formatJSON(JSRuntime *rt, uint64_t timestamp) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void
|
|
|
|
(* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* The GC slice callback is called at the beginning and end of each slice. This
|
|
|
|
* callback may be used for GC notifications as well as to perform additional
|
|
|
|
* marking.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(GCSliceCallback)
|
|
|
|
SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback);
|
|
|
|
|
|
|
|
/*
|
2014-01-23 23:47:11 +04:00
|
|
|
* Incremental GC defaults to enabled, but may be disabled for testing or in
|
|
|
|
* embeddings that have not yet implemented barriers on their native classes.
|
|
|
|
* There is not currently a way to re-enable incremental GC once it has been
|
|
|
|
* disabled on the runtime.
|
2013-01-28 00:35:12 +04:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
2014-01-23 23:47:11 +04:00
|
|
|
DisableIncrementalGC(JSRuntime *rt);
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Returns true if incremental GC is enabled. Simply having incremental GC
|
|
|
|
* enabled is not sufficient to ensure incremental collections are happening.
|
|
|
|
* See the comment "Incremental GC" above for reasons why incremental GC may be
|
|
|
|
* suppressed. Inspection of the "nonincremental reason" field of the
|
|
|
|
* GCDescription returned by GCSliceCallback may help narrow down the cause if
|
|
|
|
* collections are not happening incrementally when expected.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsIncrementalGCEnabled(JSRuntime *rt);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Returns true while an incremental GC is ongoing, both when actively
|
|
|
|
* collecting and between slices.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
IsIncrementalGCInProgress(JSRuntime *rt);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Returns true when writes to GC things must call an incremental (pre) barrier.
|
|
|
|
* This is generally only true when running mutator code in-between GC slices.
|
|
|
|
* At other times, the barrier may be elided for performance.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsIncrementalBarrierNeeded(JSRuntime *rt);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsIncrementalBarrierNeeded(JSContext *cx);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Notify the GC that a reference to a GC thing is about to be overwritten.
|
|
|
|
* These methods must be called if IsIncrementalBarrierNeeded.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
2013-01-29 06:25:23 +04:00
|
|
|
IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind);
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
IncrementalValueBarrier(const Value &v);
|
|
|
|
|
2013-01-29 06:25:23 +04:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
IncrementalObjectBarrier(JSObject *obj);
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Returns true if the most recent GC ran incrementally.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
WasIncrementalGC(JSRuntime *rt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generational GC:
|
|
|
|
*
|
2014-02-25 03:08:05 +04:00
|
|
|
* Note: Generational GC is not yet enabled by default. The following class
|
|
|
|
* is non-functional unless SpiderMonkey was configured with
|
2014-01-23 23:47:11 +04:00
|
|
|
* --enable-gcgenerational.
|
|
|
|
*/
|
|
|
|
|
2014-02-22 03:54:25 +04:00
|
|
|
/* Ensure that generational GC is disabled within some scope. */
|
|
|
|
class JS_FRIEND_API(AutoDisableGenerationalGC)
|
|
|
|
{
|
2014-05-19 14:09:55 +04:00
|
|
|
js::gc::GCRuntime *gc;
|
2014-03-01 00:51:08 +04:00
|
|
|
#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL)
|
2014-02-25 03:08:05 +04:00
|
|
|
bool restartVerifier;
|
|
|
|
#endif
|
2014-02-22 03:54:25 +04:00
|
|
|
|
|
|
|
public:
|
2014-02-25 03:08:05 +04:00
|
|
|
AutoDisableGenerationalGC(JSRuntime *rt);
|
|
|
|
~AutoDisableGenerationalGC();
|
2014-02-22 03:54:25 +04:00
|
|
|
};
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Returns true if generational allocation and collection is currently enabled
|
|
|
|
* on the given runtime.
|
|
|
|
*/
|
2013-01-28 00:35:12 +04:00
|
|
|
extern JS_FRIEND_API(bool)
|
2014-01-23 23:47:11 +04:00
|
|
|
IsGenerationalGCEnabled(JSRuntime *rt);
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Returns the GC's "number". This does not correspond directly to the number
|
|
|
|
* of GCs that have been run, but is guaranteed to be monotonically increasing
|
|
|
|
* with GC activity.
|
|
|
|
*/
|
2013-09-17 21:50:03 +04:00
|
|
|
extern JS_FRIEND_API(size_t)
|
|
|
|
GetGCNumber();
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* The GC does not immediately return the unused memory freed by a collection
|
|
|
|
* back to the system incase it is needed soon afterwards. This call forces the
|
|
|
|
* GC to return this memory immediately.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
ShrinkGCBuffers(JSRuntime *rt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assert if any GC occured while this guard object was live. This is most
|
|
|
|
* useful to help the exact rooting hazard analysis in complex regions, since
|
|
|
|
* it cannot understand dataflow.
|
|
|
|
*
|
|
|
|
* Note: GC behavior is unpredictable even when deterministice and is generally
|
|
|
|
* non-deterministic in practice. The fact that this guard has not
|
|
|
|
* asserted is not a guarantee that a GC cannot happen in the guarded
|
|
|
|
* region. As a rule, anyone performing a GC unsafe action should
|
|
|
|
* understand the GC properties of all code in that region and ensure
|
|
|
|
* that the hazard analysis is correct for that code, rather than relying
|
|
|
|
* on this class.
|
|
|
|
*/
|
2013-11-06 03:02:35 +04:00
|
|
|
class JS_PUBLIC_API(AutoAssertNoGC)
|
|
|
|
{
|
2013-12-07 03:03:08 +04:00
|
|
|
#ifdef JS_DEBUG
|
2013-11-07 03:43:19 +04:00
|
|
|
JSRuntime *runtime;
|
2013-09-17 21:50:03 +04:00
|
|
|
size_t gcNumber;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoAssertNoGC();
|
2013-11-07 03:43:19 +04:00
|
|
|
AutoAssertNoGC(JSRuntime *rt);
|
2013-09-17 21:50:03 +04:00
|
|
|
~AutoAssertNoGC();
|
2013-11-06 03:02:35 +04:00
|
|
|
#else
|
|
|
|
public:
|
|
|
|
/* Prevent unreferenced local warnings in opt builds. */
|
|
|
|
AutoAssertNoGC() {}
|
2013-11-07 03:43:19 +04:00
|
|
|
AutoAssertNoGC(JSRuntime *) {}
|
2013-09-17 21:50:03 +04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-08-18 02:50:18 +04:00
|
|
|
class JS_PUBLIC_API(ObjectPtr)
|
2013-01-28 00:35:12 +04:00
|
|
|
{
|
2013-06-06 03:40:02 +04:00
|
|
|
Heap<JSObject *> value;
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
public:
|
2013-09-19 23:24:53 +04:00
|
|
|
ObjectPtr() : value(nullptr) {}
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
ObjectPtr(JSObject *obj) : value(obj) {}
|
|
|
|
|
|
|
|
/* Always call finalize before the destructor. */
|
2014-02-18 10:24:15 +04:00
|
|
|
~ObjectPtr() { MOZ_ASSERT(!value); }
|
2013-01-28 00:35:12 +04:00
|
|
|
|
|
|
|
void finalize(JSRuntime *rt) {
|
|
|
|
if (IsIncrementalBarrierNeeded(rt))
|
2013-01-29 06:25:23 +04:00
|
|
|
IncrementalObjectBarrier(value);
|
2013-09-19 23:24:53 +04:00
|
|
|
value = nullptr;
|
2013-01-28 00:35:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void init(JSObject *obj) { value = obj; }
|
|
|
|
|
|
|
|
JSObject *get() const { return value; }
|
|
|
|
|
|
|
|
void writeBarrierPre(JSRuntime *rt) {
|
2013-01-29 06:25:23 +04:00
|
|
|
IncrementalObjectBarrier(value);
|
2013-01-28 00:35:12 +04:00
|
|
|
}
|
|
|
|
|
2013-08-18 02:50:18 +04:00
|
|
|
bool isAboutToBeFinalized();
|
2013-03-29 00:27:29 +04:00
|
|
|
|
2013-01-28 00:35:12 +04:00
|
|
|
ObjectPtr &operator=(JSObject *obj) {
|
2013-01-29 06:25:23 +04:00
|
|
|
IncrementalObjectBarrier(value);
|
2013-01-28 00:35:12 +04:00
|
|
|
value = obj;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-08-18 02:50:18 +04:00
|
|
|
void trace(JSTracer *trc, const char *name);
|
2013-03-29 00:37:22 +04:00
|
|
|
|
2013-01-28 00:35:12 +04:00
|
|
|
JSObject &operator*() const { return *value; }
|
|
|
|
JSObject *operator->() const { return value; }
|
|
|
|
operator JSObject *() const { return value; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unsets the gray bit for anything reachable from |thing|. |kind| should not be
|
|
|
|
* JSTRACE_SHAPE. |thing| should be non-null.
|
|
|
|
*/
|
2013-08-19 17:48:35 +04:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-01-28 00:35:12 +04:00
|
|
|
UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This should be called when an object that is marked gray is exposed to the JS
|
|
|
|
* engine (by handing it to running JS code or writing it into live JS
|
|
|
|
* data). During incremental GC, since the gray bits haven't been computed yet,
|
|
|
|
* we conservatively mark the object black.
|
|
|
|
*/
|
2014-01-25 08:14:56 +04:00
|
|
|
static MOZ_ALWAYS_INLINE void
|
2013-01-28 00:35:12 +04:00
|
|
|
ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind)
|
|
|
|
{
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(kind != JSTRACE_SHAPE);
|
2013-01-28 00:35:12 +04:00
|
|
|
|
2013-04-02 02:31:49 +04:00
|
|
|
shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing);
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
/*
|
|
|
|
* GC things residing in the nursery cannot be gray: they have no mark bits.
|
|
|
|
* All live objects in the nursery are moved to tenured at the beginning of
|
|
|
|
* each GC slice, so the gray marker never sees nursery things.
|
|
|
|
*/
|
2014-05-15 06:48:09 +04:00
|
|
|
if (js::gc::IsInsideNursery((js::gc::Cell *)thing))
|
2013-04-02 02:31:49 +04:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind))
|
2013-01-29 06:25:23 +04:00
|
|
|
IncrementalReferenceBarrier(thing, kind);
|
2013-04-02 02:31:49 +04:00
|
|
|
else if (GCThingIsMarkedGray(thing))
|
|
|
|
UnmarkGrayGCThingRecursively(thing, kind);
|
2013-01-28 00:35:12 +04:00
|
|
|
}
|
|
|
|
|
2014-01-25 08:14:56 +04:00
|
|
|
static MOZ_ALWAYS_INLINE void
|
2013-01-28 00:35:12 +04:00
|
|
|
ExposeValueToActiveJS(const Value &v)
|
|
|
|
{
|
|
|
|
if (v.isMarkable())
|
|
|
|
ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind());
|
|
|
|
}
|
|
|
|
|
2014-01-25 08:14:56 +04:00
|
|
|
static MOZ_ALWAYS_INLINE void
|
2013-09-09 07:28:48 +04:00
|
|
|
ExposeObjectToActiveJS(JSObject *obj)
|
|
|
|
{
|
|
|
|
ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT);
|
|
|
|
}
|
|
|
|
|
2013-11-05 03:01:38 +04:00
|
|
|
/*
|
|
|
|
* If a GC is currently marking, mark the object black.
|
|
|
|
*/
|
2014-01-25 08:14:56 +04:00
|
|
|
static MOZ_ALWAYS_INLINE void
|
2013-11-05 03:01:38 +04:00
|
|
|
MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind)
|
|
|
|
{
|
|
|
|
shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_);
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
/*
|
|
|
|
* Any object in the nursery will not be freed during any GC running at that time.
|
|
|
|
*/
|
2014-05-15 06:48:09 +04:00
|
|
|
if (js::gc::IsInsideNursery((js::gc::Cell *)thing))
|
2013-11-05 03:01:38 +04:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind))
|
|
|
|
IncrementalReferenceBarrier(thing, kind);
|
|
|
|
}
|
|
|
|
|
2014-01-25 08:14:56 +04:00
|
|
|
static MOZ_ALWAYS_INLINE void
|
2013-11-05 03:01:38 +04:00
|
|
|
MarkStringAsLive(Zone *zone, JSString *string)
|
|
|
|
{
|
|
|
|
JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread();
|
|
|
|
MarkGCThingAsLive(rt, string, JSTRACE_STRING);
|
|
|
|
}
|
|
|
|
|
2014-01-23 23:47:11 +04:00
|
|
|
/*
|
|
|
|
* Internal to Firefox.
|
|
|
|
*
|
|
|
|
* Note: this is not related to the PokeGC in nsJSEnvironment.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
PokeGC(JSRuntime *rt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal to Firefox.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
NotifyDidPaint(JSRuntime *rt);
|
|
|
|
|
2013-01-28 00:35:12 +04:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2013-06-20 04:59:09 +04:00
|
|
|
#endif /* js_GCAPI_h */
|