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>
|
|
|
|
|
2011-10-11 10:38:26 -07:00
|
|
|
#include "jsfriendapi.h"
|
2010-07-26 21:52:00 -07:00
|
|
|
#include "jsprvtd.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsatom.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "jsclist.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsdhash.h"
|
|
|
|
#include "jsgc.h"
|
2010-06-07 02:17:15 -07:00
|
|
|
#include "jsgcchunk.h"
|
2010-03-24 14:16:01 -07:00
|
|
|
#include "jspropertycache.h"
|
2010-03-22 11:11:44 -07:00
|
|
|
#include "jspropertytree.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsutil.h"
|
2010-05-26 17:00:28 -07:00
|
|
|
#include "prmjtime.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
#include "ds/LifoAlloc.h"
|
2011-08-23 17:35:09 -07:00
|
|
|
#include "gc/Statistics.h"
|
2011-10-04 15:33:00 -07:00
|
|
|
#include "js/HashTable.h"
|
|
|
|
#include "js/Vector.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "vm/StackSpace.h"
|
2011-04-13 09:27:37 -07:00
|
|
|
|
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
|
|
|
|
|
2011-06-09 01:12:21 -07:00
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
struct DtoaState;
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
struct JSSharpObjectMap {
|
|
|
|
jsrefcount depth;
|
|
|
|
uint32 sharpgen;
|
|
|
|
JSHashTable *table;
|
|
|
|
};
|
|
|
|
|
2010-01-22 14:49:18 -08:00
|
|
|
namespace js {
|
2009-10-28 16:44:44 -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-06-14 19:21:47 -07:00
|
|
|
class WeakMapBase;
|
2011-11-22 14:41:43 -08:00
|
|
|
class InterpreterFrames;
|
2011-06-14 19:21:47 -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;
|
2009-01-27 16:40:40 -08:00
|
|
|
|
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-07-25 04:04:02 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
inline GSNCache *
|
|
|
|
GetGSNCache(JSContext *cx);
|
|
|
|
|
|
|
|
struct PendingProxyOperation {
|
|
|
|
PendingProxyOperation *next;
|
|
|
|
JSObject *object;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ThreadData {
|
2011-11-15 14:33:54 -08:00
|
|
|
JSRuntime *rt;
|
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
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;
|
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
/* Temporary arena pool used while compiling and decompiling. */
|
|
|
|
static const size_t TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE = 1 << 12;
|
|
|
|
LifoAlloc tempLifoAlloc;
|
|
|
|
|
2011-11-07 13:42:31 -08:00
|
|
|
private:
|
2011-11-15 14:33:54 -08:00
|
|
|
/*
|
|
|
|
* Both of these allocators are used for regular expression code which is shared at the
|
|
|
|
* thread-data level.
|
|
|
|
*/
|
|
|
|
JSC::ExecutableAllocator *execAlloc;
|
|
|
|
WTF::BumpPointerAllocator *bumpAlloc;
|
|
|
|
js::RegExpPrivateCache *repCache;
|
2011-11-07 13:42:31 -08:00
|
|
|
|
2011-11-15 14:33:54 -08:00
|
|
|
JSC::ExecutableAllocator *createExecutableAllocator(JSContext *cx);
|
|
|
|
WTF::BumpPointerAllocator *createBumpPointerAllocator(JSContext *cx);
|
|
|
|
js::RegExpPrivateCache *createRegExpPrivateCache(JSContext *cx);
|
2011-11-07 13:42:31 -08:00
|
|
|
|
|
|
|
public:
|
2011-11-15 14:33:54 -08:00
|
|
|
JSC::ExecutableAllocator *getOrCreateExecutableAllocator(JSContext *cx) {
|
|
|
|
if (execAlloc)
|
|
|
|
return execAlloc;
|
|
|
|
|
|
|
|
return createExecutableAllocator(cx);
|
|
|
|
}
|
2011-11-07 13:42:31 -08:00
|
|
|
|
2011-11-15 14:33:54 -08:00
|
|
|
WTF::BumpPointerAllocator *getOrCreateBumpPointerAllocator(JSContext *cx) {
|
|
|
|
if (bumpAlloc)
|
|
|
|
return bumpAlloc;
|
|
|
|
|
|
|
|
return createBumpPointerAllocator(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
js::RegExpPrivateCache *getRegExpPrivateCache() {
|
|
|
|
return repCache;
|
|
|
|
}
|
|
|
|
js::RegExpPrivateCache *getOrCreateRegExpPrivateCache(JSContext *cx) {
|
2011-11-07 13:42:31 -08:00
|
|
|
if (repCache)
|
|
|
|
return repCache;
|
|
|
|
|
2011-11-15 14:33:54 -08:00
|
|
|
return createRegExpPrivateCache(cx);
|
2011-11-07 13:42:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called at the end of the global GC sweep phase to deallocate repCache memory. */
|
2011-11-15 14:33:54 -08:00
|
|
|
void purgeRegExpPrivateCache();
|
2011-11-07 13:42:31 -08:00
|
|
|
|
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
|
|
|
|
2011-06-09 01:12:21 -07:00
|
|
|
/* State used by jsdtoa.cpp. */
|
2010-03-22 16:21:10 -07:00
|
|
|
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;
|
|
|
|
|
2011-08-09 01:51:59 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
size_t noGCOrAllocationCheck;
|
|
|
|
#endif
|
|
|
|
|
2011-11-15 14:33:54 -08:00
|
|
|
ThreadData(JSRuntime *rt);
|
2011-03-13 07:45:02 -07:00
|
|
|
~ThreadData();
|
2010-06-04 07:22:28 -07:00
|
|
|
|
2010-03-22 16:21:10 -07:00
|
|
|
bool init();
|
2011-07-25 04:04:02 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
void mark(JSTracer *trc) {
|
|
|
|
stackSpace.mark(trc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void purge(JSContext *cx) {
|
2011-09-22 13:22:30 -07:00
|
|
|
tempLifoAlloc.freeUnused();
|
2011-03-13 07:45:02 -07:00
|
|
|
gsnCache.purge();
|
|
|
|
|
|
|
|
/* FIXME: bug 506341. */
|
|
|
|
propertyCache.purge(cx);
|
|
|
|
}
|
2010-07-22 13:59:59 -07:00
|
|
|
|
2011-12-01 19:08:20 -08:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
void sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, size_t *normal, size_t *temporary,
|
|
|
|
size_t *regexpCode, size_t *stackCommitted);
|
|
|
|
#endif
|
|
|
|
|
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);
|
2011-08-23 12:44:03 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Frames currently running in js::Interpret. See InterpreterFrames for
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
InterpreterFrames *interpreterFrames;
|
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
|
|
|
|
2011-12-01 19:08:20 -08:00
|
|
|
/* Number of JS_SuspendRequest calls without JS_ResumeRequest. */
|
2010-08-30 11:46:18 -07:00
|
|
|
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;
|
|
|
|
|
2011-11-15 14:33:54 -08:00
|
|
|
JSThread(JSRuntime *rt, void *id)
|
2011-03-13 07:45:02 -07:00
|
|
|
: id(id),
|
2011-11-15 14:33:54 -08:00
|
|
|
suspendCount(0),
|
2011-03-13 07:45:02 -07:00
|
|
|
# ifdef DEBUG
|
2011-11-15 14:33:54 -08:00
|
|
|
checkRequestDepth(0),
|
2011-07-25 04:04:02 -07:00
|
|
|
# endif
|
2011-11-15 14:33:54 -08:00
|
|
|
data(rt)
|
2011-03-13 07:45:02 -07:00
|
|
|
{
|
|
|
|
JS_INIT_CLIST(&contextList);
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSThread() {
|
|
|
|
/* The thread must have zero contexts. */
|
|
|
|
JS_ASSERT(JS_CLIST_IS_EMPTY(&contextList));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool init() {
|
|
|
|
return data.init();
|
|
|
|
}
|
2011-12-01 19:08:20 -08:00
|
|
|
|
|
|
|
JS_FRIEND_API(void) sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf, size_t *normal,
|
|
|
|
size_t *temporary, size_t *regexpCode,
|
|
|
|
size_t *stackCommitted);
|
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 *
|
2011-05-27 10:58:26 -07:00
|
|
|
js_CurrentThreadAndLockGC(JSRuntime *rt);
|
2009-10-27 17:55:34 -07:00
|
|
|
|
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
|
2011-05-27 10:58:26 -07:00
|
|
|
js_InitContextThreadAndLockGC(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 */
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-01 14:11:31 -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;
|
|
|
|
|
2011-07-01 14:11:31 -07:00
|
|
|
/* See comment for JS_AbortIfWrongThread in jsapi.h. */
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
public:
|
|
|
|
void clearOwnerThread();
|
|
|
|
void setOwnerThread();
|
|
|
|
JS_FRIEND_API(bool) onOwnerThread() const;
|
|
|
|
private:
|
|
|
|
void *ownerThread_;
|
|
|
|
public:
|
|
|
|
#else
|
|
|
|
public:
|
|
|
|
bool onOwnerThread() const { return true; }
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* 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;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Garbage collector state, used by jsgc.c. */
|
2011-07-26 00:55:23 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set of all GC chunks with at least one allocated thing. The
|
|
|
|
* conservative GC uses it to quickly check if a possible GC thing points
|
|
|
|
* into an allocated chunk.
|
|
|
|
*/
|
|
|
|
js::GCChunkSet gcChunkSet;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Doubly-linked lists of chunks from user and system compartments. The GC
|
|
|
|
* allocates its arenas from the corresponding list and when all arenas
|
|
|
|
* in the list head are taken, then the chunk is removed from the list.
|
|
|
|
* During the GC when all arenas in a chunk become free, that chunk is
|
|
|
|
* removed from the list and scheduled for release.
|
|
|
|
*/
|
|
|
|
js::gc::Chunk *gcSystemAvailableChunkListHead;
|
|
|
|
js::gc::Chunk *gcUserAvailableChunkListHead;
|
2011-09-23 07:14:26 -07:00
|
|
|
js::gc::ChunkPool gcChunkPool;
|
2010-08-05 05:16:56 -07:00
|
|
|
|
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;
|
2008-09-12 15:11:48 -07:00
|
|
|
uint32 gcEmptyArenaPoolLifespan;
|
2011-11-07 13:47:14 -08:00
|
|
|
/* We access this without the GC lock, however a race will not affect correctness */
|
|
|
|
volatile uint32 gcNumFreeArenas;
|
2007-03-22 10:30:00 -07:00
|
|
|
uint32 gcNumber;
|
2011-10-25 16:07:42 -07:00
|
|
|
js::GCMarker *gcIncrementalTracer;
|
2011-08-05 10:25:23 -07:00
|
|
|
void *gcVerifyData;
|
2011-06-20 14:44:26 -07:00
|
|
|
bool gcChunkAllocationSinceLastGC;
|
|
|
|
int64 gcNextFullGCTime;
|
2010-12-17 16:33:04 -08:00
|
|
|
int64 gcJitReleaseTime;
|
2011-01-09 22:57:21 -08:00
|
|
|
JSGCMode gcMode;
|
2011-10-25 16:07:42 -07:00
|
|
|
volatile jsuword gcBarrierFailed;
|
2011-08-18 00:16:08 -07:00
|
|
|
volatile jsuword gcIsNeeded;
|
2011-06-14 19:21:47 -07:00
|
|
|
js::WeakMapBase *gcWeakMapList;
|
2011-08-23 17:35:09 -07:00
|
|
|
js::gcstats::Statistics gcStats;
|
|
|
|
|
|
|
|
/* The reason that an interrupt-triggered GC should be called. */
|
|
|
|
js::gcstats::Reason gcTriggerReason;
|
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 *)];
|
2011-05-27 15:17:47 -07:00
|
|
|
void *gcMarkStackRopes[js::ROPES_MARK_STACK_SIZE / sizeof(void *)];
|
2011-08-26 09:50:48 -07:00
|
|
|
void *gcMarkStackTypes[js::TYPE_MARK_STACK_SIZE / sizeof(void *)];
|
2011-04-21 13:44:29 -07:00
|
|
|
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
|
|
|
|
2011-07-07 17:31:24 -07:00
|
|
|
/*
|
|
|
|
* If this is non-NULL, all marked objects must belong to this compartment.
|
|
|
|
* This is used to look for compartment bugs.
|
|
|
|
*/
|
|
|
|
JSCompartment *gcCheckCompartment;
|
|
|
|
|
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;
|
2009-07-27 14:29:02 -07:00
|
|
|
|
2011-06-01 17:48:52 -07:00
|
|
|
/*
|
|
|
|
* These options control the zealousness of the GC. The fundamental values
|
|
|
|
* are gcNextScheduled and gcDebugCompartmentGC. At every allocation,
|
|
|
|
* gcNextScheduled is decremented. When it reaches zero, we do either a
|
|
|
|
* full or a compartmental GC, based on gcDebugCompartmentGC.
|
|
|
|
*
|
|
|
|
* At this point, if gcZeal_ >= 2 then gcNextScheduled is reset to the
|
|
|
|
* value of gcZealFrequency. Otherwise, no additional GCs take place.
|
|
|
|
*
|
|
|
|
* You can control these values in several ways:
|
|
|
|
* - Pass the -Z flag to the shell (see the usage info for details)
|
|
|
|
* - Call gczeal() or schedulegc() from inside shell-executed JS code
|
|
|
|
* (see the help for details)
|
|
|
|
*
|
|
|
|
* Additionally, if gzZeal_ == 1 then we perform GCs in select places
|
|
|
|
* (during MaybeGC and whenever a GC poke happens). This option is mainly
|
|
|
|
* useful to embedders.
|
2011-08-05 10:25:23 -07:00
|
|
|
*
|
|
|
|
* We use gcZeal_ == 4 to enable write barrier verification. See the comment
|
|
|
|
* in jsgc.cpp for more information about this.
|
2011-06-01 17:48:52 -07:00
|
|
|
*/
|
2007-11-13 02:44:08 -08:00
|
|
|
#ifdef JS_GC_ZEAL
|
2011-06-01 17:48:52 -07:00
|
|
|
int gcZeal_;
|
|
|
|
int gcZealFrequency;
|
|
|
|
int gcNextScheduled;
|
|
|
|
bool gcDebugCompartmentGC;
|
|
|
|
|
|
|
|
int gcZeal() { return gcZeal_; }
|
|
|
|
|
|
|
|
bool needZealousGC() {
|
|
|
|
if (gcNextScheduled > 0 && --gcNextScheduled == 0) {
|
2011-08-05 10:25:23 -07:00
|
|
|
if (gcZeal() >= js::gc::ZealAllocThreshold && gcZeal() < js::gc::ZealVerifierThreshold)
|
2011-06-01 17:48:52 -07:00
|
|
|
gcNextScheduled = gcZealFrequency;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int gcZeal() { return 0; }
|
|
|
|
bool needZealousGC() { return false; }
|
2007-05-15 16:27:20 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSGCCallback gcCallback;
|
2011-11-09 13:32:17 -08:00
|
|
|
JSGCFinishedCallback gcFinishedCallback;
|
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:
|
2007-05-01 03:09:46 -07:00
|
|
|
/*
|
2011-10-10 10:25:46 -07:00
|
|
|
* The trace operations to trace embedding-specific GC roots. One is for
|
|
|
|
* tracing through black roots and the other is for tracing through gray
|
|
|
|
* roots. The black/gray distinction is only relevant to the cycle
|
|
|
|
* collector.
|
2007-05-01 03:09:46 -07:00
|
|
|
*/
|
2011-10-10 10:25:46 -07:00
|
|
|
JSTraceDataOp gcBlackRootsTraceOp;
|
|
|
|
void *gcBlackRootsData;
|
|
|
|
JSTraceDataOp gcGrayRootsTraceOp;
|
|
|
|
void *gcGrayRootsData;
|
2007-05-01 03:09:46 -07:00
|
|
|
|
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
|
|
|
|
2011-08-14 21:12:48 -07:00
|
|
|
JSAtom *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
|
|
|
|
2011-07-22 08:54:36 -07:00
|
|
|
/* If true, new compartments are initially in debug mode. */
|
Automatically turn debug mode on/off when adding/removing debuggees.
This allows most of the tests to run without the -d command-line flag.
Now a compartment is in debug mode if
* JSD1 wants debug mode on, thanks to a JS_SetDebugMode* call; OR
* JSD2 wants debug mode on, because a live Debug object has a debuggee
global in that compartment.
Since this patch only adds the second half of the rule, JSD1 should be
unaffected.
The new rule has three issues:
1. When removeDebuggee is called, it can cause debug mode to be turned
off for a compartment. If any scripts from that compartment are on
the stack, and the methodjit is enabled, returning to those stack
frames will crash.
2. When a Debug object is GC'd, it can cause debug mode to be turned off
for one or more compartments. This causes the same problem with
returning to deleted methodjit code, but the fix is different: such
Debug objects simply should not be GC'd.
3. Setting .enabled to false still does not turn off debug mode
anywhere, so it does not reduce overhead as much as it should.
A possible fix for issue #1 would be to make such removeDebuggee calls
throw; a different possibility is to turn off debug mode but leave all
the scripts alone, accepting the performance loss (as we do for JSD1 in
JSCompartment::setDebugModeFromC). The fix to issues #2 and #3 is to
tweak the rule--and to tweak the rule for Debug object GC-reachability.
--HG--
rename : js/src/jit-test/tests/debug/Debug-ctor.js => js/src/jit-test/tests/debug/Debug-ctor-01.js
2011-06-02 19:58:46 -07:00
|
|
|
bool debugMode;
|
2010-10-30 09:13:02 -07:00
|
|
|
|
2011-05-18 12:34:17 -07:00
|
|
|
/* Had an out-of-memory error which did not populate an exception. */
|
|
|
|
JSBool hadOutOfMemory;
|
|
|
|
|
2011-05-20 22:40:33 -07:00
|
|
|
/*
|
2011-07-05 05:48:26 -07:00
|
|
|
* Linked list of all js::Debugger objects. This may be accessed by the GC
|
2011-05-20 22:40:33 -07:00
|
|
|
* thread, if any, or a thread that is in a request and holds gcLock.
|
|
|
|
*/
|
|
|
|
JSCList debuggerList;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
2011-08-03 17:43:39 -07:00
|
|
|
* Mapping from NSPR thread identifiers to JSThreads.
|
|
|
|
*
|
|
|
|
* This map can be accessed by the GC thread; or by the thread that holds
|
|
|
|
* gcLock, if GC is not running.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-05-13 10:50:43 -07:00
|
|
|
JSThread::Map threads;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* JS_THREADSAFE */
|
2011-08-03 17:43:39 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
|
2011-10-11 10:38:26 -07:00
|
|
|
/* Call this to accumulate telemetry data. */
|
|
|
|
JSAccumulateTelemetryDataCallback telemetryCallback;
|
|
|
|
|
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
|
|
|
|
|
2011-06-30 09:26:56 -07:00
|
|
|
private:
|
|
|
|
JSPrincipals *trustedPrincipals_;
|
|
|
|
public:
|
|
|
|
void setTrustedPrincipals(JSPrincipals *p) { trustedPrincipals_ = p; }
|
|
|
|
JSPrincipals *trustedPrincipals() const { return trustedPrincipals_; }
|
|
|
|
|
2007-08-07 00:29:32 -07:00
|
|
|
/* Literal table maintained by jsatom.c functions. */
|
|
|
|
JSAtomState atomState;
|
|
|
|
|
2011-09-20 14:47:14 -07:00
|
|
|
/* Tables of strings that are pre-allocated in the atomsCompartment. */
|
|
|
|
js::StaticStrings staticStrings;
|
|
|
|
|
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-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.
|
|
|
|
*/
|
2011-05-22 11:50:08 -07:00
|
|
|
int32 inOOMReport;
|
2011-05-17 11:23:31 -07:00
|
|
|
|
2009-10-20 15:08:28 -07:00
|
|
|
JSRuntime();
|
|
|
|
~JSRuntime();
|
|
|
|
|
|
|
|
bool init(uint32 maxbytes);
|
|
|
|
|
2011-08-23 17:35:09 -07:00
|
|
|
JSRuntime *thisFromCtor() { return this; }
|
|
|
|
|
2011-06-20 14:44:26 -07:00
|
|
|
void setGCLastBytes(size_t lastBytes, JSGCInvocationKind gckind);
|
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
|
|
|
#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
|
|
|
|
OptionsSameVersionFlags(uint32 self, uint32 other)
|
|
|
|
{
|
2011-06-21 09:53:19 -07:00
|
|
|
static const uint32 mask = JSOPTION_XML;
|
2010-09-13 09:38:22 -07:00
|
|
|
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 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-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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-06-21 09:53:19 -07:00
|
|
|
uintN copts = VersionHasXML(version) ? JSOPTION_XML : 0;
|
2011-01-27 02:54:58 -08:00
|
|
|
JS_ASSERT((copts & JSCOMPILEOPTION_MASK) == copts);
|
|
|
|
return copts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSVersion
|
|
|
|
OptionFlagsToVersion(uintN options, JSVersion version)
|
|
|
|
{
|
|
|
|
VersionSetXML(&version, OptionsHasXML(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_* */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
2011-03-29 10:25:20 -07:00
|
|
|
int32 reportGranularity; /* see jsprobes.h */
|
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
/* 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-01 17:26:34 -07:00
|
|
|
inline void setCompartment(JSCompartment *compartment);
|
|
|
|
|
2011-09-28 09:17:51 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
private:
|
|
|
|
JSThread *thread_;
|
|
|
|
public:
|
|
|
|
JSThread *thread() const { return thread_; }
|
|
|
|
|
|
|
|
void setThread(JSThread *thread);
|
|
|
|
static const size_t threadOffset() { return offsetof(JSContext, thread_); }
|
|
|
|
#endif
|
|
|
|
|
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 */
|
2011-10-04 07:06:54 -07:00
|
|
|
inline bool hasfp() const;
|
|
|
|
inline js::StackFrame* fp() const;
|
|
|
|
inline js::StackFrame* maybefp() const;
|
|
|
|
inline js::FrameRegs& regs() const;
|
|
|
|
inline js::FrameRegs* maybeRegs() const;
|
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
|
|
|
|
2011-06-24 14:22:30 -07:00
|
|
|
private:
|
|
|
|
/* Lazily initialized pool of maps used during parse/emit. */
|
|
|
|
js::ParseMapPool *parseMapPool_;
|
|
|
|
|
|
|
|
public:
|
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;
|
|
|
|
|
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
|
|
|
|
2010-09-13 15:53:50 -07:00
|
|
|
inline js::RegExpStatics *regExpStatics();
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
2011-06-24 14:22:30 -07:00
|
|
|
js::ParseMapPool &parseMapPool() {
|
|
|
|
JS_ASSERT(parseMapPool_);
|
|
|
|
return *parseMapPool_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool ensureParseMapPool();
|
|
|
|
|
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.
|
|
|
|
*/
|
2011-10-04 07:06:54 -07:00
|
|
|
inline bool canSetDefaultVersion() const;
|
2010-09-13 09:38:22 -07:00
|
|
|
|
|
|
|
/* Force a version for future script compilation. */
|
2011-10-04 07:06:54 -07:00
|
|
|
inline void overrideVersion(JSVersion newVersion);
|
2010-09-13 09:38:22 -07:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2011-10-04 07:06:54 -07:00
|
|
|
inline bool maybeOverrideVersion(JSVersion newVersion);
|
2010-09-13 09:38:22 -07:00
|
|
|
|
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-05-13 08:56:26 -07:00
|
|
|
JS_ASSERT(stack.empty());
|
|
|
|
if (JS_UNLIKELY(isVersionOverridden())) {
|
|
|
|
defaultVersion = versionOverride;
|
|
|
|
clearVersionOverride();
|
|
|
|
}
|
2011-01-27 02:54:58 -08:00
|
|
|
}
|
|
|
|
|
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.
|
2011-09-06 22:50:26 -07:00
|
|
|
* - The default version.
|
2010-09-13 09:38:22 -07:00
|
|
|
*
|
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
|
|
|
*/
|
2011-10-04 07:06:54 -07:00
|
|
|
inline JSVersion findVersion() const;
|
2010-09-13 09:38:22 -07:00
|
|
|
|
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. */
|
2011-10-04 07:06:54 -07:00
|
|
|
inline void setCompileOptions(uintN newcopts);
|
2010-11-15 13:35:20 -08:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
uintN getRunOptions() const { return runOptions; }
|
2011-10-04 07:06:54 -07:00
|
|
|
inline uintN getCompileOptions() const;
|
|
|
|
inline uintN allOptions() const;
|
2011-01-27 02:54:58 -08:00
|
|
|
|
|
|
|
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); }
|
2011-11-08 13:28:49 -08:00
|
|
|
bool hasJITHardeningOption() const { return !hasRunOption(JSOPTION_SOFTEN); }
|
2011-01-27 02:54:58 -08:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
js::LifoAlloc &tempLifoAlloc() { return JS_THREAD_DATA(this)->tempLifoAlloc; }
|
|
|
|
inline js::LifoAlloc &typeLifoAlloc();
|
2011-04-13 09:27:37 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
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 */
|
|
|
|
#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;
|
|
|
|
|
2011-07-19 09:00:43 -07:00
|
|
|
/* Location to stash the iteration value between JSOP_MOREITER and JSOP_ITERNEXT. */
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value iterValue;
|
2010-05-07 17:52:52 -07:00
|
|
|
|
2010-09-15 22:27:17 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
bool methodJitEnabled;
|
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
|
|
|
|
2011-04-01 17:26:34 -07:00
|
|
|
bool inferenceEnabled;
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
bool typeInferenceEnabled() { return inferenceEnabled; }
|
|
|
|
|
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-11-07 13:42:31 -08:00
|
|
|
js::ThreadData *threadData() { return JS_THREAD_DATA(this); }
|
|
|
|
|
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();
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
/* For DEBUG. */
|
|
|
|
inline void assertValidStackDepth(uintN depth);
|
2010-07-28 11:20:19 -07:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
bool isExceptionPending() {
|
|
|
|
return throwing;
|
|
|
|
}
|
2010-11-15 19:40:26 -08:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
js::Value getPendingException() {
|
|
|
|
JS_ASSERT(throwing);
|
|
|
|
return exception;
|
|
|
|
}
|
2010-07-28 11:20:19 -07:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
void setPendingException(js::Value v);
|
|
|
|
|
|
|
|
void clearPendingException() {
|
|
|
|
this->throwing = false;
|
|
|
|
this->exception.setUndefined();
|
|
|
|
}
|
|
|
|
|
2011-06-24 14:22:30 -07:00
|
|
|
/*
|
|
|
|
* Count of currently active compilations.
|
|
|
|
* When there are compilations active for the context, the GC must not
|
|
|
|
* purge the ParseMapPool.
|
|
|
|
*/
|
|
|
|
uintN activeCompilations;
|
|
|
|
|
2011-06-14 18:39:53 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Controls whether a quadratic-complexity assertion is performed during
|
|
|
|
* stack iteration, defaults to true.
|
|
|
|
*/
|
|
|
|
bool stackIterAssertionEnabled;
|
|
|
|
#endif
|
|
|
|
|
2011-07-07 15:40:33 -07:00
|
|
|
/*
|
|
|
|
* See JS_SetTrustedPrincipals in jsapi.h.
|
|
|
|
* Note: !cx->compartment is treated as trusted.
|
|
|
|
*/
|
|
|
|
bool runningWithTrustedPrincipals() const;
|
|
|
|
|
2011-12-01 19:08:20 -08:00
|
|
|
JS_FRIEND_API(size_t) sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf) const;
|
|
|
|
|
2011-08-23 12:42:17 -07:00
|
|
|
static inline JSContext *fromLinkField(JSCList *link) {
|
|
|
|
JS_ASSERT(link);
|
|
|
|
return reinterpret_cast<JSContext *>(uintptr_t(link) - offsetof(JSContext, link));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
static inline JSContext *fromThreadLinks(JSCList *link) {
|
|
|
|
JS_ASSERT(link);
|
|
|
|
return reinterpret_cast<JSContext *>(uintptr_t(link) - offsetof(JSContext, threadLinks));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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); \
|
2011-07-01 14:11:31 -07:00
|
|
|
JS_ASSERT(cx->runtime->onOwnerThread()); \
|
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)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
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);
|
2011-11-18 14:59:04 -08:00
|
|
|
void traceAll(JSTracer *trc);
|
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 */
|
2011-08-09 01:51:59 -07:00
|
|
|
VALARRAY = -2, /* js::AutoValueArrayRooter */
|
2010-08-18 12:46:47 -07:00
|
|
|
PARSER = -3, /* js::Parser */
|
2011-08-09 01:51:59 -07:00
|
|
|
SHAPEVECTOR = -4, /* js::AutoShapeVector */
|
2010-08-18 12:46:47 -07:00
|
|
|
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-09-05 09:05:45 -07:00
|
|
|
OBJVECTOR = -16 /* js::AutoObjectVector */
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
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);
|
2011-09-20 11:40:24 -07:00
|
|
|
return 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);
|
2011-09-20 11:40:24 -07:00
|
|
|
return &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-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
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
~AutoEnumStateRooter();
|
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 */
|
|
|
|
|
2010-04-08 05:54:18 -07:00
|
|
|
class AutoLockGC {
|
2011-01-05 14:50:30 -08:00
|
|
|
public:
|
2011-08-18 00:16:08 -07:00
|
|
|
explicit AutoLockGC(JSRuntime *rt = NULL
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2011-08-18 00:16:08 -07:00
|
|
|
: runtime(rt)
|
2011-01-05 14:50:30 -08:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2011-08-18 00:16:08 -07:00
|
|
|
if (rt)
|
|
|
|
JS_LOCK_GC(rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool locked() const {
|
|
|
|
return !!runtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lock(JSRuntime *rt) {
|
|
|
|
JS_ASSERT(rt);
|
|
|
|
JS_ASSERT(!runtime);
|
|
|
|
runtime = rt;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_LOCK_GC(rt);
|
|
|
|
}
|
2011-08-18 00:16:08 -07:00
|
|
|
|
|
|
|
~AutoLockGC() {
|
|
|
|
if (runtime)
|
|
|
|
JS_UNLOCK_GC(runtime);
|
|
|
|
}
|
2011-01-05 14:50:30 -08:00
|
|
|
|
|
|
|
private:
|
2011-08-18 00:16:08 -07:00
|
|
|
JSRuntime *runtime;
|
2011-01-05 14:50:30 -08:00
|
|
|
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() {
|
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
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 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-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
|
|
|
|
2011-11-07 13:42:31 -08:00
|
|
|
extern void
|
|
|
|
js_PurgeThreads_PostGlobalSweep(JSContext *cx);
|
|
|
|
|
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 */
|
|
|
|
|
2011-08-23 12:42:17 -07:00
|
|
|
/*
|
|
|
|
* Enumerate all contexts in a runtime that are in the same thread as a given
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
class ThreadContextRange {
|
|
|
|
JSCList *begin;
|
|
|
|
JSCList *end;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ThreadContextRange(JSContext *cx) {
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
end = &cx->thread()->contextList;
|
|
|
|
#else
|
|
|
|
end = &cx->runtime->contextList;
|
|
|
|
#endif
|
|
|
|
begin = end->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const { return begin == end; }
|
|
|
|
void popFront() { JS_ASSERT(!empty()); begin = begin->next; }
|
|
|
|
|
|
|
|
JSContext *front() const {
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
return JSContext::fromThreadLinks(begin);
|
|
|
|
#else
|
|
|
|
return JSContext::fromLinkField(begin);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
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-06-05 22:39:45 -07:00
|
|
|
/*
|
|
|
|
* Get the topmost scripted frame in a context. Note: if the topmost frame is
|
|
|
|
* in the middle of an inline call, that call will be expanded. To avoid this,
|
|
|
|
* use cx->stack.currentScript or cx->stack.currentScriptedScopeChain.
|
|
|
|
*/
|
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);
|
|
|
|
|
2010-09-20 12:43:53 -07:00
|
|
|
extern JSScript *
|
|
|
|
js_GetCurrentScript(JSContext* cx);
|
|
|
|
|
2010-01-22 14:49:18 -08:00
|
|
|
namespace js {
|
|
|
|
|
2011-03-26 19:07:13 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
namespace mjit {
|
2011-08-01 09:09:39 -07:00
|
|
|
void ExpandInlineFrames(JSCompartment *compartment);
|
2011-03-26 19:07:13 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
2010-01-22 14:49:18 -08:00
|
|
|
|
2011-08-01 09:09:39 -07:00
|
|
|
/* How much expansion of inlined frames to do when inspecting the stack. */
|
|
|
|
enum FrameExpandKind {
|
|
|
|
FRAME_EXPAND_NONE = 0,
|
|
|
|
FRAME_EXPAND_ALL = 1
|
|
|
|
};
|
|
|
|
|
2009-10-20 15:08:28 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(Value *vec, size_t len)
|
|
|
|
{
|
|
|
|
PodZero(vec, len);
|
|
|
|
}
|
2011-03-26 19:07:13 -07:00
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(Value *beg, Value *end)
|
|
|
|
{
|
|
|
|
PodZero(beg, end - beg);
|
2009-02-18 10:47:16 -08:00
|
|
|
}
|
2008-12-09 08:38:32 -08:00
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(jsid *beg, jsid *end)
|
|
|
|
{
|
|
|
|
for (jsid *id = beg; id != end; ++id)
|
|
|
|
*id = INT_TO_JSID(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(jsid *vec, size_t len)
|
|
|
|
{
|
|
|
|
MakeRangeGCSafe(vec, vec + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(const Shape **beg, const Shape **end)
|
|
|
|
{
|
|
|
|
PodZero(beg, end - beg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(const Shape **vec, size_t len)
|
|
|
|
{
|
|
|
|
PodZero(vec, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToUndefined(Value *beg, Value *end)
|
|
|
|
{
|
|
|
|
for (Value *v = beg; v != end; ++v)
|
|
|
|
v->setUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToUndefined(Value *vec, size_t len)
|
|
|
|
{
|
|
|
|
SetValueRangeToUndefined(vec, vec + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToNull(Value *beg, Value *end)
|
|
|
|
{
|
|
|
|
for (Value *v = beg; v != end; ++v)
|
|
|
|
v->setNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToNull(Value *vec, size_t len)
|
|
|
|
{
|
|
|
|
SetValueRangeToNull(vec, vec + len);
|
|
|
|
}
|
2009-10-20 15:08:28 -07:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-06-16 11:22:37 -07:00
|
|
|
void clear() { vector.clear(); }
|
|
|
|
|
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-03-01 14:46:15 -08:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
const T *begin() const { return vector.begin(); }
|
|
|
|
T *begin() { return vector.begin(); }
|
2010-05-07 17:52:52 -07:00
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
const T *end() const { return vector.end(); }
|
|
|
|
T *end() { return vector.end(); }
|
2010-05-07 17:52:52 -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-09-20 11:40:24 -07:00
|
|
|
const jsval *jsval_begin() const { return begin(); }
|
|
|
|
jsval *jsval_begin() { return begin(); }
|
2010-07-14 23:19:36 -07:00
|
|
|
|
2011-09-20 11:40:24 -07:00
|
|
|
const jsval *jsval_end() const { return end(); }
|
|
|
|
jsval *jsval_end() { return 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-08-23 12:45:21 -07:00
|
|
|
class AutoObjectVector : public AutoVectorRooter<JSObject *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoObjectVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<JSObject *>(cx, OBJVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
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-04-24 07:56:56 -07:00
|
|
|
class AutoValueArray : public AutoGCRooter
|
|
|
|
{
|
2011-10-25 16:07:42 -07:00
|
|
|
const js::Value *start_;
|
2011-04-24 07:56:56 -07:00
|
|
|
unsigned length_;
|
|
|
|
|
|
|
|
public:
|
2011-10-25 16:07:42 -07:00
|
|
|
AutoValueArray(JSContext *cx, const js::Value *start, unsigned length
|
2011-04-24 07:56:56 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, VALARRAY), start_(start), length_(length)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
const Value *start() const { return start_; }
|
2011-04-24 07:56:56 -07:00
|
|
|
unsigned length() const { return length_; }
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2011-06-17 10:14:30 -07:00
|
|
|
/*
|
|
|
|
* Allocation policy that uses JSRuntime::malloc_ and friends, so that
|
|
|
|
* memory pressure is properly accounted for. This is suitable for
|
|
|
|
* long-lived objects owned by the JSRuntime.
|
|
|
|
*
|
|
|
|
* Since it doesn't hold a JSContext (those may not live long enough), it
|
|
|
|
* can't report out-of-memory conditions itself; the caller must check for
|
|
|
|
* OOM and take the appropriate action.
|
|
|
|
*
|
|
|
|
* FIXME bug 647103 - replace these *AllocPolicy names.
|
|
|
|
*/
|
|
|
|
class RuntimeAllocPolicy
|
|
|
|
{
|
|
|
|
JSRuntime *const runtime;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RuntimeAllocPolicy(JSRuntime *rt) : runtime(rt) {}
|
|
|
|
RuntimeAllocPolicy(JSContext *cx) : runtime(cx->runtime) {}
|
|
|
|
void *malloc_(size_t bytes) { return runtime->malloc_(bytes); }
|
|
|
|
void *realloc_(void *p, size_t bytes) { return runtime->realloc_(p, bytes); }
|
|
|
|
void free_(void *p) { runtime->free_(p); }
|
|
|
|
void reportAllocOverflow() const {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME bug 647103 - replace these *AllocPolicy names.
|
|
|
|
*/
|
|
|
|
class ContextAllocPolicy
|
|
|
|
{
|
|
|
|
JSContext *const cx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ContextAllocPolicy(JSContext *cx) : cx(cx) {}
|
|
|
|
JSContext *context() const { return cx; }
|
|
|
|
void *malloc_(size_t bytes) { return cx->malloc_(bytes); }
|
|
|
|
void *realloc_(void *p, size_t oldBytes, size_t bytes) { return cx->realloc_(p, oldBytes, bytes); }
|
|
|
|
void free_(void *p) { cx->free_(p); }
|
|
|
|
void reportAllocOverflow() const { js_ReportAllocationOverflow(cx); }
|
|
|
|
};
|
|
|
|
|
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___ */
|