2012-10-26 18:17:24 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2013-04-16 20:47:10 +00: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/. */
|
2012-10-26 18:17:24 +00:00
|
|
|
|
2013-06-20 00:59:09 +00:00
|
|
|
#ifndef js_HeapAPI_h
|
|
|
|
#define js_HeapAPI_h
|
2012-10-26 18:17:24 +00:00
|
|
|
|
2013-10-08 13:54:33 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
2015-06-11 17:03:33 +00:00
|
|
|
#include "jspubtd.h"
|
|
|
|
|
|
|
|
#include "js/TraceKind.h"
|
2013-07-24 00:34:12 +00:00
|
|
|
#include "js/Utility.h"
|
|
|
|
|
2012-10-26 18:18:50 +00:00
|
|
|
/* These values are private to the JS engine. */
|
2012-10-26 18:17:24 +00:00
|
|
|
namespace js {
|
2013-09-05 02:19:04 +00:00
|
|
|
|
|
|
|
// Whether the current thread is permitted access to any part of the specified
|
|
|
|
// runtime or zone.
|
2013-11-05 16:55:28 +00:00
|
|
|
JS_FRIEND_API(bool)
|
2015-03-28 22:22:11 +00:00
|
|
|
CurrentThreadCanAccessRuntime(JSRuntime* rt);
|
2013-11-05 16:55:28 +00:00
|
|
|
|
|
|
|
JS_FRIEND_API(bool)
|
2015-03-28 22:22:11 +00:00
|
|
|
CurrentThreadCanAccessZone(JS::Zone* zone);
|
2013-09-05 02:19:04 +00:00
|
|
|
|
2012-10-26 18:18:50 +00:00
|
|
|
namespace gc {
|
|
|
|
|
2014-04-26 08:30:04 +00:00
|
|
|
struct Cell;
|
|
|
|
|
2012-10-26 18:18:50 +00:00
|
|
|
const size_t ArenaShift = 12;
|
|
|
|
const size_t ArenaSize = size_t(1) << ArenaShift;
|
|
|
|
const size_t ArenaMask = ArenaSize - 1;
|
|
|
|
|
2014-07-15 08:42:47 +00:00
|
|
|
#ifdef JS_GC_SMALL_CHUNK_SIZE
|
|
|
|
const size_t ChunkShift = 18;
|
|
|
|
#else
|
2012-10-26 18:18:50 +00:00
|
|
|
const size_t ChunkShift = 20;
|
2014-07-15 08:42:47 +00:00
|
|
|
#endif
|
2012-10-26 18:18:50 +00:00
|
|
|
const size_t ChunkSize = size_t(1) << ChunkShift;
|
|
|
|
const size_t ChunkMask = ChunkSize - 1;
|
|
|
|
|
2012-11-29 01:03:54 +00:00
|
|
|
const size_t CellShift = 3;
|
|
|
|
const size_t CellSize = size_t(1) << CellShift;
|
|
|
|
const size_t CellMask = CellSize - 1;
|
|
|
|
|
|
|
|
/* These are magic constants derived from actual offsets in gc/Heap.h. */
|
2014-07-15 08:42:47 +00:00
|
|
|
#ifdef JS_GC_SMALL_CHUNK_SIZE
|
|
|
|
const size_t ChunkMarkBitmapOffset = 258104;
|
|
|
|
const size_t ChunkMarkBitmapBits = 31744;
|
|
|
|
#else
|
2014-05-01 16:26:12 +00:00
|
|
|
const size_t ChunkMarkBitmapOffset = 1032352;
|
2012-11-29 01:03:54 +00:00
|
|
|
const size_t ChunkMarkBitmapBits = 129024;
|
2014-07-15 08:42:47 +00:00
|
|
|
#endif
|
2013-03-20 00:59:42 +00:00
|
|
|
const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*);
|
2014-05-01 16:26:12 +00:00
|
|
|
const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t);
|
2014-12-14 16:27:51 +00:00
|
|
|
const size_t ArenaZoneOffset = 0;
|
2012-11-29 01:03:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Live objects are marked black. How many other additional colors are available
|
|
|
|
* depends on the size of the GCThing. Objects marked gray are eligible for
|
|
|
|
* cycle collection.
|
|
|
|
*/
|
|
|
|
static const uint32_t BLACK = 0;
|
|
|
|
static const uint32_t GRAY = 1;
|
|
|
|
|
2014-04-26 08:30:04 +00:00
|
|
|
/*
|
2014-06-10 05:04:14 +00:00
|
|
|
* The "location" field in the Chunk trailer is a bit vector indicting various
|
|
|
|
* roles of the chunk.
|
|
|
|
*
|
|
|
|
* The value 0 for the "location" field is invalid, at least one bit must be
|
|
|
|
* set.
|
|
|
|
*
|
|
|
|
* Some bits preclude others, for example, any "nursery" bit precludes any
|
|
|
|
* "tenured" or "middle generation" bit.
|
2014-04-26 08:30:04 +00:00
|
|
|
*/
|
2014-06-10 05:04:14 +00:00
|
|
|
const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery
|
|
|
|
const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation
|
|
|
|
|
2015-01-14 08:21:59 +00:00
|
|
|
const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery;
|
2014-04-26 08:30:04 +00:00
|
|
|
|
2014-05-15 02:48:09 +00:00
|
|
|
#ifdef JS_DEBUG
|
|
|
|
/* When downcasting, ensure we are actually the right type. */
|
|
|
|
extern JS_FRIEND_API(void)
|
2015-05-22 17:40:24 +00:00
|
|
|
AssertGCThingHasType(js::gc::Cell* cell, JS::TraceKind kind);
|
2014-05-15 02:48:09 +00:00
|
|
|
#else
|
|
|
|
inline void
|
2015-05-22 17:40:24 +00:00
|
|
|
AssertGCThingHasType(js::gc::Cell* cell, JS::TraceKind kind) {}
|
2014-05-15 02:48:09 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
MOZ_ALWAYS_INLINE bool IsInsideNursery(const js::gc::Cell* cell);
|
2014-12-05 17:38:32 +00:00
|
|
|
|
2012-10-26 18:18:50 +00:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
|
|
|
|
2013-01-27 20:37:18 +00:00
|
|
|
namespace JS {
|
2013-03-17 03:36:37 +00:00
|
|
|
struct Zone;
|
2013-01-27 20:37:18 +00:00
|
|
|
|
2014-07-11 08:59:05 +00:00
|
|
|
/* Default size for the generational nursery in bytes. */
|
2014-11-19 23:01:54 +00:00
|
|
|
const uint32_t DefaultNurseryBytes = 16 * js::gc::ChunkSize;
|
2014-07-11 08:59:05 +00:00
|
|
|
|
2014-07-16 09:01:20 +00:00
|
|
|
/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */
|
|
|
|
const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024;
|
|
|
|
|
2012-10-26 18:18:50 +00:00
|
|
|
namespace shadow {
|
|
|
|
|
2013-01-27 20:37:18 +00:00
|
|
|
struct Zone
|
2012-11-29 01:03:54 +00:00
|
|
|
{
|
2013-09-05 02:19:04 +00:00
|
|
|
protected:
|
2015-03-28 22:22:11 +00:00
|
|
|
JSRuntime* const runtime_;
|
|
|
|
JSTracer* const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|.
|
2013-09-05 02:19:04 +00:00
|
|
|
|
|
|
|
public:
|
2014-07-28 17:16:56 +00:00
|
|
|
bool needsIncrementalBarrier_;
|
2012-11-29 01:03:54 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
Zone(JSRuntime* runtime, JSTracer* barrierTracerArg)
|
2013-09-05 02:19:04 +00:00
|
|
|
: runtime_(runtime),
|
|
|
|
barrierTracer_(barrierTracerArg),
|
2014-07-28 17:16:56 +00:00
|
|
|
needsIncrementalBarrier_(false)
|
2013-09-05 02:19:04 +00:00
|
|
|
{}
|
|
|
|
|
2014-07-28 17:16:56 +00:00
|
|
|
bool needsIncrementalBarrier() const {
|
|
|
|
return needsIncrementalBarrier_;
|
2013-09-05 02:19:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSTracer* barrierTracer() {
|
2014-07-28 17:16:56 +00:00
|
|
|
MOZ_ASSERT(needsIncrementalBarrier_);
|
2014-02-18 06:24:15 +00:00
|
|
|
MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_));
|
2013-09-05 02:19:04 +00:00
|
|
|
return barrierTracer_;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSRuntime* runtimeFromMainThread() const {
|
2014-02-18 06:24:15 +00:00
|
|
|
MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_));
|
2013-09-05 02:19:04 +00:00
|
|
|
return runtime_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: Unrestricted access to the zone's runtime from an arbitrary
|
|
|
|
// thread can easily lead to races. Use this method very carefully.
|
2015-03-28 22:22:11 +00:00
|
|
|
JSRuntime* runtimeFromAnyThread() const {
|
2013-09-05 02:19:04 +00:00
|
|
|
return runtime_;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
static JS::shadow::Zone* asShadowZone(JS::Zone* zone) {
|
2013-09-05 02:19:04 +00:00
|
|
|
return reinterpret_cast<JS::shadow::Zone*>(zone);
|
|
|
|
}
|
2012-11-29 01:03:54 +00:00
|
|
|
};
|
|
|
|
|
2012-10-26 18:18:50 +00:00
|
|
|
} /* namespace shadow */
|
2014-12-01 22:49:21 +00: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.
|
|
|
|
class JS_FRIEND_API(GCCellPtr)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Construction from a void* and trace kind.
|
2015-05-22 17:40:24 +00:00
|
|
|
GCCellPtr(void* gcthing, JS::TraceKind traceKind) : ptr(checkedCast(gcthing, traceKind)) {}
|
2014-12-01 22:49:21 +00:00
|
|
|
|
2015-05-13 21:07:34 +00:00
|
|
|
// Automatically construct a null GCCellPtr from nullptr.
|
2015-05-22 17:40:24 +00:00
|
|
|
MOZ_IMPLICIT GCCellPtr(decltype(nullptr)) : ptr(checkedCast(nullptr, JS::TraceKind::Null)) {}
|
2015-05-13 21:07:34 +00:00
|
|
|
|
2014-12-01 22:49:21 +00:00
|
|
|
// Construction from an explicit type.
|
2015-07-03 22:06:23 +00:00
|
|
|
template <typename T>
|
2015-07-29 16:31:47 +00: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 17:40:24 +00:00
|
|
|
explicit GCCellPtr(JSFlatString* str) : ptr(checkedCast(str, JS::TraceKind::String)) { }
|
2015-03-28 22:22:11 +00:00
|
|
|
explicit GCCellPtr(const Value& v);
|
2014-12-01 22:49:21 +00:00
|
|
|
|
2015-05-22 17:40:24 +00:00
|
|
|
JS::TraceKind kind() const {
|
|
|
|
JS::TraceKind traceKind = JS::TraceKind(ptr & OutOfLineTraceKindMask);
|
|
|
|
if (uintptr_t(traceKind) != OutOfLineTraceKindMask)
|
2014-12-01 22:49:21 +00:00
|
|
|
return traceKind;
|
|
|
|
return outOfLineKind();
|
|
|
|
}
|
|
|
|
|
2014-12-02 06:34:25 +00:00
|
|
|
// Allow GCCellPtr to be used in a boolean context.
|
2015-02-03 16:52:36 +00:00
|
|
|
explicit operator bool() const {
|
2015-05-22 17:40:24 +00:00
|
|
|
MOZ_ASSERT(bool(asCell()) == (kind() != JS::TraceKind::Null));
|
2015-02-03 16:52:36 +00:00
|
|
|
return asCell();
|
2014-12-02 06:34:25 +00:00
|
|
|
}
|
2014-12-01 22:49:21 +00:00
|
|
|
|
2014-12-01 23:06:37 +00:00
|
|
|
// Simplify checks to the kind.
|
2015-07-03 22:06:23 +00:00
|
|
|
template <typename T>
|
|
|
|
bool is() const { return kind() == JS::MapTypeToTraceKind<T>::kind; }
|
2014-12-01 23:06:37 +00:00
|
|
|
|
2014-12-01 22:49:21 +00:00
|
|
|
// Conversions to more specific types must match the kind. Access to
|
|
|
|
// further refined types is not allowed directly from a GCCellPtr.
|
2015-07-03 22:06:23 +00:00
|
|
|
template <typename T>
|
2015-07-29 16:31:47 +00:00
|
|
|
T& as() const {
|
2015-07-03 22:06:23 +00: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-01 23:06:37 +00:00
|
|
|
}
|
2015-07-03 22:06:23 +00: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-28 22:22:11 +00:00
|
|
|
js::gc::Cell* asCell() const {
|
2015-05-22 17:40:24 +00:00
|
|
|
return reinterpret_cast<js::gc::Cell*>(ptr & ~OutOfLineTraceKindMask);
|
2014-12-02 06:34:25 +00:00
|
|
|
}
|
2014-12-01 22:49:21 +00:00
|
|
|
|
2014-12-05 17:38:32 +00:00
|
|
|
// The CC's trace logger needs an identity that is XPIDL serializable.
|
|
|
|
uint64_t unsafeAsInteger() const {
|
2015-01-09 23:42:42 +00:00
|
|
|
return static_cast<uint64_t>(unsafeAsUIntPtr());
|
2014-12-05 17:38:32 +00:00
|
|
|
}
|
2014-12-05 17:38:33 +00:00
|
|
|
// Inline mark bitmap access requires direct pointer arithmetic.
|
|
|
|
uintptr_t unsafeAsUIntPtr() const {
|
2015-01-09 23:42:42 +00:00
|
|
|
MOZ_ASSERT(asCell());
|
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(asCell()));
|
|
|
|
return reinterpret_cast<uintptr_t>(asCell());
|
2014-12-05 17:38:33 +00:00
|
|
|
}
|
2014-12-01 22:49:21 +00:00
|
|
|
|
2015-05-07 09:14:40 +00:00
|
|
|
bool mayBeOwnedByOtherRuntime() const;
|
|
|
|
|
2014-12-01 22:49:21 +00:00
|
|
|
private:
|
2015-05-22 17:40:24 +00:00
|
|
|
static uintptr_t checkedCast(void* p, JS::TraceKind traceKind) {
|
2015-03-28 22:22:11 +00:00
|
|
|
js::gc::Cell* cell = static_cast<js::gc::Cell*>(p);
|
2015-05-22 17:40:24 +00:00
|
|
|
MOZ_ASSERT((uintptr_t(p) & OutOfLineTraceKindMask) == 0);
|
2014-12-01 22:49:21 +00:00
|
|
|
AssertGCThingHasType(cell, traceKind);
|
2015-05-22 17:40:24 +00:00
|
|
|
// Note: the OutOfLineTraceKindMask bits are set on all out-of-line kinds
|
2014-12-01 22:49:21 +00:00
|
|
|
// so that we can mask instead of branching.
|
2015-05-22 17:40:24 +00:00
|
|
|
MOZ_ASSERT_IF(uintptr_t(traceKind) >= OutOfLineTraceKindMask,
|
|
|
|
(uintptr_t(traceKind) & OutOfLineTraceKindMask) == OutOfLineTraceKindMask);
|
|
|
|
return uintptr_t(p) | (uintptr_t(traceKind) & OutOfLineTraceKindMask);
|
2014-12-01 22:49:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 17:40:24 +00:00
|
|
|
JS::TraceKind outOfLineKind() const;
|
2014-12-01 22:49:21 +00:00
|
|
|
|
|
|
|
uintptr_t ptr;
|
|
|
|
};
|
|
|
|
|
2015-02-03 16:52:28 +00:00
|
|
|
inline bool
|
2015-03-28 22:22:11 +00:00
|
|
|
operator==(const GCCellPtr& ptr1, const GCCellPtr& ptr2)
|
2015-02-03 16:52:28 +00:00
|
|
|
{
|
|
|
|
return ptr1.asCell() == ptr2.asCell();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2015-03-28 22:22:11 +00:00
|
|
|
operator!=(const GCCellPtr& ptr1, const GCCellPtr& ptr2)
|
2015-02-03 16:52:28 +00:00
|
|
|
{
|
|
|
|
return !(ptr1 == ptr2);
|
|
|
|
}
|
|
|
|
|
2012-11-29 01:03:54 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
namespace gc {
|
2014-12-05 17:38:33 +00:00
|
|
|
namespace detail {
|
2012-11-29 01:03:54 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
static MOZ_ALWAYS_INLINE uintptr_t*
|
2014-12-05 17:38:33 +00:00
|
|
|
GetGCThingMarkBitmap(const uintptr_t addr)
|
2012-11-29 01:03:54 +00:00
|
|
|
{
|
2014-12-05 17:38:33 +00:00
|
|
|
MOZ_ASSERT(addr);
|
|
|
|
const uintptr_t bmap_addr = (addr & ~ChunkMask) | ChunkMarkBitmapOffset;
|
2015-03-28 22:22:11 +00:00
|
|
|
return reinterpret_cast<uintptr_t*>(bmap_addr);
|
2012-11-29 01:03:54 +00:00
|
|
|
}
|
2012-10-26 18:18:50 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
static MOZ_ALWAYS_INLINE JS::shadow::Runtime*
|
2014-12-05 17:38:33 +00:00
|
|
|
GetGCThingRuntime(const uintptr_t addr)
|
2013-03-20 00:59:42 +00:00
|
|
|
{
|
2014-12-05 17:38:33 +00:00
|
|
|
MOZ_ASSERT(addr);
|
|
|
|
const uintptr_t rt_addr = (addr & ~ChunkMask) | ChunkRuntimeOffset;
|
2015-03-28 22:22:11 +00:00
|
|
|
return *reinterpret_cast<JS::shadow::Runtime**>(rt_addr);
|
2013-03-20 00:59:42 +00:00
|
|
|
}
|
|
|
|
|
2014-01-25 04:14:56 +00:00
|
|
|
static MOZ_ALWAYS_INLINE void
|
2014-12-05 17:38:33 +00:00
|
|
|
GetGCThingMarkWordAndMask(const uintptr_t addr, uint32_t color,
|
2015-03-28 22:22:11 +00:00
|
|
|
uintptr_t** wordp, uintptr_t* maskp)
|
2012-11-29 01:03:54 +00:00
|
|
|
{
|
2014-12-05 17:38:33 +00:00
|
|
|
MOZ_ASSERT(addr);
|
|
|
|
const size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color;
|
2014-02-18 06:24:15 +00:00
|
|
|
MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits);
|
2015-03-28 22:22:11 +00:00
|
|
|
uintptr_t* bitmap = GetGCThingMarkBitmap(addr);
|
2013-10-08 13:54:33 +00:00
|
|
|
const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT;
|
|
|
|
*maskp = uintptr_t(1) << (bit % nbits);
|
|
|
|
*wordp = &bitmap[bit / nbits];
|
2012-11-29 01:03:54 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
static MOZ_ALWAYS_INLINE JS::Zone*
|
2014-12-14 16:27:51 +00:00
|
|
|
GetGCThingZone(const uintptr_t addr)
|
2012-10-26 18:18:50 +00:00
|
|
|
{
|
2014-12-05 17:38:33 +00:00
|
|
|
MOZ_ASSERT(addr);
|
2014-12-14 16:27:51 +00:00
|
|
|
const uintptr_t zone_addr = (addr & ~ArenaMask) | ArenaZoneOffset;
|
2015-03-28 22:22:11 +00:00
|
|
|
return *reinterpret_cast<JS::Zone**>(zone_addr);
|
2014-12-14 16:27:51 +00:00
|
|
|
|
2012-10-26 18:18:50 +00:00
|
|
|
}
|
2012-10-26 18:17:24 +00:00
|
|
|
|
2014-12-05 17:38:34 +00:00
|
|
|
static MOZ_ALWAYS_INLINE bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CellIsMarkedGray(const Cell* cell)
|
2014-12-05 17:38:34 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(cell);
|
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(cell));
|
2015-03-28 22:22:11 +00:00
|
|
|
uintptr_t* word, mask;
|
2014-12-05 17:38:34 +00:00
|
|
|
js::gc::detail::GetGCThingMarkWordAndMask(uintptr_t(cell), js::gc::GRAY, &word, &mask);
|
|
|
|
return *word & mask;
|
|
|
|
}
|
|
|
|
|
2014-12-05 17:38:33 +00:00
|
|
|
} /* namespace detail */
|
|
|
|
|
2014-04-26 08:30:04 +00:00
|
|
|
MOZ_ALWAYS_INLINE bool
|
2015-03-28 22:22:11 +00:00
|
|
|
IsInsideNursery(const js::gc::Cell* cell)
|
2014-04-26 08:30:04 +00:00
|
|
|
{
|
|
|
|
if (!cell)
|
|
|
|
return false;
|
|
|
|
uintptr_t addr = uintptr_t(cell);
|
|
|
|
addr &= ~js::gc::ChunkMask;
|
|
|
|
addr |= js::gc::ChunkLocationOffset;
|
2015-03-28 22:22:11 +00:00
|
|
|
uint32_t location = *reinterpret_cast<uint32_t*>(addr);
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(location != 0);
|
2014-06-10 05:04:14 +00:00
|
|
|
return location & ChunkLocationAnyNursery;
|
2014-04-26 08:30:04 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 01:03:54 +00:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
static MOZ_ALWAYS_INLINE Zone*
|
2015-06-01 21:11:08 +00:00
|
|
|
GetTenuredGCThingZone(GCCellPtr thing)
|
2013-01-27 21:51:41 +00:00
|
|
|
{
|
2015-06-01 21:11:08 +00:00
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(thing.asCell()));
|
|
|
|
return js::gc::detail::GetGCThingZone(thing.unsafeAsUIntPtr());
|
|
|
|
}
|
|
|
|
|
|
|
|
static MOZ_ALWAYS_INLINE Zone*
|
|
|
|
GetStringZone(JSString* str)
|
|
|
|
{
|
|
|
|
return js::gc::detail::GetGCThingZone(uintptr_t(str));
|
2013-01-27 21:51:41 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
extern JS_PUBLIC_API(Zone*)
|
|
|
|
GetObjectZone(JSObject* obj);
|
2013-01-27 21:51:41 +00:00
|
|
|
|
2014-12-14 16:27:52 +00:00
|
|
|
static MOZ_ALWAYS_INLINE bool
|
2015-03-28 22:22:11 +00:00
|
|
|
ObjectIsTenured(JSObject* obj)
|
2014-12-14 16:27:52 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
return !js::gc::IsInsideNursery(reinterpret_cast<js::gc::Cell*>(obj));
|
2014-12-14 16:27:52 +00:00
|
|
|
}
|
|
|
|
|
2014-01-25 04:14:56 +00:00
|
|
|
static MOZ_ALWAYS_INLINE bool
|
2015-03-28 22:22:11 +00:00
|
|
|
ObjectIsMarkedGray(JSObject* obj)
|
2012-11-29 01:03:54 +00:00
|
|
|
{
|
2013-08-19 13:48:35 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
if (js::gc::IsInsideNursery(reinterpret_cast<js::gc::Cell*>(obj)))
|
2013-08-19 13:48:35 +00:00
|
|
|
return false;
|
2015-03-28 22:22:11 +00:00
|
|
|
return js::gc::detail::CellIsMarkedGray(reinterpret_cast<js::gc::Cell*>(obj));
|
2012-11-29 01:03:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 00:22:51 +00:00
|
|
|
static MOZ_ALWAYS_INLINE bool
|
2015-03-28 22:22:11 +00:00
|
|
|
ScriptIsMarkedGray(JSScript* script)
|
2014-12-10 00:22:51 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
return js::gc::detail::CellIsMarkedGray(reinterpret_cast<js::gc::Cell*>(script));
|
2014-12-10 00:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static MOZ_ALWAYS_INLINE bool
|
2014-12-05 17:38:34 +00:00
|
|
|
GCThingIsMarkedGray(GCCellPtr thing)
|
2014-12-10 00:22:51 +00:00
|
|
|
{
|
2014-12-05 17:38:34 +00:00
|
|
|
if (js::gc::IsInsideNursery(thing.asCell()))
|
|
|
|
return false;
|
2015-05-07 09:14:40 +00:00
|
|
|
if (thing.mayBeOwnedByOtherRuntime())
|
|
|
|
return false;
|
2014-12-05 17:38:34 +00:00
|
|
|
return js::gc::detail::CellIsMarkedGray(thing.asCell());
|
2014-12-10 00:22:51 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 21:58:05 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
namespace gc {
|
|
|
|
|
2014-01-25 04:14:56 +00:00
|
|
|
static MOZ_ALWAYS_INLINE bool
|
2015-03-28 22:22:11 +00:00
|
|
|
IsIncrementalBarrierNeededOnTenuredGCThing(JS::shadow::Runtime* rt, const JS::GCCellPtr thing)
|
2012-11-29 01:03:54 +00:00
|
|
|
{
|
2014-07-29 17:47:43 +00:00
|
|
|
MOZ_ASSERT(thing);
|
2014-12-02 06:34:25 +00:00
|
|
|
MOZ_ASSERT(!js::gc::IsInsideNursery(thing.asCell()));
|
2015-06-05 16:01:12 +00:00
|
|
|
if (rt->isHeapBusy())
|
2013-03-20 00:59:42 +00:00
|
|
|
return false;
|
2015-06-01 21:11:08 +00:00
|
|
|
JS::Zone* zone = JS::GetTenuredGCThingZone(thing);
|
2014-05-19 21:58:05 +00:00
|
|
|
return JS::shadow::Zone::asShadowZone(zone)->needsIncrementalBarrier();
|
2012-11-29 01:03:54 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 23:32:54 +00:00
|
|
|
/*
|
|
|
|
* Create an object providing access to the garbage collector's internal notion
|
|
|
|
* of the current state of memory (both GC heap memory and GCthing-controlled
|
|
|
|
* malloc memory.
|
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject*)
|
|
|
|
NewMemoryInfoObject(JSContext* cx);
|
2015-01-26 23:32:54 +00:00
|
|
|
|
2014-05-19 21:58:05 +00:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
2012-10-26 18:17:24 +00:00
|
|
|
|
2013-06-20 00:59:09 +00:00
|
|
|
#endif /* js_HeapAPI_h */
|