Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc. 2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions. 3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp. 4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path. 5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property. 6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved). 7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew. 8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function. 9. JSTraceableNative loses its premature-deadwood tclasp member (my bad). 10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now. 11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning). 12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
This commit is contained in:
@@ -102,9 +102,6 @@
|
||||
#define MAXINDEX 4294967295u
|
||||
#define MAXSTR "4294967295"
|
||||
|
||||
#define ARRAY_SET_DENSE_LENGTH(obj, max) \
|
||||
(JS_ASSERT((obj)->dslots), (obj)->dslots[-1] = (jsval)(max))
|
||||
|
||||
/* Small arrays are dense, no matter what. */
|
||||
#define MIN_SPARSE_INDEX 32
|
||||
|
||||
@@ -344,8 +341,6 @@ ResizeSlots(JSContext *cx, JSObject *obj, uint32 oldlen, uint32 len)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#define ARRAY_GROWBY 8
|
||||
|
||||
static JSBool
|
||||
EnsureLength(JSContext *cx, JSObject *obj, uint32 len)
|
||||
{
|
||||
@@ -413,11 +408,8 @@ SetArrayElement(JSContext *cx, JSObject *obj, jsuint index, jsval v)
|
||||
jsid id;
|
||||
|
||||
if (OBJ_IS_DENSE_ARRAY(cx, obj)) {
|
||||
if (INDEX_TOO_SPARSE(obj, index)) {
|
||||
if (!js_MakeArraySlow(cx, obj))
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
|
||||
/* Predicted/prefeched code should favor the remains-dense case. */
|
||||
if (!INDEX_TOO_SPARSE(obj, index)) {
|
||||
if (!EnsureLength(cx, obj, index + 1))
|
||||
return JS_FALSE;
|
||||
if (index >= (uint32)obj->fslots[JSSLOT_ARRAY_LENGTH])
|
||||
@@ -427,6 +419,9 @@ SetArrayElement(JSContext *cx, JSObject *obj, jsuint index, jsval v)
|
||||
obj->dslots[index] = v;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (!js_MakeArraySlow(cx, obj))
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (index <= JSVAL_INT_MAX) {
|
||||
@@ -1164,8 +1159,16 @@ js_MakeArraySlow(JSContext *cx, JSObject *obj)
|
||||
goto out_bad;
|
||||
}
|
||||
|
||||
/* Render our formerly-reserved count property GC-safe. */
|
||||
obj->fslots[JSSLOT_ARRAY_COUNT] = JSVAL_VOID;
|
||||
/*
|
||||
* Render our formerly-reserved count property GC-safe. If length fits in
|
||||
* a jsval, set our slow/sparse COUNT to the current length as a jsval, so
|
||||
* we can tell when only named properties have been added to a dense array
|
||||
* to make it slow-but-not-sparse.
|
||||
*/
|
||||
length = obj->fslots[JSSLOT_ARRAY_LENGTH];
|
||||
obj->fslots[JSSLOT_ARRAY_COUNT] = INT_FITS_IN_JSVAL(length)
|
||||
? INT_TO_JSVAL(length)
|
||||
: JSVAL_VOID;
|
||||
|
||||
/* Make sure we preserve any flags borrowing bits in JSSLOT_CLASS. */
|
||||
obj->fslots[JSSLOT_CLASS] ^= (jsval) &js_ArrayClass;
|
||||
|
||||
Reference in New Issue
Block a user