2009-06-10 18:29:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2007-03-22 10:30:00 -07:00
|
|
|
* vim: set ts=8 sw=4 et tw=78:
|
|
|
|
*
|
|
|
|
* ***** 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 jscntxt_h___
|
|
|
|
#define jscntxt_h___
|
|
|
|
/*
|
|
|
|
* JS execution context.
|
|
|
|
*/
|
2010-02-19 09:44:23 -08:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-07-26 21:52:00 -07:00
|
|
|
#include "jsprvtd.h"
|
2010-10-01 16:46:54 -07:00
|
|
|
#include "jsarena.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsclist.h"
|
|
|
|
#include "jslong.h"
|
|
|
|
#include "jsatom.h"
|
|
|
|
#include "jsdhash.h"
|
2010-03-22 16:21:10 -07:00
|
|
|
#include "jsdtoa.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jsfun.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsgc.h"
|
2010-06-07 02:17:15 -07:00
|
|
|
#include "jsgcchunk.h"
|
2010-03-22 11:11:44 -07:00
|
|
|
#include "jshashtable.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsinterp.h"
|
2010-10-06 12:13:20 -07:00
|
|
|
#include "jsmath.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsobj.h"
|
2010-03-24 14:16:01 -07:00
|
|
|
#include "jspropertycache.h"
|
2010-03-22 11:11:44 -07:00
|
|
|
#include "jspropertytree.h"
|
2010-09-13 15:53:50 -07:00
|
|
|
#include "jsstaticcheck.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsutil.h"
|
2009-06-30 17:19:42 -07:00
|
|
|
#include "jsarray.h"
|
2009-10-20 15:08:28 -07:00
|
|
|
#include "jsvector.h"
|
2010-05-26 17:00:28 -07:00
|
|
|
#include "prmjtime.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
#include "vm/Stack.h"
|
|
|
|
|
2010-03-04 20:44:09 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4100) /* Silence unreferenced formal parameter warnings */
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4355) /* Silence warning about "this" used in base member initializer list */
|
|
|
|
#endif
|
|
|
|
|
2009-10-28 16:44:44 -07:00
|
|
|
/* Forward declarations of nanojit types. */
|
2010-01-22 14:49:18 -08:00
|
|
|
namespace nanojit {
|
|
|
|
|
|
|
|
class Assembler;
|
|
|
|
class CodeAlloc;
|
|
|
|
class Fragment;
|
|
|
|
template<typename K> struct DefaultHash;
|
|
|
|
template<typename K, typename V, typename H> class HashMap;
|
|
|
|
template<typename T> class Seq;
|
|
|
|
|
|
|
|
} /* namespace nanojit */
|
|
|
|
|
|
|
|
namespace js {
|
2009-10-28 16:44:44 -07:00
|
|
|
|
|
|
|
/* Tracer constants. */
|
|
|
|
static const size_t MONITOR_N_GLOBAL_STATES = 4;
|
|
|
|
static const size_t FRAGMENT_TABLE_SIZE = 512;
|
|
|
|
static const size_t MAX_GLOBAL_SLOTS = 4096;
|
|
|
|
static const size_t GLOBAL_SLOTS_BUFFER_SIZE = MAX_GLOBAL_SLOTS + 1;
|
|
|
|
|
|
|
|
/* Forward declarations of tracer types. */
|
|
|
|
class VMAllocator;
|
|
|
|
class FrameInfoCache;
|
|
|
|
struct FrameInfo;
|
|
|
|
struct VMSideExit;
|
2009-11-05 15:04:54 -08:00
|
|
|
struct TreeFragment;
|
2010-04-22 11:54:11 -07:00
|
|
|
struct TracerState;
|
2009-10-28 16:44:44 -07:00
|
|
|
template<typename T> class Queue;
|
|
|
|
typedef Queue<uint16> SlotList;
|
2010-03-04 20:44:09 -08:00
|
|
|
class TypeMap;
|
2010-10-21 09:36:39 -07:00
|
|
|
class LoopProfile;
|
2009-10-28 16:44:44 -07:00
|
|
|
|
2009-09-15 15:05:53 -07:00
|
|
|
#if defined(JS_JIT_SPEW) || defined(DEBUG)
|
|
|
|
struct FragPI;
|
2009-09-15 17:07:33 -07:00
|
|
|
typedef nanojit::HashMap<uint32, FragPI, nanojit::DefaultHash<uint32> > FragStatsMap;
|
2009-09-15 15:05:53 -07:00
|
|
|
#endif
|
2008-07-10 14:29:16 -07:00
|
|
|
|
2010-08-11 11:23:29 -07:00
|
|
|
namespace mjit {
|
2010-10-29 15:37:13 -07:00
|
|
|
class JaegerCompartment;
|
2010-08-11 11:23:29 -07:00
|
|
|
}
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
/*
|
|
|
|
* GetSrcNote cache to avoid O(n^2) growth in finding a source note for a
|
|
|
|
* given pc in a script. We use the script->code pointer to tag the cache,
|
|
|
|
* instead of the script address itself, so that source notes are always found
|
|
|
|
* by offset from the bytecode with which they were generated.
|
|
|
|
*/
|
|
|
|
struct GSNCache {
|
|
|
|
typedef HashMap<jsbytecode *,
|
|
|
|
jssrcnote *,
|
|
|
|
PointerHasher<jsbytecode *, 0>,
|
|
|
|
SystemAllocPolicy> Map;
|
2009-04-05 21:17:22 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
jsbytecode *code;
|
|
|
|
Map map;
|
|
|
|
#ifdef JS_GSNMETER
|
|
|
|
struct Stats {
|
|
|
|
uint32 hits;
|
|
|
|
uint32 misses;
|
|
|
|
uint32 fills;
|
|
|
|
uint32 purges;
|
2009-04-05 21:17:22 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
Stats() : hits(0), misses(0), fills(0), purges(0) { }
|
|
|
|
};
|
2010-08-01 09:58:03 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
Stats stats;
|
2009-01-27 16:40:40 -08:00
|
|
|
#endif
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
GSNCache() : code(NULL) { }
|
2010-08-01 09:58:03 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
void purge();
|
2010-06-03 18:12:01 -07:00
|
|
|
};
|
2011-03-13 07:45:02 -07:00
|
|
|
|
|
|
|
inline GSNCache *
|
|
|
|
GetGSNCache(JSContext *cx);
|
|
|
|
|
|
|
|
struct PendingProxyOperation {
|
|
|
|
PendingProxyOperation *next;
|
|
|
|
JSObject *object;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ThreadData {
|
|
|
|
/*
|
|
|
|
* If non-zero, we were been asked to call the operation callback as soon
|
|
|
|
* as possible. If the thread has an active request, this contributes
|
|
|
|
* towards rt->interruptCounter.
|
|
|
|
*/
|
|
|
|
volatile int32 interruptFlags;
|
2010-06-03 18:12:01 -07:00
|
|
|
|
2010-10-22 10:48:06 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/* The request depth for this thread. */
|
|
|
|
unsigned requestDepth;
|
|
|
|
#endif
|
|
|
|
|
2011-02-01 10:18:06 -08:00
|
|
|
#ifdef JS_TRACER
|
|
|
|
/*
|
|
|
|
* During trace execution (or during trace recording or
|
|
|
|
* profiling), these fields point to the compartment doing the
|
|
|
|
* execution on this thread. At other times, they are NULL. If a
|
|
|
|
* thread tries to execute/record/profile one trace while another
|
|
|
|
* is still running, the initial one will abort. Therefore, we
|
|
|
|
* only need to track one at a time.
|
|
|
|
*/
|
|
|
|
JSCompartment *onTraceCompartment;
|
|
|
|
JSCompartment *recordingCompartment;
|
|
|
|
JSCompartment *profilingCompartment;
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
/* Maximum size of the tracer's code cache before we start flushing. */
|
|
|
|
uint32 maxCodeCacheBytes;
|
|
|
|
|
|
|
|
static const uint32 DEFAULT_JIT_CACHE_SIZE = 16 * 1024 * 1024;
|
|
|
|
#endif
|
2010-07-22 13:59:59 -07:00
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
/* Keeper of the contiguous stack used by all contexts in this thread. */
|
2011-03-13 07:45:02 -07:00
|
|
|
StackSpace stackSpace;
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2010-07-28 11:20:19 -07:00
|
|
|
/*
|
|
|
|
* Flag indicating that we are waiving any soft limits on the GC heap
|
2010-10-07 13:43:52 -07:00
|
|
|
* because we want allocations to be infallible (except when we hit OOM).
|
2010-07-28 11:20:19 -07:00
|
|
|
*/
|
|
|
|
bool waiveGCQuota;
|
|
|
|
|
2009-03-24 05:07:35 -07:00
|
|
|
/*
|
|
|
|
* The GSN cache is per thread since even multi-cx-per-thread embeddings
|
|
|
|
* do not interleave js_GetSrcNote calls.
|
|
|
|
*/
|
2011-03-13 07:45:02 -07:00
|
|
|
GSNCache gsnCache;
|
2009-03-24 05:07:35 -07:00
|
|
|
|
|
|
|
/* Property cache for faster call/get/set invocation. */
|
2011-03-13 07:45:02 -07:00
|
|
|
PropertyCache propertyCache;
|
2009-07-16 18:36:19 -07:00
|
|
|
|
2010-03-22 16:21:10 -07:00
|
|
|
/* State used by dtoa.c. */
|
|
|
|
DtoaState *dtoaState;
|
|
|
|
|
2010-05-19 01:29:05 -07:00
|
|
|
/* Base address of the native stack for the current thread. */
|
|
|
|
jsuword *nativeStackBase;
|
2010-04-08 10:55:58 -07:00
|
|
|
|
2010-06-03 18:12:01 -07:00
|
|
|
/* List of currently pending operations on proxies. */
|
2011-03-13 07:45:02 -07:00
|
|
|
PendingProxyOperation *pendingProxyOperation;
|
2010-06-03 18:12:01 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
ConservativeGCThreadData conservativeGC;
|
|
|
|
|
|
|
|
ThreadData();
|
|
|
|
~ThreadData();
|
2010-06-04 07:22:28 -07:00
|
|
|
|
2010-03-22 16:21:10 -07:00
|
|
|
bool init();
|
2011-03-13 07:45:02 -07:00
|
|
|
|
|
|
|
void mark(JSTracer *trc) {
|
|
|
|
stackSpace.mark(trc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void purge(JSContext *cx) {
|
|
|
|
gsnCache.purge();
|
|
|
|
|
|
|
|
/* FIXME: bug 506341. */
|
|
|
|
propertyCache.purge(cx);
|
|
|
|
}
|
2010-07-22 13:59:59 -07:00
|
|
|
|
2010-10-22 10:48:06 -07:00
|
|
|
/* This must be called with the GC lock held. */
|
2011-03-13 07:45:02 -07:00
|
|
|
void triggerOperationCallback(JSRuntime *rt);
|
2009-03-24 05:07:35 -07:00
|
|
|
};
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
} /* namespace js */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure uniquely representing a thread. It holds thread-private data
|
|
|
|
* that can be accessed without a global lock.
|
|
|
|
*/
|
|
|
|
struct JSThread {
|
2010-05-13 10:50:43 -07:00
|
|
|
typedef js::HashMap<void *,
|
|
|
|
JSThread *,
|
|
|
|
js::DefaultHasher<void *>,
|
|
|
|
js::SystemAllocPolicy> Map;
|
|
|
|
|
2009-05-13 17:11:23 -07:00
|
|
|
/* Linked list of all contexts in use on this thread. */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSCList contextList;
|
|
|
|
|
|
|
|
/* Opaque thread-id, from NSPR's PR_GetCurrentThread(). */
|
2010-05-13 10:50:43 -07:00
|
|
|
void *id;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-30 11:46:18 -07:00
|
|
|
/* Number of JS_SuspendRequest calls withot JS_ResumeRequest. */
|
|
|
|
unsigned suspendCount;
|
|
|
|
|
|
|
|
# ifdef DEBUG
|
|
|
|
unsigned checkRequestDepth;
|
2010-09-07 14:08:20 -07:00
|
|
|
# endif
|
2010-08-30 11:46:18 -07:00
|
|
|
|
2009-05-13 17:11:23 -07:00
|
|
|
/* Factored out of JSThread for !JS_THREADSAFE embedding in JSRuntime. */
|
2011-03-13 07:45:02 -07:00
|
|
|
js::ThreadData data;
|
|
|
|
|
|
|
|
JSThread(void *id)
|
|
|
|
: id(id),
|
|
|
|
suspendCount(0)
|
|
|
|
# ifdef DEBUG
|
|
|
|
, checkRequestDepth(0)
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
JS_INIT_CLIST(&contextList);
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSThread() {
|
|
|
|
/* The thread must have zero contexts. */
|
|
|
|
JS_ASSERT(JS_CLIST_IS_EMPTY(&contextList));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool init() {
|
|
|
|
return data.init();
|
|
|
|
}
|
2009-03-24 05:07:35 -07:00
|
|
|
};
|
2009-03-22 02:15:27 -07:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
#define JS_THREAD_DATA(cx) (&(cx)->thread()->data)
|
2009-03-22 02:15:27 -07:00
|
|
|
|
2009-10-27 17:55:34 -07:00
|
|
|
extern JSThread *
|
|
|
|
js_CurrentThread(JSRuntime *rt);
|
|
|
|
|
2009-03-24 05:07:35 -07:00
|
|
|
/*
|
|
|
|
* The function takes the GC lock and does not release in successful return.
|
|
|
|
* On error (out of memory) the function releases the lock but delegates
|
|
|
|
* the error reporting to the caller.
|
|
|
|
*/
|
|
|
|
extern JSBool
|
|
|
|
js_InitContextThread(JSContext *cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-24 05:07:35 -07:00
|
|
|
/*
|
|
|
|
* On entrance the GC lock must be held and it will be held on exit.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
extern void
|
2009-03-24 05:07:35 -07:00
|
|
|
js_ClearContextThread(JSContext *cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif /* JS_THREADSAFE */
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
# define FUNCTION_KIND_METER_LIST(_) \
|
|
|
|
_(allfun), _(heavy), _(nofreeupvar), _(onlyfreevar), \
|
|
|
|
_(flat), _(badfunarg), \
|
|
|
|
_(joinedsetmethod), _(joinedinitmethod), \
|
|
|
|
_(joinedreplace), _(joinedsort), _(joinedmodulepat), \
|
|
|
|
_(mreadbarrier), _(mwritebarrier), _(mwslotbarrier), \
|
|
|
|
_(unjoined), _(indynamicscope)
|
|
|
|
# define identity(x) x
|
|
|
|
|
|
|
|
struct JSFunctionMeter {
|
|
|
|
int32 FUNCTION_KIND_METER_LIST(identity);
|
|
|
|
};
|
|
|
|
|
|
|
|
# undef identity
|
|
|
|
|
|
|
|
# define JS_FUNCTION_METER(cx,x) JS_RUNTIME_METER((cx)->runtime, functionMeter.x)
|
|
|
|
#else
|
|
|
|
# define JS_FUNCTION_METER(cx,x) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
typedef enum JSDestroyContextMode {
|
|
|
|
JSDCM_NO_GC,
|
|
|
|
JSDCM_MAYBE_GC,
|
|
|
|
JSDCM_FORCE_GC,
|
|
|
|
JSDCM_NEW_FAILED
|
|
|
|
} JSDestroyContextMode;
|
|
|
|
|
|
|
|
typedef enum JSRuntimeState {
|
|
|
|
JSRTS_DOWN,
|
|
|
|
JSRTS_LAUNCHING,
|
|
|
|
JSRTS_UP,
|
|
|
|
JSRTS_LANDING
|
|
|
|
} JSRuntimeState;
|
|
|
|
|
|
|
|
typedef struct JSPropertyTreeEntry {
|
|
|
|
JSDHashEntryHdr hdr;
|
2010-08-29 11:57:08 -07:00
|
|
|
js::Shape *child;
|
2007-03-22 10:30:00 -07:00
|
|
|
} JSPropertyTreeEntry;
|
|
|
|
|
2010-08-09 16:39:28 -07:00
|
|
|
typedef void
|
|
|
|
(* JSActivityCallback)(void *arg, JSBool active);
|
|
|
|
|
2010-09-17 14:54:40 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-03-08 20:58:38 -08:00
|
|
|
typedef js::Vector<JSCompartment *, 0, js::SystemAllocPolicy> CompartmentVector;
|
2010-09-17 14:54:40 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct JSRuntime {
|
2010-06-04 16:32:10 -07:00
|
|
|
/* Default compartment. */
|
2011-01-13 14:42:36 -08:00
|
|
|
JSCompartment *atomsCompartment;
|
2010-09-24 10:54:39 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-01-13 14:42:36 -08:00
|
|
|
bool atomsCompartmentIsLocked;
|
2010-09-24 10:54:39 -07:00
|
|
|
#endif
|
2010-06-04 16:32:10 -07:00
|
|
|
|
|
|
|
/* List of compartments (protected by the GC lock). */
|
2011-03-08 20:58:38 -08:00
|
|
|
js::CompartmentVector compartments;
|
2010-06-04 16:32:10 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Runtime state, synchronized by the stateChange/gcLock condvar/lock. */
|
|
|
|
JSRuntimeState state;
|
|
|
|
|
|
|
|
/* Context create/destroy callback. */
|
|
|
|
JSContextCallback cxCallback;
|
|
|
|
|
2010-07-19 13:36:49 -07:00
|
|
|
/* Compartment create/destroy callback. */
|
|
|
|
JSCompartmentCallback compartmentCallback;
|
|
|
|
|
2010-08-09 16:39:28 -07:00
|
|
|
/*
|
|
|
|
* Sets a callback that is run whenever the runtime goes idle - the
|
|
|
|
* last active request ceases - and begins activity - when it was
|
|
|
|
* idle and a request begins. Note: The callback is called under the
|
|
|
|
* GC lock.
|
|
|
|
*/
|
|
|
|
void setActivityCallback(JSActivityCallback cb, void *arg) {
|
|
|
|
activityCallback = cb;
|
|
|
|
activityCallbackArg = arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSActivityCallback activityCallback;
|
|
|
|
void *activityCallbackArg;
|
|
|
|
|
2009-05-13 17:11:23 -07:00
|
|
|
/*
|
|
|
|
* Shape regenerated whenever a prototype implicated by an "add property"
|
|
|
|
* property cache fill and induced trace guard has a readonly property or a
|
|
|
|
* setter defined on it. This number proxies for the shapes of all objects
|
|
|
|
* along the prototype chain of all objects in the runtime on which such an
|
|
|
|
* add-property result has been cached/traced.
|
|
|
|
*
|
|
|
|
* See bug 492355 for more details.
|
|
|
|
*
|
|
|
|
* This comes early in JSRuntime to minimize the immediate format used by
|
|
|
|
* trace-JITted code that reads it.
|
|
|
|
*/
|
|
|
|
uint32 protoHazardShape;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Garbage collector state, used by jsgc.c. */
|
2010-08-05 05:16:56 -07:00
|
|
|
js::GCChunkSet gcChunkSet;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
js::RootedValueMap gcRootsHash;
|
2010-05-20 13:50:08 -07:00
|
|
|
js::GCLocks gcLocksHash;
|
2007-03-22 10:30:00 -07:00
|
|
|
jsrefcount gcKeepAtoms;
|
2011-04-13 13:43:33 -07:00
|
|
|
uint32 gcBytes;
|
|
|
|
uint32 gcTriggerBytes;
|
2009-08-25 14:42:42 -07:00
|
|
|
size_t gcLastBytes;
|
|
|
|
size_t gcMaxBytes;
|
|
|
|
size_t gcMaxMallocBytes;
|
2011-02-19 22:59:49 -08:00
|
|
|
size_t gcChunksWaitingToExpire;
|
2008-09-12 15:11:48 -07:00
|
|
|
uint32 gcEmptyArenaPoolLifespan;
|
2007-03-22 10:30:00 -07:00
|
|
|
uint32 gcNumber;
|
2010-07-26 11:44:04 -07:00
|
|
|
js::GCMarker *gcMarkingTracer;
|
2010-12-17 16:33:04 -08:00
|
|
|
int64 gcJitReleaseTime;
|
2011-01-09 22:57:21 -08:00
|
|
|
JSGCMode gcMode;
|
2011-01-07 23:44:57 -08:00
|
|
|
volatile bool gcIsNeeded;
|
2011-04-16 21:23:44 -07:00
|
|
|
JSObject *gcWeakMapList;
|
2011-01-07 23:44:57 -08:00
|
|
|
|
2011-04-15 16:56:08 -07:00
|
|
|
/* Pre-allocated space for the GC mark stacks. Pointer type ensures alignment. */
|
2011-04-21 13:44:29 -07:00
|
|
|
void *gcMarkStackObjs[js::OBJECT_MARK_STACK_SIZE / sizeof(void *)];
|
|
|
|
void *gcMarkStackXMLs[js::XML_MARK_STACK_SIZE / sizeof(void *)];
|
|
|
|
void *gcMarkStackLarges[js::LARGE_MARK_STACK_SIZE / sizeof(void *)];
|
2011-04-15 16:56:08 -07:00
|
|
|
|
2011-01-07 23:44:57 -08:00
|
|
|
/*
|
|
|
|
* Compartment that triggered GC. If more than one Compatment need GC,
|
2011-02-17 16:17:45 -08:00
|
|
|
* gcTriggerCompartment is reset to NULL and a global GC is performed.
|
2011-01-07 23:44:57 -08:00
|
|
|
*/
|
|
|
|
JSCompartment *gcTriggerCompartment;
|
|
|
|
|
|
|
|
/* Compartment that is currently involved in per-compartment GC */
|
|
|
|
JSCompartment *gcCurrentCompartment;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2010-10-07 13:43:52 -07:00
|
|
|
* We can pack these flags as only the GC thread writes to them. Atomic
|
|
|
|
* updates to packed bytes are not guaranteed, so stores issued by one
|
|
|
|
* thread may be lost due to unsynchronized read-modify-write cycles on
|
|
|
|
* other threads.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-08-30 11:46:18 -07:00
|
|
|
bool gcPoke;
|
|
|
|
bool gcMarkAndSweep;
|
|
|
|
bool gcRunning;
|
|
|
|
bool gcRegenShapes;
|
2009-07-27 14:29:02 -07:00
|
|
|
|
2007-11-13 02:44:08 -08:00
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
jsrefcount gcZeal;
|
2007-05-15 16:27:20 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSGCCallback gcCallback;
|
2009-10-18 08:40:19 -07:00
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
private:
|
2009-10-18 08:40:19 -07:00
|
|
|
/*
|
|
|
|
* Malloc counter to measure memory pressure for GC scheduling. It runs
|
|
|
|
* from gcMaxMallocBytes down to zero.
|
|
|
|
*/
|
2010-09-07 14:08:20 -07:00
|
|
|
volatile ptrdiff_t gcMallocBytes;
|
2010-08-19 12:28:12 -07:00
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
public:
|
2010-09-01 11:24:45 -07:00
|
|
|
js::GCChunkAllocator *gcChunkAllocator;
|
2010-09-07 14:08:20 -07:00
|
|
|
|
2010-06-07 02:17:15 -07:00
|
|
|
void setCustomGCChunkAllocator(js::GCChunkAllocator *allocator) {
|
|
|
|
JS_ASSERT(allocator);
|
|
|
|
JS_ASSERT(state == JSRTS_DOWN);
|
|
|
|
gcChunkAllocator = allocator;
|
|
|
|
}
|
|
|
|
|
2007-05-01 03:09:46 -07:00
|
|
|
/*
|
|
|
|
* The trace operation and its data argument to trace embedding-specific
|
|
|
|
* GC roots.
|
|
|
|
*/
|
|
|
|
JSTraceDataOp gcExtraRootsTraceOp;
|
|
|
|
void *gcExtraRootsData;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Well-known numbers held for use by this runtime's contexts. */
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value NaNValue;
|
|
|
|
js::Value negativeInfinityValue;
|
|
|
|
js::Value positiveInfinityValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-12-06 10:26:58 -08:00
|
|
|
JSFlatString *emptyString;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* List of active contexts sharing this runtime; protected by gcLock. */
|
|
|
|
JSCList contextList;
|
|
|
|
|
2007-06-14 23:44:18 -07:00
|
|
|
/* Per runtime debug hooks -- see jsprvtd.h and jsdbgapi.h. */
|
|
|
|
JSDebugHooks globalDebugHooks;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-30 09:13:02 -07:00
|
|
|
/*
|
|
|
|
* Right now, we only support runtime-wide debugging.
|
|
|
|
*/
|
|
|
|
JSBool debugMode;
|
|
|
|
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
|
|
|
/* True if any debug hooks not supported by the JIT are enabled. */
|
|
|
|
bool debuggerInhibitsJIT() const {
|
2010-04-30 17:34:54 -07:00
|
|
|
return (globalDebugHooks.interruptHook ||
|
2010-07-23 19:33:49 -07:00
|
|
|
globalDebugHooks.callHook);
|
2009-11-13 09:04:23 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* More debugging state, see jsdbgapi.c. */
|
|
|
|
JSCList trapList;
|
|
|
|
JSCList watchPointList;
|
|
|
|
|
2008-10-11 10:35:39 -07:00
|
|
|
/* Client opaque pointers */
|
2007-03-22 10:30:00 -07:00
|
|
|
void *data;
|
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/* These combine to interlock the GC and new requests. */
|
|
|
|
PRLock *gcLock;
|
|
|
|
PRCondVar *gcDone;
|
|
|
|
PRCondVar *requestDone;
|
|
|
|
uint32 requestCount;
|
|
|
|
JSThread *gcThread;
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
js::GCHelperThread gcHelperThread;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Lock and owning thread pointer for JS_LOCK_RUNTIME. */
|
|
|
|
PRLock *rtLock;
|
|
|
|
#ifdef DEBUG
|
2010-05-13 10:50:43 -07:00
|
|
|
void * rtLockOwner;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Used to synchronize down/up state change; protected by gcLock. */
|
|
|
|
PRCondVar *stateChange;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock serializing trapList and watchPointList accesses, and count of all
|
|
|
|
* mutations to trapList and watchPointList made by debugger threads. To
|
|
|
|
* keep the code simple, we define debuggerMutations for the thread-unsafe
|
|
|
|
* case too.
|
|
|
|
*/
|
|
|
|
PRLock *debuggerLock;
|
2009-03-24 05:07:35 -07:00
|
|
|
|
2010-05-13 10:50:43 -07:00
|
|
|
JSThread::Map threads;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* JS_THREADSAFE */
|
|
|
|
uint32 debuggerMutations;
|
|
|
|
|
|
|
|
/*
|
2008-09-05 16:24:53 -07:00
|
|
|
* Security callbacks set on the runtime are used by each context unless
|
|
|
|
* an override is set on the context.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-09-05 16:24:53 -07:00
|
|
|
JSSecurityCallbacks *securityCallbacks;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-30 17:47:10 -07:00
|
|
|
/* Structured data callbacks are runtime-wide. */
|
|
|
|
const JSStructuredCloneCallbacks *structuredCloneCallbacks;
|
|
|
|
|
2010-03-22 11:11:44 -07:00
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* The propertyRemovals counter is incremented for every JSObject::clear,
|
|
|
|
* and for each JSObject::remove method call that frees a slot in the given
|
|
|
|
* object. See js_NativeGet and js_NativeSet in jsobj.cpp.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
int32 propertyRemovals;
|
|
|
|
|
|
|
|
/* Script filename table. */
|
|
|
|
struct JSHashTable *scriptFilenameTable;
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
PRLock *scriptFilenameTableLock;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Number localization, used by jsnum.c */
|
|
|
|
const char *thousandsSeparator;
|
|
|
|
const char *decimalSeparator;
|
|
|
|
const char *numGrouping;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Weak references to lazily-created, well-known XML singletons.
|
|
|
|
*
|
|
|
|
* NB: Singleton objects must be carefully disconnected from the rest of
|
|
|
|
* the object graph usually associated with a JSContext's global object,
|
|
|
|
* including the set of standard class objects. See jsxml.c for details.
|
|
|
|
*/
|
|
|
|
JSObject *anynameObject;
|
|
|
|
JSObject *functionNamespaceObject;
|
|
|
|
|
2010-10-22 10:48:06 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/* Number of threads with active requests and unhandled interrupts. */
|
2010-10-22 22:34:05 -07:00
|
|
|
volatile int32 interruptCounter;
|
2010-10-22 10:48:06 -07:00
|
|
|
#else
|
2011-03-13 07:45:02 -07:00
|
|
|
js::ThreadData threadData;
|
2009-03-13 10:36:46 -07:00
|
|
|
|
2009-03-24 05:07:35 -07:00
|
|
|
#define JS_THREAD_DATA(cx) (&(cx)->runtime->threadData)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-02-07 15:18:45 -08:00
|
|
|
/*
|
|
|
|
* Object shape (property cache structural type) identifier generator.
|
|
|
|
*
|
|
|
|
* Type 0 stands for the empty scope, and must not be regenerated due to
|
2009-04-20 03:10:29 -07:00
|
|
|
* uint32 wrap-around. Since js_GenerateShape (in jsinterp.cpp) uses
|
|
|
|
* atomic pre-increment, the initial value for the first typed non-empty
|
|
|
|
* scope will be 1.
|
2008-02-07 15:18:45 -08:00
|
|
|
*
|
|
|
|
* If this counter overflows into SHAPE_OVERFLOW_BIT (in jsinterp.h), the
|
2009-04-20 03:10:29 -07:00
|
|
|
* cache is disabled, to avoid aliasing two different types. It stays
|
|
|
|
* disabled until a triggered GC at some later moment compresses live
|
|
|
|
* types, minimizing rt->shapeGen in the process.
|
2008-02-07 15:18:45 -08:00
|
|
|
*/
|
2009-04-20 03:10:29 -07:00
|
|
|
volatile uint32 shapeGen;
|
2008-02-07 15:18:45 -08:00
|
|
|
|
2007-08-07 00:29:32 -07:00
|
|
|
/* Literal table maintained by jsatom.c functions. */
|
|
|
|
JSAtomState atomState;
|
|
|
|
|
2008-09-25 19:11:48 -07:00
|
|
|
/*
|
2008-01-29 14:17:25 -08:00
|
|
|
* Various metering fields are defined at the end of JSRuntime. In this
|
|
|
|
* way there is no need to recompile all the code that refers to other
|
|
|
|
* fields of JSRuntime after enabling the corresponding metering macro.
|
|
|
|
*/
|
2008-08-19 10:00:14 -07:00
|
|
|
#ifdef JS_DUMP_ENUM_CACHE_STATS
|
|
|
|
int32 nativeEnumProbes;
|
|
|
|
int32 nativeEnumMisses;
|
|
|
|
# define ENUM_CACHE_METER(name) JS_ATOMIC_INCREMENT(&cx->runtime->name)
|
|
|
|
#else
|
|
|
|
# define ENUM_CACHE_METER(name) ((void) 0)
|
|
|
|
#endif
|
2008-01-29 14:17:25 -08:00
|
|
|
|
2009-12-01 12:49:15 -08:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Function invocation metering. */
|
|
|
|
jsrefcount inlineCalls;
|
|
|
|
jsrefcount nativeCalls;
|
|
|
|
jsrefcount nonInlineCalls;
|
|
|
|
jsrefcount constructs;
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
2011-02-04 10:59:07 -08:00
|
|
|
* NB: emptyShapes (in JSCompartment) is init'ed iff at least one
|
|
|
|
* of these envars is set:
|
2010-08-29 11:57:08 -07:00
|
|
|
*
|
|
|
|
* JS_PROPTREE_STATFILE statistics on the property tree forest
|
|
|
|
* JS_PROPTREE_DUMPFILE all paths in the property tree forest
|
|
|
|
*/
|
|
|
|
const char *propTreeStatFilename;
|
|
|
|
const char *propTreeDumpFilename;
|
|
|
|
|
|
|
|
bool meterEmptyShapes() const { return propTreeStatFilename || propTreeDumpFilename; }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* String instrumentation. */
|
|
|
|
jsrefcount liveStrings;
|
|
|
|
jsrefcount totalStrings;
|
|
|
|
jsrefcount liveDependentStrings;
|
|
|
|
jsrefcount totalDependentStrings;
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-12 16:31:31 -08:00
|
|
|
jsrefcount badUndependStrings;
|
2007-03-22 10:30:00 -07:00
|
|
|
double lengthSum;
|
|
|
|
double lengthSquaredSum;
|
|
|
|
double strdepLengthSum;
|
|
|
|
double strdepLengthSquaredSum;
|
2009-10-18 17:41:24 -07:00
|
|
|
|
|
|
|
/* Script instrumentation. */
|
|
|
|
jsrefcount liveScripts;
|
|
|
|
jsrefcount totalScripts;
|
|
|
|
jsrefcount liveEmptyScripts;
|
|
|
|
jsrefcount totalEmptyScripts;
|
2010-12-02 14:23:51 -08:00
|
|
|
jsrefcount highWaterLiveScripts;
|
2009-12-01 12:49:15 -08:00
|
|
|
#endif /* DEBUG */
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-12 16:31:31 -08:00
|
|
|
|
|
|
|
#ifdef JS_SCOPE_DEPTH_METER
|
|
|
|
/*
|
|
|
|
* Stats on runtime prototype chain lookups and scope chain depths, i.e.,
|
|
|
|
* counts of objects traversed on a chain until the wanted id is found.
|
|
|
|
*/
|
|
|
|
JSBasicStats protoLookupDepthStats;
|
|
|
|
JSBasicStats scopeSearchDepthStats;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stats on compile-time host environment and lexical scope chain lengths
|
|
|
|
* (maximum depths).
|
|
|
|
*/
|
|
|
|
JSBasicStats hostenvScopeDepthStats;
|
|
|
|
JSBasicStats lexicalScopeDepthStats;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2008-01-29 14:17:25 -08:00
|
|
|
|
|
|
|
#ifdef JS_GCMETER
|
2010-09-24 10:54:39 -07:00
|
|
|
js::gc::JSGCStats gcStats;
|
|
|
|
js::gc::JSGCArenaStats globalArenaStats[js::gc::FINALIZE_LIMIT];
|
2008-01-29 14:17:25 -08:00
|
|
|
#endif
|
2009-04-05 21:17:22 -07:00
|
|
|
|
2010-08-01 09:58:03 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* If functionMeterFilename, set from an envariable in JSRuntime's ctor, is
|
|
|
|
* null, the remaining members in this ifdef'ed group are not initialized.
|
|
|
|
*/
|
|
|
|
const char *functionMeterFilename;
|
2009-04-05 21:17:22 -07:00
|
|
|
JSFunctionMeter functionMeter;
|
|
|
|
char lastScriptFilename[1024];
|
2010-08-01 09:58:03 -07:00
|
|
|
|
|
|
|
typedef js::HashMap<JSFunction *,
|
|
|
|
int32,
|
|
|
|
js::DefaultHasher<JSFunction *>,
|
|
|
|
js::SystemAllocPolicy> FunctionCountMap;
|
|
|
|
|
|
|
|
FunctionCountMap methodReadBarrierCountMap;
|
|
|
|
FunctionCountMap unjoinedFunctionCountMap;
|
2009-04-05 21:17:22 -07:00
|
|
|
#endif
|
2009-07-14 17:03:20 -07:00
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
JSWrapObjectCallback wrapObjectCallback;
|
2010-10-10 15:36:38 -07:00
|
|
|
JSPreWrapCallback preWrapObjectCallback;
|
2010-06-24 14:45:32 -07:00
|
|
|
|
2011-01-04 22:48:46 -08:00
|
|
|
#ifdef JS_METHODJIT
|
2011-05-03 17:12:58 -07:00
|
|
|
/* This measures the size of JITScripts, native maps and IC structs. */
|
|
|
|
size_t mjitDataSize;
|
2011-01-04 22:48:46 -08:00
|
|
|
#endif
|
|
|
|
|
2011-05-17 11:23:31 -07:00
|
|
|
/*
|
|
|
|
* To ensure that cx->malloc does not cause a GC, we set this flag during
|
|
|
|
* OOM reporting (in js_ReportOutOfMemory). If a GC is requested while
|
|
|
|
* reporting the OOM, we ignore it.
|
|
|
|
*/
|
|
|
|
bool inOOMReport;
|
|
|
|
|
2011-05-20 13:40:06 -07:00
|
|
|
#if defined(MOZ_GCTIMER) || defined(JSGC_TESTPILOT)
|
|
|
|
struct GCData {
|
|
|
|
/*
|
|
|
|
* Timestamp of the first GCTimer -- application runtime is determined
|
|
|
|
* relative to this value.
|
|
|
|
*/
|
|
|
|
uint64 firstEnter;
|
|
|
|
bool firstEnterValid;
|
|
|
|
|
|
|
|
void setFirstEnter(uint64 v) {
|
|
|
|
JS_ASSERT(!firstEnterValid);
|
|
|
|
firstEnter = v;
|
|
|
|
firstEnterValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef JSGC_TESTPILOT
|
|
|
|
bool infoEnabled;
|
|
|
|
|
|
|
|
bool isTimerEnabled() {
|
|
|
|
return infoEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Circular buffer with GC data.
|
|
|
|
* count may grow >= INFO_LIMIT, which would indicate data loss.
|
|
|
|
*/
|
|
|
|
static const size_t INFO_LIMIT = 64;
|
|
|
|
JSGCInfo info[INFO_LIMIT];
|
|
|
|
size_t start;
|
|
|
|
size_t count;
|
|
|
|
#else /* defined(MOZ_GCTIMER) */
|
|
|
|
bool isTimerEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} gcData;
|
|
|
|
#endif
|
|
|
|
|
2009-10-20 15:08:28 -07:00
|
|
|
JSRuntime();
|
|
|
|
~JSRuntime();
|
|
|
|
|
|
|
|
bool init(uint32 maxbytes);
|
|
|
|
|
2009-08-25 14:42:42 -07:00
|
|
|
void setGCLastBytes(size_t lastBytes);
|
2011-04-13 13:43:33 -07:00
|
|
|
void reduceGCTriggerBytes(uint32 amount);
|
2009-08-25 14:42:42 -07:00
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* Call the system malloc while checking for GC memory pressure and
|
2011-05-17 11:23:31 -07:00
|
|
|
* reporting OOM error when cx is not null. We will not GC from here.
|
2010-09-07 14:08:20 -07:00
|
|
|
*/
|
2011-03-31 01:14:12 -07:00
|
|
|
void* malloc_(size_t bytes, JSContext *cx = NULL) {
|
2010-09-07 14:08:20 -07:00
|
|
|
updateMallocCounter(bytes);
|
|
|
|
void *p = ::js_malloc(bytes);
|
|
|
|
return JS_LIKELY(!!p) ? p : onOutOfMemory(NULL, bytes, cx);
|
|
|
|
}
|
2009-07-27 21:10:12 -07:00
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* Call the system calloc while checking for GC memory pressure and
|
2011-05-17 11:23:31 -07:00
|
|
|
* reporting OOM error when cx is not null. We will not GC from here.
|
2010-09-07 14:08:20 -07:00
|
|
|
*/
|
2011-03-31 01:14:12 -07:00
|
|
|
void* calloc_(size_t bytes, JSContext *cx = NULL) {
|
2010-09-07 14:08:20 -07:00
|
|
|
updateMallocCounter(bytes);
|
|
|
|
void *p = ::js_calloc(bytes);
|
|
|
|
return JS_LIKELY(!!p) ? p : onOutOfMemory(reinterpret_cast<void *>(1), bytes, cx);
|
|
|
|
}
|
2009-07-27 21:10:12 -07:00
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
void* realloc_(void* p, size_t oldBytes, size_t newBytes, JSContext *cx = NULL) {
|
2010-12-08 16:34:38 -08:00
|
|
|
JS_ASSERT(oldBytes < newBytes);
|
|
|
|
updateMallocCounter(newBytes - oldBytes);
|
|
|
|
void *p2 = ::js_realloc(p, newBytes);
|
|
|
|
return JS_LIKELY(!!p2) ? p2 : onOutOfMemory(p, newBytes, cx);
|
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
void* realloc_(void* p, size_t bytes, JSContext *cx = NULL) {
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* For compatibility we do not account for realloc that increases
|
|
|
|
* previously allocated memory.
|
|
|
|
*/
|
|
|
|
if (!p)
|
|
|
|
updateMallocCounter(bytes);
|
|
|
|
void *p2 = ::js_realloc(p, bytes);
|
|
|
|
return JS_LIKELY(!!p2) ? p2 : onOutOfMemory(p, bytes, cx);
|
|
|
|
}
|
2010-07-23 15:17:42 -07:00
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void free_(void* p) {
|
Bug 634155: Account for NewCompartment's memory, and change allocation APIs (r=nnethercote)
This changes the allocation API, in the following way:
js_malloc -> {cx->,rt->,OffTheBooks::}malloc
js_calloc -> {cx->,rt->,OffTheBooks::}calloc
js_realloc -> {cx->,rt->,OffTheBooks::}realloc
js_free -> {cx->,rt->,Foreground::,UnwantedForeground::}free
js_new -> {cx->,rt->,OffTheBooks::}new_
js_new_array -> {cx->,rt->,OffTheBooks::}new_array
js_delete -> {cx->,rt->,Foreground::,UnwantedForeground::}delete_
This is to move as many allocations as possible through a JSContext (so that they may be aken into account by gcMallocBytes) and to move as many deallocations to the background as possible (except on error paths).
2011-03-31 01:13:49 -07:00
|
|
|
/* FIXME: Making this free in the background is buggy. Can it work? */
|
2011-03-31 01:14:12 -07:00
|
|
|
js::Foreground::free_(p);
|
Bug 634155: Account for NewCompartment's memory, and change allocation APIs (r=nnethercote)
This changes the allocation API, in the following way:
js_malloc -> {cx->,rt->,OffTheBooks::}malloc
js_calloc -> {cx->,rt->,OffTheBooks::}calloc
js_realloc -> {cx->,rt->,OffTheBooks::}realloc
js_free -> {cx->,rt->,Foreground::,UnwantedForeground::}free
js_new -> {cx->,rt->,OffTheBooks::}new_
js_new_array -> {cx->,rt->,OffTheBooks::}new_array
js_delete -> {cx->,rt->,Foreground::,UnwantedForeground::}delete_
This is to move as many allocations as possible through a JSContext (so that they may be aken into account by gcMallocBytes) and to move as many deallocations to the background as possible (except on error paths).
2011-03-31 01:13:49 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
JS_DECLARE_NEW_METHODS(malloc_, JS_ALWAYS_INLINE)
|
|
|
|
JS_DECLARE_DELETE_METHODS(free_, JS_ALWAYS_INLINE)
|
2009-10-18 08:40:19 -07:00
|
|
|
|
2010-07-28 11:20:19 -07:00
|
|
|
bool isGCMallocLimitReached() const { return gcMallocBytes <= 0; }
|
|
|
|
|
2009-10-18 08:40:19 -07:00
|
|
|
void resetGCMallocBytes() { gcMallocBytes = ptrdiff_t(gcMaxMallocBytes); }
|
|
|
|
|
|
|
|
void setGCMaxMallocBytes(size_t value) {
|
|
|
|
/*
|
|
|
|
* For compatibility treat any value that exceeds PTRDIFF_T_MAX to
|
|
|
|
* mean that value.
|
|
|
|
*/
|
|
|
|
gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1;
|
|
|
|
resetGCMallocBytes();
|
|
|
|
}
|
2010-09-07 14:08:20 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call this after allocating memory held by GC things, to update memory
|
|
|
|
* pressure counters or report the OOM error if necessary. If oomError and
|
|
|
|
* cx is not null the function also reports OOM error.
|
|
|
|
*
|
|
|
|
* The function must be called outside the GC lock and in case of OOM error
|
|
|
|
* the caller must ensure that no deadlock possible during OOM reporting.
|
|
|
|
*/
|
|
|
|
void updateMallocCounter(size_t nbytes) {
|
|
|
|
/* We tolerate any thread races when updating gcMallocBytes. */
|
|
|
|
ptrdiff_t newCount = gcMallocBytes - ptrdiff_t(nbytes);
|
|
|
|
gcMallocBytes = newCount;
|
|
|
|
if (JS_UNLIKELY(newCount <= 0))
|
|
|
|
onTooMuchMalloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The function must be called outside the GC lock.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void) onTooMuchMalloc();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This should be called after system malloc/realloc returns NULL to try
|
|
|
|
* to recove some memory or to report an error. Failures in malloc and
|
|
|
|
* calloc are signaled by p == null and p == reinterpret_cast<void *>(1).
|
|
|
|
* Other values of p mean a realloc failure.
|
|
|
|
*
|
|
|
|
* The function must be called outside the GC lock.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes, JSContext *cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-01-27 16:40:40 -08:00
|
|
|
/* Common macros to access thread-local caches in JSThread or JSRuntime. */
|
2009-03-24 05:07:35 -07:00
|
|
|
#define JS_PROPERTY_CACHE(cx) (JS_THREAD_DATA(cx)->propertyCache)
|
2009-01-27 16:40:40 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
# define JS_RUNTIME_METER(rt, which) JS_ATOMIC_INCREMENT(&(rt)->which)
|
|
|
|
# define JS_RUNTIME_UNMETER(rt, which) JS_ATOMIC_DECREMENT(&(rt)->which)
|
|
|
|
#else
|
|
|
|
# define JS_RUNTIME_METER(rt, which) /* nothing */
|
|
|
|
# define JS_RUNTIME_UNMETER(rt, which) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define JS_KEEP_ATOMS(rt) JS_ATOMIC_INCREMENT(&(rt)->gcKeepAtoms);
|
|
|
|
#define JS_UNKEEP_ATOMS(rt) JS_ATOMIC_DECREMENT(&(rt)->gcKeepAtoms);
|
|
|
|
|
|
|
|
#ifdef JS_ARGUMENT_FORMATTER_DEFINED
|
|
|
|
/*
|
|
|
|
* Linked list mapping format strings for JS_{Convert,Push}Arguments{,VA} to
|
|
|
|
* formatter functions. Elements are sorted in non-increasing format string
|
|
|
|
* length order.
|
|
|
|
*/
|
|
|
|
struct JSArgumentFormatMap {
|
|
|
|
const char *format;
|
|
|
|
size_t length;
|
|
|
|
JSArgumentFormatter formatter;
|
|
|
|
JSArgumentFormatMap *next;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-01-20 12:54:34 -08:00
|
|
|
extern const JSDebugHooks js_NullDebugHooks; /* defined in jsdbgapi.cpp */
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
namespace js {
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
class AutoGCRooter;
|
2011-03-07 14:00:00 -08:00
|
|
|
struct AutoResolving;
|
2010-08-11 13:30:07 -07:00
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
|
|
|
OptionsHasXML(uint32 options)
|
|
|
|
{
|
|
|
|
return !!(options & JSOPTION_XML);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
OptionsHasAnonFunFix(uint32 options)
|
|
|
|
{
|
|
|
|
return !!(options & JSOPTION_ANONFUNFIX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
OptionsSameVersionFlags(uint32 self, uint32 other)
|
|
|
|
{
|
|
|
|
static const uint32 mask = JSOPTION_XML | JSOPTION_ANONFUNFIX;
|
|
|
|
return !((self & mask) ^ (other & mask));
|
|
|
|
}
|
|
|
|
|
2010-11-09 09:00:54 -08:00
|
|
|
/*
|
|
|
|
* Flags accompany script version data so that a) dynamically created scripts
|
|
|
|
* can inherit their caller's compile-time properties and b) scripts can be
|
|
|
|
* appropriately compared in the eval cache across global option changes. An
|
|
|
|
* example of the latter is enabling the top-level-anonymous-function-is-error
|
|
|
|
* option: subsequent evals of the same, previously-valid script text may have
|
|
|
|
* become invalid.
|
|
|
|
*/
|
2010-09-13 09:38:22 -07:00
|
|
|
namespace VersionFlags {
|
2011-01-27 02:54:58 -08:00
|
|
|
static const uintN MASK = 0x0FFF; /* see JSVersion in jspubtd.h */
|
|
|
|
static const uintN HAS_XML = 0x1000; /* flag induced by XML option */
|
|
|
|
static const uintN ANONFUNFIX = 0x2000; /* see jsapi.h comment on JSOPTION_ANONFUNFIX */
|
|
|
|
static const uintN FULL_MASK = 0x3FFF;
|
2010-09-13 09:38:22 -07:00
|
|
|
}
|
|
|
|
|
2010-09-18 00:31:36 -07:00
|
|
|
static inline JSVersion
|
|
|
|
VersionNumber(JSVersion version)
|
|
|
|
{
|
|
|
|
return JSVersion(uint32(version) & VersionFlags::MASK);
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
|
|
|
VersionHasXML(JSVersion version)
|
|
|
|
{
|
|
|
|
return !!(version & VersionFlags::HAS_XML);
|
|
|
|
}
|
|
|
|
|
2010-09-18 00:31:36 -07:00
|
|
|
/* @warning This is a distinct condition from having the XML flag set. */
|
|
|
|
static inline bool
|
|
|
|
VersionShouldParseXML(JSVersion version)
|
|
|
|
{
|
|
|
|
return VersionHasXML(version) || VersionNumber(version) >= JSVERSION_1_6;
|
|
|
|
}
|
|
|
|
|
2010-11-09 09:00:54 -08:00
|
|
|
static inline bool
|
|
|
|
VersionHasAnonFunFix(JSVersion version)
|
|
|
|
{
|
|
|
|
return !!(version & VersionFlags::ANONFUNFIX);
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline void
|
|
|
|
VersionSetXML(JSVersion *version, bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
*version = JSVersion(uint32(*version) | VersionFlags::HAS_XML);
|
|
|
|
else
|
|
|
|
*version = JSVersion(uint32(*version) & ~VersionFlags::HAS_XML);
|
|
|
|
}
|
|
|
|
|
2010-11-09 09:00:54 -08:00
|
|
|
static inline void
|
|
|
|
VersionSetAnonFunFix(JSVersion *version, bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
*version = JSVersion(uint32(*version) | VersionFlags::ANONFUNFIX);
|
|
|
|
else
|
|
|
|
*version = JSVersion(uint32(*version) & ~VersionFlags::ANONFUNFIX);
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline JSVersion
|
|
|
|
VersionExtractFlags(JSVersion version)
|
|
|
|
{
|
|
|
|
return JSVersion(uint32(version) & ~VersionFlags::MASK);
|
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
static inline void
|
|
|
|
VersionCopyFlags(JSVersion *version, JSVersion from)
|
|
|
|
{
|
|
|
|
*version = JSVersion(VersionNumber(*version) | VersionExtractFlags(from));
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
|
|
|
VersionHasFlags(JSVersion version)
|
|
|
|
{
|
|
|
|
return !!VersionExtractFlags(version);
|
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
static inline uintN
|
|
|
|
VersionFlagsToOptions(JSVersion version)
|
|
|
|
{
|
|
|
|
uintN copts = (VersionHasXML(version) ? JSOPTION_XML : 0) |
|
|
|
|
(VersionHasAnonFunFix(version) ? JSOPTION_ANONFUNFIX : 0);
|
|
|
|
JS_ASSERT((copts & JSCOMPILEOPTION_MASK) == copts);
|
|
|
|
return copts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSVersion
|
|
|
|
OptionFlagsToVersion(uintN options, JSVersion version)
|
|
|
|
{
|
|
|
|
VersionSetXML(&version, OptionsHasXML(options));
|
|
|
|
VersionSetAnonFunFix(&version, OptionsHasAnonFunFix(options));
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
|
|
|
VersionIsKnown(JSVersion version)
|
|
|
|
{
|
|
|
|
return VersionNumber(version) != JSVERSION_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2011-03-29 15:46:51 -07:00
|
|
|
typedef HashSet<JSObject *,
|
|
|
|
DefaultHasher<JSObject *>,
|
|
|
|
SystemAllocPolicy> BusyArraysSet;
|
2011-01-24 09:47:25 -08:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
} /* namespace js */
|
2010-08-11 13:30:07 -07:00
|
|
|
|
2010-02-06 10:14:05 -08:00
|
|
|
struct JSContext
|
|
|
|
{
|
2010-03-03 17:52:26 -08:00
|
|
|
explicit JSContext(JSRuntime *rt);
|
2011-04-13 09:27:37 -07:00
|
|
|
JSContext *thisDuringConstruction() { return this; }
|
2011-03-13 07:45:02 -07:00
|
|
|
~JSContext();
|
2010-02-06 10:14:05 -08:00
|
|
|
|
2008-12-18 07:24:34 -08:00
|
|
|
/* JSRuntime contextList linkage. */
|
|
|
|
JSCList link;
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
private:
|
|
|
|
/* See JSContext::findVersion. */
|
|
|
|
JSVersion defaultVersion; /* script compilation version */
|
|
|
|
JSVersion versionOverride; /* supercedes defaultVersion when valid */
|
|
|
|
bool hasVersionOverride;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
/* Exception state -- the exception member is a GC root by definition. */
|
|
|
|
JSBool throwing; /* is there a pending exception? */
|
|
|
|
js::Value exception; /* most-recently-thrown exception */
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
/* Per-context run options. */
|
|
|
|
uintN runOptions; /* see jsapi.h for JSOPTION_* */
|
2011-01-25 04:11:47 -08:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Locale specific callbacks for string conversion. */
|
|
|
|
JSLocaleCallbacks *localeCallbacks;
|
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
js::AutoResolving *resolvingList;
|
2011-02-17 10:39:05 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* True if generating an error, to prevent runaway recursion.
|
2010-07-15 17:58:36 -07:00
|
|
|
* NB: generatingError packs with throwing below.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
JSPackedBool generatingError;
|
|
|
|
|
2007-08-27 15:21:55 -07:00
|
|
|
/* Limit pointer for checking native stack consumption during recursion. */
|
2007-03-22 10:30:00 -07:00
|
|
|
jsuword stackLimit;
|
|
|
|
|
2007-08-27 15:21:55 -07:00
|
|
|
/* Quota on the size of arenas used to compile and execute scripts. */
|
|
|
|
size_t scriptStackQuota;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Data shared by threads in an address space. */
|
2010-03-03 17:52:26 -08:00
|
|
|
JSRuntime *const runtime;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-04 16:32:10 -07:00
|
|
|
/* GC heap compartment. */
|
|
|
|
JSCompartment *compartment;
|
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* Current execution stack. */
|
|
|
|
js::ContextStack stack;
|
2010-03-03 18:10:13 -08:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* ContextStack convenience functions */
|
|
|
|
bool running() const { return stack.running(); }
|
|
|
|
js::StackFrame* fp() const { return stack.fp(); }
|
|
|
|
js::StackFrame* maybefp() const { return stack.maybefp(); }
|
|
|
|
js::FrameRegs& regs() const { return stack.regs(); }
|
|
|
|
js::FrameRegs* maybeRegs() const { return stack.maybeRegs(); }
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* Set cx->compartment based on the current scope chain. */
|
2010-09-27 18:24:24 -07:00
|
|
|
void resetCompartment();
|
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* Wrap cx->exception for the current compartment. */
|
|
|
|
void wrapPendingException();
|
2010-03-03 18:10:13 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Temporary arena pool used while compiling and decompiling. */
|
|
|
|
JSArenaPool tempPool;
|
|
|
|
|
2010-08-11 13:30:07 -07:00
|
|
|
/* Temporary arena pool used while evaluate regular expressions. */
|
|
|
|
JSArenaPool regExpPool;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Top-level object and pointer to top stack frame's scope chain. */
|
|
|
|
JSObject *globalObject;
|
|
|
|
|
|
|
|
/* State for object and array toSource conversion. */
|
|
|
|
JSSharpObjectMap sharpObjectMap;
|
2011-03-29 15:46:51 -07:00
|
|
|
js::BusyArraysSet busyArrays;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Argument formatter support for JS_{Convert,Push}Arguments{,VA}. */
|
|
|
|
JSArgumentFormatMap *argumentFormatMap;
|
|
|
|
|
2010-10-26 12:07:26 -07:00
|
|
|
/* Last message string and log file for debugging. */
|
2007-03-22 10:30:00 -07:00
|
|
|
char *lastMessage;
|
|
|
|
#ifdef DEBUG
|
2010-10-26 12:07:26 -07:00
|
|
|
void *logfp;
|
|
|
|
jsbytecode *logPrevPc;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-01-03 01:28:40 -08:00
|
|
|
/* Per-context optional error reporter. */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSErrorReporter errorReporter;
|
|
|
|
|
2009-02-10 14:07:01 -08:00
|
|
|
/* Branch callback. */
|
2008-01-03 01:28:40 -08:00
|
|
|
JSOperationCallback operationCallback;
|
|
|
|
|
2008-10-11 10:35:39 -07:00
|
|
|
/* Client opaque pointers. */
|
2007-03-22 10:30:00 -07:00
|
|
|
void *data;
|
2008-10-11 10:35:39 -07:00
|
|
|
void *data2;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-02-19 20:46:44 -08:00
|
|
|
inline js::RegExpStatics *regExpStatics();
|
2010-09-13 15:53:50 -07:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
2010-09-13 09:38:22 -07:00
|
|
|
/*
|
|
|
|
* The default script compilation version can be set iff there is no code running.
|
|
|
|
* This typically occurs via the JSAPI right after a context is constructed.
|
|
|
|
*/
|
2010-11-15 13:35:20 -08:00
|
|
|
bool canSetDefaultVersion() const {
|
2011-04-13 09:27:37 -07:00
|
|
|
return !stack.running() && !hasVersionOverride;
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
2010-09-13 09:38:22 -07:00
|
|
|
|
|
|
|
/* Force a version for future script compilation. */
|
|
|
|
void overrideVersion(JSVersion newVersion) {
|
|
|
|
JS_ASSERT(!canSetDefaultVersion());
|
|
|
|
versionOverride = newVersion;
|
|
|
|
hasVersionOverride = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the default script compilation version. */
|
2010-11-15 13:35:20 -08:00
|
|
|
void setDefaultVersion(JSVersion version) {
|
|
|
|
defaultVersion = version;
|
|
|
|
}
|
2010-09-13 09:38:22 -07:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
void clearVersionOverride() { hasVersionOverride = false; }
|
|
|
|
JSVersion getDefaultVersion() const { return defaultVersion; }
|
|
|
|
bool isVersionOverridden() const { return hasVersionOverride; }
|
|
|
|
|
|
|
|
JSVersion getVersionOverride() const {
|
|
|
|
JS_ASSERT(isVersionOverridden());
|
|
|
|
return versionOverride;
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
/*
|
|
|
|
* Set the default version if possible; otherwise, force the version.
|
|
|
|
* Return whether an override occurred.
|
|
|
|
*/
|
|
|
|
bool maybeOverrideVersion(JSVersion newVersion) {
|
|
|
|
if (canSetDefaultVersion()) {
|
|
|
|
setDefaultVersion(newVersion);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
overrideVersion(newVersion);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
/*
|
2011-04-13 09:27:37 -07:00
|
|
|
* If there is no code on the stack, turn the override version into the
|
|
|
|
* default version.
|
2011-01-27 02:54:58 -08:00
|
|
|
*/
|
|
|
|
void maybeMigrateVersionOverride() {
|
2011-04-13 09:27:37 -07:00
|
|
|
if (JS_LIKELY(!isVersionOverridden() && stack.empty()))
|
2011-01-27 02:54:58 -08:00
|
|
|
return;
|
|
|
|
defaultVersion = versionOverride;
|
|
|
|
clearVersionOverride();
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
/*
|
|
|
|
* Return:
|
|
|
|
* - The override version, if there is an override version.
|
2011-02-17 16:17:45 -08:00
|
|
|
* - The newest scripted frame's version, if there is such a frame.
|
2010-09-13 09:38:22 -07:00
|
|
|
* - The default verion.
|
|
|
|
*
|
2011-01-05 18:44:30 -08:00
|
|
|
* Note: if this ever shows up in a profile, just add caching!
|
2010-09-13 09:38:22 -07:00
|
|
|
*/
|
|
|
|
JSVersion findVersion() const {
|
|
|
|
if (hasVersionOverride)
|
|
|
|
return versionOverride;
|
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
if (stack.running()) {
|
2010-09-13 09:38:22 -07:00
|
|
|
/* There may be a scripted function somewhere on the stack! */
|
2011-04-13 09:27:37 -07:00
|
|
|
js::StackFrame *f = fp();
|
|
|
|
while (f && !f->isScriptFrame())
|
|
|
|
f = f->prev();
|
|
|
|
if (f)
|
|
|
|
return f->script()->getVersion();
|
2010-09-13 09:38:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return defaultVersion;
|
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
void setRunOptions(uintN ropts) {
|
|
|
|
JS_ASSERT((ropts & JSRUNOPTION_MASK) == ropts);
|
|
|
|
runOptions = ropts;
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
/* Note: may override the version. */
|
|
|
|
void setCompileOptions(uintN newcopts) {
|
|
|
|
JS_ASSERT((newcopts & JSCOMPILEOPTION_MASK) == newcopts);
|
|
|
|
if (JS_LIKELY(getCompileOptions() == newcopts))
|
|
|
|
return;
|
2010-11-15 13:35:20 -08:00
|
|
|
JSVersion version = findVersion();
|
2011-01-27 02:54:58 -08:00
|
|
|
JSVersion newVersion = js::OptionFlagsToVersion(newcopts, version);
|
|
|
|
maybeOverrideVersion(newVersion);
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
uintN getRunOptions() const { return runOptions; }
|
|
|
|
uintN getCompileOptions() const { return js::VersionFlagsToOptions(findVersion()); }
|
|
|
|
uintN allOptions() const { return getRunOptions() | getCompileOptions(); }
|
|
|
|
|
|
|
|
bool hasRunOption(uintN ropt) const {
|
|
|
|
JS_ASSERT((ropt & JSRUNOPTION_MASK) == ropt);
|
|
|
|
return !!(runOptions & ropt);
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
bool hasStrictOption() const { return hasRunOption(JSOPTION_STRICT); }
|
|
|
|
bool hasWErrorOption() const { return hasRunOption(JSOPTION_WERROR); }
|
|
|
|
bool hasAtLineOption() const { return hasRunOption(JSOPTION_ATLINE); }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-04-13 09:27:37 -07:00
|
|
|
private:
|
|
|
|
JSThread *thread_;
|
|
|
|
public:
|
|
|
|
JSThread *thread() const { return thread_; }
|
|
|
|
|
|
|
|
void setThread(JSThread *thread);
|
|
|
|
static const size_t threadOffset() { return offsetof(JSContext, thread_); }
|
|
|
|
|
2010-08-30 11:46:18 -07:00
|
|
|
unsigned outstandingRequests;/* number of JS_BeginRequest calls
|
|
|
|
without the corresponding
|
|
|
|
JS_EndRequest. */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSCList threadLinks; /* JSThread contextList linkage */
|
|
|
|
|
|
|
|
#define CX_FROM_THREAD_LINKS(tl) \
|
|
|
|
((JSContext *)((char *)(tl) - offsetof(JSContext, threadLinks)))
|
|
|
|
#endif
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
/* Stack of thread-stack-allocated GC roots. */
|
|
|
|
js::AutoGCRooter *autoGCRooters;
|
2007-06-14 23:44:18 -07:00
|
|
|
|
|
|
|
/* Debug hooks associated with the current context. */
|
2009-11-13 09:04:23 -08:00
|
|
|
const JSDebugHooks *debugHooks;
|
2008-09-05 16:24:53 -07:00
|
|
|
|
|
|
|
/* Security callbacks that override any defined on the runtime. */
|
|
|
|
JSSecurityCallbacks *securityCallbacks;
|
2008-09-12 15:11:48 -07:00
|
|
|
|
2008-09-25 09:13:31 -07:00
|
|
|
/* Stored here to avoid passing it around as a parameter. */
|
|
|
|
uintN resolveFlags;
|
2009-02-03 16:25:12 -08:00
|
|
|
|
2010-03-18 08:27:26 -07:00
|
|
|
/* Random number generator state, used by jsmath.cpp. */
|
|
|
|
int64 rngSeed;
|
|
|
|
|
2010-05-07 17:52:52 -07:00
|
|
|
/* Location to stash the iteration value between JSOP_MOREITER and JSOP_FOR*. */
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value iterValue;
|
2010-05-07 17:52:52 -07:00
|
|
|
|
2009-02-03 16:25:12 -08:00
|
|
|
#ifdef JS_TRACER
|
2009-11-13 09:04:23 -08:00
|
|
|
/*
|
2010-09-15 22:27:17 -07:00
|
|
|
* True if traces may be executed. Invariant: The value of traceJitenabled
|
|
|
|
* is always equal to the expression in updateJITEnabled below.
|
2009-11-13 09:04:23 -08:00
|
|
|
*
|
|
|
|
* This flag and the fields accessed by updateJITEnabled are written only
|
|
|
|
* in runtime->gcLock, to avoid race conditions that would leave the wrong
|
2010-09-15 22:27:17 -07:00
|
|
|
* value in traceJitEnabled. (But the interpreter reads this without
|
2009-11-13 09:04:23 -08:00
|
|
|
* locking. That can race against another thread setting debug hooks, but
|
|
|
|
* we always read cx->debugHooks without locking anyway.)
|
|
|
|
*/
|
2010-09-15 22:27:17 -07:00
|
|
|
bool traceJitEnabled;
|
2009-11-13 09:04:23 -08:00
|
|
|
#endif
|
|
|
|
|
2010-09-15 22:27:17 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
bool methodJitEnabled;
|
2010-10-21 09:36:39 -07:00
|
|
|
bool profilingEnabled;
|
2011-04-13 09:27:37 -07:00
|
|
|
|
|
|
|
inline js::mjit::JaegerCompartment *jaegerCompartment();
|
2009-02-03 16:25:12 -08:00
|
|
|
#endif
|
2010-09-15 22:27:17 -07:00
|
|
|
|
|
|
|
/* Caller must be holding runtime->gcLock. */
|
|
|
|
void updateJITEnabled();
|
2009-07-16 18:36:19 -07:00
|
|
|
|
2010-08-09 13:38:13 -07:00
|
|
|
#ifdef MOZ_TRACE_JSCALLS
|
|
|
|
/* Function entry/exit debugging callback. */
|
|
|
|
JSFunctionCallback functionCallback;
|
|
|
|
|
|
|
|
void doFunctionCallback(const JSFunction *fun,
|
|
|
|
const JSScript *scr,
|
2010-09-20 12:43:51 -07:00
|
|
|
int entering) const
|
2010-08-09 13:38:13 -07:00
|
|
|
{
|
|
|
|
if (functionCallback)
|
|
|
|
functionCallback(fun, scr, this, entering);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-26 17:00:28 -07:00
|
|
|
DSTOffsetCache dstOffsetCache;
|
|
|
|
|
2010-06-03 21:41:01 -07:00
|
|
|
/* List of currently active non-escaping enumerators (for-in). */
|
|
|
|
JSObject *enumerators;
|
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
private:
|
|
|
|
/*
|
|
|
|
* To go from a live generator frame (on the stack) to its generator object
|
|
|
|
* (see comment js_FloatingFrameIfGenerator), we maintain a stack of active
|
|
|
|
* generators, pushing and popping when entering and leaving generator
|
|
|
|
* frames, respectively.
|
|
|
|
*/
|
|
|
|
js::Vector<JSGenerator *, 2, js::SystemAllocPolicy> genStack;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/* Return the generator object for the given generator frame. */
|
2011-04-13 09:27:37 -07:00
|
|
|
JSGenerator *generatorFor(js::StackFrame *fp) const;
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
/* Early OOM-check. */
|
2010-03-03 18:10:13 -08:00
|
|
|
inline bool ensureGeneratorStackSpace();
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
bool enterGenerator(JSGenerator *gen) {
|
|
|
|
return genStack.append(gen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void leaveGenerator(JSGenerator *gen) {
|
|
|
|
JS_ASSERT(genStack.back() == gen);
|
|
|
|
genStack.popBack();
|
|
|
|
}
|
|
|
|
|
2010-04-27 06:46:24 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/*
|
2011-03-31 01:14:12 -07:00
|
|
|
* When non-null JSContext::free_ delegates the job to the background
|
2010-09-07 14:08:20 -07:00
|
|
|
* thread.
|
2010-04-27 06:46:24 -07:00
|
|
|
*/
|
2010-09-07 14:08:20 -07:00
|
|
|
js::GCHelperThread *gcBackgroundFree;
|
2009-07-27 21:10:12 -07:00
|
|
|
#endif
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* malloc_(size_t bytes) {
|
|
|
|
return runtime->malloc_(bytes, this);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
|
|
|
|
2009-09-19 02:40:43 -07:00
|
|
|
inline void* mallocNoReport(size_t bytes) {
|
|
|
|
JS_ASSERT(bytes != 0);
|
2011-03-31 01:14:12 -07:00
|
|
|
return runtime->malloc_(bytes, NULL);
|
2009-09-19 02:40:43 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* calloc_(size_t bytes) {
|
2009-07-27 21:10:12 -07:00
|
|
|
JS_ASSERT(bytes != 0);
|
2011-03-31 01:14:12 -07:00
|
|
|
return runtime->calloc_(bytes, this);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* realloc_(void* p, size_t bytes) {
|
|
|
|
return runtime->realloc_(p, bytes, this);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* realloc_(void* p, size_t oldBytes, size_t newBytes) {
|
|
|
|
return runtime->realloc_(p, oldBytes, newBytes, this);
|
2010-12-08 16:34:38 -08:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void free_(void* p) {
|
2010-04-27 06:46:24 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2010-09-07 14:08:20 -07:00
|
|
|
if (gcBackgroundFree) {
|
|
|
|
gcBackgroundFree->freeLater(p);
|
2009-07-27 21:10:12 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-04-27 06:46:24 -07:00
|
|
|
#endif
|
2011-03-31 01:14:12 -07:00
|
|
|
runtime->free_(p);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
2009-09-01 18:46:19 -07:00
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
JS_DECLARE_NEW_METHODS(malloc_, inline)
|
|
|
|
JS_DECLARE_DELETE_METHODS(free_, inline)
|
2009-10-18 08:40:19 -07:00
|
|
|
|
2010-02-19 09:44:23 -08:00
|
|
|
void purge();
|
|
|
|
|
2010-03-03 18:10:13 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
void assertValidStackDepth(uintN depth) {
|
2011-04-13 09:27:37 -07:00
|
|
|
JS_ASSERT(0 <= regs().sp - fp()->base());
|
|
|
|
JS_ASSERT(depth <= uintptr_t(regs().sp - fp()->base()));
|
2010-03-03 18:10:13 -08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void assertValidStackDepth(uintN /*depth*/) {}
|
|
|
|
#endif
|
2010-07-28 11:20:19 -07:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
bool isExceptionPending() {
|
|
|
|
return throwing;
|
|
|
|
}
|
|
|
|
|
|
|
|
js::Value getPendingException() {
|
|
|
|
JS_ASSERT(throwing);
|
|
|
|
return exception;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPendingException(js::Value v);
|
|
|
|
|
|
|
|
void clearPendingException() {
|
|
|
|
this->throwing = false;
|
|
|
|
this->exception.setUndefined();
|
|
|
|
}
|
|
|
|
|
2010-12-29 16:25:04 -08:00
|
|
|
private:
|
2010-07-28 11:20:19 -07:00
|
|
|
/*
|
|
|
|
* The allocation code calls the function to indicate either OOM failure
|
|
|
|
* when p is null or that a memory pressure counter has reached some
|
|
|
|
* threshold when p is not null. The function takes the pointer and not
|
|
|
|
* a boolean flag to minimize the amount of code in its inlined callers.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void) checkMallocGCPressure(void *p);
|
2010-11-15 19:40:26 -08:00
|
|
|
}; /* struct JSContext */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
namespace js {
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-04-13 09:27:37 -07:00
|
|
|
# define JS_THREAD_ID(cx) ((cx)->thread() ? (cx)->thread()->id : 0)
|
2010-06-04 07:22:28 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined JS_THREADSAFE && defined DEBUG
|
|
|
|
|
|
|
|
class AutoCheckRequestDepth {
|
|
|
|
JSContext *cx;
|
|
|
|
public:
|
2011-04-13 09:27:37 -07:00
|
|
|
AutoCheckRequestDepth(JSContext *cx) : cx(cx) { cx->thread()->checkRequestDepth++; }
|
2010-06-04 07:22:28 -07:00
|
|
|
|
|
|
|
~AutoCheckRequestDepth() {
|
2011-04-13 09:27:37 -07:00
|
|
|
JS_ASSERT(cx->thread()->checkRequestDepth != 0);
|
|
|
|
cx->thread()->checkRequestDepth--;
|
2010-06-04 07:22:28 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-30 11:46:18 -07:00
|
|
|
# define CHECK_REQUEST(cx) \
|
2011-04-13 09:27:37 -07:00
|
|
|
JS_ASSERT((cx)->thread()); \
|
|
|
|
JS_ASSERT((cx)->thread()->data.requestDepth || (cx)->thread() == (cx)->runtime->gcThread); \
|
2010-06-04 07:22:28 -07:00
|
|
|
AutoCheckRequestDepth _autoCheckRequestDepth(cx);
|
|
|
|
|
2010-06-02 00:23:43 -07:00
|
|
|
#else
|
2010-08-30 11:46:18 -07:00
|
|
|
# define CHECK_REQUEST(cx) ((void) 0)
|
|
|
|
# define CHECK_REQUEST_THREAD(cx) ((void) 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2010-03-03 18:10:13 -08:00
|
|
|
static inline uintN
|
2011-04-13 09:27:37 -07:00
|
|
|
FramePCOffset(JSContext *cx, js::StackFrame* fp)
|
2010-03-03 18:10:13 -08:00
|
|
|
{
|
2010-08-09 22:43:33 -07:00
|
|
|
jsbytecode *pc = fp->hasImacropc() ? fp->imacropc() : fp->pc(cx);
|
|
|
|
return uintN(pc - fp->script()->code);
|
2010-03-03 18:10:13 -08:00
|
|
|
}
|
2009-01-23 14:33:42 -08:00
|
|
|
|
|
|
|
static inline JSAtom **
|
2011-04-13 09:27:37 -07:00
|
|
|
FrameAtomBase(JSContext *cx, js::StackFrame *fp)
|
2009-01-23 14:33:42 -08:00
|
|
|
{
|
2010-08-09 22:43:33 -07:00
|
|
|
return fp->hasImacropc()
|
2011-05-17 12:15:12 -07:00
|
|
|
? cx->runtime->atomState.commonAtomsStart()
|
2010-08-09 22:43:33 -07:00
|
|
|
: fp->script()->atomMap.vector;
|
2009-01-23 14:33:42 -08:00
|
|
|
}
|
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
struct AutoResolving {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
|
|
|
LOOKUP,
|
|
|
|
WATCH
|
|
|
|
};
|
|
|
|
|
|
|
|
AutoResolving(JSContext *cx, JSObject *obj, jsid id, Kind kind = LOOKUP
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: context(cx), object(obj), id(id), kind(kind), link(cx->resolvingList)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_ASSERT(obj);
|
|
|
|
cx->resolvingList = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoResolving() {
|
|
|
|
JS_ASSERT(context->resolvingList == this);
|
|
|
|
context->resolvingList = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool alreadyStarted() const {
|
|
|
|
return link && alreadyStartedSlow();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool alreadyStartedSlow() const;
|
|
|
|
|
|
|
|
JSContext *const context;
|
|
|
|
JSObject *const object;
|
|
|
|
jsid const id;
|
|
|
|
Kind const kind;
|
|
|
|
AutoResolving *const link;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
class AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoGCRooter(JSContext *cx, ptrdiff_t tag)
|
|
|
|
: down(cx->autoGCRooters), tag(tag), context(cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(this != cx->autoGCRooters);
|
2010-08-30 11:46:18 -07:00
|
|
|
CHECK_REQUEST(cx);
|
2010-01-11 09:52:21 -08:00
|
|
|
cx->autoGCRooters = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoGCRooter() {
|
|
|
|
JS_ASSERT(this == context->autoGCRooters);
|
2010-08-30 11:46:18 -07:00
|
|
|
CHECK_REQUEST(context);
|
2010-01-11 09:52:21 -08:00
|
|
|
context->autoGCRooters = down;
|
|
|
|
}
|
|
|
|
|
2010-06-16 14:13:01 -07:00
|
|
|
/* Implemented in jsgc.cpp. */
|
2010-01-11 09:52:21 -08:00
|
|
|
inline void trace(JSTracer *trc);
|
|
|
|
|
2010-04-01 09:01:14 -07:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# pragma GCC visibility push(default)
|
|
|
|
#endif
|
2011-01-08 18:55:54 -08:00
|
|
|
friend JS_FRIEND_API(void) MarkContext(JSTracer *trc, JSContext *acx);
|
2010-08-30 11:46:18 -07:00
|
|
|
friend void MarkRuntime(JSTracer *trc);
|
2010-04-01 09:01:14 -07:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# pragma GCC visibility pop
|
|
|
|
#endif
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
AutoGCRooter * const down;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discriminates actual subclass of this being used. If non-negative, the
|
2010-07-14 23:19:36 -07:00
|
|
|
* subclass roots an array of values of the length stored in this field.
|
2010-01-11 09:52:21 -08:00
|
|
|
* If negative, meaning is indicated by the corresponding value in the enum
|
|
|
|
* below. Any other negative value indicates some deeper problem such as
|
|
|
|
* memory corruption.
|
|
|
|
*/
|
|
|
|
ptrdiff_t tag;
|
|
|
|
|
|
|
|
JSContext * const context;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
JSVAL = -1, /* js::AutoValueRooter */
|
2010-08-29 11:57:08 -07:00
|
|
|
SHAPE = -2, /* js::AutoShapeRooter */
|
2010-08-18 12:46:47 -07:00
|
|
|
PARSER = -3, /* js::Parser */
|
|
|
|
SCRIPT = -4, /* js::AutoScriptRooter */
|
|
|
|
ENUMERATOR = -5, /* js::AutoEnumStateRooter */
|
|
|
|
IDARRAY = -6, /* js::AutoIdArray */
|
|
|
|
DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */
|
|
|
|
NAMESPACES = -8, /* js::AutoNamespaceArray */
|
|
|
|
XML = -9, /* js::AutoXMLRooter */
|
|
|
|
OBJECT = -10, /* js::AutoObjectRooter */
|
|
|
|
ID = -11, /* js::AutoIdRooter */
|
|
|
|
VALVECTOR = -12, /* js::AutoValueVector */
|
|
|
|
DESCRIPTOR = -13, /* js::AutoPropertyDescriptorRooter */
|
|
|
|
STRING = -14, /* js::AutoStringRooter */
|
2011-01-05 14:50:30 -08:00
|
|
|
IDVECTOR = -15, /* js::AutoIdVector */
|
2011-02-07 12:06:32 -08:00
|
|
|
BINDINGS = -16, /* js::Bindings */
|
|
|
|
SHAPEVECTOR = -17 /* js::AutoShapeVector */
|
2010-01-11 09:52:21 -08:00
|
|
|
};
|
2010-04-16 14:00:51 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
/* No copy or assignment semantics. */
|
|
|
|
AutoGCRooter(AutoGCRooter &ida);
|
|
|
|
void operator=(AutoGCRooter &ida);
|
2010-01-11 09:52:21 -08:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* FIXME(bug 332648): Move this into a public header. */
|
2010-01-11 09:52:21 -08:00
|
|
|
class AutoValueRooter : private AutoGCRooter
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-07-14 23:19:36 -07:00
|
|
|
explicit AutoValueRooter(JSContext *cx
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-07-14 23:19:36 -07:00
|
|
|
: AutoGCRooter(cx, JSVAL), val(js::NullValue())
|
2010-01-11 09:52:21 -08:00
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-07-14 23:19:36 -07:00
|
|
|
|
|
|
|
AutoValueRooter(JSContext *cx, const Value &v
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-07-14 23:19:36 -07:00
|
|
|
: AutoGCRooter(cx, JSVAL), val(v)
|
2010-01-11 09:52:21 -08:00
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-07-14 23:19:36 -07:00
|
|
|
|
|
|
|
AutoValueRooter(JSContext *cx, jsval v
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-07-14 23:19:36 -07:00
|
|
|
: AutoGCRooter(cx, JSVAL), val(js::Valueify(v))
|
2010-01-11 09:52:21 -08:00
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2009-01-15 17:54:05 -08:00
|
|
|
}
|
2010-01-11 09:52:21 -08:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
/*
|
|
|
|
* If you are looking for Object* overloads, use AutoObjectRooter instead;
|
|
|
|
* rooting Object*s as a js::Value requires discerning whether or not it is
|
|
|
|
* a function object. Also, AutoObjectRooter is smaller.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void set(Value v) {
|
2010-05-25 03:54:55 -07:00
|
|
|
JS_ASSERT(tag == JSVAL);
|
|
|
|
val = v;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
void set(jsval v) {
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(tag == JSVAL);
|
2010-07-14 23:19:36 -07:00
|
|
|
val = js::Valueify(v);
|
2010-01-11 09:52:21 -08:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
const Value &value() const {
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(tag == JSVAL);
|
2010-07-14 23:19:36 -07:00
|
|
|
return val;
|
2010-01-11 09:52:21 -08:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
Value *addr() {
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(tag == JSVAL);
|
2010-07-14 23:19:36 -07:00
|
|
|
return &val;
|
2010-01-11 09:52:21 -08:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
const jsval &jsval_value() const {
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(tag == JSVAL);
|
2010-07-14 23:19:36 -07:00
|
|
|
return Jsvalify(val);
|
2010-01-11 09:52:21 -08:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
jsval *jsval_addr() {
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(tag == JSVAL);
|
2010-07-14 23:19:36 -07:00
|
|
|
return Jsvalify(&val);
|
2010-01-11 09:52:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
2010-08-30 11:46:18 -07:00
|
|
|
friend void MarkRuntime(JSTracer *trc);
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
private:
|
2010-07-14 23:19:36 -07:00
|
|
|
Value val;
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
|
|
|
class AutoObjectRooter : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoObjectRooter(JSContext *cx, JSObject *obj = NULL
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, OBJECT), obj(obj)
|
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2009-10-21 13:27:35 -07:00
|
|
|
}
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
void setObject(JSObject *obj) {
|
|
|
|
this->obj = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject * object() const {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject ** addr() {
|
|
|
|
return &obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
2010-08-30 11:46:18 -07:00
|
|
|
friend void MarkRuntime(JSTracer *trc);
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
JSObject *obj;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
class AutoStringRooter : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoStringRooter(JSContext *cx, JSString *str = NULL
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, STRING), str(str)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setString(JSString *str) {
|
|
|
|
this->str = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString * string() const {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString ** addr() {
|
|
|
|
return &str;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSString *str;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
class AutoArrayRooter : private AutoGCRooter {
|
|
|
|
public:
|
2010-07-14 23:19:36 -07:00
|
|
|
AutoArrayRooter(JSContext *cx, size_t len, Value *vec
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, len), array(vec)
|
|
|
|
{
|
2009-10-21 13:27:35 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(tag >= 0);
|
Bug 480132: Clone lexical blocks only when needed. r=igor
Terminology:
A "script block" is an object of class Block allocated by the byte
compiler and associated with a script. Script blocks are never
modified, and may be used as a prototype for a "closure block":
A "closure block" is an object of class Block that holds variables
that have been closed over (although we actually leave the variables
on the stack until we leave their dynamic scope). A closure block is
a clone of a script block (its prototype is a script block).
Adjust the meanings of fp->blockChain and fp->scopeChain:
fp->blockChain is always the innermost script block in whose static
scope we're executing.
fp->scopeChain is the current scope chain, including 'call' objects
and closure blocks for those function calls and blocks in whose
static scope we are currently executing, and 'with' objects for with
statements; the chain is typically terminated by a global object.
However, as an optimization, the young end of the chain omits block
objects we have not yet needed to clone.
Closures need fully reified scope chains, so have js_GetScopeChain
reify any closure blocks missing from the young end of fp->scopeChain
by cloning script blocks as needed from fp->blockChain. Thus, if we
never actually close over a particular block, we never place a closure
block for it on fp->scopeChain.
Have JSOP_ENTERBLOCK and JSOP_LEAVEBLOCK always keep fp->blockChain
current. When JSOP_LEAVEBLOCK pops a block from fp->blockChain that
has been cloned on fp->scopeChain, pop fp->scopeChain as well.
Remove the JSFRAME_POP_BLOCKS flag, as it is no longer needed.
Ensure that the JIT won't have to create closure blocks or call
js_PutBlockObject; it can't handle those things yet. Note our current
script block when we begin recording. Abort recording if we leave
that block; we can't tell in advance whether it will need to be "put"
in future trace invocations. Leave trace if we call js_GetScopeChain
while in the static scope of lexical blocks. Remove JIT tests based
on JSFRAME_POP_BLOCKS.
Verify that generators capture the correct value for blockChain.
Add a constructor to JSAutoTempValueRooter for rooting JSObject
pointers.
2009-03-16 09:55:06 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
AutoArrayRooter(JSContext *cx, size_t len, jsval *vec
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, len), array(Valueify(vec))
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_ASSERT(tag >= 0);
|
|
|
|
}
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
void changeLength(size_t newLength) {
|
|
|
|
tag = ptrdiff_t(newLength);
|
|
|
|
JS_ASSERT(tag >= 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
void changeArray(Value *newArray, size_t newLength) {
|
2010-01-11 09:52:21 -08:00
|
|
|
changeLength(newLength);
|
|
|
|
array = newArray;
|
|
|
|
}
|
2009-02-11 11:33:17 -08:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
Value *array;
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
class AutoShapeRooter : private AutoGCRooter {
|
2010-01-11 09:52:21 -08:00
|
|
|
public:
|
2010-08-29 11:57:08 -07:00
|
|
|
AutoShapeRooter(JSContext *cx, const js::Shape *shape
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, SHAPE), shape(shape)
|
2010-01-11 09:52:21 -08:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
2010-08-30 11:46:18 -07:00
|
|
|
friend void MarkRuntime(JSTracer *trc);
|
2008-10-13 15:53:33 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2010-08-29 11:57:08 -07:00
|
|
|
const js::Shape * const shape;
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
2008-09-25 09:13:31 -07:00
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
class AutoScriptRooter : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoScriptRooter(JSContext *cx, JSScript *script
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, SCRIPT), script(script)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setScript(JSScript *script) {
|
|
|
|
this->script = script;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSScript *script;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
|
|
|
class AutoIdRooter : private AutoGCRooter
|
2009-02-11 11:33:17 -08:00
|
|
|
{
|
2009-09-19 02:40:43 -07:00
|
|
|
public:
|
2010-01-11 09:52:21 -08:00
|
|
|
explicit AutoIdRooter(JSContext *cx, jsid id = INT_TO_JSID(0)
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-07-14 23:19:36 -07:00
|
|
|
: AutoGCRooter(cx, ID), id_(id)
|
2010-01-11 09:52:21 -08:00
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2009-02-11 11:33:17 -08:00
|
|
|
}
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
jsid id() {
|
2010-07-14 23:19:36 -07:00
|
|
|
return id_;
|
2010-01-11 09:52:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
jsid * addr() {
|
2010-07-14 23:19:36 -07:00
|
|
|
return &id_;
|
2009-02-11 11:33:17 -08:00
|
|
|
}
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
2010-08-30 11:46:18 -07:00
|
|
|
friend void MarkRuntime(JSTracer *trc);
|
2009-02-11 11:33:17 -08:00
|
|
|
|
2009-09-19 02:40:43 -07:00
|
|
|
private:
|
2010-07-14 23:19:36 -07:00
|
|
|
jsid id_;
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2009-02-11 11:33:17 -08:00
|
|
|
};
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
class AutoIdArray : private AutoGCRooter {
|
2009-09-08 15:59:14 -07:00
|
|
|
public:
|
2010-04-11 15:05:07 -07:00
|
|
|
AutoIdArray(JSContext *cx, JSIdArray *ida JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, IDARRAY), idArray(ida)
|
2010-01-11 09:52:21 -08:00
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2009-09-08 15:59:14 -07:00
|
|
|
}
|
2010-01-11 09:52:21 -08:00
|
|
|
~AutoIdArray() {
|
|
|
|
if (idArray)
|
|
|
|
JS_DestroyIdArray(context, idArray);
|
2009-09-08 15:59:14 -07:00
|
|
|
}
|
|
|
|
bool operator!() {
|
|
|
|
return idArray == NULL;
|
|
|
|
}
|
|
|
|
jsid operator[](size_t i) const {
|
|
|
|
JS_ASSERT(idArray);
|
|
|
|
JS_ASSERT(i < size_t(idArray->length));
|
|
|
|
return idArray->vector[i];
|
|
|
|
}
|
|
|
|
size_t length() const {
|
|
|
|
return idArray->length;
|
|
|
|
}
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
JSIdArray *steal() {
|
|
|
|
JSIdArray *copy = idArray;
|
|
|
|
idArray = NULL;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
protected:
|
|
|
|
inline void trace(JSTracer *trc);
|
|
|
|
|
2009-09-08 15:59:14 -07:00
|
|
|
private:
|
2010-05-18 19:21:43 -07:00
|
|
|
JSIdArray * idArray;
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2010-03-04 20:44:09 -08:00
|
|
|
|
|
|
|
/* No copy or assignment semantics. */
|
2010-01-11 09:52:21 -08:00
|
|
|
AutoIdArray(AutoIdArray &ida);
|
|
|
|
void operator=(AutoIdArray &ida);
|
2009-09-08 15:59:14 -07:00
|
|
|
};
|
|
|
|
|
2009-09-19 02:40:43 -07:00
|
|
|
/* The auto-root for enumeration object and its state. */
|
2010-01-11 09:52:21 -08:00
|
|
|
class AutoEnumStateRooter : private AutoGCRooter
|
2009-09-19 02:40:43 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-01-11 09:52:21 -08:00
|
|
|
AutoEnumStateRooter(JSContext *cx, JSObject *obj
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-07-14 23:19:36 -07:00
|
|
|
: AutoGCRooter(cx, ENUMERATOR), obj(obj), stateValue()
|
2009-09-19 02:40:43 -07:00
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2009-09-19 02:40:43 -07:00
|
|
|
JS_ASSERT(obj);
|
|
|
|
}
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
~AutoEnumStateRooter() {
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!stateValue.isNull()) {
|
2011-04-20 16:27:30 -07:00
|
|
|
DebugOnly<JSBool> ok =
|
|
|
|
obj->enumerate(context, JSENUMERATE_DESTROY, &stateValue, 0);
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(ok);
|
|
|
|
}
|
2009-09-19 02:40:43 -07:00
|
|
|
}
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
const Value &state() const { return stateValue; }
|
|
|
|
Value *addr() { return &stateValue; }
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
protected:
|
2010-09-24 10:54:39 -07:00
|
|
|
void trace(JSTracer *trc);
|
2009-09-19 02:40:43 -07:00
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
JSObject * const obj;
|
|
|
|
|
2009-09-19 02:40:43 -07:00
|
|
|
private:
|
2010-07-14 23:19:36 -07:00
|
|
|
Value stateValue;
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2009-09-19 02:40:43 -07:00
|
|
|
};
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
#ifdef JS_HAS_XML_SUPPORT
|
|
|
|
class AutoXMLRooter : private AutoGCRooter {
|
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
AutoXMLRooter(JSContext *cx, JSXML *xml
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-01-11 09:52:21 -08:00
|
|
|
: AutoGCRooter(cx, XML), xml(xml)
|
|
|
|
{
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
2010-08-30 11:46:18 -07:00
|
|
|
friend void MarkRuntime(JSTracer *trc);
|
2010-01-11 09:52:21 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
JSXML * const xml;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2010-01-11 09:52:21 -08:00
|
|
|
};
|
|
|
|
#endif /* JS_HAS_XML_SUPPORT */
|
|
|
|
|
2011-01-05 14:50:30 -08:00
|
|
|
class AutoBindingsRooter : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoBindingsRooter(JSContext *cx, Bindings &bindings
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, BINDINGS), bindings(bindings)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Bindings &bindings;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-04-08 05:54:18 -07:00
|
|
|
class AutoLockGC {
|
2011-01-05 14:50:30 -08:00
|
|
|
public:
|
|
|
|
explicit AutoLockGC(JSRuntime *rt
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: rt(rt)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_LOCK_GC(rt);
|
|
|
|
}
|
2011-01-07 13:03:39 -08:00
|
|
|
~AutoLockGC() { JS_UNLOCK_GC(rt); }
|
2011-01-05 14:50:30 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
JSRuntime *rt;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2010-04-08 05:54:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class AutoUnlockGC {
|
2011-01-05 14:50:30 -08:00
|
|
|
private:
|
2010-04-08 05:54:18 -07:00
|
|
|
JSRuntime *rt;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoUnlockGC(JSRuntime *rt
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: rt(rt)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_UNLOCK_GC(rt);
|
|
|
|
}
|
2010-04-08 05:54:18 -07:00
|
|
|
~AutoUnlockGC() { JS_LOCK_GC(rt); }
|
|
|
|
};
|
|
|
|
|
2011-01-13 14:42:36 -08:00
|
|
|
class AutoLockAtomsCompartment {
|
2010-09-24 10:54:39 -07:00
|
|
|
private:
|
2011-01-05 14:50:30 -08:00
|
|
|
JSContext *cx;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2010-09-24 10:54:39 -07:00
|
|
|
public:
|
2011-01-13 14:42:36 -08:00
|
|
|
AutoLockAtomsCompartment(JSContext *cx
|
2011-05-17 12:15:12 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2011-01-05 14:50:30 -08:00
|
|
|
: cx(cx)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-09-24 10:54:39 -07:00
|
|
|
JS_LOCK(cx, &cx->runtime->atomState.lock);
|
|
|
|
#ifdef JS_THREADSAFE
|
2011-01-13 14:42:36 -08:00
|
|
|
cx->runtime->atomsCompartmentIsLocked = true;
|
2010-09-24 10:54:39 -07:00
|
|
|
#endif
|
|
|
|
}
|
2011-01-13 14:42:36 -08:00
|
|
|
~AutoLockAtomsCompartment() {
|
2010-09-24 10:54:39 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-01-13 14:42:36 -08:00
|
|
|
cx->runtime->atomsCompartmentIsLocked = false;
|
2010-09-24 10:54:39 -07:00
|
|
|
#endif
|
2011-01-05 17:26:31 -08:00
|
|
|
JS_UNLOCK(cx, &cx->runtime->atomState.lock);
|
2010-09-24 10:54:39 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-01-13 14:42:36 -08:00
|
|
|
class AutoUnlockAtomsCompartment {
|
2011-01-05 14:50:30 -08:00
|
|
|
JSContext *cx;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2010-09-24 10:54:39 -07:00
|
|
|
public:
|
2011-01-13 14:42:36 -08:00
|
|
|
AutoUnlockAtomsCompartment(JSContext *cx
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: cx(cx)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-09-24 10:54:39 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-01-13 14:42:36 -08:00
|
|
|
cx->runtime->atomsCompartmentIsLocked = false;
|
2010-09-24 10:54:39 -07:00
|
|
|
#endif
|
2011-01-06 11:30:15 -08:00
|
|
|
JS_UNLOCK(cx, &cx->runtime->atomState.lock);
|
2010-09-24 10:54:39 -07:00
|
|
|
}
|
2011-01-13 14:42:36 -08:00
|
|
|
~AutoUnlockAtomsCompartment() {
|
2011-01-06 11:30:15 -08:00
|
|
|
JS_LOCK(cx, &cx->runtime->atomState.lock);
|
2010-09-24 10:54:39 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-01-13 14:42:36 -08:00
|
|
|
cx->runtime->atomsCompartmentIsLocked = true;
|
2010-09-24 10:54:39 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-04-08 05:54:18 -07:00
|
|
|
class AutoKeepAtoms {
|
|
|
|
JSRuntime *rt;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2010-04-08 05:54:18 -07:00
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
explicit AutoKeepAtoms(JSRuntime *rt
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: rt(rt)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_KEEP_ATOMS(rt);
|
|
|
|
}
|
2010-04-08 05:54:18 -07:00
|
|
|
~AutoKeepAtoms() { JS_UNKEEP_ATOMS(rt); }
|
|
|
|
};
|
|
|
|
|
2010-08-11 13:30:07 -07:00
|
|
|
class AutoArenaAllocator {
|
|
|
|
JSArenaPool *pool;
|
|
|
|
void *mark;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2010-08-11 13:30:07 -07:00
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
explicit AutoArenaAllocator(JSArenaPool *pool
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: pool(pool), mark(JS_ARENA_MARK(pool))
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
2010-08-11 13:30:07 -07:00
|
|
|
~AutoArenaAllocator() { JS_ARENA_RELEASE(pool, mark); }
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T *alloc(size_t elems) {
|
|
|
|
void *ptr;
|
|
|
|
JS_ARENA_ALLOCATE(ptr, pool, elems * sizeof(T));
|
|
|
|
return static_cast<T *>(ptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class AutoReleasePtr {
|
|
|
|
JSContext *cx;
|
|
|
|
void *ptr;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2010-08-11 13:30:07 -07:00
|
|
|
AutoReleasePtr operator=(const AutoReleasePtr &other);
|
2011-01-05 14:50:30 -08:00
|
|
|
|
2010-08-11 13:30:07 -07:00
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
explicit AutoReleasePtr(JSContext *cx, void *ptr
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: cx(cx), ptr(ptr)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
2011-03-31 01:14:12 -07:00
|
|
|
~AutoReleasePtr() { cx->free_(ptr); }
|
2010-08-11 13:30:07 -07:00
|
|
|
};
|
|
|
|
|
2010-10-19 09:00:51 -07:00
|
|
|
/*
|
|
|
|
* FIXME: bug 602774: cleaner API for AutoReleaseNullablePtr
|
|
|
|
*/
|
|
|
|
class AutoReleaseNullablePtr {
|
|
|
|
JSContext *cx;
|
|
|
|
void *ptr;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2010-10-19 09:00:51 -07:00
|
|
|
AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other);
|
2011-01-05 14:50:30 -08:00
|
|
|
|
2010-10-19 09:00:51 -07:00
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
explicit AutoReleaseNullablePtr(JSContext *cx, void *ptr
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: cx(cx), ptr(ptr)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
2010-10-19 09:00:51 -07:00
|
|
|
void reset(void *ptr2) {
|
|
|
|
if (ptr)
|
2011-03-31 01:14:12 -07:00
|
|
|
cx->free_(ptr);
|
2010-10-19 09:00:51 -07:00
|
|
|
ptr = ptr2;
|
|
|
|
}
|
2011-03-31 01:14:12 -07:00
|
|
|
~AutoReleaseNullablePtr() { if (ptr) cx->free_(ptr); }
|
2010-10-19 09:00:51 -07:00
|
|
|
};
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
class AutoLocalNameArray {
|
|
|
|
public:
|
|
|
|
explicit AutoLocalNameArray(JSContext *cx, JSFunction *fun
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: context(cx),
|
|
|
|
mark(JS_ARENA_MARK(&cx->tempPool)),
|
2010-11-16 15:34:24 -08:00
|
|
|
names(fun->script()->bindings.getLocalNameArray(cx, &cx->tempPool)),
|
|
|
|
count(fun->script()->bindings.countLocalNames())
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoLocalNameArray() {
|
|
|
|
JS_ARENA_RELEASE(&context->tempPool, mark);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator bool() const { return !!names; }
|
|
|
|
|
|
|
|
uint32 length() const { return count; }
|
|
|
|
|
|
|
|
const jsuword &operator [](unsigned i) const { return names[i]; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSContext *context;
|
|
|
|
void *mark;
|
|
|
|
jsuword *names;
|
|
|
|
uint32 count;
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2011-01-05 18:44:30 -08:00
|
|
|
template <class RefCountable>
|
2011-01-17 14:58:53 -08:00
|
|
|
class AlreadyIncRefed
|
|
|
|
{
|
|
|
|
typedef RefCountable *****ConvertibleToBool;
|
|
|
|
|
|
|
|
RefCountable *obj;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AlreadyIncRefed(RefCountable *obj) : obj(obj) {}
|
|
|
|
|
|
|
|
bool null() const { return obj == NULL; }
|
|
|
|
operator ConvertibleToBool() const { return (ConvertibleToBool)obj; }
|
|
|
|
|
|
|
|
RefCountable *operator->() const { JS_ASSERT(!null()); return obj; }
|
|
|
|
RefCountable &operator*() const { JS_ASSERT(!null()); return *obj; }
|
|
|
|
RefCountable *get() const { return obj; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class RefCountable>
|
|
|
|
class NeedsIncRef
|
|
|
|
{
|
|
|
|
typedef RefCountable *****ConvertibleToBool;
|
|
|
|
|
|
|
|
RefCountable *obj;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit NeedsIncRef(RefCountable *obj) : obj(obj) {}
|
|
|
|
|
|
|
|
bool null() const { return obj == NULL; }
|
|
|
|
operator ConvertibleToBool() const { return (ConvertibleToBool)obj; }
|
|
|
|
|
|
|
|
RefCountable *operator->() const { JS_ASSERT(!null()); return obj; }
|
|
|
|
RefCountable &operator*() const { JS_ASSERT(!null()); return *obj; }
|
|
|
|
RefCountable *get() const { return obj; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class RefCountable>
|
|
|
|
class AutoRefCount
|
|
|
|
{
|
|
|
|
typedef RefCountable *****ConvertibleToBool;
|
|
|
|
|
|
|
|
JSContext *const cx;
|
|
|
|
RefCountable *obj;
|
|
|
|
|
|
|
|
AutoRefCount(const AutoRefCount &);
|
|
|
|
void operator=(const AutoRefCount &);
|
2011-01-05 18:44:30 -08:00
|
|
|
|
|
|
|
public:
|
2011-01-17 14:58:53 -08:00
|
|
|
explicit AutoRefCount(JSContext *cx)
|
|
|
|
: cx(cx), obj(NULL)
|
|
|
|
{}
|
2011-01-05 18:44:30 -08:00
|
|
|
|
2011-01-17 14:58:53 -08:00
|
|
|
AutoRefCount(JSContext *cx, NeedsIncRef<RefCountable> aobj)
|
|
|
|
: cx(cx), obj(aobj.get())
|
|
|
|
{
|
|
|
|
if (obj)
|
|
|
|
obj->incref(cx);
|
2011-01-05 18:44:30 -08:00
|
|
|
}
|
|
|
|
|
2011-01-17 14:58:53 -08:00
|
|
|
AutoRefCount(JSContext *cx, AlreadyIncRefed<RefCountable> aobj)
|
|
|
|
: cx(cx), obj(aobj.get())
|
|
|
|
{}
|
|
|
|
|
2011-01-05 18:44:30 -08:00
|
|
|
~AutoRefCount() {
|
|
|
|
if (obj)
|
|
|
|
obj->decref(cx);
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:58:53 -08:00
|
|
|
void reset(NeedsIncRef<RefCountable> aobj) {
|
2011-01-05 18:44:30 -08:00
|
|
|
if (obj)
|
|
|
|
obj->decref(cx);
|
2011-01-17 14:58:53 -08:00
|
|
|
obj = aobj.get();
|
2011-01-05 18:44:30 -08:00
|
|
|
if (obj)
|
|
|
|
obj->incref(cx);
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:58:53 -08:00
|
|
|
void reset(AlreadyIncRefed<RefCountable> aobj) {
|
|
|
|
if (obj)
|
|
|
|
obj->decref(cx);
|
|
|
|
obj = aobj.get();
|
2011-01-05 18:44:30 -08:00
|
|
|
}
|
2011-01-17 14:58:53 -08:00
|
|
|
|
|
|
|
bool null() const { return obj == NULL; }
|
|
|
|
operator ConvertibleToBool() const { return (ConvertibleToBool)obj; }
|
|
|
|
|
|
|
|
RefCountable *operator->() const { JS_ASSERT(!null()); return obj; }
|
|
|
|
RefCountable &operator*() const { JS_ASSERT(!null()); return *obj; }
|
|
|
|
RefCountable *get() const { return obj; }
|
2011-01-05 18:44:30 -08:00
|
|
|
};
|
|
|
|
|
2010-03-26 21:53:40 -07:00
|
|
|
} /* namespace js */
|
|
|
|
|
2008-09-25 09:13:31 -07:00
|
|
|
class JSAutoResolveFlags
|
|
|
|
{
|
|
|
|
public:
|
2009-09-27 23:17:47 -07:00
|
|
|
JSAutoResolveFlags(JSContext *cx, uintN flags
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-01-11 09:52:21 -08:00
|
|
|
: mContext(cx), mSaved(cx->resolveFlags)
|
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2008-09-25 09:13:31 -07:00
|
|
|
cx->resolveFlags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSAutoResolveFlags() { mContext->resolveFlags = mSaved; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSContext *mContext;
|
|
|
|
uintN mSaved;
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2008-09-25 09:13:31 -07:00
|
|
|
};
|
2009-01-23 14:33:42 -08:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
extern js::ThreadData *
|
2009-10-27 17:55:34 -07:00
|
|
|
js_CurrentThreadData(JSRuntime *rt);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSBool
|
2009-03-24 05:07:35 -07:00
|
|
|
js_InitThreads(JSRuntime *rt);
|
2009-03-22 02:07:14 -07:00
|
|
|
|
2009-03-24 05:07:35 -07:00
|
|
|
extern void
|
|
|
|
js_FinishThreads(JSRuntime *rt);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_PurgeThreads(JSContext *cx);
|
2008-12-02 13:12:43 -08:00
|
|
|
|
2010-05-13 10:50:43 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
/* Iterator over ThreadData from all JSThread instances. */
|
2010-05-13 10:50:43 -07:00
|
|
|
class ThreadDataIter : public JSThread::Map::Range
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThreadDataIter(JSRuntime *rt) : JSThread::Map::Range(rt->threads.all()) {}
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
ThreadData *threadData() const {
|
2010-05-13 10:50:43 -07:00
|
|
|
return &front().value->data;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#else /* !JS_THREADSAFE */
|
|
|
|
|
|
|
|
class ThreadDataIter
|
|
|
|
{
|
|
|
|
JSRuntime *runtime;
|
|
|
|
bool done;
|
|
|
|
public:
|
|
|
|
ThreadDataIter(JSRuntime *rt) : runtime(rt), done(false) {}
|
|
|
|
|
|
|
|
bool empty() const {
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
void popFront() {
|
|
|
|
JS_ASSERT(!done);
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
ThreadData *threadData() const {
|
2010-05-13 10:50:43 -07:00
|
|
|
JS_ASSERT(!done);
|
|
|
|
return &runtime->threadData;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !JS_THREADSAFE */
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
} /* namespace js */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create and destroy functions for JSContext, which is manually allocated
|
|
|
|
* and exclusively owned.
|
|
|
|
*/
|
|
|
|
extern JSContext *
|
|
|
|
js_NewContext(JSRuntime *rt, size_t stackChunkSize);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_DestroyContext(JSContext *cx, JSDestroyContextMode mode);
|
|
|
|
|
2008-12-18 07:24:34 -08:00
|
|
|
static JS_INLINE JSContext *
|
|
|
|
js_ContextFromLinkField(JSCList *link)
|
|
|
|
{
|
|
|
|
JS_ASSERT(link);
|
|
|
|
return (JSContext *) ((uint8 *) link - offsetof(JSContext, link));
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* If unlocked, acquire and release rt->gcLock around *iterp update; otherwise
|
|
|
|
* the caller must be holding rt->gcLock.
|
|
|
|
*/
|
2009-01-05 16:22:42 -08:00
|
|
|
extern JSContext *
|
2007-03-22 10:30:00 -07:00
|
|
|
js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp);
|
|
|
|
|
2009-02-10 14:07:01 -08:00
|
|
|
/*
|
|
|
|
* Iterate through contexts with active requests. The caller must be holding
|
|
|
|
* rt->gcLock in case of a thread-safe build, or otherwise guarantee that the
|
|
|
|
* context list is not alternated asynchroniously.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSContext *)
|
|
|
|
js_NextActiveContext(JSRuntime *, JSContext *);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Report an exception, which is currently realized as a printf-style format
|
|
|
|
* string and its arguments.
|
|
|
|
*/
|
|
|
|
typedef enum JSErrNum {
|
|
|
|
#define MSG_DEF(name, number, count, exception, format) \
|
|
|
|
name = number,
|
|
|
|
#include "js.msg"
|
|
|
|
#undef MSG_DEF
|
|
|
|
JSErr_Limit
|
|
|
|
} JSErrNum;
|
|
|
|
|
2008-08-19 19:38:24 -07:00
|
|
|
extern JS_FRIEND_API(const JSErrorFormatString *)
|
2007-03-22 10:30:00 -07:00
|
|
|
js_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
|
|
|
|
|
|
|
|
#ifdef va_start
|
|
|
|
extern JSBool
|
|
|
|
js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap);
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
|
|
|
|
void *userRef, const uintN errorNumber,
|
|
|
|
JSBool charArgs, va_list ap);
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
|
|
|
void *userRef, const uintN errorNumber,
|
|
|
|
char **message, JSErrorReport *reportp,
|
2009-11-19 09:23:20 -08:00
|
|
|
bool charArgs, va_list ap);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2010-07-28 11:20:19 -07:00
|
|
|
extern void
|
|
|
|
js_ReportOutOfMemory(JSContext *cx);
|
|
|
|
|
2007-11-22 14:21:18 -08:00
|
|
|
/*
|
|
|
|
* Report that cx->scriptStackQuota is exhausted.
|
|
|
|
*/
|
2010-03-03 17:52:26 -08:00
|
|
|
void
|
2011-04-13 09:27:37 -07:00
|
|
|
js_ReportOutOfScriptQuota(JSContext *maybecx);
|
2007-11-22 14:21:18 -08:00
|
|
|
|
2011-04-26 14:34:09 -07:00
|
|
|
/* JS_CHECK_RECURSION is used outside JS, so JS_FRIEND_API. */
|
|
|
|
JS_FRIEND_API(void)
|
2011-04-13 09:27:37 -07:00
|
|
|
js_ReportOverRecursed(JSContext *maybecx);
|
2007-11-22 14:21:18 -08:00
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
extern JS_FRIEND_API(void)
|
2008-03-12 16:07:47 -07:00
|
|
|
js_ReportAllocationOverflow(JSContext *cx);
|
|
|
|
|
2008-01-31 22:01:17 -08:00
|
|
|
#define JS_CHECK_RECURSION(cx, onerror) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
int stackDummy_; \
|
|
|
|
\
|
2010-09-24 10:54:39 -07:00
|
|
|
if (!JS_CHECK_STACK_SIZE(cx->stackLimit, &stackDummy_)) { \
|
2008-01-31 22:01:17 -08:00
|
|
|
js_ReportOverRecursed(cx); \
|
|
|
|
onerror; \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Report an exception using a previously composed JSErrorReport.
|
|
|
|
* XXXbe remove from "friend" API
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_ReportIsNotDefined(JSContext *cx, const char *name);
|
|
|
|
|
2007-11-12 21:23:22 -08:00
|
|
|
/*
|
|
|
|
* Report an attempt to access the property of a null or undefined value (v).
|
|
|
|
*/
|
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_ReportIsNullOrUndefined(JSContext *cx, intN spindex, const js::Value &v,
|
2007-11-12 21:23:22 -08:00
|
|
|
JSString *fallback);
|
|
|
|
|
2008-08-08 09:02:50 -07:00
|
|
|
extern void
|
2010-07-14 23:19:36 -07:00
|
|
|
js_ReportMissingArg(JSContext *cx, const js::Value &v, uintN arg);
|
2008-08-08 09:02:50 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Report error using js_DecompileValueGenerator(cx, spindex, v, fallback) as
|
|
|
|
* the first argument for the error message. If the error message has less
|
|
|
|
* then 3 arguments, use null for arg1 or arg2.
|
|
|
|
*/
|
|
|
|
extern JSBool
|
|
|
|
js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber,
|
2010-07-14 23:19:36 -07:00
|
|
|
intN spindex, const js::Value &v, JSString *fallback,
|
2007-03-22 10:30:00 -07:00
|
|
|
const char *arg1, const char *arg2);
|
|
|
|
|
|
|
|
#define js_ReportValueError(cx,errorNumber,spindex,v,fallback) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
|
|
|
spindex, v, fallback, NULL, NULL))
|
|
|
|
|
|
|
|
#define js_ReportValueError2(cx,errorNumber,spindex,v,fallback,arg1) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
|
|
|
spindex, v, fallback, arg1, NULL))
|
|
|
|
|
|
|
|
#define js_ReportValueError3(cx,errorNumber,spindex,v,fallback,arg1,arg2) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
|
|
|
spindex, v, fallback, arg1, arg2))
|
|
|
|
|
|
|
|
extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
|
|
|
|
|
2010-07-23 09:32:50 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-04-13 09:27:37 -07:00
|
|
|
# define JS_ASSERT_REQUEST_DEPTH(cx) (JS_ASSERT((cx)->thread()), \
|
|
|
|
JS_ASSERT((cx)->thread()->data.requestDepth >= 1))
|
2010-07-23 09:32:50 -07:00
|
|
|
#else
|
|
|
|
# define JS_ASSERT_REQUEST_DEPTH(cx) ((void) 0)
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2009-02-10 14:07:01 -08:00
|
|
|
* If the operation callback flag was set, call the operation callback.
|
2008-01-03 01:28:40 -08:00
|
|
|
* This macro can run the full GC. Return true if it is OK to continue and
|
|
|
|
* false otherwise.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-07-22 13:59:59 -07:00
|
|
|
#define JS_CHECK_OPERATION_LIMIT(cx) \
|
2010-07-23 09:32:50 -07:00
|
|
|
(JS_ASSERT_REQUEST_DEPTH(cx), \
|
2010-10-22 10:48:06 -07:00
|
|
|
(!JS_THREAD_DATA(cx)->interruptFlags || js_InvokeOperationCallback(cx)))
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2009-02-10 14:07:01 -08:00
|
|
|
* Invoke the operation callback and return false if the current execution
|
|
|
|
* is to be terminated.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
extern JSBool
|
2009-02-10 14:07:01 -08:00
|
|
|
js_InvokeOperationCallback(JSContext *cx);
|
2009-01-14 09:23:51 -08:00
|
|
|
|
2010-06-07 23:55:13 -07:00
|
|
|
extern JSBool
|
|
|
|
js_HandleExecutionInterrupt(JSContext *cx);
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
namespace js {
|
2010-07-29 13:23:33 -07:00
|
|
|
|
2010-10-22 10:48:06 -07:00
|
|
|
/* These must be called with GC lock taken. */
|
|
|
|
|
2010-10-22 11:42:34 -07:00
|
|
|
JS_FRIEND_API(void)
|
2010-10-22 10:48:06 -07:00
|
|
|
TriggerOperationCallback(JSContext *cx);
|
|
|
|
|
2010-09-01 11:24:45 -07:00
|
|
|
void
|
2010-09-07 14:08:20 -07:00
|
|
|
TriggerAllOperationCallbacks(JSRuntime *rt);
|
|
|
|
|
|
|
|
} /* namespace js */
|
2010-07-28 11:20:19 -07:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
extern js::StackFrame *
|
|
|
|
js_GetScriptedCaller(JSContext *cx, js::StackFrame *fp);
|
2009-02-18 10:47:16 -08:00
|
|
|
|
2009-03-20 17:07:30 -07:00
|
|
|
extern jsbytecode*
|
|
|
|
js_GetCurrentBytecodePC(JSContext* cx);
|
|
|
|
|
2009-08-20 12:13:21 -07:00
|
|
|
extern bool
|
|
|
|
js_CurrentPCIsInImacro(JSContext *cx);
|
|
|
|
|
2010-01-22 14:49:18 -08:00
|
|
|
namespace js {
|
|
|
|
|
2010-09-13 15:53:50 -07:00
|
|
|
class RegExpStatics;
|
|
|
|
|
2010-12-22 12:02:25 -08:00
|
|
|
extern JS_FORCES_STACK JS_FRIEND_API(void)
|
|
|
|
LeaveTrace(JSContext *cx);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
2010-01-22 14:49:18 -08:00
|
|
|
|
2008-12-09 08:38:32 -08:00
|
|
|
/*
|
2010-08-22 16:00:20 -07:00
|
|
|
* Get the current frame, first lazily instantiating stack frames if needed.
|
|
|
|
* (Do not access cx->fp() directly except in JS_REQUIRES_STACK code.)
|
2008-12-09 08:38:32 -08:00
|
|
|
*
|
|
|
|
* Defined in jstracer.cpp if JS_TRACER is defined.
|
|
|
|
*/
|
2011-04-13 09:27:37 -07:00
|
|
|
static JS_FORCES_STACK JS_INLINE js::StackFrame *
|
2009-02-18 10:47:16 -08:00
|
|
|
js_GetTopStackFrame(JSContext *cx)
|
|
|
|
{
|
2010-01-22 14:49:18 -08:00
|
|
|
js::LeaveTrace(cx);
|
2010-08-22 16:00:20 -07:00
|
|
|
return cx->maybefp();
|
2009-02-18 10:47:16 -08:00
|
|
|
}
|
2008-12-09 08:38:32 -08:00
|
|
|
|
2009-09-18 06:55:01 -07:00
|
|
|
static JS_INLINE JSBool
|
|
|
|
js_IsPropertyCacheDisabled(JSContext *cx)
|
|
|
|
{
|
2010-03-24 19:20:44 -07:00
|
|
|
return cx->runtime->shapeGen >= js::SHAPE_OVERFLOW_BIT;
|
2009-09-18 06:55:01 -07:00
|
|
|
}
|
|
|
|
|
2009-04-20 03:10:29 -07:00
|
|
|
static JS_INLINE uint32
|
2011-02-04 10:59:07 -08:00
|
|
|
js_RegenerateShapeForGC(JSRuntime *rt)
|
2009-04-20 03:10:29 -07:00
|
|
|
{
|
2011-02-04 10:59:07 -08:00
|
|
|
JS_ASSERT(rt->gcRunning);
|
|
|
|
JS_ASSERT(rt->gcRegenShapes);
|
2009-04-20 03:10:29 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Under the GC, compared with js_GenerateShape, we don't need to use
|
|
|
|
* atomic increments but we still must make sure that after an overflow
|
|
|
|
* the shape stays such.
|
|
|
|
*/
|
2011-02-04 10:59:07 -08:00
|
|
|
uint32 shape = rt->shapeGen;
|
2010-03-24 19:20:44 -07:00
|
|
|
shape = (shape + 1) | (shape & js::SHAPE_OVERFLOW_BIT);
|
2011-02-04 10:59:07 -08:00
|
|
|
rt->shapeGen = shape;
|
2009-04-20 03:10:29 -07:00
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
2009-10-20 15:08:28 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
template<class T>
|
|
|
|
class AutoVectorRooter : protected AutoGCRooter
|
2010-03-01 14:46:15 -08:00
|
|
|
{
|
|
|
|
public:
|
2011-02-07 12:06:32 -08:00
|
|
|
explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, tag), vector(cx)
|
2010-03-01 14:46:15 -08:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t length() const { return vector.length(); }
|
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
bool append(const T &v) { return vector.append(v); }
|
2010-03-01 14:46:15 -08:00
|
|
|
|
2011-02-18 18:32:29 -08:00
|
|
|
/* For use when space has already been reserved. */
|
|
|
|
void infallibleAppend(const T &v) { vector.infallibleAppend(v); }
|
|
|
|
|
2010-05-07 17:52:52 -07:00
|
|
|
void popBack() { vector.popBack(); }
|
2011-03-23 16:34:53 -07:00
|
|
|
T popCopy() { return vector.popCopy(); }
|
2010-03-01 14:46:15 -08:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
bool growBy(size_t inc) {
|
2010-08-09 11:56:38 -07:00
|
|
|
size_t oldLength = vector.length();
|
|
|
|
if (!vector.growByUninitialized(inc))
|
|
|
|
return false;
|
2011-02-07 12:06:32 -08:00
|
|
|
MakeRangeGCSafe(vector.begin() + oldLength, vector.end());
|
2010-08-09 11:56:38 -07:00
|
|
|
return true;
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2010-03-01 14:46:15 -08:00
|
|
|
bool resize(size_t newLength) {
|
2010-08-09 11:56:38 -07:00
|
|
|
size_t oldLength = vector.length();
|
2010-08-09 12:02:26 -07:00
|
|
|
if (newLength <= oldLength) {
|
2010-08-09 11:56:38 -07:00
|
|
|
vector.shrinkBy(oldLength - newLength);
|
2010-08-09 12:02:26 -07:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-09 11:56:38 -07:00
|
|
|
if (!vector.growByUninitialized(newLength - oldLength))
|
|
|
|
return false;
|
2011-02-07 12:06:32 -08:00
|
|
|
MakeRangeGCSafe(vector.begin() + oldLength, vector.end());
|
2010-08-09 11:56:38 -07:00
|
|
|
return true;
|
2010-03-01 14:46:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool reserve(size_t newLength) {
|
|
|
|
return vector.reserve(newLength);
|
|
|
|
}
|
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
T &operator[](size_t i) { return vector[i]; }
|
|
|
|
const T &operator[](size_t i) const { return vector[i]; }
|
2010-05-07 17:52:52 -07:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
const T *begin() const { return vector.begin(); }
|
|
|
|
T *begin() { return vector.begin(); }
|
2010-07-26 19:49:27 -07:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
const T *end() const { return vector.end(); }
|
|
|
|
T *end() { return vector.end(); }
|
2010-07-26 19:49:27 -07:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
const T &back() const { return vector.back(); }
|
2010-03-01 14:46:15 -08:00
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
2010-09-07 14:08:20 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
private:
|
2011-03-30 03:10:12 -07:00
|
|
|
typedef Vector<T, 8> VectorImpl;
|
|
|
|
VectorImpl vector;
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
class AutoValueVector : public AutoVectorRooter<Value>
|
2010-07-14 23:19:36 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-02-07 12:06:32 -08:00
|
|
|
explicit AutoValueVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<Value>(cx, VALVECTOR)
|
2010-07-14 23:19:36 -07:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
const jsval *jsval_begin() const { return Jsvalify(begin()); }
|
|
|
|
jsval *jsval_begin() { return Jsvalify(begin()); }
|
2010-07-14 23:19:36 -07:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
const jsval *jsval_end() const { return Jsvalify(end()); }
|
|
|
|
jsval *jsval_end() { return Jsvalify(end()); }
|
2010-07-14 23:19:36 -07:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
2010-07-14 23:19:36 -07:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
class AutoIdVector : public AutoVectorRooter<jsid>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoIdVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<jsid>(cx, IDVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
2010-03-01 14:46:15 -08:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
class AutoShapeVector : public AutoVectorRooter<const Shape *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoShapeVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<const Shape *>(cx, SHAPEVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2010-03-01 14:46:15 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2011-03-31 19:55:10 -07:00
|
|
|
JSIdArray *
|
|
|
|
NewIdArray(JSContext *cx, jsint length);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
|
|
|
|
2010-03-04 20:44:09 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* jscntxt_h___ */
|