1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* ***** BEGIN LICENSE BLOCK *****
4
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 1.1 (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
9
* http://www.mozilla.org/MPL/
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
16
* The Original Code is Mozilla Communicator client code, released
19
* The Initial Developer of the Original Code is
20
* Netscape Communications Corporation.
21
* Portions created by the Initial Developer are Copyright (C) 1998
22
* the Initial Developer. All Rights Reserved.
26
* Alternatively, the contents of this file may be used under the terms of
27
* either of the GNU General Public License Version 2 or later (the "GPL"),
28
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
* in which case the provisions of the GPL or the LGPL are applicable instead
30
* of those above. If you wish to allow use of your version of this file only
31
* under the terms of either the GPL or the LGPL, and not to allow others to
32
* use your version of this file under the terms of the MPL, indicate your
33
* decision by deleting the provisions above and replace them with the notice
34
* and other provisions required by the GPL or the LGPL. If you do not delete
35
* the provisions above, a recipient may use your version of this file under
36
* the terms of any one of the MPL, the GPL or the LGPL.
38
* ***** END LICENSE BLOCK ***** */
43
* JS interpreter interface.
51
* JS stack frame, allocated on the C stack.
54
JSObject *callobj; /* lazily created Call object */
55
JSObject *argsobj; /* lazily created arguments object */
56
JSObject *varobj; /* variables object, where vars go */
57
JSScript *script; /* script being interpreted */
58
JSFunction *fun; /* function being called or null */
59
JSObject *thisp; /* "this" pointer if in method */
60
uintN argc; /* actual argument count */
61
jsval *argv; /* base of argument stack slots */
62
jsval rval; /* function return value */
63
uintN nvars; /* local variable count */
64
jsval *vars; /* base of variable stack slots */
65
JSStackFrame *down; /* previous frame */
66
void *annotation; /* used by Java security */
67
JSObject *scopeChain; /* scope chain */
68
jsbytecode *pc; /* program counter */
69
jsval *sp; /* stack pointer */
70
jsval *spbase; /* operand stack base */
71
uintN sharpDepth; /* array/object initializer depth */
72
JSObject *sharpArray; /* scope for #n= initializer vars */
73
uint32 flags; /* frame flags -- see below */
74
JSStackFrame *dormantNext; /* next dormant frame chain */
75
JSAtomMap *objAtomMap; /* object atom map, non-null only if we
76
hit a regexp object literal */
79
typedef struct JSInlineFrame {
80
JSStackFrame frame; /* base struct */
81
void *mark; /* mark before inline frame */
82
void *hookData; /* debugger call hook data */
83
JSVersion callerVersion; /* dynamic version of calling script */
86
/* JS stack frame flags. */
87
#define JSFRAME_CONSTRUCTING 0x01 /* frame is for a constructor invocation */
88
#define JSFRAME_INTERNAL 0x02 /* internal call, not invoked by a script */
89
#define JSFRAME_SKIP_CALLER 0x04 /* skip one link when evaluating f.caller
90
for this invocation of f */
91
#define JSFRAME_ASSIGNING 0x08 /* a complex (not simplex JOF_ASSIGNING) op
92
is currently assigning to a property */
93
#define JSFRAME_DEBUGGER 0x10 /* frame for JS_EvaluateInStackFrame */
94
#define JSFRAME_EVAL 0x20 /* frame for obj_eval */
95
#define JSFRAME_SPECIAL 0x30 /* special evaluation frame flags */
96
#define JSFRAME_COMPILING 0x40 /* frame is being used by compiler */
97
#define JSFRAME_COMPILE_N_GO 0x80 /* compiler-and-go mode, can optimize name
98
references based on scope chain */
100
#define JSFRAME_OVERRIDE_SHIFT 24 /* override bit-set params; see jsfun.c */
101
#define JSFRAME_OVERRIDE_BITS 8
104
* Property cache for quickened get/set property opcodes.
106
#define PROPERTY_CACHE_LOG2 10
107
#define PROPERTY_CACHE_SIZE JS_BIT(PROPERTY_CACHE_LOG2)
108
#define PROPERTY_CACHE_MASK JS_BITMASK(PROPERTY_CACHE_LOG2)
110
#define PROPERTY_CACHE_HASH(obj, id) \
111
((((jsuword)(obj) >> JSVAL_TAGBITS) ^ (jsuword)(id)) & PROPERTY_CACHE_MASK)
115
#if HAVE_ATOMIC_DWORD_ACCESS
117
#define PCE_LOAD(cache, pce, entry) JS_ATOMIC_DWORD_LOAD(pce, entry)
118
#define PCE_STORE(cache, pce, entry) JS_ATOMIC_DWORD_STORE(pce, entry)
120
#else /* !HAVE_ATOMIC_DWORD_ACCESS */
122
#define JS_PROPERTY_CACHE_METERING 1
124
#define PCE_LOAD(cache, pce, entry) \
127
uint32 fills_ = (cache)->fills; \
129
/* Load until cache->fills is stable (see FILL macro below). */ \
130
prefills_ = fills_; \
132
} while ((fills_ = (cache)->fills) != prefills_); \
135
#define PCE_STORE(cache, pce, entry) \
138
/* Store until no racing collider stores half or all of pce. */ \
140
} while (PCE_OBJECT(*pce) != PCE_OBJECT(entry) || \
141
PCE_PROPERTY(*pce) != PCE_PROPERTY(entry)); \
144
#endif /* !HAVE_ATOMIC_DWORD_ACCESS */
146
#else /* !JS_THREADSAFE */
148
#define PCE_LOAD(cache, pce, entry) ((entry) = *(pce))
149
#define PCE_STORE(cache, pce, entry) (*(pce) = (entry))
151
#endif /* !JS_THREADSAFE */
153
typedef union JSPropertyCacheEntry {
155
JSObject *object; /* weak link to object */
156
JSScopeProperty *property; /* weak link to property */
158
#ifdef HAVE_ATOMIC_DWORD_ACCESS
161
} JSPropertyCacheEntry;
163
/* These may be called in lvalue or rvalue position. */
164
#define PCE_OBJECT(entry) ((entry).s.object)
165
#define PCE_PROPERTY(entry) ((entry).s.property)
167
typedef struct JSPropertyCache {
168
JSPropertyCacheEntry table[PROPERTY_CACHE_SIZE];
171
#ifdef JS_PROPERTY_CACHE_METERING
177
# define PCMETER(x) x
179
# define PCMETER(x) /* nothing */
183
#define PROPERTY_CACHE_FILL(cache, obj, id, sprop) \
185
JSPropertyCache *cache_ = (cache); \
186
if (!cache_->disabled) { \
187
uintN hashIndex_ = (uintN) PROPERTY_CACHE_HASH(obj, id); \
188
JSPropertyCacheEntry *pce_ = &cache_->table[hashIndex_]; \
189
JSPropertyCacheEntry entry_; \
190
JSScopeProperty *pce_sprop_; \
191
PCE_LOAD(cache_, pce_, entry_); \
192
pce_sprop_ = PCE_PROPERTY(entry_); \
193
PCMETER(if (pce_sprop_ && pce_sprop_ != sprop) \
194
cache_->recycles++); \
195
PCE_OBJECT(entry_) = obj; \
196
PCE_PROPERTY(entry_) = sprop; \
197
cache_->empty = JS_FALSE; \
198
PCMETER(cache_->fills++); \
199
PCE_STORE(cache_, pce_, entry_); \
203
#define PROPERTY_CACHE_TEST(cache, obj, id, sprop) \
205
uintN hashIndex_ = (uintN) PROPERTY_CACHE_HASH(obj, id); \
206
JSPropertyCache *cache_ = (cache); \
207
JSPropertyCacheEntry *pce_ = &cache_->table[hashIndex_]; \
208
JSPropertyCacheEntry entry_; \
209
JSScopeProperty *pce_sprop_; \
210
PCE_LOAD(cache_, pce_, entry_); \
211
pce_sprop_ = PCE_PROPERTY(entry_); \
212
PCMETER(cache_->tests++); \
214
PCE_OBJECT(entry_) == obj && \
215
pce_sprop_->id == id) { \
216
sprop = pce_sprop_; \
218
PCMETER(cache_->misses++); \
224
js_FlushPropertyCache(JSContext *cx);
227
js_DisablePropertyCache(JSContext *cx);
230
js_EnablePropertyCache(JSContext *cx);
232
extern JS_FRIEND_API(jsval *)
233
js_AllocStack(JSContext *cx, uintN nslots, void **markp);
235
extern JS_FRIEND_API(void)
236
js_FreeStack(JSContext *cx, void *mark);
239
js_GetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
242
js_SetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
245
js_GetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
248
js_SetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
251
* NB: js_Invoke requires that cx is currently running JS (i.e., that cx->fp
254
extern JS_FRIEND_API(JSBool)
255
js_Invoke(JSContext *cx, uintN argc, uintN flags);
258
* Consolidated js_Invoke flags simply rename the low JSFRAME_* flags.
260
#define JSINVOKE_CONSTRUCT JSFRAME_CONSTRUCTING
261
#define JSINVOKE_INTERNAL JSFRAME_INTERNAL
262
#define JSINVOKE_SKIP_CALLER JSFRAME_SKIP_CALLER
265
* "Internal" calls may come from C or C++ code using a JSContext on which no
266
* JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
268
#define js_InternalCall(cx,obj,fval,argc,argv,rval) \
269
js_InternalInvoke(cx, obj, fval, 0, argc, argv, rval)
271
#define js_InternalConstruct(cx,obj,fval,argc,argv,rval) \
272
js_InternalInvoke(cx, obj, fval, JSINVOKE_CONSTRUCT, argc, argv, rval)
275
js_InternalInvoke(JSContext *cx, JSObject *obj, jsval fval, uintN flags,
276
uintN argc, jsval *argv, jsval *rval);
279
js_InternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, jsval fval,
280
JSAccessMode mode, uintN argc, jsval *argv, jsval *rval);
283
js_Execute(JSContext *cx, JSObject *chain, JSScript *script,
284
JSStackFrame *down, uintN flags, jsval *result);
287
js_CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs,
291
js_Interpret(JSContext *cx, jsval *result);
295
#endif /* jsinterp_h___ */