]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/ArrayConventions.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / ArrayConventions.h
index 3177c6c971eebdbd5f9d414ed914f34ea9ab074d..9c62ea9b8e559b26fbf65c52eeb7eb1f56c0301f 100644 (file)
@@ -38,7 +38,7 @@ namespace JSC {
 // (specifically, this is only one property - the value 0xFFFFFFFFU as an unsigned 32-bit
 // integer) are not considered array indices and will be stored in the JSObject property map.
 //
 // (specifically, this is only one property - the value 0xFFFFFFFFU as an unsigned 32-bit
 // integer) are not considered array indices and will be stored in the JSObject property map.
 //
-// All properties with a numeric identifer, representable as an unsigned integer i,
+// All properties with a numeric identifier, representable as an unsigned integer i,
 // where (i <= MAX_ARRAY_INDEX), are an array index and will be stored in either the
 // storage vector or the sparse map. An array index i will be handled in the following
 // fashion:
 // where (i <= MAX_ARRAY_INDEX), are an array index and will be stored in either the
 // storage vector or the sparse map. An array index i will be handled in the following
 // fashion:
@@ -58,7 +58,14 @@ namespace JSC {
 
 // These values have to be macros to be used in max() and min() without introducing
 // a PIC branch in Mach-O binaries, see <rdar://problem/5971391>.
 
 // These values have to be macros to be used in max() and min() without introducing
 // a PIC branch in Mach-O binaries, see <rdar://problem/5971391>.
+
+// If you grow an ArrayStorage array by more than this, then the array will go sparse. Note that we
+// could probably make this smaller (it's large because it used to be conflated with
+// MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH).
 #define MIN_SPARSE_ARRAY_INDEX 100000U
 #define MIN_SPARSE_ARRAY_INDEX 100000U
+// If you try to allocate a contiguous array larger than this, then we will allocate an ArrayStorage
+// array instead. We allow for an array that occupies 1GB of VM.
+#define MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH 1024 * 1024 * 1024 / 8
 #define MAX_STORAGE_VECTOR_INDEX (MAX_STORAGE_VECTOR_LENGTH - 1)
 // 0xFFFFFFFF is a bit weird -- is not an array index even though it's an integer.
 #define MAX_ARRAY_INDEX 0xFFFFFFFEU
 #define MAX_STORAGE_VECTOR_INDEX (MAX_STORAGE_VECTOR_LENGTH - 1)
 // 0xFFFFFFFF is a bit weird -- is not an array index even though it's an integer.
 #define MAX_ARRAY_INDEX 0xFFFFFFFEU
@@ -71,6 +78,8 @@ namespace JSC {
 // is added.
 #define FIRST_VECTOR_GROW 4U
 
 // is added.
 #define FIRST_VECTOR_GROW 4U
 
+#define MIN_BEYOND_LENGTH_SPARSE_INDEX 1000
+
 // Our policy for when to use a vector and when to use a sparse map.
 // For all array indices under MIN_SPARSE_ARRAY_INDEX, we always use a vector.
 // When indices greater than MIN_SPARSE_ARRAY_INDEX are involved, we use a vector
 // Our policy for when to use a vector and when to use a sparse map.
 // For all array indices under MIN_SPARSE_ARRAY_INDEX, we always use a vector.
 // When indices greater than MIN_SPARSE_ARRAY_INDEX are involved, we use a vector
@@ -82,6 +91,11 @@ inline bool isDenseEnoughForVector(unsigned length, unsigned numValues)
     return length / minDensityMultiplier <= numValues;
 }
 
     return length / minDensityMultiplier <= numValues;
 }
 
+inline bool indexIsSufficientlyBeyondLengthForSparseMap(unsigned i, unsigned length)
+{
+    return i >= MIN_BEYOND_LENGTH_SPARSE_INDEX && i > length;
+}
+
 inline IndexingHeader indexingHeaderForArray(unsigned length, unsigned vectorLength)
 {
     IndexingHeader result;
 inline IndexingHeader indexingHeaderForArray(unsigned length, unsigned vectorLength)
 {
     IndexingHeader result;