2010-04-12 13:59:19 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2007-03-22 10:30:00 -07: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 Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* 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 jsgc_h___
|
|
|
|
#define jsgc_h___
|
|
|
|
/*
|
|
|
|
* JS Garbage Collector.
|
|
|
|
*/
|
2010-06-04 07:22:28 -07:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
#include "jstypes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsprvtd.h"
|
|
|
|
#include "jspubtd.h"
|
|
|
|
#include "jsdhash.h"
|
2008-02-26 13:01:42 -08:00
|
|
|
#include "jsbit.h"
|
2010-08-05 05:16:56 -07:00
|
|
|
#include "jsgcchunk.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsutil.h"
|
2009-07-27 21:10:12 -07:00
|
|
|
#include "jstask.h"
|
2010-04-27 06:46:24 -07:00
|
|
|
#include "jsvector.h"
|
2010-03-22 11:11:44 -07:00
|
|
|
#include "jsversion.h"
|
2010-08-09 09:11:22 -07:00
|
|
|
#include "jsobj.h"
|
|
|
|
#include "jsfun.h"
|
2010-08-24 18:57:14 -07:00
|
|
|
#include "jsgcstats.h"
|
2010-08-05 05:16:56 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
#define JSTRACE_XML 2
|
2007-11-14 20:16:35 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* One past the maximum trace kind.
|
|
|
|
*/
|
2010-07-14 23:19:36 -07:00
|
|
|
#define JSTRACE_LIMIT 3
|
2007-11-14 20:16:35 -08:00
|
|
|
|
2009-10-02 01:21:19 -07:00
|
|
|
const uintN JS_EXTERNAL_STRING_LIMIT = 8;
|
|
|
|
|
2007-11-14 20:16:35 -08:00
|
|
|
/*
|
|
|
|
* Get the type of the external string or -1 if the string was not created
|
|
|
|
* with JS_NewExternalString.
|
|
|
|
*/
|
|
|
|
extern intN
|
|
|
|
js_GetExternalStringGCType(JSString *str);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(uint32)
|
|
|
|
js_GetGCThingTraceKind(void *thing);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-24 18:57:14 -07:00
|
|
|
extern size_t
|
|
|
|
ThingsPerArena(size_t thingSize);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* The sole purpose of the function is to preserve public API compatibility
|
|
|
|
* in JS_GetStringBytes which takes only single JSString* argument.
|
|
|
|
*/
|
2010-04-22 23:58:44 -07:00
|
|
|
JSRuntime *
|
|
|
|
js_GetGCThingRuntime(void *thing);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JS_TRUE)
|
|
|
|
#else
|
|
|
|
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JSVAL_IS_GCTHING(oldval))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern JSBool
|
2009-09-17 15:40:37 -07:00
|
|
|
js_InitGC(JSRuntime *rt, uint32 maxbytes);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern void
|
|
|
|
js_FinishGC(JSRuntime *rt);
|
|
|
|
|
2007-09-19 15:04:47 -07:00
|
|
|
extern intN
|
|
|
|
js_ChangeExternalStringFinalizer(JSStringFinalizeOp oldop,
|
|
|
|
JSStringFinalizeOp newop);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_AddRoot(JSContext *cx, js::Value *vp, const char *name);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
2010-06-07 17:05:02 -07:00
|
|
|
js_AddGCThingRoot(JSContext *cx, void **rp, const char *name);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
extern void
|
|
|
|
js_DumpNamedRoots(JSRuntime *rt,
|
2010-07-14 23:19:36 -07:00
|
|
|
void (*dump)(const char *name, void *rp, JSGCRootType type, void *data),
|
2007-03-22 10:30:00 -07:00
|
|
|
void *data);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern uint32
|
|
|
|
js_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
|
|
|
|
|
|
|
|
/* Table of pointers with count valid members. */
|
|
|
|
typedef struct JSPtrTable {
|
|
|
|
size_t count;
|
|
|
|
void **array;
|
|
|
|
} JSPtrTable;
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_RegisterCloseableIterator(JSContext *cx, JSObject *obj);
|
|
|
|
|
2008-12-11 15:53:05 -08:00
|
|
|
#ifdef JS_TRACER
|
|
|
|
extern JSBool
|
|
|
|
js_ReserveObjects(JSContext *cx, size_t nobjects);
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSBool
|
|
|
|
js_LockGCThingRT(JSRuntime *rt, void *thing);
|
|
|
|
|
2009-12-13 23:55:17 -08:00
|
|
|
extern void
|
2007-03-22 10:30:00 -07:00
|
|
|
js_UnlockGCThingRT(JSRuntime *rt, void *thing);
|
|
|
|
|
2010-07-15 17:58:36 -07:00
|
|
|
extern JS_FRIEND_API(bool)
|
2009-12-13 23:55:17 -08:00
|
|
|
js_IsAboutToBeFinalized(void *thing);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-15 17:58:36 -07:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
js_GCThingIsMarked(void *thing, uint32 color);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2007-04-16 23:53:37 -07:00
|
|
|
* Macro to test if a traversal is the marking phase of GC to avoid exposing
|
2007-08-13 13:23:34 -07:00
|
|
|
* ScriptFilenameEntry to traversal implementations.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-04-16 23:53:37 -07:00
|
|
|
#define IS_GC_MARKING_TRACER(trc) ((trc)->callback == NULL)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-16 23:53:37 -07:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
2008-08-29 01:10:34 -07:00
|
|
|
# define JS_IS_VALID_TRACE_KIND(kind) ((uint32)(kind) < JSTRACE_LIMIT)
|
2007-04-16 23:53:37 -07:00
|
|
|
#else
|
2008-04-02 00:46:12 -07:00
|
|
|
# define JS_IS_VALID_TRACE_KIND(kind) ((uint32)(kind) <= JSTRACE_STRING)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-04-16 23:53:37 -07:00
|
|
|
extern void
|
|
|
|
js_TraceStackFrame(JSTracer *trc, JSStackFrame *fp);
|
|
|
|
|
2009-01-30 15:40:05 -08:00
|
|
|
extern JS_REQUIRES_STACK void
|
2010-08-29 12:41:24 -07:00
|
|
|
js_TraceRuntime(JSTracer *trc);
|
2007-04-16 23:53:37 -07:00
|
|
|
|
2009-01-30 15:40:05 -08:00
|
|
|
extern JS_REQUIRES_STACK JS_FRIEND_API(void)
|
2010-08-29 12:41:24 -07:00
|
|
|
js_TraceContext(JSTracer *trc, JSContext *acx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-28 11:20:19 -07:00
|
|
|
/*
|
|
|
|
* Schedule the GC call at a later safe point.
|
|
|
|
*/
|
|
|
|
#ifndef JS_THREADSAFE
|
|
|
|
# define js_TriggerGC(cx, gcLocked) js_TriggerGC (cx)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_TriggerGC(JSContext *cx, JSBool gcLocked);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Kinds of js_GC invocation.
|
|
|
|
*/
|
|
|
|
typedef enum JSGCInvocationKind {
|
|
|
|
/* Normal invocation. */
|
2008-01-29 22:29:49 -08:00
|
|
|
GC_NORMAL = 0,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called from js_DestroyContext for last JSContext in a JSRuntime, when
|
|
|
|
* it is imperative that rt->gcPoke gets cleared early in js_GC.
|
|
|
|
*/
|
2008-01-29 22:29:49 -08:00
|
|
|
GC_LAST_CONTEXT = 1,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flag bit telling js_GC that the caller has already acquired rt->gcLock.
|
|
|
|
*/
|
2010-05-14 06:55:17 -07:00
|
|
|
GC_LOCK_HELD = 0x10
|
2007-03-22 10:30:00 -07:00
|
|
|
} JSGCInvocationKind;
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_GC(JSContext *cx, JSGCInvocationKind gckind);
|
|
|
|
|
2010-05-27 07:57:55 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/*
|
|
|
|
* This is a helper for code at can potentially run outside JS request to
|
|
|
|
* ensure that the GC is not running when the function returns.
|
|
|
|
*
|
|
|
|
* This function must be called with the GC lock held.
|
|
|
|
*/
|
|
|
|
extern void
|
|
|
|
js_WaitForGC(JSRuntime *rt);
|
|
|
|
|
|
|
|
#else /* !JS_THREADSAFE */
|
|
|
|
|
|
|
|
# define js_WaitForGC(rt) ((void) 0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-10-02 07:34:22 -07:00
|
|
|
/*
|
|
|
|
* The kind of GC thing with a finalizer. The external strings follow the
|
|
|
|
* ordinary string to simplify js_GetExternalStringGCType.
|
|
|
|
*/
|
|
|
|
enum JSFinalizeGCThingKind {
|
|
|
|
FINALIZE_OBJECT,
|
|
|
|
FINALIZE_FUNCTION,
|
|
|
|
#if JS_HAS_XML_SUPPORT
|
|
|
|
FINALIZE_XML,
|
|
|
|
#endif
|
2010-07-24 20:26:34 -07:00
|
|
|
FINALIZE_SHORT_STRING,
|
2009-10-02 07:34:22 -07:00
|
|
|
FINALIZE_STRING,
|
|
|
|
FINALIZE_EXTERNAL_STRING0,
|
|
|
|
FINALIZE_EXTERNAL_STRING1,
|
|
|
|
FINALIZE_EXTERNAL_STRING2,
|
|
|
|
FINALIZE_EXTERNAL_STRING3,
|
|
|
|
FINALIZE_EXTERNAL_STRING4,
|
|
|
|
FINALIZE_EXTERNAL_STRING5,
|
|
|
|
FINALIZE_EXTERNAL_STRING6,
|
|
|
|
FINALIZE_EXTERNAL_STRING7,
|
|
|
|
FINALIZE_EXTERNAL_STRING_LAST = FINALIZE_EXTERNAL_STRING7,
|
|
|
|
FINALIZE_LIMIT
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
IsFinalizableStringKind(unsigned thingKind)
|
|
|
|
{
|
2010-07-24 20:26:34 -07:00
|
|
|
return unsigned(FINALIZE_SHORT_STRING) <= thingKind &&
|
2009-10-02 07:34:22 -07:00
|
|
|
thingKind <= unsigned(FINALIZE_EXTERNAL_STRING_LAST);
|
|
|
|
}
|
|
|
|
|
2009-10-15 23:10:54 -07: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.
|
|
|
|
*/
|
|
|
|
extern void *
|
2009-11-12 03:53:25 -08:00
|
|
|
js_NewFinalizableGCThing(JSContext *cx, unsigned thingKind);
|
2009-10-15 23:10:54 -07:00
|
|
|
|
|
|
|
static inline JSObject *
|
|
|
|
js_NewGCObject(JSContext *cx)
|
|
|
|
{
|
2009-11-12 03:53:25 -08:00
|
|
|
return (JSObject *) js_NewFinalizableGCThing(cx, FINALIZE_OBJECT);
|
2009-10-15 23:10:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSString *
|
|
|
|
js_NewGCString(JSContext *cx)
|
|
|
|
{
|
2009-11-12 03:53:25 -08:00
|
|
|
return (JSString *) js_NewFinalizableGCThing(cx, FINALIZE_STRING);
|
2009-10-15 23:10:54 -07:00
|
|
|
}
|
|
|
|
|
2010-07-24 20:26:34 -07:00
|
|
|
struct JSShortString;
|
|
|
|
|
|
|
|
static inline JSShortString *
|
|
|
|
js_NewGCShortString(JSContext *cx)
|
|
|
|
{
|
|
|
|
return (JSShortString *) js_NewFinalizableGCThing(cx, FINALIZE_SHORT_STRING);
|
|
|
|
}
|
|
|
|
|
2009-10-15 23:10:54 -07:00
|
|
|
static inline JSString *
|
|
|
|
js_NewGCExternalString(JSContext *cx, uintN type)
|
|
|
|
{
|
|
|
|
JS_ASSERT(type < JS_EXTERNAL_STRING_LIMIT);
|
2009-11-12 03:53:25 -08:00
|
|
|
type += FINALIZE_EXTERNAL_STRING0;
|
|
|
|
return (JSString *) js_NewFinalizableGCThing(cx, type);
|
2009-10-15 23:10:54 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
static inline JSFunction *
|
2009-10-15 23:10:54 -07:00
|
|
|
js_NewGCFunction(JSContext *cx)
|
|
|
|
{
|
2010-08-09 09:11:22 -07:00
|
|
|
JSFunction* obj = (JSFunction *)js_NewFinalizableGCThing(cx, FINALIZE_FUNCTION);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (obj) {
|
|
|
|
memset((uint8 *) obj + sizeof(JSObject), JS_FREE_PATTERN,
|
|
|
|
sizeof(JSFunction) - sizeof(JSObject));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return obj;
|
2009-10-15 23:10:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#if JS_HAS_XML_SUPPORT
|
|
|
|
static inline JSXML *
|
|
|
|
js_NewGCXML(JSContext *cx)
|
|
|
|
{
|
2009-11-12 03:53:25 -08:00
|
|
|
return (JSXML *) js_NewFinalizableGCThing(cx, FINALIZE_XML);
|
2009-10-15 23:10:54 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-14 00:27:32 -08:00
|
|
|
struct JSGCArena;
|
2008-01-29 14:17:25 -08:00
|
|
|
|
|
|
|
struct JSGCArenaList {
|
2010-01-14 00:27:32 -08:00
|
|
|
JSGCArena *head; /* list start */
|
|
|
|
JSGCArena *cursor; /* arena with free things */
|
2009-10-02 07:34:22 -07:00
|
|
|
uint32 thingKind; /* one of JSFinalizeGCThingKind */
|
2009-07-12 07:29:18 -07:00
|
|
|
uint32 thingSize; /* size of things to allocate on this list
|
2008-01-29 14:17:25 -08:00
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
2009-10-15 23:10:54 -07:00
|
|
|
struct JSGCFreeLists {
|
|
|
|
JSGCThing *finalizables[FINALIZE_LIMIT];
|
|
|
|
|
|
|
|
void purge();
|
2009-11-12 03:53:25 -08:00
|
|
|
void moveTo(JSGCFreeLists * another);
|
2009-10-15 23:10:54 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2009-11-12 03:53:25 -08:00
|
|
|
bool isEmpty() const {
|
|
|
|
for (size_t i = 0; i != JS_ARRAY_LENGTH(finalizables); ++i) {
|
|
|
|
if (finalizables[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2009-10-15 23:10:54 -07:00
|
|
|
}
|
|
|
|
#endif
|
2009-10-08 09:08:00 -07:00
|
|
|
};
|
2008-02-26 13:01:42 -08:00
|
|
|
|
2009-03-24 05:07:35 -07:00
|
|
|
extern void
|
|
|
|
js_DestroyScriptsToGC(JSContext *cx, JSThreadData *data);
|
|
|
|
|
2010-05-28 05:19:20 -07:00
|
|
|
namespace js {
|
|
|
|
|
2010-06-04 07:22:28 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
|
2010-04-27 06:46:24 -07:00
|
|
|
/*
|
|
|
|
* During the finalization we do not free immediately. Rather we add the
|
|
|
|
* corresponding pointers to a buffer which we later release on the
|
|
|
|
* background thread.
|
|
|
|
*
|
|
|
|
* The buffer is implemented as a vector of 64K arrays of pointers, not as a
|
|
|
|
* simple vector, to avoid realloc calls during the vector growth and to not
|
|
|
|
* bloat the binary size of the inlined freeLater method. Any OOM during
|
|
|
|
* buffer growth results in the pointer being freed immediately.
|
|
|
|
*/
|
|
|
|
class BackgroundSweepTask : public JSBackgroundTask {
|
|
|
|
static const size_t FREE_ARRAY_SIZE = size_t(1) << 16;
|
|
|
|
static const size_t FREE_ARRAY_LENGTH = FREE_ARRAY_SIZE / sizeof(void *);
|
|
|
|
|
|
|
|
Vector<void **, 16, js::SystemAllocPolicy> freeVector;
|
|
|
|
void **freeCursor;
|
|
|
|
void **freeCursorEnd;
|
|
|
|
|
2010-04-28 17:17:34 -07:00
|
|
|
JS_FRIEND_API(void)
|
|
|
|
replenishAndFreeLater(void *ptr);
|
2010-04-27 06:46:24 -07:00
|
|
|
|
|
|
|
static void freeElementsAndArray(void **array, void **end) {
|
|
|
|
JS_ASSERT(array <= end);
|
|
|
|
for (void **p = array; p != end; ++p)
|
|
|
|
js_free(*p);
|
|
|
|
js_free(array);
|
2009-08-25 14:42:42 -07:00
|
|
|
}
|
|
|
|
|
2010-04-27 06:46:24 -07:00
|
|
|
public:
|
|
|
|
BackgroundSweepTask()
|
|
|
|
: freeCursor(NULL), freeCursorEnd(NULL) { }
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
void freeLater(void *ptr) {
|
2010-04-27 06:46:24 -07:00
|
|
|
if (freeCursor != freeCursorEnd)
|
|
|
|
*freeCursor++ = ptr;
|
|
|
|
else
|
|
|
|
replenishAndFreeLater(ptr);
|
2009-08-25 14:42:42 -07:00
|
|
|
}
|
2010-04-27 06:46:24 -07:00
|
|
|
|
|
|
|
virtual void run();
|
2009-07-27 21:10:12 -07:00
|
|
|
};
|
2010-04-27 06:46:24 -07:00
|
|
|
|
2010-06-04 07:22:28 -07:00
|
|
|
#endif /* JS_THREADSAFE */
|
|
|
|
|
2010-08-05 05:16:56 -07:00
|
|
|
|
|
|
|
struct GCChunkInfo;
|
|
|
|
|
|
|
|
struct GCChunkHasher {
|
|
|
|
typedef jsuword Lookup;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip zeros for better distribution after multiplying by the golden
|
|
|
|
* ratio.
|
|
|
|
*/
|
|
|
|
static HashNumber hash(jsuword chunk) {
|
|
|
|
JS_ASSERT(!(chunk & GC_CHUNK_MASK));
|
|
|
|
return HashNumber(chunk >> GC_CHUNK_SHIFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool match(jsuword k, jsuword l) {
|
|
|
|
JS_ASSERT(!(k & GC_CHUNK_MASK));
|
|
|
|
JS_ASSERT(!(l & GC_CHUNK_MASK));
|
|
|
|
return k == l;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef HashSet<jsuword, GCChunkHasher, SystemAllocPolicy> GCChunkSet;
|
|
|
|
typedef Vector<GCChunkInfo *, 32, SystemAllocPolicy> GCChunkInfoVector;
|
|
|
|
|
2010-06-04 07:22:28 -07:00
|
|
|
struct ConservativeGCThreadData {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The GC scans conservatively between JSThreadData::nativeStackBase and
|
|
|
|
* nativeStackTop unless the latter is NULL.
|
|
|
|
*/
|
|
|
|
jsuword *nativeStackTop;
|
|
|
|
|
|
|
|
union {
|
|
|
|
jmp_buf jmpbuf;
|
|
|
|
jsuword words[JS_HOWMANY(sizeof(jmp_buf), sizeof(jsuword))];
|
|
|
|
} registerSnapshot;
|
|
|
|
|
2010-08-29 12:41:24 -07:00
|
|
|
int enableCount;
|
2010-06-04 07:22:28 -07:00
|
|
|
|
2010-08-29 12:41:24 -07:00
|
|
|
JS_NEVER_INLINE JS_FRIEND_API(void) enable(bool knownStackBoundary = false);
|
|
|
|
JS_FRIEND_API(void) disable();
|
|
|
|
bool isEnabled() const { return enableCount > 0; }
|
2010-06-04 07:22:28 -07:00
|
|
|
};
|
|
|
|
|
2010-08-05 05:16:56 -07:00
|
|
|
struct GCMarker : public JSTracer {
|
|
|
|
private:
|
|
|
|
/* The color is only applied to objects, functions and xml. */
|
|
|
|
uint32 color;
|
|
|
|
|
|
|
|
/* See comments before delayMarkingChildren is jsgc.cpp. */
|
|
|
|
JSGCArena *unmarkedArenaStackTop;
|
|
|
|
#ifdef DEBUG
|
|
|
|
size_t markLaterCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2010-08-05 05:16:56 -07:00
|
|
|
public:
|
|
|
|
#if defined(JS_DUMP_CONSERVATIVE_GC_ROOTS) || defined(JS_GCMETER)
|
|
|
|
ConservativeGCStats conservativeStats;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef JS_DUMP_CONSERVATIVE_GC_ROOTS
|
|
|
|
struct ConservativeRoot { void *thing; uint32 traceKind; };
|
|
|
|
Vector<ConservativeRoot, 0, SystemAllocPolicy> conservativeRoots;
|
|
|
|
const char *conservativeDumpFileName;
|
2010-06-04 07:22:28 -07:00
|
|
|
|
2010-08-05 05:16:56 -07:00
|
|
|
void dumpConservativeRoots();
|
2010-06-04 07:22:28 -07:00
|
|
|
#endif
|
|
|
|
|
2010-08-05 05:16:56 -07:00
|
|
|
js::Vector<JSObject *, 0, js::SystemAllocPolicy> arraysToSlowify;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit GCMarker(JSContext *cx);
|
|
|
|
~GCMarker();
|
|
|
|
|
|
|
|
uint32 getMarkColor() const {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMarkColor(uint32 newColor) {
|
|
|
|
/*
|
|
|
|
* We must process any delayed marking here, otherwise we confuse
|
|
|
|
* colors.
|
|
|
|
*/
|
|
|
|
markDelayedChildren();
|
|
|
|
color = newColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void delayMarkingChildren(void *thing);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void) markDelayedChildren();
|
|
|
|
|
|
|
|
void slowifyArrays();
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_FinalizeStringRT(JSRuntime *rt, JSString *str);
|
|
|
|
|
2009-11-12 14:13:25 -08:00
|
|
|
/*
|
|
|
|
* This function is defined in jsdbgapi.cpp but is declared here to avoid
|
|
|
|
* polluting jsdbgapi.h, a public API header, with internal functions.
|
|
|
|
*/
|
|
|
|
extern void
|
|
|
|
js_MarkTraps(JSTracer *trc);
|
|
|
|
|
2010-03-28 13:34:16 -07:00
|
|
|
namespace js {
|
|
|
|
|
2010-06-17 15:23:17 -07:00
|
|
|
/*
|
|
|
|
* Set object's prototype while checking that doing so would not create
|
|
|
|
* a cycle in the proto chain. The cycle check and proto change are done
|
|
|
|
* only when all other requests are finished or suspended to ensure exclusive
|
|
|
|
* access to the chain. If there is a cycle, return false without reporting
|
|
|
|
* an error. Otherwise, set the proto and return true.
|
|
|
|
*/
|
|
|
|
extern bool
|
|
|
|
SetProtoCheckingForCycles(JSContext *cx, JSObject *obj, JSObject *proto);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
/* N.B. Assumes JS_SET_TRACING_NAME/INDEX has already been called. */
|
2010-03-28 13:34:16 -07:00
|
|
|
void
|
2010-07-14 23:19:36 -07:00
|
|
|
Mark(JSTracer *trc, void *thing, uint32 kind);
|
2010-03-28 13:34:16 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static inline void
|
|
|
|
Mark(JSTracer *trc, void *thing, uint32 kind, const char *name)
|
2010-03-28 13:34:16 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_ASSERT(thing);
|
|
|
|
JS_SET_TRACING_NAME(trc, name);
|
|
|
|
Mark(trc, thing, kind);
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:54:14 -07:00
|
|
|
static inline void
|
|
|
|
MarkString(JSTracer *trc, JSString *str)
|
|
|
|
{
|
|
|
|
JS_ASSERT(str);
|
|
|
|
Mark(trc, str, JSTRACE_STRING);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static inline void
|
|
|
|
MarkString(JSTracer *trc, JSString *str, const char *name)
|
|
|
|
{
|
|
|
|
JS_ASSERT(str);
|
|
|
|
JS_SET_TRACING_NAME(trc, name);
|
|
|
|
Mark(trc, str, JSTRACE_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkAtomRange(JSTracer *trc, size_t len, JSAtom **vec, const char *name)
|
|
|
|
{
|
|
|
|
for (uint32 i = 0; i < len; i++) {
|
|
|
|
if (JSAtom *atom = vec[i]) {
|
|
|
|
JS_SET_TRACING_INDEX(trc, name, i);
|
|
|
|
Mark(trc, ATOM_TO_STRING(atom), JSTRACE_STRING);
|
2010-03-28 13:34:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static inline void
|
|
|
|
MarkObject(JSTracer *trc, JSObject *obj, const char *name)
|
|
|
|
{
|
|
|
|
JS_ASSERT(obj);
|
|
|
|
JS_SET_TRACING_NAME(trc, name);
|
|
|
|
Mark(trc, obj, JSTRACE_OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkObjectRange(JSTracer *trc, size_t len, JSObject **vec, const char *name)
|
|
|
|
{
|
|
|
|
for (uint32 i = 0; i < len; i++) {
|
|
|
|
if (JSObject *obj = vec[i]) {
|
|
|
|
JS_SET_TRACING_INDEX(trc, name, i);
|
|
|
|
Mark(trc, obj, JSTRACE_OBJECT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* N.B. Assumes JS_SET_TRACING_NAME/INDEX has already been called. */
|
|
|
|
static inline void
|
|
|
|
MarkValueRaw(JSTracer *trc, const js::Value &v)
|
|
|
|
{
|
|
|
|
if (v.isMarkable())
|
|
|
|
return Mark(trc, v.asGCThing(), v.gcKind());
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkValue(JSTracer *trc, const js::Value &v, const char *name)
|
|
|
|
{
|
|
|
|
JS_SET_TRACING_NAME(trc, name);
|
|
|
|
MarkValueRaw(trc, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkValueRange(JSTracer *trc, Value *beg, Value *end, const char *name)
|
|
|
|
{
|
|
|
|
for (Value *vp = beg; vp < end; ++vp) {
|
|
|
|
JS_SET_TRACING_INDEX(trc, name, vp - beg);
|
|
|
|
MarkValueRaw(trc, *vp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkValueRange(JSTracer *trc, size_t len, Value *vec, const char *name)
|
|
|
|
{
|
|
|
|
MarkValueRange(trc, vec, vec + len, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkId(JSTracer *trc, jsid id)
|
|
|
|
{
|
|
|
|
if (JSID_IS_STRING(id))
|
|
|
|
Mark(trc, JSID_TO_STRING(id), JSTRACE_STRING);
|
|
|
|
else if (JS_UNLIKELY(JSID_IS_OBJECT(id)))
|
|
|
|
Mark(trc, JSID_TO_OBJECT(id), JSTRACE_OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkId(JSTracer *trc, jsid id, const char *name)
|
|
|
|
{
|
|
|
|
JS_SET_TRACING_NAME(trc, name);
|
|
|
|
MarkId(trc, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkIdRange(JSTracer *trc, jsid *beg, jsid *end, const char *name)
|
|
|
|
{
|
|
|
|
for (jsid *idp = beg; idp != end; ++idp) {
|
|
|
|
JS_SET_TRACING_INDEX(trc, name, (idp - beg));
|
|
|
|
MarkId(trc, *idp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkIdRange(JSTracer *trc, size_t len, jsid *vec, const char *name)
|
|
|
|
{
|
|
|
|
MarkIdRange(trc, vec, vec + len, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* N.B. Assumes JS_SET_TRACING_NAME/INDEX has already been called. */
|
|
|
|
void
|
|
|
|
MarkGCThing(JSTracer *trc, void *thing);
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkGCThing(JSTracer *trc, void *thing, const char *name)
|
|
|
|
{
|
|
|
|
JS_SET_TRACING_NAME(trc, name);
|
|
|
|
MarkGCThing(trc, thing);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MarkGCThing(JSTracer *trc, void *thing, const char *name, size_t index)
|
2010-03-03 17:52:26 -08:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_SET_TRACING_INDEX(trc, name, index);
|
|
|
|
MarkGCThing(trc, thing);
|
2010-03-28 13:34:16 -07:00
|
|
|
}
|
|
|
|
|
2010-06-04 16:32:10 -07:00
|
|
|
JSCompartment *
|
2010-06-24 14:45:32 -07:00
|
|
|
NewCompartment(JSContext *cx, JSPrincipals *principals);
|
2010-06-04 16:32:10 -07:00
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
} /* namespace js */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* jsgc_h___ */
|