Bug 720316 - Use uint32_t indexes for JOF_ATOM opcodes. r=jorendorff

This commit is contained in:
Jeff Walden
2012-02-03 18:53:29 -08:00
parent 48de0a2af9
commit 13a15f762d
31 changed files with 299 additions and 506 deletions

View File

@@ -82,7 +82,7 @@ typedef enum JSOp {
#define JOF_LOOKUPSWITCH 5 /* lookup switch */
#define JOF_QARG 6 /* quickened get/set function argument ops */
#define JOF_LOCAL 7 /* var or block-local variable */
/* 8 is unused */
#define JOF_DOUBLE 8 /* uint32_t index for double value */
#define JOF_UINT24 12 /* extended unsigned 24-bit literal (index) */
#define JOF_UINT8 13 /* uint8_t immediate, e.g. top 8 bits of 24-bit
atom index */
@@ -113,7 +113,7 @@ typedef enum JSOp {
#define JOF_BACKPATCH (1U<<15) /* backpatch placeholder during codegen */
#define JOF_LEFTASSOC (1U<<16) /* left-associative operator */
#define JOF_DECLARING (1U<<17) /* var, const, or function declaration op */
#define JOF_INDEXBASE (1U<<18) /* atom segment base setting prefix op */
/* (1U<<18) is unused */
#define JOF_PARENHEAD (1U<<20) /* opcode consumes value of expression in
parenthesized statement head */
#define JOF_INVOKE (1U<<21) /* JSOP_CALL, JSOP_NEW, JSOP_EVAL */
@@ -192,7 +192,7 @@ SET_JUMP_OFFSET(jsbytecode *pc, int32_t off)
#define UINT32_INDEX_LEN 4
static JS_ALWAYS_INLINE uint32_t
GET_UINT32_INDEX(jsbytecode *pc)
GET_UINT32_INDEX(const jsbytecode *pc)
{
return (pc[1] << 24) | (pc[2] << 16) | (pc[3] << 8) | pc[4];
}
@@ -206,22 +206,6 @@ SET_UINT32_INDEX(jsbytecode *pc, uint32_t index)
pc[4] = (jsbytecode)index;
}
/*
* A literal is indexed by a per-script atom map. Most scripts have relatively
* few literals, so the standard JOF_ATOM format specifies a fixed 16 bits of
* immediate operand index. A script with more than 64K literals must wrap the
* bytecode into an JSOP_INDEXBASE and JSOP_RESETBASE pair.
*/
#define INDEX_LEN 2
#define INDEX_HI(i) ((jsbytecode)((i) >> 8))
#define INDEX_LO(i) ((jsbytecode)(i))
#define GET_INDEX(pc) GET_UINT16(pc)
#define SET_INDEX(pc,i) ((pc)[1] = INDEX_HI(i), (pc)[2] = INDEX_LO(i))
#define GET_INDEXBASE(pc) (JS_ASSERT(*(pc) == JSOP_INDEXBASE), \
((uintN)((pc)[1])) << 16)
#define INDEXBASE_LEN 1
#define UINT24_HI(i) ((jsbytecode)((i) >> 16))
#define UINT24_MID(i) ((jsbytecode)((i) >> 8))
#define UINT24_LO(i) ((jsbytecode)(i))
@@ -320,26 +304,10 @@ js_printf(JSPrinter *jp, const char *format, ...);
extern JSBool
js_puts(JSPrinter *jp, const char *s);
/*
* Get index operand from the bytecode using a bytecode analysis to deduce the
* the index register. This function is infallible, in spite of taking cx as
* its first parameter; it uses only cx->runtime when calling JS_GetTrapOpcode.
* The GET_*_FROM_BYTECODE macros that call it pick up cx from their caller's
* lexical environments.
*/
uintN
js_GetIndexFromBytecode(JSScript *script, jsbytecode *pc, ptrdiff_t pcoff);
/*
* A slower version of GET_ATOM when the caller does not want to maintain
* the index segment register itself.
*/
#define GET_ATOM_FROM_BYTECODE(script, pc, pcoff, atom) \
JS_BEGIN_MACRO \
JS_ASSERT(*(pc) != JSOP_DOUBLE); \
JS_ASSERT(js_CodeSpec[*(pc)].format & JOF_ATOM); \
uintN index_ = js_GetIndexFromBytecode((script), (pc), (pcoff)); \
(atom) = (script)->getAtom(index_); \
(atom) = (script)->getAtom(GET_UINT32_INDEX((pc) + (pcoff))); \
JS_END_MACRO
#define GET_NAME_FROM_BYTECODE(script, pc, pcoff, name) \
@@ -350,13 +318,6 @@ js_GetIndexFromBytecode(JSScript *script, jsbytecode *pc, ptrdiff_t pcoff);
(name) = atom_->asPropertyName(); \
JS_END_MACRO
#define GET_DOUBLE_FROM_BYTECODE(script, pc, pcoff, dbl) \
JS_BEGIN_MACRO \
uintN index_ = js_GetIndexFromBytecode((script), (pc), (pcoff)); \
JS_ASSERT(index_ < (script)->consts()->length); \
(dbl) = (script)->getConst(index_).toDouble(); \
JS_END_MACRO
namespace js {
extern uintN
@@ -529,8 +490,8 @@ static inline uintN
GetDecomposeLength(jsbytecode *pc, size_t len)
{
/*
* The last byte of a DECOMPOSE op stores the decomposed length. This can
* vary across different instances of an opcode due to INDEXBASE ops.
* The last byte of a DECOMPOSE op stores the decomposed length. This is a
* constant: perhaps we should just hardcode values instead?
*/
JS_ASSERT(size_t(js_CodeSpec[*pc].length) == len);
return (uintN) pc[len - 1];