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
|
|
|
|
|
|
|
#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"
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2013-03-12 21:05:57 +00:00
|
|
|
#include "js/RootingAPI.h"
|
2011-10-04 22:33:00 +00:00
|
|
|
#include "js/TemplateLib.h"
|
2013-01-26 15:03:19 +00:00
|
|
|
#include "vm/Shape.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-02-07 02:08:16 +00:00
|
|
|
if (zone->rt->gcManipulatingDeadZones && zone->scheduledForDestruction) {
|
|
|
|
zone->rt->gcObjectsMarkedInDeadZones++;
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-10-13 18:49:22 +00:00
|
|
|
namespace gc {
|
|
|
|
|
|
|
|
/* Capacity for slotsToThingKind */
|
|
|
|
const size_t SLOTS_TO_THING_KIND_LIMIT = 17;
|
|
|
|
|
2013-06-18 01:31:47 +00:00
|
|
|
extern const AllocKind slotsToThingKind[];
|
2012-11-16 21:59:26 +00:00
|
|
|
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
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)
|
|
|
|
{
|
|
|
|
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-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
|
|
|
{
|
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
|
|
|
{
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-07 01:52:31 +00:00
|
|
|
inline bool
|
2013-03-11 17:47:33 +00:00
|
|
|
IsInsideNursery(JSRuntime *rt, const void *thing)
|
2013-03-07 01:52:31 +00:00
|
|
|
{
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
2013-03-14 17:26:06 +00:00
|
|
|
return rt->gcNursery.isInside(thing);
|
2013-03-07 01:52:31 +00:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if (IsInsideNursery(cell->runtime(), cell))
|
|
|
|
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() {
|
|
|
|
aheader = NULL;
|
|
|
|
remainingHeader = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(ArenaHeader *aheaderArg) {
|
|
|
|
aheader = aheaderArg;
|
|
|
|
remainingHeader = NULL;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
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() {
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
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:
|
2013-03-17 03:36:37 +00:00
|
|
|
CellIterUnderGC(JS::Zone *zone, AllocKind kind) {
|
|
|
|
JS_ASSERT(zone->rt->isHeapBusy());
|
|
|
|
init(zone, kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
2012-02-17 22:35:20 +00:00
|
|
|
|
|
|
|
CellIterUnderGC(ArenaHeader *aheader) {
|
2013-01-27 20:37:18 +00:00
|
|
|
JS_ASSERT(aheader->zone->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:
|
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-03-17 03:36:37 +00:00
|
|
|
gc::FinishBackgroundFinalize(zone->rt);
|
2013-02-08 08:40:39 +00:00
|
|
|
}
|
2011-08-18 07:16:08 +00:00
|
|
|
if (lists->isSynchronizedFreeList(kind)) {
|
2011-08-09 08:51:59 +00:00
|
|
|
lists = NULL;
|
|
|
|
} else {
|
2013-03-17 03:36:37 +00:00
|
|
|
JS_ASSERT(!zone->rt->isHeapBusy());
|
2011-08-18 07:16:08 +00:00
|
|
|
lists->copyFreeListToArena(kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2013-03-17 03:36:37 +00:00
|
|
|
counter = &zone->rt->noGCOrAllocationCheck;
|
2011-08-09 08:51:59 +00:00
|
|
|
++*counter;
|
|
|
|
#endif
|
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-03-17 03:36:37 +00:00
|
|
|
GCZonesIter(JSRuntime *rt) : zone(rt) {
|
|
|
|
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
|
|
|
|
* room in the nursery or there is an OOM, this method will return NULL.
|
|
|
|
*/
|
|
|
|
template <typename T, AllowGC allowGC>
|
|
|
|
inline T *
|
|
|
|
TryNewNurseryGCThing(JSContext *cx, size_t thingSize)
|
|
|
|
{
|
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) {
|
|
|
|
MinorGC(rt, JS::gcreason::OUT_OF_NURSERY);
|
|
|
|
|
|
|
|
/* Exceeding gcMaxBytes while tenuring can disable the Nursery. */
|
|
|
|
if (nursery.isEnabled()) {
|
|
|
|
t = static_cast<T *>(nursery.allocate(thingSize));
|
|
|
|
JS_ASSERT(t);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#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-01-28 19:01:54 +00:00
|
|
|
NewGCThing(JSContext *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));
|
2013-06-10 21:22:18 +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);
|
2013-06-10 21:22:18 +00:00
|
|
|
JS_ASSERT(!cx->runtime()->isHeapBusy());
|
|
|
|
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-06-10 21:22:18 +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)
|
2013-03-08 08:54:59 +00:00
|
|
|
MaybeCheckStackRoots(cx);
|
2011-12-31 14:32:04 +00:00
|
|
|
|
2013-03-14 17:26:06 +00:00
|
|
|
#if defined(JSGC_GENERATIONAL)
|
2013-06-10 21:22:18 +00:00
|
|
|
if (ShouldNurseryAllocate(cx->runtime()->gcNursery, kind, heap)) {
|
2013-03-14 17:26:06 +00:00
|
|
|
T *t = TryNewNurseryGCThing<T, allowGC>(cx, thingSize);
|
|
|
|
if (t)
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-27 21:51:41 +00:00
|
|
|
JS::Zone *zone = cx->zone();
|
|
|
|
T *t = static_cast<T *>(zone->allocator.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
|
|
|
|
2013-01-27 21:51:41 +00:00
|
|
|
JS_ASSERT_IF(t && zone->wasGCStarted() && (zone->isGCMarking() || zone->isGCSweeping()),
|
2012-12-18 13:27:28 +00:00
|
|
|
t->arenaHeader()->allocatedDuringIncremental);
|
2012-06-21 01:48:56 +00:00
|
|
|
|
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-01-28 19:01:54 +00:00
|
|
|
js_NewGCObject(JSContext *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-01-28 19:01:54 +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 *
|
|
|
|
js_NewGCString(JSContext *cx)
|
|
|
|
{
|
2013-01-28 19:01:54 +00:00
|
|
|
return js::gc::NewGCThing<JSString, allowGC>(cx, js::gc::FINALIZE_STRING,
|
|
|
|
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 *
|
|
|
|
js_NewGCShortString(JSContext *cx)
|
|
|
|
{
|
2013-01-28 19:01:54 +00:00
|
|
|
return js::gc::NewGCThing<JSShortString, allowGC>(cx, js::gc::FINALIZE_SHORT_STRING,
|
|
|
|
sizeof(JSShortString), js::gc::TenuredHeap);
|
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-25 03:18:34 +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 *
|
|
|
|
js_NewGCScript(JSContext *cx)
|
|
|
|
{
|
2013-01-28 19:01:54 +00:00
|
|
|
return js::gc::NewGCThing<JSScript, js::CanGC>(cx, js::gc::FINALIZE_SCRIPT,
|
|
|
|
sizeof(JSScript), js::gc::TenuredHeap);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 12:29:56 +00:00
|
|
|
inline js::LazyScript *
|
|
|
|
js_NewGCLazyScript(JSContext *cx)
|
|
|
|
{
|
|
|
|
return js::gc::NewGCThing<js::LazyScript, js::CanGC>(cx, js::gc::FINALIZE_LAZY_SCRIPT,
|
|
|
|
sizeof(js::LazyScript), js::gc::TenuredHeap);
|
|
|
|
}
|
|
|
|
|
2013-04-30 22:40:09 +00:00
|
|
|
inline js::Shape *
|
2011-03-23 18:57:44 +00:00
|
|
|
js_NewGCShape(JSContext *cx)
|
|
|
|
{
|
2013-01-28 19:01:54 +00:00
|
|
|
return js::gc::NewGCThing<js::Shape, js::CanGC>(cx, js::gc::FINALIZE_SHAPE,
|
|
|
|
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 *
|
2011-09-28 22:04:55 +00:00
|
|
|
js_NewGCBaseShape(JSContext *cx)
|
|
|
|
{
|
2013-01-28 19:01:54 +00:00
|
|
|
return js::gc::NewGCThing<js::BaseShape, allowGC>(cx, js::gc::FINALIZE_BASE_SHAPE,
|
|
|
|
sizeof(js::BaseShape), js::gc::TenuredHeap);
|
2011-09-28 22:04:55 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 17:54:39 +00:00
|
|
|
#endif /* jsgcinlines_h___ */
|