2011-04-20 05:30:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2010-09-24 17:54:39 +00:00
|
|
|
*
|
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
|
|
|
|
|
|
|
#ifndef jsgcinlines_h___
|
|
|
|
#define jsgcinlines_h___
|
|
|
|
|
|
|
|
#include "jsgc.h"
|
|
|
|
#include "jscntxt.h"
|
|
|
|
#include "jscompartment.h"
|
2011-10-04 22:33:00 +00:00
|
|
|
#include "jslock.h"
|
2011-03-14 20:59:53 +00:00
|
|
|
#include "jsscope.h"
|
2011-05-11 12:46:33 +00:00
|
|
|
#include "jsxml.h"
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2012-11-07 01:35:18 +00:00
|
|
|
#include "gc/Root.h"
|
|
|
|
|
2011-10-04 22:33:00 +00:00
|
|
|
#include "js/TemplateLib.h"
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2012-11-07 01:35:18 +00:00
|
|
|
using JS::AssertCanGC;
|
2012-10-04 21:22:51 +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
|
2012-11-12 22:57:53 +00:00
|
|
|
* be set on an object in a dead compartment. See AutoMaybeTouchDeadCompartments
|
|
|
|
* for more details.
|
2012-11-09 19:44:21 +00:00
|
|
|
*/
|
|
|
|
struct AutoMarkInDeadCompartment
|
|
|
|
{
|
|
|
|
AutoMarkInDeadCompartment(JSCompartment *comp)
|
|
|
|
: compartment(comp),
|
|
|
|
scheduled(comp->scheduledForDestruction)
|
|
|
|
{
|
2012-11-12 22:57:53 +00:00
|
|
|
if (comp->rt->gcManipulatingDeadCompartments && comp->scheduledForDestruction) {
|
2012-11-09 19:44:21 +00:00
|
|
|
comp->rt->gcObjectsMarkedInDeadCompartments++;
|
|
|
|
comp->scheduledForDestruction = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoMarkInDeadCompartment() {
|
|
|
|
compartment->scheduledForDestruction = scheduled;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSCompartment *compartment;
|
|
|
|
bool scheduled;
|
|
|
|
};
|
|
|
|
|
2010-10-13 18:49:22 +00:00
|
|
|
namespace gc {
|
|
|
|
|
2011-08-09 08:51:59 +00:00
|
|
|
inline JSGCTraceKind
|
2011-03-23 18:57:15 +00:00
|
|
|
GetGCThingTraceKind(const void *thing)
|
2011-03-14 20:59:53 +00:00
|
|
|
{
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2011-03-14 20:59:53 +00:00
|
|
|
JS_ASSERT(thing);
|
2011-03-23 18:57:15 +00:00
|
|
|
const Cell *cell = reinterpret_cast<const Cell *>(thing);
|
2011-08-18 07:16:08 +00:00
|
|
|
return MapAllocToTraceKind(cell->getAllocKind());
|
2011-03-14 20:59:53 +00:00
|
|
|
}
|
|
|
|
|
2010-10-13 18:49:22 +00:00
|
|
|
/* Capacity for slotsToThingKind */
|
|
|
|
const size_t SLOTS_TO_THING_KIND_LIMIT = 17;
|
|
|
|
|
2012-11-16 21:59:26 +00:00
|
|
|
extern AllocKind slotsToThingKind[];
|
|
|
|
|
2011-05-17 05:59:40 +00:00
|
|
|
/* Get the best kind to use when making an object with the given slot count. */
|
2011-08-18 07:16:08 +00:00
|
|
|
static inline AllocKind
|
2011-10-10 18:41:03 +00:00
|
|
|
GetGCObjectKind(size_t numSlots)
|
2010-10-13 18:49:22 +00:00
|
|
|
{
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2011-10-10 18:41:03 +00:00
|
|
|
if (numSlots >= SLOTS_TO_THING_KIND_LIMIT)
|
|
|
|
return FINALIZE_OBJECT16;
|
2010-10-13 18:49:22 +00:00
|
|
|
return slotsToThingKind[numSlots];
|
|
|
|
}
|
|
|
|
|
2011-10-11 00:14:38 +00:00
|
|
|
static inline AllocKind
|
|
|
|
GetGCObjectKind(Class *clasp)
|
|
|
|
{
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2011-10-11 22:28:54 +00:00
|
|
|
if (clasp == &FunctionClass)
|
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);
|
|
|
|
}
|
|
|
|
|
2011-10-10 18:41:03 +00:00
|
|
|
/* As for GetGCObjectKind, but for dense array allocation. */
|
|
|
|
static inline AllocKind
|
|
|
|
GetGCArrayKind(size_t numSlots)
|
|
|
|
{
|
|
|
|
extern AllocKind slotsToThingKind[];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dense arrays can use their fixed slots to hold their elements array
|
|
|
|
* (less two Values worth of ObjectElements header), but if more than the
|
|
|
|
* maximum number of fixed slots is needed then the fixed slots will be
|
|
|
|
* unused.
|
|
|
|
*/
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2011-11-08 21:03:33 +00:00
|
|
|
JS_STATIC_ASSERT(ObjectElements::VALUES_PER_HEADER == 2);
|
2011-10-14 18:06:15 +00:00
|
|
|
if (numSlots > JSObject::NELEMENTS_LIMIT || numSlots + 2 >= SLOTS_TO_THING_KIND_LIMIT)
|
2011-10-10 18:41:03 +00:00
|
|
|
return FINALIZE_OBJECT2;
|
|
|
|
return slotsToThingKind[numSlots + 2];
|
|
|
|
}
|
|
|
|
|
2011-08-16 10:27:34 +00:00
|
|
|
static inline AllocKind
|
|
|
|
GetGCObjectFixedSlotsKind(size_t numFixedSlots)
|
|
|
|
{
|
|
|
|
extern AllocKind slotsToThingKind[];
|
|
|
|
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2011-08-16 10:27:34 +00:00
|
|
|
JS_ASSERT(numFixedSlots < SLOTS_TO_THING_KIND_LIMIT);
|
|
|
|
return slotsToThingKind[numFixedSlots];
|
|
|
|
}
|
|
|
|
|
2011-08-18 07:16:08 +00:00
|
|
|
static inline AllocKind
|
|
|
|
GetBackgroundAllocKind(AllocKind kind)
|
2011-06-04 03:48:16 +00:00
|
|
|
{
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2012-08-21 08:47:15 +00:00
|
|
|
JS_ASSERT(!IsBackgroundFinalized(kind));
|
|
|
|
JS_ASSERT(kind <= FINALIZE_OBJECT_LAST);
|
2011-08-18 07:16:08 +00:00
|
|
|
return (AllocKind) (kind + 1);
|
2011-06-04 03:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 07:16:08 +00:00
|
|
|
/*
|
|
|
|
* Try to get the next larger size for an object, keeping BACKGROUND
|
|
|
|
* consistent.
|
|
|
|
*/
|
2011-06-04 03:48:16 +00:00
|
|
|
static inline bool
|
2011-08-18 07:16:08 +00:00
|
|
|
TryIncrementAllocKind(AllocKind *kindp)
|
2011-06-04 03:48:16 +00:00
|
|
|
{
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2011-08-18 07:16:08 +00:00
|
|
|
size_t next = size_t(*kindp) + 2;
|
2011-10-25 23:07:42 +00:00
|
|
|
if (next >= size_t(FINALIZE_OBJECT_LIMIT))
|
2011-08-18 07:16:08 +00:00
|
|
|
return false;
|
|
|
|
*kindp = AllocKind(next);
|
|
|
|
return true;
|
2011-06-04 03:48:16 +00:00
|
|
|
}
|
|
|
|
|
2010-10-13 18:49:22 +00:00
|
|
|
/* Get the number of fixed slots and initial capacity associated with a kind. */
|
|
|
|
static inline size_t
|
2011-08-18 07:16:08 +00:00
|
|
|
GetGCKindSlots(AllocKind thingKind)
|
2010-10-13 18:49:22 +00:00
|
|
|
{
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2010-10-13 18:49:22 +00:00
|
|
|
/* Using a switch in hopes that thingKind will usually be a compile-time constant. */
|
|
|
|
switch (thingKind) {
|
|
|
|
case FINALIZE_OBJECT0:
|
2011-04-13 20:43:33 +00:00
|
|
|
case FINALIZE_OBJECT0_BACKGROUND:
|
2010-10-13 18:49:22 +00:00
|
|
|
return 0;
|
|
|
|
case FINALIZE_OBJECT2:
|
2011-04-13 20:43:33 +00:00
|
|
|
case FINALIZE_OBJECT2_BACKGROUND:
|
2010-10-13 18:49:22 +00:00
|
|
|
return 2;
|
|
|
|
case FINALIZE_OBJECT4:
|
2011-04-13 20:43:33 +00:00
|
|
|
case FINALIZE_OBJECT4_BACKGROUND:
|
2010-10-13 18:49:22 +00:00
|
|
|
return 4;
|
|
|
|
case FINALIZE_OBJECT8:
|
2011-04-13 20:43:33 +00:00
|
|
|
case FINALIZE_OBJECT8_BACKGROUND:
|
2010-10-13 18:49:22 +00:00
|
|
|
return 8;
|
|
|
|
case FINALIZE_OBJECT12:
|
2011-04-13 20:43:33 +00:00
|
|
|
case FINALIZE_OBJECT12_BACKGROUND:
|
2010-10-13 18:49:22 +00:00
|
|
|
return 12;
|
|
|
|
case FINALIZE_OBJECT16:
|
2011-04-13 20:43:33 +00:00
|
|
|
case FINALIZE_OBJECT16_BACKGROUND:
|
2010-10-13 18:49:22 +00:00
|
|
|
return 16;
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("Bad object finalize kind");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 18:06:15 +00:00
|
|
|
static inline size_t
|
|
|
|
GetGCKindSlots(AllocKind thingKind, Class *clasp)
|
|
|
|
{
|
2012-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
2011-10-14 18:06:15 +00:00
|
|
|
size_t nslots = GetGCKindSlots(thingKind);
|
2011-10-26 20:02:57 +00:00
|
|
|
|
|
|
|
/* An object's private data uses the space taken by its last fixed slot. */
|
2011-10-14 18:06:15 +00:00
|
|
|
if (clasp->flags & JSCLASS_HAS_PRIVATE) {
|
|
|
|
JS_ASSERT(nslots > 0);
|
|
|
|
nslots--;
|
|
|
|
}
|
2011-10-26 20:02:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions have a larger finalize kind than FINALIZE_OBJECT to reserve
|
|
|
|
* space for the extra fields in JSFunction, but have no fixed slots.
|
|
|
|
*/
|
|
|
|
if (clasp == &FunctionClass)
|
|
|
|
nslots = 0;
|
|
|
|
|
2011-10-14 18:06:15 +00:00
|
|
|
return nslots;
|
|
|
|
}
|
|
|
|
|
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-10-04 21:22:51 +00:00
|
|
|
AutoAssertNoGC nogc;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
ArenaIter(JSCompartment *comp, AllocKind kind) {
|
|
|
|
init(comp, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
aheader = NULL;
|
|
|
|
remainingHeader = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(ArenaHeader *aheaderArg) {
|
|
|
|
aheader = aheaderArg;
|
|
|
|
remainingHeader = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(JSCompartment *comp, AllocKind kind) {
|
|
|
|
aheader = comp->arenas.getFirstArena(kind);
|
|
|
|
remainingHeader = comp->arenas.getFirstArenaToSweep(kind);
|
|
|
|
if (!aheader) {
|
|
|
|
aheader = remainingHeader;
|
|
|
|
remainingHeader = NULL;
|
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;
|
|
|
|
remainingHeader = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
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() {
|
|
|
|
}
|
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
void initSpan(JSCompartment *comp, AllocKind kind) {
|
2011-09-06 14:13:56 +00:00
|
|
|
JS_ASSERT(comp->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) {
|
2012-08-09 18:16:33 +00:00
|
|
|
initSpan(singleAheader->compartment, singleAheader->getAllocKind());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void init(JSCompartment *comp, AllocKind kind) {
|
|
|
|
initSpan(comp, kind);
|
2012-08-09 18:16:33 +00:00
|
|
|
aiter.init(comp, 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;
|
|
|
|
if (JS_LIKELY(span->hasNext())) {
|
|
|
|
thing = span->last + thingSize;
|
|
|
|
span = span->nextSpan();
|
|
|
|
break;
|
|
|
|
}
|
2012-08-09 18:16:33 +00:00
|
|
|
if (aiter.done()) {
|
2011-08-09 08:51:59 +00:00
|
|
|
cell = NULL;
|
|
|
|
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:
|
2011-08-18 07:16:08 +00:00
|
|
|
CellIterUnderGC(JSCompartment *comp, AllocKind kind) {
|
2012-07-04 00:24:03 +00:00
|
|
|
JS_ASSERT(comp->rt->isHeapBusy());
|
2011-08-18 07:16:08 +00:00
|
|
|
init(comp, kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
2012-02-17 22:35:20 +00:00
|
|
|
|
|
|
|
CellIterUnderGC(ArenaHeader *aheader) {
|
2012-07-04 00:24:03 +00:00
|
|
|
JS_ASSERT(aheader->compartment->rt->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:
|
2012-02-29 20:23:53 +00:00
|
|
|
CellIter(JSCompartment *comp, AllocKind kind)
|
2011-08-18 07:16:08 +00:00
|
|
|
: lists(&comp->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
|
|
|
|
* background finalization; make sure people aren't using CellIter to
|
|
|
|
* walk such allocation kinds.
|
|
|
|
*/
|
2012-08-21 08:47:15 +00:00
|
|
|
JS_ASSERT(!IsBackgroundFinalized(kind));
|
2011-08-18 07:16:08 +00:00
|
|
|
if (lists->isSynchronizedFreeList(kind)) {
|
2011-08-09 08:51:59 +00:00
|
|
|
lists = NULL;
|
|
|
|
} else {
|
2012-07-04 00:24:03 +00:00
|
|
|
JS_ASSERT(!comp->rt->isHeapBusy());
|
2011-08-18 07:16:08 +00:00
|
|
|
lists->copyFreeListToArena(kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2012-02-29 20:23:53 +00:00
|
|
|
counter = &comp->rt->noGCOrAllocationCheck;
|
2011-08-09 08:51:59 +00:00
|
|
|
++*counter;
|
|
|
|
#endif
|
2011-08-18 07:16:08 +00:00
|
|
|
init(comp, 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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-09 18:16:33 +00:00
|
|
|
/*
|
|
|
|
* Invoke ArenaOp and CellOp on every arena and cell in a compartment which
|
|
|
|
* have the specified thing kind.
|
|
|
|
*/
|
|
|
|
template <class ArenaOp, class CellOp>
|
|
|
|
void
|
|
|
|
ForEachArenaAndCell(JSCompartment *compartment, AllocKind thingKind,
|
|
|
|
ArenaOp arenaOp, CellOp cellOp)
|
|
|
|
{
|
|
|
|
for (ArenaIter aiter(compartment, thingKind); !aiter.done(); aiter.next()) {
|
|
|
|
ArenaHeader *aheader = aiter.get();
|
|
|
|
arenaOp(aheader->getArena());
|
|
|
|
for (CellIterUnderGC iter(aheader); !iter.done(); iter.next())
|
|
|
|
cellOp(iter.getCell());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-26 19:39:31 +00:00
|
|
|
/* Signatures for ArenaOp and CellOp above. */
|
|
|
|
|
|
|
|
inline void EmptyArenaOp(Arena *arena) {}
|
|
|
|
inline void EmptyCellOp(Cell *t) {}
|
|
|
|
|
2012-04-03 00:02:25 +00:00
|
|
|
class GCCompartmentsIter {
|
|
|
|
private:
|
|
|
|
JSCompartment **it, **end;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GCCompartmentsIter(JSRuntime *rt) {
|
2012-07-04 00:24:03 +00:00
|
|
|
JS_ASSERT(rt->isHeapBusy());
|
2012-04-03 00:02:25 +00:00
|
|
|
it = rt->compartments.begin();
|
|
|
|
end = rt->compartments.end();
|
|
|
|
if (!(*it)->isCollecting())
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool done() const { return it == end; }
|
|
|
|
|
|
|
|
void next() {
|
|
|
|
JS_ASSERT(!done());
|
|
|
|
do {
|
|
|
|
it++;
|
|
|
|
} while (it != end && !(*it)->isCollecting());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSCompartment *get() const {
|
|
|
|
JS_ASSERT(!done());
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator JSCompartment *() const { return get(); }
|
|
|
|
JSCompartment *operator->() const { return get(); }
|
|
|
|
};
|
|
|
|
|
2012-12-04 19:31:41 +00:00
|
|
|
/* Iterates over all compartments in the current compartment group. */
|
2012-11-16 15:34:22 +00:00
|
|
|
class GCCompartmentGroupIter {
|
|
|
|
private:
|
|
|
|
JSCompartment *current;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GCCompartmentGroupIter(JSRuntime *rt) {
|
|
|
|
JS_ASSERT(rt->isHeapBusy());
|
2012-12-04 19:31:41 +00:00
|
|
|
current = rt->gcCurrentCompartmentGroup;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
JSCompartment *get() const {
|
|
|
|
JS_ASSERT(!done());
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator JSCompartment *() const { return get(); }
|
|
|
|
JSCompartment *operator->() const { return get(); }
|
|
|
|
};
|
|
|
|
|
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 *
|
2011-08-18 07:16:08 +00:00
|
|
|
NewGCThing(JSContext *cx, js::gc::AllocKind kind, size_t thingSize)
|
2010-09-24 17:54:39 +00:00
|
|
|
{
|
2013-01-23 22:22:10 +00:00
|
|
|
if (allowGC)
|
|
|
|
AssertCanGC();
|
|
|
|
|
2011-08-18 07:16:08 +00:00
|
|
|
JS_ASSERT(thingSize == js::gc::Arena::thingSize(kind));
|
2012-06-13 09:27:45 +00:00
|
|
|
JS_ASSERT_IF(cx->compartment == cx->runtime->atomsCompartment,
|
2012-11-14 14:46:31 +00:00
|
|
|
kind == FINALIZE_STRING ||
|
|
|
|
kind == FINALIZE_SHORT_STRING ||
|
|
|
|
kind == FINALIZE_IONCODE);
|
2012-07-04 00:24:03 +00:00
|
|
|
JS_ASSERT(!cx->runtime->isHeapBusy());
|
2011-07-18 21:54:48 +00:00
|
|
|
JS_ASSERT(!cx->runtime->noGCOrAllocationCheck);
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2012-03-10 20:53:03 +00:00
|
|
|
/* For testing out of memory conditions */
|
2012-04-14 18:37:32 +00:00
|
|
|
JS_OOM_POSSIBLY_FAIL_REPORT(cx);
|
2012-03-10 20:53:03 +00:00
|
|
|
|
2011-06-02 00:48:52 +00:00
|
|
|
#ifdef JS_GC_ZEAL
|
2013-01-23 22:22:10 +00:00
|
|
|
if (cx->runtime->needZealousGC() && allowGC)
|
2011-06-02 00:48:52 +00:00
|
|
|
js::gc::RunDebugGC(cx);
|
|
|
|
#endif
|
|
|
|
|
2013-01-23 22:22:10 +00:00
|
|
|
if (allowGC)
|
|
|
|
MaybeCheckStackRoots(cx, /* relax = */ false);
|
2011-12-31 14:32:04 +00:00
|
|
|
|
2011-10-25 23:07:42 +00:00
|
|
|
JSCompartment *comp = cx->compartment;
|
2012-12-18 13:27:28 +00:00
|
|
|
T *t = static_cast<T *>(comp->arenas.allocateFromFreeList(kind, thingSize));
|
2011-10-25 23:07:42 +00:00
|
|
|
if (!t)
|
2013-01-23 22:22:10 +00:00
|
|
|
t = static_cast<T *>(js::gc::ArenaLists::refillFreeList<allowGC>(cx, kind));
|
2011-11-03 16:57:12 +00:00
|
|
|
|
2012-11-16 15:34:22 +00:00
|
|
|
JS_ASSERT_IF(t && comp->wasGCStarted() && (comp->isGCMarking() || comp->isGCSweeping()),
|
2012-12-18 13:27:28 +00:00
|
|
|
t->arenaHeader()->allocatedDuringIncremental);
|
2012-06-21 01:48:56 +00:00
|
|
|
|
|
|
|
#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL)
|
|
|
|
if (cx->runtime->gcVerifyPostData && IsNurseryAllocable(kind) && !IsAtomsCompartment(comp))
|
|
|
|
comp->gcNursery.insertPointer(t);
|
|
|
|
#endif
|
2012-12-18 13:27:28 +00:00
|
|
|
|
|
|
|
return t;
|
2011-11-03 16:57:12 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 16:23:28 +00:00
|
|
|
/*
|
|
|
|
* Instances of this class set the |JSRuntime::suppressGC| flag for the duration
|
|
|
|
* that they are live. Use of this class is highly discouraged. Please carefully
|
|
|
|
* read the comment in jscntxt.h above |suppressGC| and take all appropriate
|
|
|
|
* precautions before instantiating this class.
|
|
|
|
*/
|
|
|
|
class AutoSuppressGC
|
|
|
|
{
|
|
|
|
int32_t &suppressGC_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoSuppressGC(JSContext *cx)
|
|
|
|
: suppressGC_(cx->runtime->mainThread.suppressGC)
|
|
|
|
{
|
|
|
|
suppressGC_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoSuppressGC(JSCompartment *comp)
|
|
|
|
: suppressGC_(comp->rt->mainThread.suppressGC)
|
|
|
|
{
|
|
|
|
suppressGC_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSuppressGC()
|
|
|
|
{
|
|
|
|
suppressGC_--;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 *
|
2011-08-18 07:16:08 +00:00
|
|
|
js_NewGCObject(JSContext *cx, js::gc::AllocKind kind)
|
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-01-23 22:22:10 +00:00
|
|
|
return js::gc::NewGCThing<JSObject, allowGC>(cx, kind, js::gc::Arena::thingSize(kind));
|
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 *
|
|
|
|
js_NewGCString(JSContext *cx)
|
|
|
|
{
|
2013-01-23 22:22:10 +00:00
|
|
|
return js::gc::NewGCThing<JSString, allowGC>(cx, js::gc::FINALIZE_STRING, sizeof(JSString));
|
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 *
|
|
|
|
js_NewGCShortString(JSContext *cx)
|
|
|
|
{
|
2013-01-23 22:22:10 +00:00
|
|
|
return js::gc::NewGCThing<JSShortString, allowGC>(cx, js::gc::FINALIZE_SHORT_STRING, sizeof(JSShortString));
|
2013-01-15 21:51:56 +00:00
|
|
|
}
|
|
|
|
|
2010-11-15 20:39:00 +00:00
|
|
|
inline JSExternalString *
|
2011-05-11 12:46:33 +00:00
|
|
|
js_NewGCExternalString(JSContext *cx)
|
2010-09-24 17:54:39 +00:00
|
|
|
{
|
2013-01-23 22:22:10 +00:00
|
|
|
return js::gc::NewGCThing<JSExternalString, js::ALLOW_GC>(cx, js::gc::FINALIZE_EXTERNAL_STRING,
|
|
|
|
sizeof(JSExternalString));
|
2010-09-24 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-09 08:51:59 +00:00
|
|
|
inline JSScript *
|
|
|
|
js_NewGCScript(JSContext *cx)
|
|
|
|
{
|
2013-01-23 22:22:10 +00:00
|
|
|
return js::gc::NewGCThing<JSScript, js::ALLOW_GC>(cx, js::gc::FINALIZE_SCRIPT, sizeof(JSScript));
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 18:22:10 +00:00
|
|
|
inline js::UnrootedShape
|
2011-03-23 18:57:44 +00:00
|
|
|
js_NewGCShape(JSContext *cx)
|
|
|
|
{
|
2013-01-23 22:22:10 +00:00
|
|
|
return js::gc::NewGCThing<js::Shape, js::ALLOW_GC>(cx, js::gc::FINALIZE_SHAPE, sizeof(js::Shape));
|
2011-03-23 18:57:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 22:22:10 +00:00
|
|
|
template <js::AllowGC allowGC>
|
2012-12-04 19:10:53 +00:00
|
|
|
inline js::UnrootedBaseShape
|
2011-09-28 22:04:55 +00:00
|
|
|
js_NewGCBaseShape(JSContext *cx)
|
|
|
|
{
|
2013-01-23 22:22:10 +00:00
|
|
|
return js::gc::NewGCThing<js::BaseShape, allowGC>(cx, js::gc::FINALIZE_BASE_SHAPE, sizeof(js::BaseShape));
|
2011-09-28 22:04:55 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 17:54:39 +00:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
2011-07-07 22:40:33 +00:00
|
|
|
extern JSXML *
|
|
|
|
js_NewGCXML(JSContext *cx);
|
2010-09-24 17:54:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* jsgcinlines_h___ */
|