2011-04-20 05:30:10 +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:
|
2012-05-21 11:12:37 +00: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/. */
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2013-06-20 00:59:46 +00:00
|
|
|
#ifndef jsgcinlines_h
|
|
|
|
#define jsgcinlines_h
|
2010-09-24 17:54:39 +00:00
|
|
|
|
|
|
|
#include "jsgc.h"
|
2013-07-24 00:34:18 +00:00
|
|
|
|
2013-08-08 23:07:22 +00:00
|
|
|
#include "gc/Zone.h"
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2010-10-13 18:49:22 +00:00
|
|
|
namespace js {
|
2011-03-23 18:57:44 +00:00
|
|
|
|
2012-12-22 00:16:50 +00:00
|
|
|
class Shape;
|
2011-03-23 18:57:44 +00:00
|
|
|
|
2012-11-09 19:44:21 +00:00
|
|
|
/*
|
|
|
|
* This auto class should be used around any code that might cause a mark bit to
|
2013-02-07 02:08:16 +00:00
|
|
|
* be set on an object in a dead zone. See AutoMaybeTouchDeadZones
|
2012-11-12 22:57:53 +00:00
|
|
|
* for more details.
|
2012-11-09 19:44:21 +00:00
|
|
|
*/
|
2013-02-07 02:08:16 +00:00
|
|
|
struct AutoMarkInDeadZone
|
2012-11-09 19:44:21 +00:00
|
|
|
{
|
2013-02-07 02:08:16 +00:00
|
|
|
AutoMarkInDeadZone(JS::Zone *zone)
|
|
|
|
: zone(zone),
|
|
|
|
scheduled(zone->scheduledForDestruction)
|
2012-11-09 19:44:21 +00:00
|
|
|
{
|
2013-08-05 14:48:34 +00:00
|
|
|
JSRuntime *rt = zone->runtimeFromMainThread();
|
|
|
|
if (rt->gcManipulatingDeadZones && zone->scheduledForDestruction) {
|
|
|
|
rt->gcObjectsMarkedInDeadZones++;
|
2013-02-07 02:08:16 +00:00
|
|
|
zone->scheduledForDestruction = false;
|
2012-11-09 19:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 02:08:16 +00:00
|
|
|
~AutoMarkInDeadZone() {
|
|
|
|
zone->scheduledForDestruction = scheduled;
|
2012-11-09 19:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-02-07 02:08:16 +00:00
|
|
|
JS::Zone *zone;
|
2012-11-09 19:44:21 +00:00
|
|
|
bool scheduled;
|
|
|
|
};
|
|
|
|
|
2013-06-21 00:39:24 +00:00
|
|
|
inline Allocator *const
|
|
|
|
ThreadSafeContext::allocator()
|
|
|
|
{
|
|
|
|
JS_ASSERT_IF(isJSContext(), &asJSContext()->zone()->allocator == allocator_);
|
|
|
|
return allocator_;
|
|
|
|
}
|
|
|
|
|
2013-10-08 22:14:03 +00:00
|
|
|
template <typename T>
|
|
|
|
inline bool
|
|
|
|
ThreadSafeContext::isThreadLocal(T thing) const
|
|
|
|
{
|
2014-01-31 22:57:57 +00:00
|
|
|
if (!isForkJoinContext())
|
2013-10-08 22:14:03 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!IsInsideNursery(runtime_, thing) &&
|
|
|
|
allocator_->arenas.containsArena(runtime_, thing->arenaHeader()))
|
|
|
|
{
|
|
|
|
// GC should be suppressed in preparation for mutating thread local
|
|
|
|
// objects, as we don't want to trip any barriers.
|
|
|
|
JS_ASSERT(!thing->zoneFromAnyThread()->needsBarrier());
|
|
|
|
JS_ASSERT(!thing->runtimeFromAnyThread()->needsBarrier());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:49:22 +00:00
|
|
|
namespace gc {
|
|
|
|
|
2011-10-11 00:14:38 +00:00
|
|
|
static inline AllocKind
|
2013-09-11 12:49:05 +00:00
|
|
|
GetGCObjectKind(const Class *clasp)
|
2011-10-11 00:14:38 +00:00
|
|
|
{
|
2013-06-18 06:53:49 +00:00
|
|
|
if (clasp == FunctionClassPtr)
|
2011-10-26 20:02:57 +00:00
|
|
|
return JSFunction::FinalizeKind;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint32_t nslots = JSCLASS_RESERVED_SLOTS(clasp);
|
2011-10-11 00:14:38 +00:00
|
|
|
if (clasp->flags & JSCLASS_HAS_PRIVATE)
|
|
|
|
nslots++;
|
|
|
|
return GetGCObjectKind(nslots);
|
|
|
|
}
|
|
|
|
|
2013-02-05 22:07:28 +00:00
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
inline bool
|
2013-06-17 20:16:29 +00:00
|
|
|
ShouldNurseryAllocate(const Nursery &nursery, AllocKind kind, InitialHeap heap)
|
2013-02-05 22:07:28 +00:00
|
|
|
{
|
|
|
|
return nursery.isEnabled() && IsNurseryAllocable(kind) && heap != TenuredHeap;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-11 17:47:33 +00:00
|
|
|
inline JSGCTraceKind
|
|
|
|
GetGCThingTraceKind(const void *thing)
|
|
|
|
{
|
|
|
|
JS_ASSERT(thing);
|
|
|
|
const Cell *cell = static_cast<const Cell *>(thing);
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
2013-08-05 14:48:34 +00:00
|
|
|
if (IsInsideNursery(cell->runtimeFromMainThread(), cell))
|
2013-03-11 17:47:33 +00:00
|
|
|
return JSTRACE_OBJECT;
|
|
|
|
#endif
|
2013-02-14 22:51:07 +00:00
|
|
|
return MapAllocToTraceKind(cell->tenuredGetAllocKind());
|
2013-03-11 17:47:33 +00:00
|
|
|
}
|
|
|
|
|
2011-06-02 00:48:52 +00:00
|
|
|
static inline void
|
2013-01-11 00:53:11 +00:00
|
|
|
GCPoke(JSRuntime *rt)
|
2011-06-02 00:48:52 +00:00
|
|
|
{
|
2012-02-05 20:07:23 +00:00
|
|
|
rt->gcPoke = true;
|
2011-06-02 00:48:52 +00:00
|
|
|
|
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
/* Schedule a GC to happen "soon" after a GC poke. */
|
2012-02-17 22:35:20 +00:00
|
|
|
if (rt->gcZeal() == js::gc::ZealPokeValue)
|
2012-02-05 20:07:23 +00:00
|
|
|
rt->gcNextScheduled = 1;
|
2011-06-02 00:48:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-09 18:16:33 +00:00
|
|
|
class ArenaIter
|
2011-08-26 19:39:31 +00:00
|
|
|
{
|
2012-08-09 18:16:33 +00:00
|
|
|
ArenaHeader *aheader;
|
|
|
|
ArenaHeader *remainingHeader;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ArenaIter() {
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2013-01-27 21:51:41 +00:00
|
|
|
ArenaIter(JS::Zone *zone, AllocKind kind) {
|
|
|
|
init(zone, kind);
|
2012-08-09 18:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
2013-10-07 16:43:32 +00:00
|
|
|
aheader = nullptr;
|
|
|
|
remainingHeader = nullptr;
|
2012-08-09 18:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init(ArenaHeader *aheaderArg) {
|
|
|
|
aheader = aheaderArg;
|
2013-10-07 16:43:32 +00:00
|
|
|
remainingHeader = nullptr;
|
2012-08-09 18:16:33 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 21:51:41 +00:00
|
|
|
void init(JS::Zone *zone, AllocKind kind) {
|
|
|
|
aheader = zone->allocator.arenas.getFirstArena(kind);
|
|
|
|
remainingHeader = zone->allocator.arenas.getFirstArenaToSweep(kind);
|
2012-08-09 18:16:33 +00:00
|
|
|
if (!aheader) {
|
|
|
|
aheader = remainingHeader;
|
2013-10-07 16:43:32 +00:00
|
|
|
remainingHeader = nullptr;
|
2011-08-26 19:39:31 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-09 18:16:33 +00:00
|
|
|
|
|
|
|
bool done() {
|
|
|
|
return !aheader;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArenaHeader *get() {
|
|
|
|
return aheader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void next() {
|
|
|
|
aheader = aheader->next;
|
|
|
|
if (!aheader) {
|
|
|
|
aheader = remainingHeader;
|
2013-10-07 16:43:32 +00:00
|
|
|
remainingHeader = nullptr;
|
2012-08-09 18:16:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2011-08-26 19:39:31 +00:00
|
|
|
|
2011-08-09 08:51:59 +00:00
|
|
|
class CellIterImpl
|
|
|
|
{
|
2011-08-18 07:16:08 +00:00
|
|
|
size_t firstThingOffset;
|
2011-08-09 08:51:59 +00:00
|
|
|
size_t thingSize;
|
2012-08-09 18:16:33 +00:00
|
|
|
ArenaIter aiter;
|
2011-08-09 08:51:59 +00:00
|
|
|
FreeSpan firstSpan;
|
|
|
|
const FreeSpan *span;
|
|
|
|
uintptr_t thing;
|
|
|
|
Cell *cell;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CellIterImpl() {
|
|
|
|
}
|
|
|
|
|
2013-01-27 21:51:41 +00:00
|
|
|
void initSpan(JS::Zone *zone, AllocKind kind) {
|
|
|
|
JS_ASSERT(zone->allocator.arenas.isSynchronizedFreeList(kind));
|
2011-08-18 07:16:08 +00:00
|
|
|
firstThingOffset = Arena::firstThingOffset(kind);
|
|
|
|
thingSize = Arena::thingSize(kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
firstSpan.initAsEmpty();
|
|
|
|
span = &firstSpan;
|
|
|
|
thing = span->first;
|
2012-02-17 22:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init(ArenaHeader *singleAheader) {
|
2013-01-27 20:37:18 +00:00
|
|
|
initSpan(singleAheader->zone, singleAheader->getAllocKind());
|
2012-08-09 18:16:33 +00:00
|
|
|
aiter.init(singleAheader);
|
2012-02-17 22:35:20 +00:00
|
|
|
next();
|
2012-08-09 18:16:33 +00:00
|
|
|
aiter.init();
|
2012-02-17 22:35:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
void init(JS::Zone *zone, AllocKind kind) {
|
|
|
|
initSpan(zone, kind);
|
|
|
|
aiter.init(zone, kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool done() const {
|
|
|
|
return !cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T> T *get() const {
|
|
|
|
JS_ASSERT(!done());
|
|
|
|
return static_cast<T *>(cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
Cell *getCell() const {
|
|
|
|
JS_ASSERT(!done());
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
void next() {
|
|
|
|
for (;;) {
|
|
|
|
if (thing != span->first)
|
|
|
|
break;
|
2014-01-26 06:04:37 +00:00
|
|
|
if (MOZ_LIKELY(span->hasNext())) {
|
2011-08-09 08:51:59 +00:00
|
|
|
thing = span->last + thingSize;
|
|
|
|
span = span->nextSpan();
|
|
|
|
break;
|
|
|
|
}
|
2012-08-09 18:16:33 +00:00
|
|
|
if (aiter.done()) {
|
2013-10-07 16:43:32 +00:00
|
|
|
cell = nullptr;
|
2011-08-09 08:51:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-09 18:16:33 +00:00
|
|
|
ArenaHeader *aheader = aiter.get();
|
2011-08-09 08:51:59 +00:00
|
|
|
firstSpan = aheader->getFirstFreeSpan();
|
|
|
|
span = &firstSpan;
|
2011-08-18 07:16:08 +00:00
|
|
|
thing = aheader->arenaAddress() | firstThingOffset;
|
2012-08-09 18:16:33 +00:00
|
|
|
aiter.next();
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
cell = reinterpret_cast<Cell *>(thing);
|
|
|
|
thing += thingSize;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
class CellIterUnderGC : public CellIterImpl
|
|
|
|
{
|
2011-08-09 08:51:59 +00:00
|
|
|
public:
|
2013-03-17 03:36:37 +00:00
|
|
|
CellIterUnderGC(JS::Zone *zone, AllocKind kind) {
|
2013-12-04 23:23:30 +00:00
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
JS_ASSERT(zone->runtimeFromAnyThread()->gcNursery.isEmpty());
|
|
|
|
#endif
|
2013-08-05 14:48:34 +00:00
|
|
|
JS_ASSERT(zone->runtimeFromAnyThread()->isHeapBusy());
|
2013-03-17 03:36:37 +00:00
|
|
|
init(zone, kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
2012-02-17 22:35:20 +00:00
|
|
|
|
|
|
|
CellIterUnderGC(ArenaHeader *aheader) {
|
2013-08-05 14:48:34 +00:00
|
|
|
JS_ASSERT(aheader->zone->runtimeFromAnyThread()->isHeapBusy());
|
2012-02-17 22:35:20 +00:00
|
|
|
init(aheader);
|
|
|
|
}
|
2011-08-09 08:51:59 +00:00
|
|
|
};
|
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
class CellIter : public CellIterImpl
|
2011-08-09 08:51:59 +00:00
|
|
|
{
|
2011-08-18 07:16:08 +00:00
|
|
|
ArenaLists *lists;
|
|
|
|
AllocKind kind;
|
2011-08-09 08:51:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
size_t *counter;
|
|
|
|
#endif
|
|
|
|
public:
|
2013-03-17 03:36:37 +00:00
|
|
|
CellIter(JS::Zone *zone, AllocKind kind)
|
|
|
|
: lists(&zone->allocator.arenas),
|
2012-02-17 22:35:20 +00:00
|
|
|
kind(kind)
|
|
|
|
{
|
2012-03-03 01:19:56 +00:00
|
|
|
/*
|
|
|
|
* We have a single-threaded runtime, so there's no need to protect
|
|
|
|
* against other threads iterating or allocating. However, we do have
|
2013-02-08 08:40:39 +00:00
|
|
|
* background finalization; we have to wait for this to finish if it's
|
|
|
|
* currently active.
|
2012-03-03 01:19:56 +00:00
|
|
|
*/
|
2013-02-08 08:40:39 +00:00
|
|
|
if (IsBackgroundFinalized(kind) &&
|
2013-03-17 03:36:37 +00:00
|
|
|
zone->allocator.arenas.needBackgroundFinalizeWait(kind))
|
2013-02-08 08:40:39 +00:00
|
|
|
{
|
2013-08-05 14:48:34 +00:00
|
|
|
gc::FinishBackgroundFinalize(zone->runtimeFromMainThread());
|
2013-02-08 08:40:39 +00:00
|
|
|
}
|
2013-12-04 23:23:30 +00:00
|
|
|
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
/* Evict the nursery before iterating so we can see all things. */
|
|
|
|
JSRuntime *rt = zone->runtimeFromMainThread();
|
|
|
|
if (!rt->gcNursery.isEmpty())
|
|
|
|
MinorGC(rt, JS::gcreason::EVICT_NURSERY);
|
|
|
|
#endif
|
|
|
|
|
2011-08-18 07:16:08 +00:00
|
|
|
if (lists->isSynchronizedFreeList(kind)) {
|
2013-10-07 16:43:32 +00:00
|
|
|
lists = nullptr;
|
2011-08-09 08:51:59 +00:00
|
|
|
} else {
|
2013-08-05 14:48:34 +00:00
|
|
|
JS_ASSERT(!zone->runtimeFromMainThread()->isHeapBusy());
|
2011-08-18 07:16:08 +00:00
|
|
|
lists->copyFreeListToArena(kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
2013-12-04 23:23:30 +00:00
|
|
|
|
2011-08-09 08:51:59 +00:00
|
|
|
#ifdef DEBUG
|
2013-12-04 23:23:30 +00:00
|
|
|
/* Assert that no GCs can occur while a CellIter is live. */
|
2013-08-05 14:48:34 +00:00
|
|
|
counter = &zone->runtimeFromAnyThread()->noGCOrAllocationCheck;
|
2011-08-09 08:51:59 +00:00
|
|
|
++*counter;
|
|
|
|
#endif
|
2013-12-04 23:23:30 +00:00
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
init(zone, kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~CellIter() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
JS_ASSERT(*counter > 0);
|
|
|
|
--*counter;
|
|
|
|
#endif
|
|
|
|
if (lists)
|
2011-08-18 07:16:08 +00:00
|
|
|
lists->clearFreeListInArena(kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
class GCZonesIter
|
2012-08-09 18:16:33 +00:00
|
|
|
{
|
2012-04-03 00:02:25 +00:00
|
|
|
private:
|
2013-03-17 03:36:37 +00:00
|
|
|
ZonesIter zone;
|
2012-04-03 00:02:25 +00:00
|
|
|
|
|
|
|
public:
|
2013-11-11 06:48:58 +00:00
|
|
|
GCZonesIter(JSRuntime *rt) : zone(rt, WithAtoms) {
|
2013-03-17 03:36:37 +00:00
|
|
|
if (!zone->isCollecting())
|
2012-04-03 00:02:25 +00:00
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
bool done() const { return zone.done(); }
|
2012-04-03 00:02:25 +00:00
|
|
|
|
|
|
|
void next() {
|
|
|
|
JS_ASSERT(!done());
|
|
|
|
do {
|
2013-03-17 03:36:37 +00:00
|
|
|
zone.next();
|
|
|
|
} while (!zone.done() && !zone->isCollecting());
|
2012-04-03 00:02:25 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
JS::Zone *get() const {
|
2012-04-03 00:02:25 +00:00
|
|
|
JS_ASSERT(!done());
|
2013-03-17 03:36:37 +00:00
|
|
|
return zone;
|
2012-04-03 00:02:25 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
operator JS::Zone *() const { return get(); }
|
|
|
|
JS::Zone *operator->() const { return get(); }
|
2012-04-03 00:02:25 +00:00
|
|
|
};
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
typedef CompartmentsIterT<GCZonesIter> GCCompartmentsIter;
|
2013-01-27 21:51:40 +00:00
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
/* Iterates over all zones in the current zone group. */
|
|
|
|
class GCZoneGroupIter {
|
2012-11-16 15:34:22 +00:00
|
|
|
private:
|
2013-03-17 03:36:37 +00:00
|
|
|
JS::Zone *current;
|
2012-11-16 15:34:22 +00:00
|
|
|
|
|
|
|
public:
|
2013-03-17 03:36:37 +00:00
|
|
|
GCZoneGroupIter(JSRuntime *rt) {
|
2012-11-16 15:34:22 +00:00
|
|
|
JS_ASSERT(rt->isHeapBusy());
|
2013-01-27 21:51:40 +00:00
|
|
|
current = rt->gcCurrentZoneGroup;
|
2012-11-16 15:34:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 19:31:41 +00:00
|
|
|
bool done() const { return !current; }
|
2012-11-16 15:34:22 +00:00
|
|
|
|
|
|
|
void next() {
|
|
|
|
JS_ASSERT(!done());
|
2012-12-04 19:31:41 +00:00
|
|
|
current = current->nextNodeInGroup();
|
2012-11-16 15:34:22 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
JS::Zone *get() const {
|
2012-11-16 15:34:22 +00:00
|
|
|
JS_ASSERT(!done());
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
operator JS::Zone *() const { return get(); }
|
|
|
|
JS::Zone *operator->() const { return get(); }
|
2012-11-16 15:34:22 +00:00
|
|
|
};
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
typedef CompartmentsIterT<GCZoneGroupIter> GCCompartmentGroupIter;
|
2013-01-27 21:51:40 +00:00
|
|
|
|
2013-03-14 17:26:06 +00:00
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
/*
|
|
|
|
* Attempt to allocate a new GC thing out of the nursery. If there is not enough
|
2013-10-07 16:43:32 +00:00
|
|
|
* room in the nursery or there is an OOM, this method will return nullptr.
|
2013-03-14 17:26:06 +00:00
|
|
|
*/
|
|
|
|
template <typename T, AllowGC allowGC>
|
|
|
|
inline T *
|
2013-07-11 01:25:42 +00:00
|
|
|
TryNewNurseryGCThing(ThreadSafeContext *cxArg, size_t thingSize)
|
2013-03-14 17:26:06 +00:00
|
|
|
{
|
2013-06-20 23:40:53 +00:00
|
|
|
/* TODO: Integrate PJS with generational GC. */
|
2013-07-11 01:25:42 +00:00
|
|
|
JSContext *cx = cxArg->asJSContext();
|
2013-06-20 23:40:53 +00:00
|
|
|
|
2013-06-10 22:08:55 +00:00
|
|
|
JS_ASSERT(!IsAtomsCompartment(cx->compartment()));
|
|
|
|
JSRuntime *rt = cx->runtime();
|
2013-03-14 17:26:06 +00:00
|
|
|
Nursery &nursery = rt->gcNursery;
|
|
|
|
T *t = static_cast<T *>(nursery.allocate(thingSize));
|
|
|
|
if (t)
|
|
|
|
return t;
|
|
|
|
if (allowGC && !rt->mainThread.suppressGC) {
|
2013-11-22 03:20:25 +00:00
|
|
|
MinorGC(cx, JS::gcreason::OUT_OF_NURSERY);
|
2013-03-14 17:26:06 +00:00
|
|
|
|
|
|
|
/* Exceeding gcMaxBytes while tenuring can disable the Nursery. */
|
|
|
|
if (nursery.isEnabled()) {
|
|
|
|
t = static_cast<T *>(nursery.allocate(thingSize));
|
|
|
|
JS_ASSERT(t);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
2013-10-07 16:43:32 +00:00
|
|
|
return nullptr;
|
2013-03-14 17:26:06 +00:00
|
|
|
}
|
|
|
|
#endif /* JSGC_GENERATIONAL */
|
|
|
|
|
2010-09-24 17:54:39 +00:00
|
|
|
/*
|
|
|
|
* Allocates a new GC thing. After a successful allocation the caller must
|
|
|
|
* fully initialize the thing before calling any function that can potentially
|
|
|
|
* trigger GC. This will ensure that GC tracing never sees junk values stored
|
|
|
|
* in the partially initialized thing.
|
|
|
|
*/
|
2013-01-23 22:22:10 +00:00
|
|
|
template <typename T, AllowGC allowGC>
|
2011-04-15 23:56:08 +00:00
|
|
|
inline T *
|
2013-07-11 01:25:42 +00:00
|
|
|
NewGCThing(ThreadSafeContext *cx, AllocKind kind, size_t thingSize, InitialHeap heap)
|
2010-09-24 17:54:39 +00:00
|
|
|
{
|
2011-08-18 07:16:08 +00:00
|
|
|
JS_ASSERT(thingSize == js::gc::Arena::thingSize(kind));
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2013-07-11 01:25:42 +00:00
|
|
|
if (cx->isJSContext()) {
|
|
|
|
JSContext *ncx = cx->asJSContext();
|
2014-01-08 18:21:30 +00:00
|
|
|
#if defined(JS_GC_ZEAL) || defined(DEBUG)
|
2013-09-20 17:24:29 +00:00
|
|
|
JSRuntime *rt = ncx->runtime();
|
|
|
|
JS_ASSERT_IF(rt->isAtomsCompartment(ncx->compartment()),
|
2013-06-20 23:40:53 +00:00
|
|
|
kind == FINALIZE_STRING ||
|
|
|
|
kind == FINALIZE_SHORT_STRING ||
|
2013-12-18 22:01:51 +00:00
|
|
|
kind == FINALIZE_JITCODE);
|
2013-09-20 17:24:29 +00:00
|
|
|
JS_ASSERT(!rt->isHeapBusy());
|
|
|
|
JS_ASSERT(!rt->noGCOrAllocationCheck);
|
2014-01-08 18:21:30 +00:00
|
|
|
#endif
|
2013-06-20 23:40:53 +00:00
|
|
|
|
|
|
|
/* For testing out of memory conditions */
|
2013-07-11 01:25:42 +00:00
|
|
|
JS_OOM_POSSIBLY_FAIL_REPORT(ncx);
|
2012-03-10 20:53:03 +00:00
|
|
|
|
2011-06-02 00:48:52 +00:00
|
|
|
#ifdef JS_GC_ZEAL
|
2013-12-16 08:57:37 +00:00
|
|
|
if (allowGC && rt->needZealousGC())
|
2013-07-11 01:25:42 +00:00
|
|
|
js::gc::RunDebugGC(ncx);
|
2011-06-02 00:48:52 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-20 23:40:53 +00:00
|
|
|
if (allowGC)
|
2013-07-11 01:25:42 +00:00
|
|
|
MaybeCheckStackRoots(ncx);
|
2013-06-20 23:40:53 +00:00
|
|
|
}
|
2011-12-31 14:32:04 +00:00
|
|
|
|
2013-07-10 15:29:52 +00:00
|
|
|
#ifdef JSGC_GENERATIONAL
|
2013-07-11 01:25:42 +00:00
|
|
|
if (cx->hasNursery() && ShouldNurseryAllocate(cx->nursery(), kind, heap)) {
|
|
|
|
T *t = TryNewNurseryGCThing<T, allowGC>(cx, thingSize);
|
2013-03-14 17:26:06 +00:00
|
|
|
if (t)
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-11 01:25:42 +00:00
|
|
|
T *t = static_cast<T *>(cx->allocator()->arenas.allocateFromFreeList(kind, thingSize));
|
2011-10-25 23:07:42 +00:00
|
|
|
if (!t)
|
2013-07-11 01:25:42 +00:00
|
|
|
t = static_cast<T *>(js::gc::ArenaLists::refillFreeList<allowGC>(cx, kind));
|
2013-06-20 23:40:53 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-07-11 01:25:42 +00:00
|
|
|
if (cx->isJSContext()) {
|
|
|
|
Zone *zone = cx->asJSContext()->zone();
|
2013-06-20 23:40:53 +00:00
|
|
|
JS_ASSERT_IF(t && zone->wasGCStarted() && (zone->isGCMarking() || zone->isGCSweeping()),
|
|
|
|
t->arenaHeader()->allocatedDuringIncremental);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-18 13:27:28 +00:00
|
|
|
return t;
|
2011-11-03 16:57:12 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 22:40:14 +00:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
|
|
|
|
2013-01-23 22:22:10 +00:00
|
|
|
template <js::AllowGC allowGC>
|
2010-09-24 17:54:39 +00:00
|
|
|
inline JSObject *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCObject(js::ThreadSafeContext *cx, js::gc::AllocKind kind, js::gc::InitialHeap heap)
|
2010-09-24 17:54:39 +00:00
|
|
|
{
|
2011-10-26 20:02:57 +00:00
|
|
|
JS_ASSERT(kind >= js::gc::FINALIZE_OBJECT0 && kind <= js::gc::FINALIZE_OBJECT_LAST);
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<JSObject, allowGC>(cx, kind, js::gc::Arena::thingSize(kind), heap);
|
2011-11-03 16:57:12 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 22:22:10 +00:00
|
|
|
template <js::AllowGC allowGC>
|
2010-09-24 17:54:39 +00:00
|
|
|
inline JSString *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCString(js::ThreadSafeContext *cx)
|
2010-09-24 17:54:39 +00:00
|
|
|
{
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<JSString, allowGC>(cx, js::gc::FINALIZE_STRING,
|
2013-01-28 19:01:54 +00:00
|
|
|
sizeof(JSString), js::gc::TenuredHeap);
|
2013-01-15 21:51:56 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 22:22:10 +00:00
|
|
|
template <js::AllowGC allowGC>
|
2010-09-24 17:54:39 +00:00
|
|
|
inline JSShortString *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCShortString(js::ThreadSafeContext *cx)
|
2010-09-24 17:54:39 +00:00
|
|
|
{
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<JSShortString, allowGC>(cx, js::gc::FINALIZE_SHORT_STRING,
|
2013-01-28 19:01:54 +00:00
|
|
|
sizeof(JSShortString), js::gc::TenuredHeap);
|
2013-01-15 21:51:56 +00:00
|
|
|
}
|
|
|
|
|
2010-11-15 20:39:00 +00:00
|
|
|
inline JSExternalString *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCExternalString(js::ThreadSafeContext *cx)
|
2010-09-24 17:54:39 +00:00
|
|
|
{
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<JSExternalString, js::CanGC>(cx, js::gc::FINALIZE_EXTERNAL_STRING,
|
2013-01-28 19:01:54 +00:00
|
|
|
sizeof(JSExternalString), js::gc::TenuredHeap);
|
2010-09-24 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-09 08:51:59 +00:00
|
|
|
inline JSScript *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCScript(js::ThreadSafeContext *cx)
|
2011-08-09 08:51:59 +00:00
|
|
|
{
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<JSScript, js::CanGC>(cx, js::gc::FINALIZE_SCRIPT,
|
2013-01-28 19:01:54 +00:00
|
|
|
sizeof(JSScript), js::gc::TenuredHeap);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 12:29:56 +00:00
|
|
|
inline js::LazyScript *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCLazyScript(js::ThreadSafeContext *cx)
|
2013-05-30 12:29:56 +00:00
|
|
|
{
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<js::LazyScript, js::CanGC>(cx, js::gc::FINALIZE_LAZY_SCRIPT,
|
2013-05-30 12:29:56 +00:00
|
|
|
sizeof(js::LazyScript), js::gc::TenuredHeap);
|
|
|
|
}
|
|
|
|
|
2013-04-30 22:40:09 +00:00
|
|
|
inline js::Shape *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCShape(js::ThreadSafeContext *cx)
|
2011-03-23 18:57:44 +00:00
|
|
|
{
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<js::Shape, js::CanGC>(cx, js::gc::FINALIZE_SHAPE,
|
2013-01-28 19:01:54 +00:00
|
|
|
sizeof(js::Shape), js::gc::TenuredHeap);
|
2011-03-23 18:57:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 22:22:10 +00:00
|
|
|
template <js::AllowGC allowGC>
|
2013-04-30 22:39:45 +00:00
|
|
|
inline js::BaseShape *
|
2013-07-11 01:25:42 +00:00
|
|
|
js_NewGCBaseShape(js::ThreadSafeContext *cx)
|
2011-09-28 22:04:55 +00:00
|
|
|
{
|
2013-07-11 01:25:42 +00:00
|
|
|
return js::gc::NewGCThing<js::BaseShape, allowGC>(cx, js::gc::FINALIZE_BASE_SHAPE,
|
2013-01-28 19:01:54 +00:00
|
|
|
sizeof(js::BaseShape), js::gc::TenuredHeap);
|
2011-09-28 22:04:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 00:59:46 +00:00
|
|
|
#endif /* jsgcinlines_h */
|