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
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is SpiderMonkey code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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
|
|
|
|
2011-10-04 22:33:00 +00:00
|
|
|
#include "js/TemplateLib.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
|
|
|
|
|
|
|
struct Shape;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
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-08-18 07:16:08 +00:00
|
|
|
extern AllocKind slotsToThingKind[];
|
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)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
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[];
|
|
|
|
|
|
|
|
JS_ASSERT(numFixedSlots < SLOTS_TO_THING_KIND_LIMIT);
|
|
|
|
return slotsToThingKind[numFixedSlots];
|
|
|
|
}
|
|
|
|
|
2011-06-04 03:48:16 +00:00
|
|
|
static inline bool
|
2011-08-18 07:16:08 +00:00
|
|
|
IsBackgroundAllocKind(AllocKind kind)
|
2011-06-04 03:48:16 +00:00
|
|
|
{
|
2011-10-26 20:02:57 +00:00
|
|
|
JS_ASSERT(kind <= FINALIZE_OBJECT_LAST);
|
2011-06-04 03:48:16 +00:00
|
|
|
return kind % 2 == 1;
|
|
|
|
}
|
|
|
|
|
2011-08-18 07:16:08 +00:00
|
|
|
static inline AllocKind
|
|
|
|
GetBackgroundAllocKind(AllocKind kind)
|
2011-06-04 03:48:16 +00:00
|
|
|
{
|
2011-08-18 07:16:08 +00:00
|
|
|
JS_ASSERT(!IsBackgroundAllocKind(kind));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-06-02 00:48:52 +00:00
|
|
|
static inline void
|
2012-02-05 20:07:23 +00:00
|
|
|
GCPoke(JSRuntime *rt, Value oldval)
|
2011-06-02 00:48:52 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Since we're forcing a GC from JS_GC anyway, don't bother wasting cycles
|
|
|
|
* loading oldval. XXX remove implied force, fix jsinterp.c's "second arg
|
|
|
|
* ignored", etc.
|
|
|
|
*/
|
|
|
|
#if 1
|
2012-02-05 20:07:23 +00:00
|
|
|
rt->gcPoke = true;
|
2011-06-02 00:48:52 +00:00
|
|
|
#else
|
2012-02-05 20:07:23 +00:00
|
|
|
rt->gcPoke = oldval.isGCThing();
|
2011-06-02 00:48:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
2011-08-26 19:39:31 +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
|
2011-08-18 07:16:08 +00:00
|
|
|
ForEachArenaAndCell(JSCompartment *compartment, AllocKind thingKind,
|
2011-08-26 19:39:31 +00:00
|
|
|
ArenaOp arenaOp, CellOp cellOp)
|
|
|
|
{
|
2011-08-18 07:16:08 +00:00
|
|
|
size_t thingSize = Arena::thingSize(thingKind);
|
|
|
|
ArenaHeader *aheader = compartment->arenas.getFirstArena(thingKind);
|
2011-08-26 19:39:31 +00:00
|
|
|
|
|
|
|
for (; aheader; aheader = aheader->next) {
|
|
|
|
Arena *arena = aheader->getArena();
|
|
|
|
arenaOp(arena);
|
|
|
|
FreeSpan firstSpan(aheader->getFirstFreeSpan());
|
|
|
|
const FreeSpan *span = &firstSpan;
|
|
|
|
|
2011-08-18 07:16:08 +00:00
|
|
|
for (uintptr_t thing = arena->thingsStart(thingKind); ; thing += thingSize) {
|
2011-08-26 19:39:31 +00:00
|
|
|
JS_ASSERT(thing <= arena->thingsEnd());
|
|
|
|
if (thing == span->first) {
|
|
|
|
if (!span->hasNext())
|
|
|
|
break;
|
|
|
|
thing = span->last;
|
|
|
|
span = span->nextSpan();
|
|
|
|
} else {
|
|
|
|
Cell *t = reinterpret_cast<Cell *>(thing);
|
|
|
|
cellOp(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
ArenaHeader *aheader;
|
|
|
|
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) {
|
|
|
|
aheader = singleAheader;
|
|
|
|
initSpan(aheader->compartment, aheader->getAllocKind());
|
|
|
|
next();
|
|
|
|
aheader = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(JSCompartment *comp, AllocKind kind) {
|
|
|
|
initSpan(comp, kind);
|
|
|
|
aheader = comp->arenas.getFirstArena(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;
|
|
|
|
}
|
|
|
|
if (!aheader) {
|
|
|
|
cell = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
firstSpan = aheader->getFirstFreeSpan();
|
|
|
|
span = &firstSpan;
|
2011-08-18 07:16:08 +00:00
|
|
|
thing = aheader->arenaAddress() | firstThingOffset;
|
2011-08-09 08:51:59 +00:00
|
|
|
aheader = aheader->next;
|
|
|
|
}
|
|
|
|
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) {
|
2011-08-09 08:51:59 +00:00
|
|
|
JS_ASSERT(comp->rt->gcRunning);
|
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) {
|
|
|
|
JS_ASSERT(aheader->compartment->rt->gcRunning);
|
|
|
|
init(aheader);
|
|
|
|
}
|
2011-08-09 08:51:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When using the iterator outside the GC the caller must ensure that no GC or
|
|
|
|
* allocations of GC things are possible and that the background finalization
|
|
|
|
* for the given thing kind is not enabled or is done.
|
|
|
|
*/
|
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:
|
2011-08-18 07:16:08 +00:00
|
|
|
CellIter(JSContext *cx, JSCompartment *comp, AllocKind kind)
|
|
|
|
: lists(&comp->arenas),
|
2012-02-17 22:35:20 +00:00
|
|
|
kind(kind)
|
|
|
|
{
|
2011-08-09 08:51:59 +00:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-08-18 07:16:08 +00:00
|
|
|
JS_ASSERT(comp->arenas.doneBackgroundFinalize(kind));
|
2011-08-09 08:51:59 +00:00
|
|
|
#endif
|
2011-08-18 07:16:08 +00:00
|
|
|
if (lists->isSynchronizedFreeList(kind)) {
|
2011-08-09 08:51:59 +00:00
|
|
|
lists = NULL;
|
|
|
|
} else {
|
|
|
|
JS_ASSERT(!comp->rt->gcRunning);
|
2011-08-18 07:16:08 +00:00
|
|
|
lists->copyFreeListToArena(kind);
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2011-07-18 21:54:48 +00:00
|
|
|
counter = &cx->runtime->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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-08-26 19:39:31 +00:00
|
|
|
/* Signatures for ArenaOp and CellOp above. */
|
|
|
|
|
|
|
|
inline void EmptyArenaOp(Arena *arena) {}
|
|
|
|
inline void EmptyCellOp(Cell *t) {}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T>
|
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
|
|
|
{
|
2011-08-18 07:16:08 +00:00
|
|
|
JS_ASSERT(thingSize == js::gc::Arena::thingSize(kind));
|
2010-10-01 18:10:30 +00:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-01-13 22:42:36 +00:00
|
|
|
JS_ASSERT_IF((cx->compartment == cx->runtime->atomsCompartment),
|
2011-08-18 07:16:08 +00:00
|
|
|
kind == js::gc::FINALIZE_STRING || kind == js::gc::FINALIZE_SHORT_STRING);
|
2010-10-01 18:10:30 +00:00
|
|
|
#endif
|
2011-04-21 22:20:12 +00:00
|
|
|
JS_ASSERT(!cx->runtime->gcRunning);
|
2011-07-18 21:54:48 +00:00
|
|
|
JS_ASSERT(!cx->runtime->noGCOrAllocationCheck);
|
2010-09-24 17:54:39 +00:00
|
|
|
|
2011-06-02 00:48:52 +00:00
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
if (cx->runtime->needZealousGC())
|
|
|
|
js::gc::RunDebugGC(cx);
|
|
|
|
#endif
|
|
|
|
|
2011-12-31 14:32:04 +00:00
|
|
|
js::gc::MaybeCheckStackRoots(cx);
|
|
|
|
|
2011-10-25 23:07:42 +00:00
|
|
|
JSCompartment *comp = cx->compartment;
|
|
|
|
void *t = comp->arenas.allocateFromFreeList(kind, thingSize);
|
|
|
|
if (!t)
|
|
|
|
t = js::gc::ArenaLists::refillFreeList(cx, kind);
|
2012-02-17 22:35:20 +00:00
|
|
|
|
|
|
|
JS_ASSERT_IF(t && comp->needsBarrier(),
|
|
|
|
static_cast<T *>(t)->arenaHeader()->allocatedDuringIncremental);
|
2011-10-25 23:07:42 +00:00
|
|
|
return static_cast<T *>(t);
|
2010-09-24 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 16:57:12 +00:00
|
|
|
/* Alternate form which allocates a GC thing if doing so cannot trigger a GC. */
|
|
|
|
template <typename T>
|
|
|
|
inline T *
|
|
|
|
TryNewGCThing(JSContext *cx, js::gc::AllocKind kind, size_t thingSize)
|
|
|
|
{
|
|
|
|
JS_ASSERT(thingSize == js::gc::Arena::thingSize(kind));
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
JS_ASSERT_IF((cx->compartment == cx->runtime->atomsCompartment),
|
|
|
|
kind == js::gc::FINALIZE_STRING || kind == js::gc::FINALIZE_SHORT_STRING);
|
|
|
|
#endif
|
|
|
|
JS_ASSERT(!cx->runtime->gcRunning);
|
2011-07-18 21:54:48 +00:00
|
|
|
JS_ASSERT(!cx->runtime->noGCOrAllocationCheck);
|
2011-11-03 16:57:12 +00:00
|
|
|
|
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
if (cx->runtime->needZealousGC())
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void *t = cx->compartment->arenas.allocateFromFreeList(kind, thingSize);
|
2012-02-17 22:35:20 +00:00
|
|
|
JS_ASSERT_IF(t && cx->compartment->needsBarrier(),
|
|
|
|
static_cast<T *>(t)->arenaHeader()->allocatedDuringIncremental);
|
2011-11-03 16:57:12 +00:00
|
|
|
return static_cast<T *>(t);
|
|
|
|
}
|
|
|
|
|
2011-11-18 22:40:14 +00:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
|
|
|
|
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);
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::NewGCThing<JSObject>(cx, kind, js::gc::Arena::thingSize(kind));
|
2010-09-24 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 16:57:12 +00:00
|
|
|
inline JSObject *
|
|
|
|
js_TryNewGCObject(JSContext *cx, js::gc::AllocKind kind)
|
|
|
|
{
|
|
|
|
JS_ASSERT(kind >= js::gc::FINALIZE_OBJECT0 && kind <= js::gc::FINALIZE_OBJECT_LAST);
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::TryNewGCThing<JSObject>(cx, kind, js::gc::Arena::thingSize(kind));
|
2011-11-03 16:57:12 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 17:54:39 +00:00
|
|
|
inline JSString *
|
|
|
|
js_NewGCString(JSContext *cx)
|
|
|
|
{
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::NewGCThing<JSString>(cx, js::gc::FINALIZE_STRING, sizeof(JSString));
|
2010-09-24 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSShortString *
|
|
|
|
js_NewGCShortString(JSContext *cx)
|
|
|
|
{
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::NewGCThing<JSShortString>(cx, js::gc::FINALIZE_SHORT_STRING, sizeof(JSShortString));
|
2010-09-24 17:54:39 +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
|
|
|
{
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::NewGCThing<JSExternalString>(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)
|
|
|
|
{
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::NewGCThing<JSScript>(cx, js::gc::FINALIZE_SCRIPT, sizeof(JSScript));
|
2011-08-09 08:51:59 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 18:57:44 +00:00
|
|
|
inline js::Shape *
|
|
|
|
js_NewGCShape(JSContext *cx)
|
|
|
|
{
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::NewGCThing<js::Shape>(cx, js::gc::FINALIZE_SHAPE, sizeof(js::Shape));
|
2011-03-23 18:57:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-28 22:04:55 +00:00
|
|
|
inline js::BaseShape *
|
|
|
|
js_NewGCBaseShape(JSContext *cx)
|
|
|
|
{
|
2011-11-18 22:40:14 +00:00
|
|
|
return js::gc::NewGCThing<js::BaseShape>(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___ */
|