1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=78:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla Communicator client code, released
20 * The Initial Developer of the Original Code is
21 * Netscape Communications Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 1998
23 * the Initial Developer. All Rights Reserved.
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
44 * JS execution context.
46 #include "jsarena.h" /* Added by JSIFY */
50 #include "jsversion.h"
64 * js_GetSrcNote cache to avoid O(n^2) growth in finding a source note for a
65 * given pc in a script. We use the script->code pointer to tag the cache,
66 * instead of the script address itself, so that source notes are always found
67 * by offset from the bytecode with which they were generated.
69 typedef struct JSGSNCache
{
77 # define GSN_CACHE_METER(cache,cnt) (++(cache)->cnt)
79 # define GSN_CACHE_METER(cache,cnt) /* nothing */
83 #define js_FinishGSNCache(cache) js_PurgeGSNCache(cache)
86 js_PurgeGSNCache(JSGSNCache
*cache
);
88 /* These helper macros take a cx as parameter and operate on its GSN cache. */
89 #define JS_PURGE_GSN_CACHE(cx) js_PurgeGSNCache(&JS_GSN_CACHE(cx))
90 #define JS_METER_GSN_CACHE(cx,cnt) GSN_CACHE_METER(&JS_GSN_CACHE(cx), cnt)
92 typedef struct InterpState InterpState
;
93 typedef struct VMSideExit VMSideExit
;
102 extern "C++" { template<typename T
> class Queue
; }
103 typedef Queue
<uint16
> SlotList
;
107 # define CLS(T) void*
110 #define FRAGMENT_TABLE_SIZE 512
113 #define MONITOR_N_GLOBAL_STATES 4
117 CLS(SlotList
) globalSlots
;
121 * Trace monitor. Every JSThread (if JS_THREADSAFE) or JSRuntime (if not
122 * JS_THREADSAFE) has an associated trace monitor that keeps track of loop
123 * frequencies for all JavaScript code loaded into that runtime.
125 struct JSTraceMonitor
{
127 * The context currently executing JIT-compiled code on this thread, or
128 * NULL if none. Among other things, this can in certain cases prevent
129 * last-ditch GC and suppress calls to JS_ReportOutOfMemory.
131 * !tracecx && !recorder: not on trace
132 * !tracecx && !recorder && prohibitFlush: deep-bailed
133 * !tracecx && recorder && !recorder->deepAborted: recording
134 * !tracecx && recorder && recorder->deepAborted: deep aborted
135 * tracecx && !recorder: executing a trace
136 * tracecx && recorder: executing inner loop, recording outer loop
140 CLS(nanojit::LirBuffer
) lirbuf
;
141 CLS(nanojit::Fragmento
) fragmento
;
142 CLS(TraceRecorder
) recorder
;
143 jsval
*reservedDoublePool
;
144 jsval
*reservedDoublePoolPtr
;
146 struct GlobalState globalStates
[MONITOR_N_GLOBAL_STATES
];
147 struct VMFragment
* vmfragments
[FRAGMENT_TABLE_SIZE
];
148 JSDHashTable recordAttempts
;
151 * Maximum size of the code cache before we start flushing. 1/16 of this
152 * size is used as threshold for the regular expression code cache.
154 uint32 maxCodeCacheBytes
;
157 * If nonzero, do not flush the JIT cache after a deep bail. That would
158 * free JITted code pages that we will later return to. Instead, set the
159 * needFlush flag so that it can be flushed later.
161 * NB: needFlush and useReservedObjects are packed together.
164 JSPackedBool needFlush
;
167 * reservedObjects is a linked list (via fslots[0]) of preallocated JSObjects.
168 * The JIT uses this to ensure that leaving a trace tree can't fail.
170 JSPackedBool useReservedObjects
;
171 JSObject
*reservedObjects
;
173 /* Fragmento for the regular expression compiler. This is logically
174 * a distinct compiler but needs to be managed in exactly the same
175 * way as the real tracing Fragmento. */
176 CLS(nanojit::LirBuffer
) reLirBuf
;
177 CLS(nanojit::Fragmento
) reFragmento
;
179 /* Keep a list of recorders we need to abort on cache flush. */
180 CLS(TraceRecorder
) abortStack
;
183 typedef struct InterpStruct InterpStruct
;
186 * N.B. JS_ON_TRACE(cx) is true if JIT code is on the stack in the current
187 * thread, regardless of whether cx is the context in which that trace is
188 * executing. cx must be a context on the current thread.
191 # define JS_ON_TRACE(cx) (JS_TRACE_MONITOR(cx).tracecx != NULL)
193 # define JS_ON_TRACE(cx) JS_FALSE
197 # define JS_EVAL_CACHE_METERING 1
198 # define JS_FUNCTION_METERING 1
201 /* Number of potentially reusable scriptsToGC to search for the eval cache. */
202 #ifndef JS_EVAL_CACHE_SHIFT
203 # define JS_EVAL_CACHE_SHIFT 6
205 #define JS_EVAL_CACHE_SIZE JS_BIT(JS_EVAL_CACHE_SHIFT)
207 #ifdef JS_EVAL_CACHE_METERING
208 # define EVAL_CACHE_METER_LIST(_) _(probe), _(hit), _(step), _(noscope)
209 # define identity(x) x
211 struct JSEvalCacheMeter
{
212 uint64
EVAL_CACHE_METER_LIST(identity
);
218 #ifdef JS_FUNCTION_METERING
219 # define FUNCTION_KIND_METER_LIST(_) \
220 _(allfun), _(heavy), _(nofreeupvar), _(onlyfreevar), \
221 _(display), _(flat), _(setupvar), _(badfunarg)
222 # define identity(x) x
224 typedef struct JSFunctionMeter
{
225 int32
FUNCTION_KIND_METER_LIST(identity
);
231 struct JSThreadData
{
233 * The GSN cache is per thread since even multi-cx-per-thread embeddings
234 * do not interleave js_GetSrcNote calls.
238 /* Property cache for faster call/get/set invocation. */
239 JSPropertyCache propertyCache
;
242 /* Trace-tree JIT recorder/interpreter state. */
243 JSTraceMonitor traceMonitor
;
246 /* Lock-free hashed lists of scripts created by eval to garbage-collect. */
247 JSScript
*scriptsToGC
[JS_EVAL_CACHE_SIZE
];
249 #ifdef JS_EVAL_CACHE_METERING
250 JSEvalCacheMeter evalCacheMeter
;
254 * Thread-local version of JSRuntime.gcMallocBytes to avoid taking
255 * locks on each JS_malloc.
257 size_t gcMallocBytes
;
263 * Structure uniquely representing a thread. It holds thread-private data
264 * that can be accessed without a global lock.
267 /* Linked list of all contexts in use on this thread. */
270 /* Opaque thread-id, from NSPR's PR_GetCurrentThread(). */
273 /* Indicates that the thread is waiting in ClaimTitle from jslock.cpp. */
274 JSTitle
*titleToShare
;
276 /* Factored out of JSThread for !JS_THREADSAFE embedding in JSRuntime. */
280 #define JS_THREAD_DATA(cx) (&(cx)->thread->data)
282 struct JSThreadsHashEntry
{
283 JSDHashEntryHdr base
;
288 * The function takes the GC lock and does not release in successful return.
289 * On error (out of memory) the function releases the lock but delegates
290 * the error reporting to the caller.
293 js_InitContextThread(JSContext
*cx
);
296 * On entrance the GC lock must be held and it will be held on exit.
299 js_ClearContextThread(JSContext
*cx
);
301 #endif /* JS_THREADSAFE */
303 typedef enum JSDestroyContextMode
{
308 } JSDestroyContextMode
;
310 typedef enum JSRuntimeState
{
317 typedef enum JSBuiltinFunctionId
{
318 JSBUILTIN_ObjectToIterator
,
319 JSBUILTIN_CallIteratorNext
,
320 JSBUILTIN_GetProperty
,
321 JSBUILTIN_GetElement
,
322 JSBUILTIN_SetProperty
,
323 JSBUILTIN_SetElement
,
324 JSBUILTIN_HasInstance
,
326 } JSBuiltinFunctionId
;
328 typedef struct JSPropertyTreeEntry
{
330 JSScopeProperty
*child
;
331 } JSPropertyTreeEntry
;
333 typedef struct JSSetSlotRequest JSSetSlotRequest
;
335 struct JSSetSlotRequest
{
336 JSObject
*obj
; /* object containing slot to set */
337 JSObject
*pobj
; /* new proto or parent reference */
338 uint16 slot
; /* which to set, proto or parent */
339 JSPackedBool cycle
; /* true if a cycle was detected */
340 JSSetSlotRequest
*next
; /* next request in GC worklist */
344 /* Runtime state, synchronized by the stateChange/gcLock condvar/lock. */
345 JSRuntimeState state
;
347 /* Context create/destroy callback. */
348 JSContextCallback cxCallback
;
351 * Shape regenerated whenever a prototype implicated by an "add property"
352 * property cache fill and induced trace guard has a readonly property or a
353 * setter defined on it. This number proxies for the shapes of all objects
354 * along the prototype chain of all objects in the runtime on which such an
355 * add-property result has been cached/traced.
357 * See bug 492355 for more details.
359 * This comes early in JSRuntime to minimize the immediate format used by
360 * trace-JITted code that reads it.
362 uint32 protoHazardShape
;
364 /* Garbage collector state, used by jsgc.c. */
365 JSGCChunkInfo
*gcChunkList
;
366 JSGCArenaList gcArenaList
[GC_NUM_FREELISTS
];
367 JSGCDoubleArenaList gcDoubleArenaList
;
368 JSGCFreeListSet
*gcFreeListsPool
;
369 JSDHashTable gcRootsHash
;
370 JSDHashTable
*gcLocksHash
;
371 jsrefcount gcKeepAtoms
;
375 size_t gcMaxMallocBytes
;
376 uint32 gcEmptyArenaPoolLifespan
;
379 JSTracer
*gcMarkingTracer
;
380 uint32 gcTriggerFactor
;
381 size_t gcTriggerBytes
;
382 volatile JSBool gcIsNeeded
;
385 * NB: do not pack another flag here by claiming gcPadding unless the new
386 * flag is written only by the GC thread. Atomic updates to packed bytes
387 * are not guaranteed, so stores issued by one thread may be lost due to
388 * unsynchronized read-modify-write cycles on other threads.
391 JSPackedBool gcRunning
;
392 JSPackedBool gcRegenShapes
;
398 JSGCCallback gcCallback
;
399 size_t gcMallocBytes
;
400 JSGCArenaInfo
*gcUntracedArenaStackTop
;
402 size_t gcTraceLaterCount
;
406 * Table for tracking iterators to ensure that we close iterator's state
407 * before finalizing the iterable object.
409 JSPtrTable gcIteratorTable
;
412 * The trace operation and its data argument to trace embedding-specific
415 JSTraceDataOp gcExtraRootsTraceOp
;
416 void *gcExtraRootsData
;
419 * Used to serialize cycle checks when setting __proto__ or __parent__ by
420 * requesting the GC handle the required cycle detection. If the GC hasn't
421 * been poked, it won't scan for garbage. This member is protected by
424 JSSetSlotRequest
*setSlotRequests
;
426 /* Random number generator state, used by jsmath.c. */
427 JSBool rngInitialized
;
434 /* Well-known numbers held for use by this runtime's contexts. */
436 jsdouble
*jsNegativeInfinity
;
437 jsdouble
*jsPositiveInfinity
;
440 JSLock
*deflatedStringCacheLock
;
442 JSHashTable
*deflatedStringCache
;
444 uint32 deflatedStringCacheBytes
;
448 * Empty and unit-length strings held for use by this runtime's contexts.
449 * The unitStrings array and its elements are created on demand.
451 JSString
*emptyString
;
452 JSString
**unitStrings
;
455 * Builtin functions, lazily created and held for use by the trace recorder.
457 * This field would be #ifdef JS_TRACER, but XPConnect is compiled without
458 * -DJS_TRACER and includes this header.
460 JSObject
*builtinFunctions
[JSBUILTIN_LIMIT
];
462 /* List of active contexts sharing this runtime; protected by gcLock. */
465 /* Per runtime debug hooks -- see jsprvtd.h and jsdbgapi.h. */
466 JSDebugHooks globalDebugHooks
;
468 /* More debugging state, see jsdbgapi.c. */
470 JSCList watchPointList
;
472 /* Client opaque pointers */
476 /* These combine to interlock the GC and new requests. */
479 PRCondVar
*requestDone
;
483 /* Lock and owning thread pointer for JS_LOCK_RUNTIME. */
489 /* Used to synchronize down/up state change; protected by gcLock. */
490 PRCondVar
*stateChange
;
493 * State for sharing single-threaded titles, once a second thread tries to
494 * lock a title. The titleSharingDone condvar is protected by rt->gcLock
495 * to minimize number of locks taken in JS_EndRequest.
497 * The titleSharingTodo linked list is likewise "global" per runtime, not
498 * one-list-per-context, to conserve space over all contexts, optimizing
499 * for the likely case that titles become shared rarely, and among a very
500 * small set of threads (contexts).
502 PRCondVar
*titleSharingDone
;
503 JSTitle
*titleSharingTodo
;
506 * Magic terminator for the rt->titleSharingTodo linked list, threaded through
507 * title->u.link. This hack allows us to test whether a title is on the list
508 * by asking whether title->u.link is non-null. We use a large, likely bogus
509 * pointer here to distinguish this value from any valid u.count (small int)
512 #define NO_TITLE_SHARING_TODO ((JSTitle *) 0xfeedbeef)
515 * Lock serializing trapList and watchPointList accesses, and count of all
516 * mutations to trapList and watchPointList made by debugger threads. To
517 * keep the code simple, we define debuggerMutations for the thread-unsafe
520 PRLock
*debuggerLock
;
522 JSDHashTable threads
;
523 #endif /* JS_THREADSAFE */
524 uint32 debuggerMutations
;
527 * Security callbacks set on the runtime are used by each context unless
528 * an override is set on the context.
530 JSSecurityCallbacks
*securityCallbacks
;
533 * Shared scope property tree, and arena-pool for allocating its nodes.
534 * The propertyRemovals counter is incremented for every JSScope::clear,
535 * and for each JSScope::remove method call that frees a slot in an object.
536 * See js_NativeGet and js_NativeSet in jsobj.c.
538 JSDHashTable propertyTreeHash
;
539 JSScopeProperty
*propertyFreeList
;
540 JSArenaPool propertyArenaPool
;
541 int32 propertyRemovals
;
543 /* Script filename table. */
544 struct JSHashTable
*scriptFilenameTable
;
545 JSCList scriptFilenamePrefixes
;
547 PRLock
*scriptFilenameTableLock
;
550 /* Number localization, used by jsnum.c */
551 const char *thousandsSeparator
;
552 const char *decimalSeparator
;
553 const char *numGrouping
;
556 * Weak references to lazily-created, well-known XML singletons.
558 * NB: Singleton objects must be carefully disconnected from the rest of
559 * the object graph usually associated with a JSContext's global object,
560 * including the set of standard class objects. See jsxml.c for details.
562 JSObject
*anynameObject
;
563 JSObject
*functionNamespaceObject
;
566 * A helper list for the GC, so it can mark native iterator states. See
567 * js_TraceNativeEnumerators for details.
569 JSNativeEnumerator
*nativeEnumerators
;
571 #ifndef JS_THREADSAFE
572 JSThreadData threadData
;
574 #define JS_THREAD_DATA(cx) (&(cx)->runtime->threadData)
578 * Object shape (property cache structural type) identifier generator.
580 * Type 0 stands for the empty scope, and must not be regenerated due to
581 * uint32 wrap-around. Since js_GenerateShape (in jsinterp.cpp) uses
582 * atomic pre-increment, the initial value for the first typed non-empty
585 * If this counter overflows into SHAPE_OVERFLOW_BIT (in jsinterp.h), the
586 * cache is disabled, to avoid aliasing two different types. It stays
587 * disabled until a triggered GC at some later moment compresses live
588 * types, minimizing rt->shapeGen in the process.
590 volatile uint32 shapeGen
;
592 /* Literal table maintained by jsatom.c functions. */
593 JSAtomState atomState
;
596 * Cache of reusable JSNativeEnumerators mapped by shape identifiers (as
597 * stored in scope->shape). This cache is nulled by the GC and protected
600 #define NATIVE_ENUM_CACHE_LOG2 8
601 #define NATIVE_ENUM_CACHE_MASK JS_BITMASK(NATIVE_ENUM_CACHE_LOG2)
602 #define NATIVE_ENUM_CACHE_SIZE JS_BIT(NATIVE_ENUM_CACHE_LOG2)
604 #define NATIVE_ENUM_CACHE_HASH(shape) \
605 ((((shape) >> NATIVE_ENUM_CACHE_LOG2) ^ (shape)) & NATIVE_ENUM_CACHE_MASK)
607 jsuword nativeEnumCache
[NATIVE_ENUM_CACHE_SIZE
];
610 * Various metering fields are defined at the end of JSRuntime. In this
611 * way there is no need to recompile all the code that refers to other
612 * fields of JSRuntime after enabling the corresponding metering macro.
614 #ifdef JS_DUMP_ENUM_CACHE_STATS
615 int32 nativeEnumProbes
;
616 int32 nativeEnumMisses
;
617 # define ENUM_CACHE_METER(name) JS_ATOMIC_INCREMENT(&cx->runtime->name)
619 # define ENUM_CACHE_METER(name) ((void) 0)
622 #ifdef JS_DUMP_LOOP_STATS
623 /* Loop statistics, to trigger trace recording and compiling. */
624 JSBasicStats loopStats
;
627 #if defined DEBUG || defined JS_DUMP_PROPTREE_STATS
628 /* Function invocation metering. */
629 jsrefcount inlineCalls
;
630 jsrefcount nativeCalls
;
631 jsrefcount nonInlineCalls
;
632 jsrefcount constructs
;
634 /* Title lock and scope property metering. */
635 jsrefcount claimAttempts
;
636 jsrefcount claimedTitles
;
637 jsrefcount deadContexts
;
638 jsrefcount deadlocksAvoided
;
639 jsrefcount liveScopes
;
640 jsrefcount sharedTitles
;
641 jsrefcount totalScopes
;
642 jsrefcount liveScopeProps
;
643 jsrefcount liveScopePropsPreSweep
;
644 jsrefcount totalScopeProps
;
645 jsrefcount livePropTreeNodes
;
646 jsrefcount duplicatePropTreeNodes
;
647 jsrefcount totalPropTreeNodes
;
648 jsrefcount propTreeKidsChunks
;
649 jsrefcount middleDeleteFixups
;
651 /* String instrumentation. */
652 jsrefcount liveStrings
;
653 jsrefcount totalStrings
;
654 jsrefcount liveDependentStrings
;
655 jsrefcount totalDependentStrings
;
656 jsrefcount badUndependStrings
;
658 double lengthSquaredSum
;
659 double strdepLengthSum
;
660 double strdepLengthSquaredSum
;
661 #endif /* DEBUG || JS_DUMP_PROPTREE_STATS */
663 #ifdef JS_SCOPE_DEPTH_METER
665 * Stats on runtime prototype chain lookups and scope chain depths, i.e.,
666 * counts of objects traversed on a chain until the wanted id is found.
668 JSBasicStats protoLookupDepthStats
;
669 JSBasicStats scopeSearchDepthStats
;
672 * Stats on compile-time host environment and lexical scope chain lengths
675 JSBasicStats hostenvScopeDepthStats
;
676 JSBasicStats lexicalScopeDepthStats
;
683 #ifdef JS_FUNCTION_METERING
684 JSFunctionMeter functionMeter
;
685 char lastScriptFilename
[1024];
688 void setGCTriggerFactor(uint32 factor
);
689 void setGCLastBytes(size_t lastBytes
);
692 /* Common macros to access thread-local caches in JSThread or JSRuntime. */
693 #define JS_GSN_CACHE(cx) (JS_THREAD_DATA(cx)->gsnCache)
694 #define JS_PROPERTY_CACHE(cx) (JS_THREAD_DATA(cx)->propertyCache)
695 #define JS_TRACE_MONITOR(cx) (JS_THREAD_DATA(cx)->traceMonitor)
696 #define JS_SCRIPTS_TO_GC(cx) (JS_THREAD_DATA(cx)->scriptsToGC)
698 #ifdef JS_EVAL_CACHE_METERING
699 # define EVAL_CACHE_METER(x) (JS_THREAD_DATA(cx)->evalCacheMeter.x++)
701 # define EVAL_CACHE_METER(x) ((void) 0)
705 # define JS_RUNTIME_METER(rt, which) JS_ATOMIC_INCREMENT(&(rt)->which)
706 # define JS_RUNTIME_UNMETER(rt, which) JS_ATOMIC_DECREMENT(&(rt)->which)
708 # define JS_RUNTIME_METER(rt, which) /* nothing */
709 # define JS_RUNTIME_UNMETER(rt, which) /* nothing */
712 #define JS_KEEP_ATOMS(rt) JS_ATOMIC_INCREMENT(&(rt)->gcKeepAtoms);
713 #define JS_UNKEEP_ATOMS(rt) JS_ATOMIC_DECREMENT(&(rt)->gcKeepAtoms);
715 #ifdef JS_ARGUMENT_FORMATTER_DEFINED
717 * Linked list mapping format strings for JS_{Convert,Push}Arguments{,VA} to
718 * formatter functions. Elements are sorted in non-increasing format string
721 struct JSArgumentFormatMap
{
724 JSArgumentFormatter formatter
;
725 JSArgumentFormatMap
*next
;
729 struct JSStackHeader
{
734 #define JS_STACK_SEGMENT(sh) ((jsval *)(sh) + 2)
737 * Key and entry types for the JSContext.resolvingTable hash table, typedef'd
738 * here because all consumers need to see these declarations (and not just the
739 * typedef names, as would be the case for an opaque pointer-to-typedef'd-type
740 * declaration), along with cx->resolvingTable.
742 typedef struct JSResolvingKey
{
747 typedef struct JSResolvingEntry
{
753 #define JSRESFLAG_LOOKUP 0x1 /* resolving id from lookup */
754 #define JSRESFLAG_WATCH 0x2 /* resolving id from watch */
756 typedef struct JSLocalRootChunk JSLocalRootChunk
;
758 #define JSLRS_CHUNK_SHIFT 8
759 #define JSLRS_CHUNK_SIZE JS_BIT(JSLRS_CHUNK_SHIFT)
760 #define JSLRS_CHUNK_MASK JS_BITMASK(JSLRS_CHUNK_SHIFT)
762 struct JSLocalRootChunk
{
763 jsval roots
[JSLRS_CHUNK_SIZE
];
764 JSLocalRootChunk
*down
;
767 typedef struct JSLocalRootStack
{
770 JSLocalRootChunk
*topChunk
;
771 JSLocalRootChunk firstChunk
;
774 #define JSLRS_NULL_MARK ((uint32) -1)
777 * Macros to push/pop JSTempValueRooter instances to context-linked stack of
778 * temporary GC roots. If you need to protect a result value that flows out of
779 * a C function across several layers of other functions, use the
780 * js_LeaveLocalRootScopeWithResult internal API (see further below) instead.
782 * The macros also provide a simple way to get a single rooted pointer via
783 * JS_PUSH_TEMP_ROOT_<KIND>(cx, NULL, &tvr). Then &tvr.u.<kind> gives the
786 * JSTempValueRooter.count defines the type of the rooted value referenced by
787 * JSTempValueRooter.u union of type JSTempValueUnion. When count is positive
788 * or zero, u.array points to a vector of jsvals. Otherwise it must be one of
789 * the following constants:
791 #define JSTVU_SINGLE (-1) /* u.value or u.<gcthing> is single jsval
793 #define JSTVU_TRACE (-2) /* u.trace is a hook to trace a custom
795 #define JSTVU_SPROP (-3) /* u.sprop roots property tree node */
796 #define JSTVU_WEAK_ROOTS (-4) /* u.weakRoots points to saved weak roots */
797 #define JSTVU_COMPILER (-5) /* u.compiler roots JSCompiler* */
798 #define JSTVU_SCRIPT (-6) /* u.script roots JSScript* */
801 * Here single JSTVU_SINGLE covers both jsval and pointers to any GC-thing via
802 * reinterpreting the thing as JSVAL_OBJECT. It works because the GC-thing is
803 * aligned on a 0 mod 8 boundary, and object has the 0 jsval tag. So any
804 * GC-thing may be tagged as if it were an object and untagged, if it's then
805 * used only as an opaque pointer until discriminated by other means than tag
806 * bits. This is how, for example, js_GetGCThingTraceKind uses its |thing|
807 * parameter -- it consults GC-thing flags stored separately from the thing to
808 * decide the kind of thing.
810 #define JS_PUSH_TEMP_ROOT_COMMON(cx,x,tvr,cnt,kind) \
812 JS_ASSERT((cx)->tempValueRooters != (tvr)); \
813 (tvr)->count = (cnt); \
814 (tvr)->u.kind = (x); \
815 (tvr)->down = (cx)->tempValueRooters; \
816 (cx)->tempValueRooters = (tvr); \
819 #define JS_POP_TEMP_ROOT(cx,tvr) \
821 JS_ASSERT((cx)->tempValueRooters == (tvr)); \
822 (cx)->tempValueRooters = (tvr)->down; \
825 #define JS_PUSH_TEMP_ROOT(cx,cnt,arr,tvr) \
827 JS_ASSERT((int)(cnt) >= 0); \
828 JS_PUSH_TEMP_ROOT_COMMON(cx, arr, tvr, (ptrdiff_t) (cnt), array); \
831 #define JS_PUSH_SINGLE_TEMP_ROOT(cx,val,tvr) \
832 JS_PUSH_TEMP_ROOT_COMMON(cx, val, tvr, JSTVU_SINGLE, value)
834 #define JS_PUSH_TEMP_ROOT_OBJECT(cx,obj,tvr) \
835 JS_PUSH_TEMP_ROOT_COMMON(cx, obj, tvr, JSTVU_SINGLE, object)
837 #define JS_PUSH_TEMP_ROOT_STRING(cx,str,tvr) \
838 JS_PUSH_TEMP_ROOT_COMMON(cx, str, tvr, JSTVU_SINGLE, string)
840 #define JS_PUSH_TEMP_ROOT_XML(cx,xml_,tvr) \
841 JS_PUSH_TEMP_ROOT_COMMON(cx, xml_, tvr, JSTVU_SINGLE, xml)
843 #define JS_PUSH_TEMP_ROOT_TRACE(cx,trace_,tvr) \
844 JS_PUSH_TEMP_ROOT_COMMON(cx, trace_, tvr, JSTVU_TRACE, trace)
846 #define JS_PUSH_TEMP_ROOT_SPROP(cx,sprop_,tvr) \
847 JS_PUSH_TEMP_ROOT_COMMON(cx, sprop_, tvr, JSTVU_SPROP, sprop)
849 #define JS_PUSH_TEMP_ROOT_WEAK_COPY(cx,weakRoots_,tvr) \
850 JS_PUSH_TEMP_ROOT_COMMON(cx, weakRoots_, tvr, JSTVU_WEAK_ROOTS, weakRoots)
852 #define JS_PUSH_TEMP_ROOT_COMPILER(cx,pc,tvr) \
853 JS_PUSH_TEMP_ROOT_COMMON(cx, pc, tvr, JSTVU_COMPILER, compiler)
855 #define JS_PUSH_TEMP_ROOT_SCRIPT(cx,script_,tvr) \
856 JS_PUSH_TEMP_ROOT_COMMON(cx, script_, tvr, JSTVU_SCRIPT, script)
859 #define JSRESOLVE_INFER 0xffff /* infer bits from current bytecode */
863 * If this flag is set, we were asked to call back the operation callback
864 * as soon as possible.
866 volatile jsint operationCallbackFlag
;
868 /* JSRuntime contextList linkage. */
871 #if JS_HAS_XML_SUPPORT
873 * Bit-set formed from binary exponentials of the XML_* tiny-ids defined
874 * for boolean settings in jsxml.c, plus an XSF_CACHE_VALID bit. Together
875 * these act as a cache of the boolean XML.ignore* and XML.prettyPrinting
876 * property values associated with this context's global object.
878 uint8 xmlSettingFlags
;
885 * Classic Algol "display" static link optimization.
887 #define JS_DISPLAY_SIZE 16U
889 JSStackFrame
*display
[JS_DISPLAY_SIZE
];
891 /* Runtime version control identifier. */
894 /* Per-context options. */
895 uint32 options
; /* see jsapi.h for JSOPTION_* */
897 /* Locale specific callbacks for string conversion. */
898 JSLocaleCallbacks
*localeCallbacks
;
901 * cx->resolvingTable is non-null and non-empty if we are initializing
902 * standard classes lazily, or if we are otherwise recursing indirectly
903 * from js_LookupProperty through a JSClass.resolve hook. It is used to
904 * limit runaway recursion (see jsapi.c and jsobj.c).
906 JSDHashTable
*resolvingTable
;
908 #if JS_HAS_LVALUE_RETURN
910 * Secondary return value from native method called on the left-hand side
911 * of an assignment operator. The native should store the object in which
912 * to set a property in *rval, and return the property's id expressed as a
913 * jsval by calling JS_SetCallReturnValue2(cx, idval).
916 JSPackedBool rval2set
;
920 * True if generating an error, to prevent runaway recursion.
921 * NB: generatingError packs with rval2set, #if JS_HAS_LVALUE_RETURN;
922 * with insideGCMarkCallback and with throwing below.
924 JSPackedBool generatingError
;
926 /* Flag to indicate that we run inside gcCallback(cx, JSGC_MARK_END). */
927 JSPackedBool insideGCMarkCallback
;
929 /* Exception state -- the exception member is a GC root by definition. */
930 JSPackedBool throwing
; /* is there a pending exception? */
931 jsval exception
; /* most-recently-thrown exception */
933 /* Limit pointer for checking native stack consumption during recursion. */
936 /* Quota on the size of arenas used to compile and execute scripts. */
937 size_t scriptStackQuota
;
939 /* Data shared by threads in an address space. */
942 /* Stack arena pool and frame pointer register. */
944 JSArenaPool stackPool
;
949 /* Temporary arena pool used while compiling and decompiling. */
950 JSArenaPool tempPool
;
952 /* Top-level object and pointer to top stack frame's scope chain. */
953 JSObject
*globalObject
;
955 /* Storage to root recently allocated GC things and script result. */
956 JSWeakRoots weakRoots
;
958 /* Regular expression class statics (XXX not shared globally). */
959 JSRegExpStatics regExpStatics
;
961 /* State for object and array toSource conversion. */
962 JSSharpObjectMap sharpObjectMap
;
963 JSHashTable
*busyArrayTable
;
965 /* Argument formatter support for JS_{Convert,Push}Arguments{,VA}. */
966 JSArgumentFormatMap
*argumentFormatMap
;
968 /* Last message string and trace file for debugging. */
972 jsbytecode
*tracePrevPc
;
975 /* Per-context optional error reporter. */
976 JSErrorReporter errorReporter
;
978 /* Branch callback. */
979 JSOperationCallback operationCallback
;
981 /* Interpreter activation count. */
984 /* Client opaque pointers. */
988 /* GC and thread-safe state. */
989 JSStackFrame
*dormantFrameChain
; /* dormant stack frame to scan */
992 jsrefcount requestDepth
;
993 /* Same as requestDepth but ignoring JS_SuspendRequest/JS_ResumeRequest */
994 jsrefcount outstandingRequests
;
995 JSTitle
*lockedSealedTitle
; /* weak ref, for low-cost sealed
997 JSCList threadLinks
; /* JSThread contextList linkage */
999 #define CX_FROM_THREAD_LINKS(tl) \
1000 ((JSContext *)((char *)(tl) - offsetof(JSContext, threadLinks)))
1003 /* PDL of stack headers describing stack slots not rooted by argv, etc. */
1004 JSStackHeader
*stackHeaders
;
1006 /* Optional stack of heap-allocated scoped local GC roots. */
1007 JSLocalRootStack
*localRootStack
;
1009 /* Stack of thread-stack-allocated temporary GC roots. */
1010 JSTempValueRooter
*tempValueRooters
;
1012 #ifdef JS_THREADSAFE
1013 JSGCFreeListSet
*gcLocalFreeLists
;
1016 /* List of pre-allocated doubles. */
1017 JSGCDoubleCell
*doubleFreeList
;
1019 /* Debug hooks associated with the current context. */
1020 JSDebugHooks
*debugHooks
;
1022 /* Security callbacks that override any defined on the runtime. */
1023 JSSecurityCallbacks
*securityCallbacks
;
1025 /* Pinned regexp pool used for regular expressions. */
1026 JSArenaPool regexpPool
;
1028 /* Stored here to avoid passing it around as a parameter. */
1033 * State for the current tree execution. bailExit is valid if the tree has
1034 * called back into native code via a _FAIL builtin and has not yet bailed,
1035 * else garbage (NULL in debug builds).
1037 InterpState
*interpState
;
1038 VMSideExit
*bailExit
;
1040 /* Used when calling natives from trace to root the vp vector. */
1045 /* Call this after succesful malloc of memory for GC-related things. */
1047 updateMallocCounter(size_t nbytes
)
1049 size_t *pbytes
, bytes
;
1051 pbytes
= &JS_THREAD_DATA(this)->gcMallocBytes
;
1053 *pbytes
= (size_t(-1) - bytes
<= nbytes
) ? size_t(-1) : bytes
+ nbytes
;
1057 #ifdef JS_THREADSAFE
1058 # define JS_THREAD_ID(cx) ((cx)->thread ? (cx)->thread->id : 0)
1063 static inline JSAtom
**
1064 FrameAtomBase(JSContext
*cx
, JSStackFrame
*fp
)
1067 ? COMMON_ATOMS_START(&cx
->runtime
->atomState
)
1068 : fp
->script
->atomMap
.vector
;
1071 /* FIXME(bug 332648): Move this into a public header. */
1072 class JSAutoTempValueRooter
1075 JSAutoTempValueRooter(JSContext
*cx
, size_t len
, jsval
*vec
)
1077 JS_PUSH_TEMP_ROOT(mContext
, len
, vec
, &mTvr
);
1079 explicit JSAutoTempValueRooter(JSContext
*cx
, jsval v
= JSVAL_NULL
)
1081 JS_PUSH_SINGLE_TEMP_ROOT(mContext
, v
, &mTvr
);
1083 JSAutoTempValueRooter(JSContext
*cx
, JSString
*str
)
1085 JS_PUSH_TEMP_ROOT_STRING(mContext
, str
, &mTvr
);
1087 JSAutoTempValueRooter(JSContext
*cx
, JSObject
*obj
)
1089 JS_PUSH_TEMP_ROOT_OBJECT(mContext
, obj
, &mTvr
);
1092 ~JSAutoTempValueRooter() {
1093 JS_POP_TEMP_ROOT(mContext
, &mTvr
);
1096 jsval
value() { return mTvr
.u
.value
; }
1097 jsval
*addr() { return &mTvr
.u
.value
; }
1100 JSContext
*mContext
;
1104 static void *operator new(size_t);
1105 static void operator delete(void *, size_t);
1108 JSTempValueRooter mTvr
;
1111 class JSAutoTempIdRooter
1114 explicit JSAutoTempIdRooter(JSContext
*cx
, jsid id
= INT_TO_JSID(0))
1116 JS_PUSH_SINGLE_TEMP_ROOT(mContext
, ID_TO_VALUE(id
), &mTvr
);
1119 ~JSAutoTempIdRooter() {
1120 JS_POP_TEMP_ROOT(mContext
, &mTvr
);
1123 jsid
id() { return (jsid
) mTvr
.u
.value
; }
1124 jsid
* addr() { return (jsid
*) &mTvr
.u
.value
; }
1127 JSContext
*mContext
;
1128 JSTempValueRooter mTvr
;
1131 class JSAutoResolveFlags
1134 JSAutoResolveFlags(JSContext
*cx
, uintN flags
)
1135 : mContext(cx
), mSaved(cx
->resolveFlags
) {
1136 cx
->resolveFlags
= flags
;
1139 ~JSAutoResolveFlags() { mContext
->resolveFlags
= mSaved
; }
1142 JSContext
*mContext
;
1146 #endif /* __cpluscplus */
1149 * Slightly more readable macros for testing per-context option settings (also
1150 * to hide bitset implementation detail).
1152 * JSOPTION_XML must be handled specially in order to propagate from compile-
1153 * to run-time (from cx->options to script->version/cx->version). To do that,
1154 * we copy JSOPTION_XML from cx->options into cx->version as JSVERSION_HAS_XML
1155 * whenever options are set, and preserve this XML flag across version number
1156 * changes done via the JS_SetVersion API.
1158 * But when executing a script or scripted function, the interpreter changes
1159 * cx->version, including the XML flag, to script->version. Thus JSOPTION_XML
1160 * is a compile-time option that causes a run-time version change during each
1161 * activation of the compiled script. That version change has the effect of
1162 * changing JS_HAS_XML_OPTION, so that any compiling done via eval enables XML
1163 * support. If an XML-enabled script or function calls a non-XML function,
1164 * the flag bit will be cleared during the callee's activation.
1166 * Note that JS_SetVersion API calls never pass JSVERSION_HAS_XML or'd into
1167 * that API's version parameter.
1169 * Note also that script->version must contain this XML option flag in order
1170 * for XDR'ed scripts to serialize and deserialize with that option preserved
1171 * for detection at run-time. We can't copy other compile-time options into
1172 * script->version because that would break backward compatibility (certain
1173 * other options, e.g. JSOPTION_VAROBJFIX, are analogous to JSOPTION_XML).
1175 #define JS_HAS_OPTION(cx,option) (((cx)->options & (option)) != 0)
1176 #define JS_HAS_STRICT_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_STRICT)
1177 #define JS_HAS_WERROR_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_WERROR)
1178 #define JS_HAS_COMPILE_N_GO_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_COMPILE_N_GO)
1179 #define JS_HAS_ATLINE_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_ATLINE)
1181 #define JSVERSION_MASK 0x0FFF /* see JSVersion in jspubtd.h */
1182 #define JSVERSION_HAS_XML 0x1000 /* flag induced by XML option */
1183 #define JSVERSION_ANONFUNFIX 0x2000 /* see jsapi.h, the comments
1184 for JSOPTION_ANONFUNFIX */
1186 #define JSVERSION_NUMBER(cx) ((JSVersion)((cx)->version & \
1188 #define JS_HAS_XML_OPTION(cx) ((cx)->version & JSVERSION_HAS_XML || \
1189 JSVERSION_NUMBER(cx) >= JSVERSION_1_6)
1192 js_InitThreads(JSRuntime
*rt
);
1195 js_FinishThreads(JSRuntime
*rt
);
1198 js_PurgeThreads(JSContext
*cx
);
1201 * Ensures the JSOPTION_XML and JSOPTION_ANONFUNFIX bits of cx->options are
1202 * reflected in cx->version, since each bit must travel with a script that has
1206 js_SyncOptionsToVersion(JSContext
*cx
);
1209 * Common subroutine of JS_SetVersion and js_SetVersion, to update per-context
1210 * data that depends on version.
1213 js_OnVersionChange(JSContext
*cx
);
1216 * Unlike the JS_SetVersion API, this function stores JSVERSION_HAS_XML and
1217 * any future non-version-number flags induced by compiler options.
1220 js_SetVersion(JSContext
*cx
, JSVersion version
);
1223 * Create and destroy functions for JSContext, which is manually allocated
1224 * and exclusively owned.
1227 js_NewContext(JSRuntime
*rt
, size_t stackChunkSize
);
1230 js_DestroyContext(JSContext
*cx
, JSDestroyContextMode mode
);
1233 * Return true if cx points to a context in rt->contextList, else return false.
1234 * NB: the caller (see jslock.c:ClaimTitle) must hold rt->gcLock.
1237 js_ValidContextPointer(JSRuntime
*rt
, JSContext
*cx
);
1239 static JS_INLINE JSContext
*
1240 js_ContextFromLinkField(JSCList
*link
)
1243 return (JSContext
*) ((uint8
*) link
- offsetof(JSContext
, link
));
1247 * If unlocked, acquire and release rt->gcLock around *iterp update; otherwise
1248 * the caller must be holding rt->gcLock.
1251 js_ContextIterator(JSRuntime
*rt
, JSBool unlocked
, JSContext
**iterp
);
1254 * Iterate through contexts with active requests. The caller must be holding
1255 * rt->gcLock in case of a thread-safe build, or otherwise guarantee that the
1256 * context list is not alternated asynchroniously.
1258 extern JS_FRIEND_API(JSContext
*)
1259 js_NextActiveContext(JSRuntime
*, JSContext
*);
1261 #ifdef JS_THREADSAFE
1264 * Count the number of contexts entered requests on the current thread.
1267 js_CountThreadRequests(JSContext
*cx
);
1270 * This is a helper for code at can potentially run outside JS request to
1271 * ensure that the GC is not running when the function returns.
1273 * This function must be called with the GC lock held.
1276 js_WaitForGC(JSRuntime
*rt
);
1279 * If we're in one or more requests (possibly on more than one context)
1280 * running on the current thread, indicate, temporarily, that all these
1281 * requests are inactive so a possible GC can proceed on another thread.
1282 * This function returns the number of discounted requests. The number must
1283 * be passed later to js_ActivateRequestAfterGC to reactivate the requests.
1285 * This function must be called with the GC lock held.
1288 js_DiscountRequestsForGC(JSContext
*cx
);
1291 * This function must be called with the GC lock held.
1294 js_RecountRequestsAfterGC(JSRuntime
*rt
, uint32 requestDebit
);
1296 #else /* !JS_THREADSAFE */
1298 # define js_WaitForGC(rt) ((void) 0)
1303 * JSClass.resolve and watchpoint recursion damping machinery.
1306 js_StartResolving(JSContext
*cx
, JSResolvingKey
*key
, uint32 flag
,
1307 JSResolvingEntry
**entryp
);
1310 js_StopResolving(JSContext
*cx
, JSResolvingKey
*key
, uint32 flag
,
1311 JSResolvingEntry
*entry
, uint32 generation
);
1314 * Local root set management.
1316 * NB: the jsval parameters below may be properly tagged jsvals, or GC-thing
1317 * pointers cast to (jsval). This relies on JSObject's tag being zero, but
1318 * on the up side it lets us push int-jsval-encoded scopeMark values on the
1322 js_EnterLocalRootScope(JSContext
*cx
);
1324 #define js_LeaveLocalRootScope(cx) \
1325 js_LeaveLocalRootScopeWithResult(cx, JSVAL_NULL)
1328 js_LeaveLocalRootScopeWithResult(JSContext
*cx
, jsval rval
);
1331 js_ForgetLocalRoot(JSContext
*cx
, jsval v
);
1334 js_PushLocalRoot(JSContext
*cx
, JSLocalRootStack
*lrs
, jsval v
);
1337 js_TraceLocalRoots(JSTracer
*trc
, JSLocalRootStack
*lrs
);
1340 * Report an exception, which is currently realized as a printf-style format
1341 * string and its arguments.
1343 typedef enum JSErrNum
{
1344 #define MSG_DEF(name, number, count, exception, format) \
1351 extern JS_FRIEND_API(const JSErrorFormatString
*)
1352 js_GetErrorMessage(void *userRef
, const char *locale
, const uintN errorNumber
);
1356 js_ReportErrorVA(JSContext
*cx
, uintN flags
, const char *format
, va_list ap
);
1359 js_ReportErrorNumberVA(JSContext
*cx
, uintN flags
, JSErrorCallback callback
,
1360 void *userRef
, const uintN errorNumber
,
1361 JSBool charArgs
, va_list ap
);
1364 js_ExpandErrorArguments(JSContext
*cx
, JSErrorCallback callback
,
1365 void *userRef
, const uintN errorNumber
,
1366 char **message
, JSErrorReport
*reportp
,
1367 JSBool
*warningp
, JSBool charArgs
, va_list ap
);
1371 js_ReportOutOfMemory(JSContext
*cx
);
1374 * Report that cx->scriptStackQuota is exhausted.
1377 js_ReportOutOfScriptQuota(JSContext
*cx
);
1380 js_ReportOverRecursed(JSContext
*cx
);
1383 js_ReportAllocationOverflow(JSContext
*cx
);
1385 #define JS_CHECK_RECURSION(cx, onerror) \
1389 if (!JS_CHECK_STACK_SIZE(cx, stackDummy_)) { \
1390 js_ReportOverRecursed(cx); \
1396 * Report an exception using a previously composed JSErrorReport.
1397 * XXXbe remove from "friend" API
1399 extern JS_FRIEND_API(void)
1400 js_ReportErrorAgain(JSContext
*cx
, const char *message
, JSErrorReport
*report
);
1403 js_ReportIsNotDefined(JSContext
*cx
, const char *name
);
1406 * Report an attempt to access the property of a null or undefined value (v).
1409 js_ReportIsNullOrUndefined(JSContext
*cx
, intN spindex
, jsval v
,
1410 JSString
*fallback
);
1413 js_ReportMissingArg(JSContext
*cx
, jsval
*vp
, uintN arg
);
1416 * Report error using js_DecompileValueGenerator(cx, spindex, v, fallback) as
1417 * the first argument for the error message. If the error message has less
1418 * then 3 arguments, use null for arg1 or arg2.
1421 js_ReportValueErrorFlags(JSContext
*cx
, uintN flags
, const uintN errorNumber
,
1422 intN spindex
, jsval v
, JSString
*fallback
,
1423 const char *arg1
, const char *arg2
);
1425 #define js_ReportValueError(cx,errorNumber,spindex,v,fallback) \
1426 ((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
1427 spindex, v, fallback, NULL, NULL))
1429 #define js_ReportValueError2(cx,errorNumber,spindex,v,fallback,arg1) \
1430 ((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
1431 spindex, v, fallback, arg1, NULL))
1433 #define js_ReportValueError3(cx,errorNumber,spindex,v,fallback,arg1,arg2) \
1434 ((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
1435 spindex, v, fallback, arg1, arg2))
1437 extern JSErrorFormatString js_ErrorFormatString
[JSErr_Limit
];
1440 * See JS_SetThreadStackLimit in jsapi.c, where we check that the stack grows
1441 * in the expected direction. On Unix-y systems, JS_STACK_GROWTH_DIRECTION is
1442 * computed on the build host by jscpucfg.c and written into jsautocfg.h. The
1443 * macro is hardcoded in jscpucfg.h on Windows and Mac systems (for historical
1444 * reasons pre-dating autoconf usage).
1446 #if JS_STACK_GROWTH_DIRECTION > 0
1447 # define JS_CHECK_STACK_SIZE(cx, lval) ((jsuword)&(lval) < (cx)->stackLimit)
1449 # define JS_CHECK_STACK_SIZE(cx, lval) ((jsuword)&(lval) > (cx)->stackLimit)
1453 * If the operation callback flag was set, call the operation callback.
1454 * This macro can run the full GC. Return true if it is OK to continue and
1457 #define JS_CHECK_OPERATION_LIMIT(cx) \
1458 (!(cx)->operationCallbackFlag || js_InvokeOperationCallback(cx))
1461 * Invoke the operation callback and return false if the current execution
1462 * is to be terminated.
1465 js_InvokeOperationCallback(JSContext
*cx
);
1467 #ifndef JS_THREADSAFE
1468 # define js_TriggerAllOperationCallbacks(rt, gcLocked) \
1469 js_TriggerAllOperationCallbacks (rt)
1473 js_TriggerAllOperationCallbacks(JSRuntime
*rt
, JSBool gcLocked
);
1475 extern JSStackFrame
*
1476 js_GetScriptedCaller(JSContext
*cx
, JSStackFrame
*fp
);
1479 js_GetCurrentBytecodePC(JSContext
* cx
);
1483 * Reconstruct the JS stack and clear cx->tracecx. We must be currently in a
1484 * _FAIL builtin from trace on cx or another context on the same thread. The
1485 * machine code for the trace remains on the C stack when js_DeepBail returns.
1487 * Implemented in jstracer.cpp.
1489 JS_FORCES_STACK
JS_FRIEND_API(void)
1490 js_DeepBail(JSContext
*cx
);
1493 static JS_FORCES_STACK JS_INLINE
void
1494 js_LeaveTrace(JSContext
*cx
)
1497 if (JS_ON_TRACE(cx
))
1502 static JS_INLINE
void
1503 js_LeaveTraceIfGlobalObject(JSContext
*cx
, JSObject
*obj
)
1505 if (!obj
->fslots
[JSSLOT_PARENT
])
1509 static JS_INLINE JSBool
1510 js_CanLeaveTrace(JSContext
*cx
)
1512 JS_ASSERT(JS_ON_TRACE(cx
));
1514 return cx
->bailExit
!= NULL
;
1521 * Get the current cx->fp, first lazily instantiating stack frames if needed.
1522 * (Do not access cx->fp directly except in JS_REQUIRES_STACK code.)
1524 * Defined in jstracer.cpp if JS_TRACER is defined.
1526 static JS_FORCES_STACK JS_INLINE JSStackFrame
*
1527 js_GetTopStackFrame(JSContext
*cx
)
1533 static JS_INLINE JSBool
1534 js_IsPropertyCacheDisabled(JSContext
*cx
)
1536 return cx
->runtime
->shapeGen
>= SHAPE_OVERFLOW_BIT
;
1539 static JS_INLINE uint32
1540 js_RegenerateShapeForGC(JSContext
*cx
)
1542 JS_ASSERT(cx
->runtime
->gcRunning
);
1543 JS_ASSERT(cx
->runtime
->gcRegenShapes
);
1546 * Under the GC, compared with js_GenerateShape, we don't need to use
1547 * atomic increments but we still must make sure that after an overflow
1548 * the shape stays such.
1550 uint32 shape
= cx
->runtime
->shapeGen
;
1551 shape
= (shape
+ 1) | (shape
& SHAPE_OVERFLOW_BIT
);
1552 cx
->runtime
->shapeGen
= shape
;
1558 #endif /* jscntxt_h___ */