2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 18:39:55 +03:00
|
|
|
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
2013-04-17 00:47:10 +04:00
|
|
|
* 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/. */
|
2012-10-26 22:17:24 +04:00
|
|
|
|
2013-06-20 04:59:09 +04:00
|
|
|
#ifndef js_HeapAPI_h
|
|
|
|
#define js_HeapAPI_h
|
2012-10-26 22:17:24 +04:00
|
|
|
|
2013-10-08 17:54:33 +04:00
|
|
|
#include <limits.h>
|
|
|
|
|
2015-06-11 20:03:33 +03:00
|
|
|
#include "jspubtd.h"
|
|
|
|
|
|
|
|
#include "js/TraceKind.h"
|
2013-07-24 04:34:12 +04:00
|
|
|
#include "js/Utility.h"
|
|
|
|
|
2018-05-08 02:42:54 +03:00
|
|
|
struct JSStringFinalizer;
|
|
|
|
|
2012-10-26 22:18:50 +04:00
|
|
|
/* These values are private to the JS engine. */
|
2012-10-26 22:17:24 +04:00
|
|
|
namespace js {
|
2013-09-05 06:19:04 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_FRIEND_API bool CurrentThreadCanAccessZone(JS::Zone* zone);
|
2013-09-05 06:19:04 +04:00
|
|
|
|
2012-10-26 22:18:50 +04:00
|
|
|
namespace gc {
|
|
|
|
|
2014-04-26 12:30:04 +04:00
|
|
|
struct Cell;
|
|
|
|
|
2012-10-26 22:18:50 +04:00
|
|
|
const size_t ArenaShift = 12;
|
|
|
|
const size_t ArenaSize = size_t(1) << ArenaShift;
|
|
|
|
const size_t ArenaMask = ArenaSize - 1;
|
|
|
|
|
2014-07-15 12:42:47 +04:00
|
|
|
#ifdef JS_GC_SMALL_CHUNK_SIZE
|
|
|
|
const size_t ChunkShift = 18;
|
|
|
|
#else
|
2012-10-26 22:18:50 +04:00
|
|
|
const size_t ChunkShift = 20;
|
2014-07-15 12:42:47 +04:00
|
|
|
#endif
|
2012-10-26 22:18:50 +04:00
|
|
|
const size_t ChunkSize = size_t(1) << ChunkShift;
|
|
|
|
const size_t ChunkMask = ChunkSize - 1;
|
|
|
|
|
2017-05-09 13:38:32 +03:00
|
|
|
const size_t CellAlignShift = 3;
|
|
|
|
const size_t CellAlignBytes = size_t(1) << CellAlignShift;
|
|
|
|
const size_t CellAlignMask = CellAlignBytes - 1;
|
|
|
|
|
|
|
|
const size_t CellBytesPerMarkBit = CellAlignBytes;
|
2012-11-29 05:03:54 +04:00
|
|
|
|
2017-10-18 12:09:05 +03:00
|
|
|
/*
|
|
|
|
* We sometimes use an index to refer to a cell in an arena. The index for a
|
|
|
|
* cell is found by dividing by the cell alignment so not all indicies refer to
|
|
|
|
* valid cells.
|
|
|
|
*/
|
|
|
|
const size_t ArenaCellIndexBytes = CellAlignBytes;
|
|
|
|
const size_t MaxArenaCellIndex = ArenaSize / CellAlignBytes;
|
|
|
|
|
2012-11-29 05:03:54 +04:00
|
|
|
/* These are magic constants derived from actual offsets in gc/Heap.h. */
|
2014-07-15 12:42:47 +04:00
|
|
|
#ifdef JS_GC_SMALL_CHUNK_SIZE
|
|
|
|
const size_t ChunkMarkBitmapOffset = 258104;
|
|
|
|
const size_t ChunkMarkBitmapBits = 31744;
|
|
|
|
#else
|
2014-05-01 20:26:12 +04:00
|
|
|
const size_t ChunkMarkBitmapOffset = 1032352;
|
2012-11-29 05:03:54 +04:00
|
|
|
const size_t ChunkMarkBitmapBits = 129024;
|
2014-07-15 12:42:47 +04:00
|
|
|
#endif
|
2013-03-20 04:59:42 +04:00
|
|
|
const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*);
|
2015-08-20 20:35:22 +03:00
|
|
|
const size_t ChunkTrailerSize = 2 * sizeof(uintptr_t) + sizeof(uint64_t);
|
|
|
|
const size_t ChunkLocationOffset = ChunkSize - ChunkTrailerSize;
|
2018-02-06 03:22:22 +03:00
|
|
|
const size_t ChunkStoreBufferOffset =
|
|
|
|
ChunkSize - ChunkTrailerSize + sizeof(uint64_t);
|
2016-02-29 19:21:00 +03:00
|
|
|
const size_t ArenaZoneOffset = sizeof(size_t);
|
2016-06-21 17:30:34 +03:00
|
|
|
const size_t ArenaHeaderSize =
|
|
|
|
sizeof(size_t) + 2 * sizeof(uintptr_t) + sizeof(size_t) + sizeof(uintptr_t);
|
2012-11-29 05:03:54 +04:00
|
|
|
|
|
|
|
/*
|
2017-07-12 20:31:55 +03:00
|
|
|
* Live objects are marked black or gray. Everything reachable from a JS root is
|
|
|
|
* marked black. Objects marked gray are eligible for cycle collection.
|
|
|
|
*
|
|
|
|
* BlackBit: GrayOrBlackBit: Color:
|
2016-12-15 00:59:43 +03:00
|
|
|
* 0 0 white
|
|
|
|
* 0 1 gray
|
|
|
|
* 1 0 black
|
|
|
|
* 1 1 black
|
|
|
|
*/
|
|
|
|
enum class ColorBit : uint32_t { BlackBit = 0, GrayOrBlackBit = 1 };
|
|
|
|
|
2014-04-26 12:30:04 +04:00
|
|
|
/*
|
2016-08-11 19:14:56 +03:00
|
|
|
* The "location" field in the Chunk trailer is a enum indicating various roles
|
|
|
|
* of the chunk.
|
2014-04-26 12:30:04 +04:00
|
|
|
*/
|
2016-08-11 19:14:56 +03:00
|
|
|
enum class ChunkLocation : uint32_t {
|
|
|
|
Invalid = 0,
|
|
|
|
Nursery = 1,
|
|
|
|
TenuredHeap = 2
|
|
|
|
};
|
2014-04-26 12:30:04 +04:00
|
|
|
|
2014-05-15 06:48:09 +04:00
|
|
|
#ifdef JS_DEBUG
|
|
|
|
/* When downcasting, ensure we are actually the right type. */
|
2015-05-22 20:40:24 +03:00
|
|
|
extern JS_FRIEND_API void AssertGCThingHasType(js::gc::Cell* cell,
|
|
|
|
JS::TraceKind kind);
|
2014-05-15 06:48:09 +04:00
|
|
|
#else
|
2015-05-22 20:40:24 +03:00
|
|
|
inline void AssertGCThingHasType(js::gc::Cell* cell, JS::TraceKind kind) {}
|
2014-05-15 06:48:09 +04:00
|
|
|
#endif
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
MOZ_ALWAYS_INLINE bool IsInsideNursery(const js::gc::Cell* cell);
|
2014-12-05 20:38:32 +03:00
|
|
|
|
2012-10-26 22:18:50 +04:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
|
|
|
|
2013-01-28 00:37:18 +04:00
|
|
|
namespace JS {
|
2017-11-16 15:21:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This list enumerates the different types of conceptual stacks we have in
|
|
|
|
* SpiderMonkey. In reality, they all share the C stack, but we allow different
|
|
|
|
* stack limits depending on the type of code running.
|
|
|
|
*/
|
|
|
|
enum StackKind {
|
|
|
|
StackForSystemCode, // C++, such as the GC, running on behalf of the VM.
|
|
|
|
StackForTrustedScript, // Script running with trusted principals.
|
|
|
|
StackForUntrustedScript, // Script running with untrusted principals.
|
|
|
|
StackKindCount
|
|
|
|
};
|
2013-01-28 00:37:18 +04:00
|
|
|
|
2017-07-21 07:34:46 +03:00
|
|
|
/*
|
|
|
|
* Default size for the generational nursery in bytes.
|
|
|
|
* This is the initial nursery size, when running in the browser this is
|
|
|
|
* updated by JS_SetGCParameter().
|
|
|
|
*/
|
2014-11-20 02:01:54 +03:00
|
|
|
const uint32_t DefaultNurseryBytes = 16 * js::gc::ChunkSize;
|
2014-07-11 12:59:05 +04:00
|
|
|
|
2017-07-21 08:56:11 +03:00
|
|
|
/* Default maximum heap size in bytes to pass to JS_NewContext(). */
|
2014-07-16 13:01:20 +04:00
|
|
|
const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024;
|
|
|
|
|
2012-10-26 22:18:50 +04:00
|
|
|
namespace shadow {
|
|
|
|
|
2013-01-28 00:37:18 +04:00
|
|
|
struct Zone {
|
2017-04-26 13:18:39 +03:00
|
|
|
enum GCState : uint8_t { NoGC, Mark, MarkGray, Sweep, Finished, Compact };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-05 06:19:04 +04:00
|
|
|
protected:
|
2015-03-29 01:22:11 +03:00
|
|
|
JSRuntime* const runtime_;
|
|
|
|
JSTracer* const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|.
|
2017-04-30 15:42:34 +03:00
|
|
|
uint32_t needsIncrementalBarrier_;
|
2017-04-26 13:18:39 +03:00
|
|
|
GCState gcState_;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
Zone(JSRuntime* runtime, JSTracer* barrierTracerArg)
|
2013-09-05 06:19:04 +04:00
|
|
|
: runtime_(runtime),
|
|
|
|
barrierTracer_(barrierTracerArg),
|
2017-04-30 15:42:34 +03:00
|
|
|
needsIncrementalBarrier_(0),
|
2017-04-26 13:18:39 +03:00
|
|
|
gcState_(NoGC) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-26 13:18:39 +03:00
|
|
|
public:
|
2014-07-28 21:16:56 +04:00
|
|
|
bool needsIncrementalBarrier() const { return needsIncrementalBarrier_; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
JSTracer* barrierTracer() {
|
2014-07-28 21:16:56 +04:00
|
|
|
MOZ_ASSERT(needsIncrementalBarrier_);
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_));
|
2013-09-05 06:19:04 +04:00
|
|
|
return barrierTracer_;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-15 14:18:46 +03:00
|
|
|
JSRuntime* runtimeFromMainThread() const {
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_));
|
2013-09-05 06:19:04 +04:00
|
|
|
return runtime_;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-05 06:19:04 +04:00
|
|
|
// Note: Unrestricted access to the zone's runtime from an arbitrary
|
|
|
|
// thread can easily lead to races. Use this method very carefully.
|
2015-03-29 01:22:11 +03:00
|
|
|
JSRuntime* runtimeFromAnyThread() const { return runtime_; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-26 13:18:39 +03:00
|
|
|
GCState gcState() const { return gcState_; }
|
|
|
|
bool wasGCStarted() const { return gcState_ != NoGC; }
|
2017-06-02 12:32:37 +03:00
|
|
|
bool isGCMarkingBlack() const { return gcState_ == Mark; }
|
|
|
|
bool isGCMarkingGray() const { return gcState_ == MarkGray; }
|
|
|
|
bool isGCSweeping() const { return gcState_ == Sweep; }
|
|
|
|
bool isGCFinished() const { return gcState_ == Finished; }
|
|
|
|
bool isGCCompacting() const { return gcState_ == Compact; }
|
2017-06-16 12:25:41 +03:00
|
|
|
bool isGCMarking() const { return gcState_ == Mark || gcState_ == MarkGray; }
|
2017-06-02 12:32:37 +03:00
|
|
|
bool isGCSweepingOrCompacting() const {
|
|
|
|
return gcState_ == Sweep || gcState_ == Compact;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-25 22:32:36 +03:00
|
|
|
static MOZ_ALWAYS_INLINE JS::shadow::Zone* asShadowZone(JS::Zone* zone) {
|
2013-09-05 06:19:04 +04:00
|
|
|
return reinterpret_cast<JS::shadow::Zone*>(zone);
|
|
|
|
}
|
2012-11-29 05:03:54 +04:00
|
|
|
};
|
|
|
|
|
2018-05-08 02:42:54 +03:00
|
|
|
struct String {
|
2018-08-02 21:32:16 +03:00
|
|
|
static const uint32_t NON_ATOM_BIT = JS_BIT(1);
|
|
|
|
static const uint32_t LINEAR_BIT = JS_BIT(4);
|
|
|
|
static const uint32_t INLINE_CHARS_BIT = JS_BIT(6);
|
|
|
|
static const uint32_t LATIN1_CHARS_BIT = JS_BIT(9);
|
|
|
|
static const uint32_t EXTERNAL_FLAGS = LINEAR_BIT | NON_ATOM_BIT | JS_BIT(8);
|
|
|
|
static const uint32_t TYPE_FLAGS_MASK = JS_BITMASK(9) - JS_BIT(2) - JS_BIT(0);
|
|
|
|
static const uint32_t PERMANENT_ATOM_MASK = NON_ATOM_BIT | JS_BIT(8);
|
2018-08-02 08:05:13 +03:00
|
|
|
static const uint32_t PERMANENT_ATOM_FLAGS = JS_BIT(8);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-02 21:32:16 +03:00
|
|
|
uintptr_t flags_;
|
|
|
|
#if JS_BITS_PER_WORD == 32
|
2018-08-02 08:05:13 +03:00
|
|
|
uint32_t length_;
|
2018-08-02 21:32:16 +03:00
|
|
|
#endif
|
2018-05-08 02:42:54 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
union {
|
2018-05-08 02:42:54 +03:00
|
|
|
const JS::Latin1Char* nonInlineCharsLatin1;
|
|
|
|
const char16_t* nonInlineCharsTwoByte;
|
|
|
|
JS::Latin1Char inlineStorageLatin1[1];
|
|
|
|
char16_t inlineStorageTwoByte[1];
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2018-05-08 02:42:54 +03:00
|
|
|
const JSStringFinalizer* externalFinalizer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-02 08:05:13 +03:00
|
|
|
inline uint32_t flags() const { return uint32_t(flags_); }
|
|
|
|
inline uint32_t length() const {
|
2018-08-02 21:32:16 +03:00
|
|
|
#if JS_BITS_PER_WORD == 32
|
2014-07-28 21:16:56 +04:00
|
|
|
return length_;
|
2018-11-30 13:46:48 +03:00
|
|
|
#else
|
2018-08-02 21:32:16 +03:00
|
|
|
return uint32_t(flags_ >> 32);
|
2018-11-30 13:46:48 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-08 02:42:54 +03:00
|
|
|
static bool isPermanentAtom(const js::gc::Cell* cell) {
|
2018-08-02 08:05:13 +03:00
|
|
|
uint32_t flags = reinterpret_cast<const String*>(cell)->flags();
|
2018-05-08 02:42:54 +03:00
|
|
|
return (flags & PERMANENT_ATOM_MASK) == PERMANENT_ATOM_FLAGS;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-11 08:02:59 +03:00
|
|
|
struct Symbol {
|
2018-08-23 04:34:37 +03:00
|
|
|
void* _1;
|
2018-05-11 08:02:59 +03:00
|
|
|
uint32_t code_;
|
|
|
|
static const uint32_t WellKnownAPILimit = 0x80000000;
|
|
|
|
|
|
|
|
static bool isWellKnownSymbol(const js::gc::Cell* cell) {
|
|
|
|
return reinterpret_cast<const Symbol*>(cell)->code_ < WellKnownAPILimit;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-26 22:18:50 +04:00
|
|
|
} /* namespace shadow */
|
2014-12-02 01:49:21 +03:00
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/**
|
|
|
|
* A GC pointer, tagged with the trace kind.
|
|
|
|
*
|
|
|
|
* In general, a GC pointer should be stored with an exact type. This class
|
|
|
|
* is for use when that is not possible because a single pointer must point
|
|
|
|
* to several kinds of GC thing.
|
|
|
|
*/
|
2018-11-19 20:02:47 +03:00
|
|
|
class JS_FRIEND_API GCCellPtr {
|
2014-12-02 01:49:21 +03:00
|
|
|
public:
|
|
|
|
// Construction from a void* and trace kind.
|
2015-05-22 20:40:24 +03:00
|
|
|
GCCellPtr(void* gcthing, JS::TraceKind traceKind)
|
|
|
|
: ptr(checkedCast(gcthing, traceKind)) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-14 00:07:34 +03:00
|
|
|
// Automatically construct a null GCCellPtr from nullptr.
|
2015-05-22 20:40:24 +03:00
|
|
|
MOZ_IMPLICIT GCCellPtr(decltype(nullptr))
|
|
|
|
: ptr(checkedCast(nullptr, JS::TraceKind::Null)) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-02 01:49:21 +03:00
|
|
|
// Construction from an explicit type.
|
2015-07-04 01:06:23 +03:00
|
|
|
template <typename T>
|
2015-07-29 19:31:47 +03:00
|
|
|
explicit GCCellPtr(T* p)
|
|
|
|
: ptr(checkedCast(p, JS::MapTypeToTraceKind<T>::kind)) {}
|
|
|
|
explicit GCCellPtr(JSFunction* p)
|
|
|
|
: ptr(checkedCast(p, JS::TraceKind::Object)) {}
|
2015-05-22 20:40:24 +03:00
|
|
|
explicit GCCellPtr(JSFlatString* str)
|
|
|
|
: ptr(checkedCast(str, JS::TraceKind::String)) {}
|
2015-03-29 01:22:11 +03:00
|
|
|
explicit GCCellPtr(const Value& v);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-22 20:40:24 +03:00
|
|
|
JS::TraceKind kind() const {
|
|
|
|
JS::TraceKind traceKind = JS::TraceKind(ptr & OutOfLineTraceKindMask);
|
2018-09-06 13:11:07 +03:00
|
|
|
if (uintptr_t(traceKind) != OutOfLineTraceKindMask) {
|
2014-12-02 01:49:21 +03:00
|
|
|
return traceKind;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2014-12-02 01:49:21 +03:00
|
|
|
return outOfLineKind();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-02 09:34:25 +03:00
|
|
|
// Allow GCCellPtr to be used in a boolean context.
|
2015-02-03 19:52:36 +03:00
|
|
|
explicit operator bool() const {
|
2015-05-22 20:40:24 +03:00
|
|
|
MOZ_ASSERT(bool(asCell()) == (kind() != JS::TraceKind::Null));
|
2015-02-03 19:52:36 +03:00
|
|
|
return asCell();
|
2014-12-02 09:34:25 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-02 02:06:37 +03:00
|
|
|
// Simplify checks to the kind.
|
2015-07-04 01:06:23 +03:00
|
|
|
template <typename T>
|
|
|
|
bool is() const {
|
|
|
|
return kind() == JS::MapTypeToTraceKind<T>::kind;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-02 01:49:21 +03:00
|
|
|
// Conversions to more specific types must match the kind. Access to
|
|
|
|
// further refined types is not allowed directly from a GCCellPtr.
|
2015-07-04 01:06:23 +03:00
|
|
|
template <typename T>
|
2015-07-29 19:31:47 +03:00
|
|
|
T& as() const {
|
2015-07-04 01:06:23 +03:00
|
|
|
MOZ_ASSERT(kind() == JS::MapTypeToTraceKind<T>::kind);
|
|
|
|
// We can't use static_cast here, because the fact that JSObject
|
|
|
|
// inherits from js::gc::Cell is not part of the public API.
|
|
|
|
return *reinterpret_cast<T*>(asCell());
|
2014-12-02 02:06:37 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-04 01:06:23 +03:00
|
|
|
// Return a pointer to the cell this |GCCellPtr| refers to, or |nullptr|.
|
|
|
|
// (It would be more symmetrical with |to| for this to return a |Cell&|, but
|
|
|
|
// the result can be |nullptr|, and null references are undefined behavior.)
|
2015-03-29 01:22:11 +03:00
|
|
|
js::gc::Cell* asCell() const {
|
2015-05-22 20:40:24 +03:00
|
|
|
return reinterpret_cast<js::gc::Cell*>(ptr & ~OutOfLineTraceKindMask);
|
2014-12-02 09:34:25 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-05 20:38:32 +03:00
|
|
|
// The CC's trace logger needs an identity that is XPIDL serializable.
|
|
|
|
uint64_t unsafeAsInteger() const {
|
2015-01-10 02:42:42 +03:00
|
|
|
return static_cast<uint64_t>(unsafeAsUIntPtr());
|
2014-12-05 20:38:32 +03:00
|
|
|
}
|
2014-12-05 20:38:33 +03:00
|
|
|
// Inline mark bitmap access requires direct pointer arithmetic.
|
|
|
|
uintptr_t unsafeAsUIntPtr() const {
|
2015-01-10 02:42:42 +03:00
|
|
|
MOZ_ASSERT(asCell());
|
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(asCell()));
|
|
|
|
return reinterpret_cast<uintptr_t>(asCell());
|
2014-12-05 20:38:33 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-25 16:07:55 +03:00
|
|
|
MOZ_ALWAYS_INLINE bool mayBeOwnedByOtherRuntime() const {
|
2018-09-06 13:11:07 +03:00
|
|
|
if (!is<JSString>() && !is<JS::Symbol>()) {
|
2018-05-08 02:42:54 +03:00
|
|
|
return false;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
|
|
|
if (is<JSString>()) {
|
2018-05-08 02:42:54 +03:00
|
|
|
return JS::shadow::String::isPermanentAtom(asCell());
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2018-05-11 08:02:59 +03:00
|
|
|
MOZ_ASSERT(is<JS::Symbol>());
|
|
|
|
return JS::shadow::Symbol::isWellKnownSymbol(asCell());
|
2017-04-25 16:07:55 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-02 01:49:21 +03:00
|
|
|
private:
|
2015-05-22 20:40:24 +03:00
|
|
|
static uintptr_t checkedCast(void* p, JS::TraceKind traceKind) {
|
2015-03-29 01:22:11 +03:00
|
|
|
js::gc::Cell* cell = static_cast<js::gc::Cell*>(p);
|
2015-05-22 20:40:24 +03:00
|
|
|
MOZ_ASSERT((uintptr_t(p) & OutOfLineTraceKindMask) == 0);
|
2014-12-02 01:49:21 +03:00
|
|
|
AssertGCThingHasType(cell, traceKind);
|
2015-05-22 20:40:24 +03:00
|
|
|
// Note: the OutOfLineTraceKindMask bits are set on all out-of-line kinds
|
2014-12-02 01:49:21 +03:00
|
|
|
// so that we can mask instead of branching.
|
2015-05-22 20:40:24 +03:00
|
|
|
MOZ_ASSERT_IF(uintptr_t(traceKind) >= OutOfLineTraceKindMask,
|
|
|
|
(uintptr_t(traceKind) & OutOfLineTraceKindMask) ==
|
|
|
|
OutOfLineTraceKindMask);
|
|
|
|
return uintptr_t(p) | (uintptr_t(traceKind) & OutOfLineTraceKindMask);
|
2014-12-02 01:49:21 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-25 16:07:55 +03:00
|
|
|
bool mayBeOwnedByOtherRuntimeSlow() const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-22 20:40:24 +03:00
|
|
|
JS::TraceKind outOfLineKind() const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-02 01:49:21 +03:00
|
|
|
uintptr_t ptr;
|
|
|
|
};
|
|
|
|
|
2015-09-17 20:57:55 +03:00
|
|
|
// Unwraps the given GCCellPtr and calls the given functor with a template
|
|
|
|
// argument of the actual type of the pointer.
|
|
|
|
template <typename F, typename... Args>
|
|
|
|
auto DispatchTyped(F f, GCCellPtr thing, Args&&... args)
|
2018-06-01 19:30:30 +03:00
|
|
|
-> decltype(f(static_cast<JSObject*>(nullptr),
|
|
|
|
std::forward<Args>(args)...)) {
|
2015-09-17 20:57:55 +03:00
|
|
|
switch (thing.kind()) {
|
|
|
|
#define JS_EXPAND_DEF(name, type, _) \
|
|
|
|
case JS::TraceKind::name: \
|
2018-06-01 19:30:30 +03:00
|
|
|
return f(&thing.as<type>(), std::forward<Args>(args)...);
|
2015-09-17 20:57:55 +03:00
|
|
|
JS_FOR_EACH_TRACEKIND(JS_EXPAND_DEF);
|
|
|
|
#undef JS_EXPAND_DEF
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Invalid trace kind in DispatchTyped for GCCellPtr.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-29 05:03:54 +04:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2018-05-18 23:43:14 +03:00
|
|
|
// These are defined in the toplevel namespace instead of within JS so that
|
|
|
|
// they won't shadow other operator== overloads (see bug 1456512.)
|
|
|
|
|
|
|
|
inline bool operator==(const JS::GCCellPtr& ptr1, const JS::GCCellPtr& ptr2) {
|
|
|
|
return ptr1.asCell() == ptr2.asCell();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const JS::GCCellPtr& ptr1, const JS::GCCellPtr& ptr2) {
|
|
|
|
return !(ptr1 == ptr2);
|
|
|
|
}
|
|
|
|
|
2012-11-29 05:03:54 +04:00
|
|
|
namespace js {
|
|
|
|
namespace gc {
|
2014-12-05 20:38:33 +03:00
|
|
|
namespace detail {
|
2012-11-29 05:03:54 +04:00
|
|
|
|
2014-12-05 20:38:33 +03:00
|
|
|
static MOZ_ALWAYS_INLINE uintptr_t* GetGCThingMarkBitmap(const uintptr_t addr) {
|
2017-11-22 11:40:00 +03:00
|
|
|
// Note: the JIT pre-barrier trampolines inline this code. Update that
|
|
|
|
// code too when making changes here!
|
2014-12-05 20:38:33 +03:00
|
|
|
MOZ_ASSERT(addr);
|
|
|
|
const uintptr_t bmap_addr = (addr & ~ChunkMask) | ChunkMarkBitmapOffset;
|
2015-03-29 01:22:11 +03:00
|
|
|
return reinterpret_cast<uintptr_t*>(bmap_addr);
|
2012-11-29 05:03:54 +04:00
|
|
|
}
|
2012-10-26 22:18:50 +04:00
|
|
|
|
2016-12-15 00:59:43 +03:00
|
|
|
static MOZ_ALWAYS_INLINE void GetGCThingMarkWordAndMask(const uintptr_t addr,
|
|
|
|
ColorBit colorBit,
|
2015-03-29 01:22:11 +03:00
|
|
|
uintptr_t** wordp,
|
|
|
|
uintptr_t* maskp) {
|
2017-11-22 11:40:00 +03:00
|
|
|
// Note: the JIT pre-barrier trampolines inline this code. Update that
|
|
|
|
// code too when making changes here!
|
2014-12-05 20:38:33 +03:00
|
|
|
MOZ_ASSERT(addr);
|
2016-12-15 00:59:43 +03:00
|
|
|
const size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellBytesPerMarkBit +
|
|
|
|
static_cast<uint32_t>(colorBit);
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits);
|
2015-03-29 01:22:11 +03:00
|
|
|
uintptr_t* bitmap = GetGCThingMarkBitmap(addr);
|
2013-10-08 17:54:33 +04:00
|
|
|
const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT;
|
|
|
|
*maskp = uintptr_t(1) << (bit % nbits);
|
|
|
|
*wordp = &bitmap[bit / nbits];
|
2012-11-29 05:03:54 +04:00
|
|
|
}
|
|
|
|
|
2014-12-14 19:27:51 +03:00
|
|
|
static MOZ_ALWAYS_INLINE JS::Zone* GetGCThingZone(const uintptr_t addr) {
|
2014-12-05 20:38:33 +03:00
|
|
|
MOZ_ASSERT(addr);
|
2014-12-14 19:27:51 +03:00
|
|
|
const uintptr_t zone_addr = (addr & ~ArenaMask) | ArenaZoneOffset;
|
2015-03-29 01:22:11 +03:00
|
|
|
return *reinterpret_cast<JS::Zone**>(zone_addr);
|
2012-10-26 22:18:50 +04:00
|
|
|
}
|
2012-10-26 22:17:24 +04:00
|
|
|
|
2017-04-25 16:07:55 +03:00
|
|
|
static MOZ_ALWAYS_INLINE bool TenuredCellIsMarkedGray(const Cell* cell) {
|
2016-12-15 00:59:43 +03:00
|
|
|
// Return true if GrayOrBlackBit is set and BlackBit is not set.
|
2014-12-05 20:38:34 +03:00
|
|
|
MOZ_ASSERT(cell);
|
2017-04-25 16:07:55 +03:00
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(cell));
|
2016-12-15 00:59:43 +03:00
|
|
|
|
|
|
|
uintptr_t *grayWord, grayMask;
|
|
|
|
js::gc::detail::GetGCThingMarkWordAndMask(
|
|
|
|
uintptr_t(cell), js::gc::ColorBit::GrayOrBlackBit, &grayWord, &grayMask);
|
2018-09-06 13:11:07 +03:00
|
|
|
if (!(*grayWord & grayMask)) {
|
2016-12-15 00:59:43 +03:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-12-15 00:59:43 +03:00
|
|
|
uintptr_t *blackWord, blackMask;
|
|
|
|
js::gc::detail::GetGCThingMarkWordAndMask(
|
|
|
|
uintptr_t(cell), js::gc::ColorBit::BlackBit, &blackWord, &blackMask);
|
|
|
|
return !(*blackWord & blackMask);
|
2014-12-05 20:38:34 +03:00
|
|
|
}
|
|
|
|
|
2017-04-25 16:07:55 +03:00
|
|
|
static MOZ_ALWAYS_INLINE bool CellIsMarkedGray(const Cell* cell) {
|
|
|
|
MOZ_ASSERT(cell);
|
2018-09-06 13:11:07 +03:00
|
|
|
if (js::gc::IsInsideNursery(cell)) {
|
2017-04-25 16:07:55 +03:00
|
|
|
return false;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2017-04-25 16:07:55 +03:00
|
|
|
return TenuredCellIsMarkedGray(cell);
|
|
|
|
}
|
|
|
|
|
2017-01-31 13:15:17 +03:00
|
|
|
extern JS_PUBLIC_API bool CellIsMarkedGrayIfKnown(const Cell* cell);
|
2017-01-06 14:23:21 +03:00
|
|
|
|
2017-03-02 13:22:47 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
extern JS_PUBLIC_API bool CellIsNotGray(const Cell* cell);
|
2018-02-16 14:40:04 +03:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API bool ObjectIsMarkedBlack(const JSObject* obj);
|
2017-03-02 13:22:47 +03:00
|
|
|
#endif
|
|
|
|
|
2017-09-19 14:31:31 +03:00
|
|
|
MOZ_ALWAYS_INLINE ChunkLocation GetCellLocation(const void* cell) {
|
|
|
|
uintptr_t addr = uintptr_t(cell);
|
|
|
|
addr &= ~js::gc::ChunkMask;
|
|
|
|
addr |= js::gc::ChunkLocationOffset;
|
|
|
|
return *reinterpret_cast<ChunkLocation*>(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ALWAYS_INLINE bool NurseryCellHasStoreBuffer(const void* cell) {
|
|
|
|
uintptr_t addr = uintptr_t(cell);
|
|
|
|
addr &= ~js::gc::ChunkMask;
|
|
|
|
addr |= js::gc::ChunkStoreBufferOffset;
|
|
|
|
return *reinterpret_cast<void**>(addr) != nullptr;
|
|
|
|
}
|
|
|
|
|
2014-12-05 20:38:33 +03:00
|
|
|
} /* namespace detail */
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
MOZ_ALWAYS_INLINE bool IsInsideNursery(const js::gc::Cell* cell) {
|
2018-09-06 13:11:07 +03:00
|
|
|
if (!cell) {
|
2014-04-26 12:30:04 +04:00
|
|
|
return false;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2017-09-19 14:31:31 +03:00
|
|
|
auto location = detail::GetCellLocation(cell);
|
2016-08-11 19:14:56 +03:00
|
|
|
MOZ_ASSERT(location == ChunkLocation::Nursery ||
|
|
|
|
location == ChunkLocation::TenuredHeap);
|
|
|
|
return location == ChunkLocation::Nursery;
|
2014-04-26 12:30:04 +04:00
|
|
|
}
|
|
|
|
|
2017-09-19 14:31:31 +03:00
|
|
|
MOZ_ALWAYS_INLINE bool IsCellPointerValid(const void* cell) {
|
|
|
|
auto addr = uintptr_t(cell);
|
2018-09-06 13:11:07 +03:00
|
|
|
if (addr < ChunkSize || addr % CellAlignBytes != 0) {
|
2017-09-19 14:31:31 +03:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-09-19 14:31:31 +03:00
|
|
|
auto location = detail::GetCellLocation(cell);
|
2018-09-06 13:11:07 +03:00
|
|
|
if (location == ChunkLocation::TenuredHeap) {
|
2017-09-19 14:31:31 +03:00
|
|
|
return !!detail::GetGCThingZone(addr);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-09-06 13:11:07 +03:00
|
|
|
if (location == ChunkLocation::Nursery) {
|
2017-09-19 14:31:31 +03:00
|
|
|
return detail::NurseryCellHasStoreBuffer(cell);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-09-19 14:31:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-26 12:23:14 +03:00
|
|
|
MOZ_ALWAYS_INLINE bool IsCellPointerValidOrNull(const void* cell) {
|
2018-09-06 13:11:07 +03:00
|
|
|
if (!cell) {
|
2017-09-26 12:23:14 +03:00
|
|
|
return true;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2017-09-26 12:23:14 +03:00
|
|
|
return IsCellPointerValid(cell);
|
|
|
|
}
|
|
|
|
|
2012-11-29 05:03:54 +04:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2015-06-02 00:11:08 +03:00
|
|
|
static MOZ_ALWAYS_INLINE Zone* GetTenuredGCThingZone(GCCellPtr thing) {
|
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(thing.asCell()));
|
|
|
|
return js::gc::detail::GetGCThingZone(thing.unsafeAsUIntPtr());
|
|
|
|
}
|
|
|
|
|
2017-07-30 23:21:53 +03:00
|
|
|
extern JS_PUBLIC_API Zone* GetNurseryStringZone(JSString* str);
|
|
|
|
|
|
|
|
static MOZ_ALWAYS_INLINE Zone* GetStringZone(JSString* str) {
|
2018-09-06 13:11:07 +03:00
|
|
|
if (!js::gc::IsInsideNursery(reinterpret_cast<js::gc::Cell*>(str))) {
|
2017-07-30 23:21:53 +03:00
|
|
|
return js::gc::detail::GetGCThingZone(reinterpret_cast<uintptr_t>(str));
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2017-07-30 23:21:53 +03:00
|
|
|
return GetNurseryStringZone(str);
|
|
|
|
}
|
2013-01-28 01:51:41 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
extern JS_PUBLIC_API Zone* GetObjectZone(JSObject* obj);
|
2013-01-28 01:51:41 +04:00
|
|
|
|
2014-12-05 20:38:34 +03:00
|
|
|
static MOZ_ALWAYS_INLINE bool GCThingIsMarkedGray(GCCellPtr thing) {
|
2018-09-06 13:11:07 +03:00
|
|
|
if (thing.mayBeOwnedByOtherRuntime()) {
|
2015-05-07 12:14:40 +03:00
|
|
|
return false;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2017-01-06 14:23:21 +03:00
|
|
|
return js::gc::detail::CellIsMarkedGrayIfKnown(thing.asCell());
|
2014-12-10 03:22:51 +03:00
|
|
|
}
|
|
|
|
|
2018-11-19 20:02:47 +03:00
|
|
|
extern JS_PUBLIC_API JS::TraceKind GCThingTraceKind(void* thing);
|
2016-04-30 04:10:07 +03:00
|
|
|
|
2017-11-04 00:00:14 +03:00
|
|
|
extern JS_PUBLIC_API void EnableNurseryStrings(JSContext* cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API void DisableNurseryStrings(JSContext* cx);
|
|
|
|
|
2017-11-16 15:21:07 +03:00
|
|
|
/*
|
|
|
|
* Returns true when writes to GC thing pointers (and reads from weak pointers)
|
|
|
|
* must call an incremental barrier. This is generally only true when running
|
|
|
|
* mutator code in-between GC slices. At other times, the barrier may be elided
|
|
|
|
* for performance.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API bool IsIncrementalBarrierNeeded(JSContext* cx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify the GC that a reference to a JSObject is about to be overwritten.
|
|
|
|
* This method must be called if IsIncrementalBarrierNeeded.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API void IncrementalPreWriteBarrier(JSObject* obj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify the GC that a weak reference to a GC thing has been read.
|
|
|
|
* This method must be called if IsIncrementalBarrierNeeded.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API void IncrementalReadBarrier(GCCellPtr thing);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unsets the gray bit for anything reachable from |thing|. |kind| should not be
|
|
|
|
* JS::TraceKind::Shape. |thing| should be non-null. The return value indicates
|
|
|
|
* if anything was unmarked.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API bool UnmarkGrayGCThingRecursively(GCCellPtr thing);
|
|
|
|
|
|
|
|
} // namespace JS
|
2014-05-20 01:58:05 +04:00
|
|
|
|
|
|
|
namespace js {
|
|
|
|
namespace gc {
|
|
|
|
|
2017-02-02 22:12:43 +03:00
|
|
|
static MOZ_ALWAYS_INLINE bool IsIncrementalBarrierNeededOnTenuredGCThing(
|
|
|
|
const JS::GCCellPtr thing) {
|
2014-07-29 21:47:43 +04:00
|
|
|
MOZ_ASSERT(thing);
|
2014-12-02 09:34:25 +03:00
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(thing.asCell()));
|
2016-11-04 20:32:36 +03:00
|
|
|
|
2018-06-16 01:05:06 +03:00
|
|
|
// TODO: I'd like to assert !RuntimeHeapIsBusy() here but this gets
|
2017-02-02 22:12:43 +03:00
|
|
|
// called while we are tracing the heap, e.g. during memory reporting
|
|
|
|
// (see bug 1313318).
|
2018-06-16 01:05:06 +03:00
|
|
|
MOZ_ASSERT(!JS::RuntimeHeapIsCollecting());
|
2016-11-04 20:32:36 +03:00
|
|
|
|
2015-06-02 00:11:08 +03:00
|
|
|
JS::Zone* zone = JS::GetTenuredGCThingZone(thing);
|
2014-05-20 01:58:05 +04:00
|
|
|
return JS::shadow::Zone::asShadowZone(zone)->needsIncrementalBarrier();
|
2012-11-29 05:03:54 +04:00
|
|
|
}
|
|
|
|
|
2017-11-16 15:21:07 +03:00
|
|
|
static MOZ_ALWAYS_INLINE void ExposeGCThingToActiveJS(JS::GCCellPtr thing) {
|
|
|
|
// 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.
|
2018-09-06 13:11:07 +03:00
|
|
|
if (IsInsideNursery(thing.asCell())) {
|
2017-11-16 15:21:07 +03:00
|
|
|
return;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-16 15:21:07 +03:00
|
|
|
// There's nothing to do for permanent GC things that might be owned by
|
|
|
|
// another runtime.
|
2018-09-06 13:11:07 +03:00
|
|
|
if (thing.mayBeOwnedByOtherRuntime()) {
|
2017-11-16 15:21:07 +03:00
|
|
|
return;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-06 13:11:07 +03:00
|
|
|
if (IsIncrementalBarrierNeededOnTenuredGCThing(thing)) {
|
2017-11-16 15:21:07 +03:00
|
|
|
JS::IncrementalReadBarrier(thing);
|
2018-09-06 13:11:07 +03:00
|
|
|
} else if (js::gc::detail::TenuredCellIsMarkedGray(thing.asCell())) {
|
2017-11-16 15:21:07 +03:00
|
|
|
JS::UnmarkGrayGCThingRecursively(thing);
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-16 15:21:07 +03:00
|
|
|
MOZ_ASSERT(!js::gc::detail::TenuredCellIsMarkedGray(thing.asCell()));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
extern JS_PUBLIC_API bool EdgeNeedsSweepUnbarrieredSlow(T* thingp);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-16 15:21:07 +03:00
|
|
|
static MOZ_ALWAYS_INLINE bool EdgeNeedsSweepUnbarriered(JSObject** objp) {
|
|
|
|
// This function does not handle updating nursery pointers. Raw JSObject
|
|
|
|
// pointers should be updated separately or replaced with
|
|
|
|
// JS::Heap<JSObject*> which handles this automatically.
|
2018-06-16 01:05:06 +03:00
|
|
|
MOZ_ASSERT(!JS::RuntimeHeapIsMinorCollecting());
|
2018-09-06 13:11:07 +03:00
|
|
|
if (IsInsideNursery(reinterpret_cast<Cell*>(*objp))) {
|
2017-11-16 15:21:07 +03:00
|
|
|
return false;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2017-11-16 15:21:07 +03:00
|
|
|
|
|
|
|
auto zone =
|
|
|
|
JS::shadow::Zone::asShadowZone(detail::GetGCThingZone(uintptr_t(*objp)));
|
2018-09-06 13:11:07 +03:00
|
|
|
if (!zone->isGCSweepingOrCompacting()) {
|
2017-11-16 15:21:07 +03:00
|
|
|
return false;
|
2018-09-06 13:11:07 +03:00
|
|
|
}
|
2017-11-16 15:21:07 +03:00
|
|
|
|
|
|
|
return EdgeNeedsSweepUnbarrieredSlow(objp);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gc
|
|
|
|
} // namespace js
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
2015-01-27 02:32:54 +03:00
|
|
|
*/
|
2017-11-16 15:21:07 +03:00
|
|
|
static MOZ_ALWAYS_INLINE void ExposeObjectToActiveJS(JSObject* obj) {
|
|
|
|
MOZ_ASSERT(obj);
|
|
|
|
MOZ_ASSERT(!js::gc::EdgeNeedsSweepUnbarrieredSlow(&obj));
|
|
|
|
js::gc::ExposeGCThingToActiveJS(GCCellPtr(obj));
|
|
|
|
}
|
2015-01-27 02:32:54 +03:00
|
|
|
|
2017-11-16 15:21:07 +03:00
|
|
|
static MOZ_ALWAYS_INLINE void ExposeScriptToActiveJS(JSScript* script) {
|
|
|
|
MOZ_ASSERT(!js::gc::EdgeNeedsSweepUnbarrieredSlow(&script));
|
|
|
|
js::gc::ExposeGCThingToActiveJS(GCCellPtr(script));
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace JS */
|
2012-10-26 22:17:24 +04:00
|
|
|
|
2013-06-20 04:59:09 +04:00
|
|
|
#endif /* js_HeapAPI_h */
|