Bug 966575 part 5 -- Add length to sized array descriptors r=sfink
authorNicholas D. Matsakis <nmatsakis@mozilla.com>
Thu, 30 Jan 2014 09:02:55 -0500
changeset 168102 639a7d0a840413c4bf1638518294c83c2090dfd8
parent 168101 47b5dae4253d78b5e3fdfb3e4eafe5bb22213fcf
child 168103 7ff5470b1d28d35d607646cfd4ab0c402d6535a2
push id39654
push usernmatsakis@mozilla.com
push dateTue, 11 Feb 2014 19:39:16 +0000
treeherdermozilla-inbound@2ab85f86868a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs966575
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 966575 part 5 -- Add length to sized array descriptors r=sfink
js/src/builtin/TypedObject.cpp
js/src/builtin/TypedObject.h
js/src/builtin/TypedObject.js
js/src/builtin/TypedObjectConstants.h
--- a/js/src/builtin/TypedObject.cpp
+++ b/js/src/builtin/TypedObject.cpp
@@ -647,16 +647,18 @@ UnsizedArrayTypeDescr::dimension(JSConte
     // Create the sized type object.
     Rooted<SizedTypeDescr*> elementType(cx, &unsizedTypeDescr->elementType());
     Rooted<SizedArrayTypeDescr*> obj(cx);
     obj = ArrayMetaTypeDescr::create<SizedArrayTypeDescr>(
         cx, unsizedTypeDescr, sizedTypeReprObj, elementType);
     if (!obj)
         return false;
 
+    obj->initReservedSlot(JS_DESCR_SLOT_SIZED_ARRAY_LENGTH, Int32Value(length));
+
     // Add `length` property.
     RootedValue lengthVal(cx, Int32Value(length));
     if (!JSObject::defineProperty(cx, obj, cx->names().length,
                                   lengthVal, nullptr, nullptr,
                                   JSPROP_READONLY | JSPROP_PERMANENT))
         return nullptr;
 
     // Add `unsized` property, which is a link from the sized
--- a/js/src/builtin/TypedObject.h
+++ b/js/src/builtin/TypedObject.h
@@ -284,16 +284,20 @@ class UnsizedArrayTypeDescr : public Typ
 class SizedArrayTypeDescr : public SizedTypeDescr
 {
   public:
     static const Class class_;
 
     SizedTypeDescr &elementType() {
         return getReservedSlot(JS_DESCR_SLOT_ARRAY_ELEM_TYPE).toObject().as<SizedTypeDescr>();
     }
+
+    size_t length() {
+        return (size_t) getReservedSlot(JS_DESCR_SLOT_SIZED_ARRAY_LENGTH).toInt32();
+    }
 };
 
 /*
  * Properties and methods of the `StructType` meta type object. There
  * is no `class_` field because `StructType` is just a native
  * constructor function.
  */
 class StructMetaTypeDescr : public JSObject
--- a/js/src/builtin/TypedObject.js
+++ b/js/src/builtin/TypedObject.js
@@ -17,16 +17,18 @@
 // Type object slots
 
 #define DESCR_TYPE_REPR(obj) \
     UnsafeGetReservedSlot(obj, JS_DESCR_SLOT_TYPE_REPR)
 #define DESCR_KIND(obj) \
     REPR_KIND(DESCR_TYPE_REPR(obj))
 #define DESCR_SIZE(obj) \
     UnsafeGetReservedSlot(obj, JS_DESCR_SLOT_SIZE)
+#define DESCR_SIZED_ARRAY_LENGTH(obj) \
+    TO_INT32(UnsafeGetReservedSlot(obj, JS_DESCR_SLOT_SIZED_ARRAY_LENGTH))
 #define DESCR_TYPE(obj)   \
     UnsafeGetReservedSlot(obj, JS_DESCR_SLOT_TYPE)
 
 // Typed object slots
 
 #define DATUM_TYPE_DESCR(obj) \
     UnsafeGetReservedSlot(obj, JS_DATUM_SLOT_TYPE_DESCR)
 #define DATUM_OWNER(obj) \
@@ -111,17 +113,17 @@ function DescrToSource(descr) {
 
   case JS_TYPEREPR_UNSIZED_ARRAY_KIND:
     return "new ArrayType(" + DescrToSource(descr.elementType) + ")";
 
   case JS_TYPEREPR_SIZED_ARRAY_KIND:
     var result = ".array";
     var sep = "(";
     while (DESCR_KIND(descr) == JS_TYPEREPR_SIZED_ARRAY_KIND) {
-      result += sep + descr.length;
+      result += sep + DESCR_SIZED_ARRAY_LENGTH(descr);
       descr = descr.elementType;
       sep = ", ";
     }
     return DescrToSource(descr) + result + ")";
   }
 
   assert(false, "Unhandled kind: " + DESCR_KIND(descr));
   return undefined;
@@ -183,17 +185,17 @@ TypedObjectPointer.prototype.kind = func
   return DESCR_KIND(this.descr);
 }
 
 // Extract the length. This does a switch on kind, so it's
 // best if we can avoid it.
 TypedObjectPointer.prototype.length = function() {
   switch (this.kind()) {
   case JS_TYPEREPR_SIZED_ARRAY_KIND:
-    return this.descr.length;
+    return DESCR_SIZED_ARRAY_LENGTH(this.descr);
 
   case JS_TYPEREPR_UNSIZED_ARRAY_KIND:
     return this.datum.length;
   }
   assert(false, "Invalid kind for length");
   return false;
 }
 
@@ -208,17 +210,17 @@ TypedObjectPointer.prototype.length = fu
 TypedObjectPointer.prototype.moveTo = function(propName) {
   switch (this.kind()) {
   case JS_TYPEREPR_SCALAR_KIND:
   case JS_TYPEREPR_REFERENCE_KIND:
   case JS_TYPEREPR_X4_KIND:
     break;
 
   case JS_TYPEREPR_SIZED_ARRAY_KIND:
-    return this.moveToArray(propName, this.descr.length);
+    return this.moveToArray(propName, DESCR_SIZED_ARRAY_LENGTH(this.descr));
 
   case JS_TYPEREPR_UNSIZED_ARRAY_KIND:
     return this.moveToArray(propName, this.datum.length);
 
   case JS_TYPEREPR_STRUCT_KIND:
     if (HAS_PROPERTY(this.descr.fieldTypes, propName))
       return this.moveToField(propName);
     break;
@@ -440,17 +442,17 @@ TypedObjectPointer.prototype.set = funct
     this.setReference(fromValue);
     return;
 
   case JS_TYPEREPR_X4_KIND:
     this.setX4(fromValue);
     return;
 
   case JS_TYPEREPR_SIZED_ARRAY_KIND:
-    if (this.setArray(fromValue, this.descr.length))
+    if (this.setArray(fromValue, DESCR_SIZED_ARRAY_LENGTH(this.descr)))
       return;
     break;
 
   case JS_TYPEREPR_UNSIZED_ARRAY_KIND:
     if (this.setArray(fromValue, this.datum.length))
       return;
     break;
 
@@ -609,17 +611,17 @@ function Reify(sourceDescr,
   return ptr.get();
 }
 
 function FillTypedArrayWithValue(destArray, fromValue) {
   assert(IsObject(handle) && ObjectIsTypedDatum(destArray),
          "FillTypedArrayWithValue: not typed handle");
 
   var descr = DATUM_TYPE_DESCR(destArray);
-  var length = descr.length;
+  var length = DESCR_SIZED_ARRAY_LENGTH(descr);
   if (length === 0)
     return;
 
   // Use convert and copy to to produce the first element:
   var ptr = TypedObjectPointer.fromTypedDatum(destArray);
   ptr.moveToElem(0);
   ptr.set(fromValue);
 
--- a/js/src/builtin/TypedObjectConstants.h
+++ b/js/src/builtin/TypedObjectConstants.h
@@ -23,21 +23,24 @@
 #define JS_DESCR_SLOT_ALIGNMENT          2  // Alignment in bytes, if sized
 
 // Slots on scalars, references, and x4s
 #define JS_DESCR_SLOT_TYPE               3  // Type code
 
 // Slots on all array descriptors
 #define JS_DESCR_SLOT_ARRAY_ELEM_TYPE    3
 
+// Slots on sized array descriptors
+#define JS_DESCR_SLOT_SIZED_ARRAY_LENGTH 4
+
 // Slots on struct type objects
 #define JS_DESCR_SLOT_STRUCT_FIELD_TYPES 3
 
 // Maximum number of slots for any descriptor
-#define JS_DESCR_SLOTS                   4
+#define JS_DESCR_SLOTS                   5
 
 ///////////////////////////////////////////////////////////////////////////
 // Slots for type representation objects
 //
 // Some slots apply to all type representations and some are specific
 // to particular kinds of type representations. Because all type
 // representations share the same class, however, they always have the
 // same number of slots, though not all of them will be initialized or