summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/ArrayStorage.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/runtime/ArrayStorage.h')
-rw-r--r--Source/JavaScriptCore/runtime/ArrayStorage.h81
1 files changed, 72 insertions, 9 deletions
diff --git a/Source/JavaScriptCore/runtime/ArrayStorage.h b/Source/JavaScriptCore/runtime/ArrayStorage.h
index a0287c921..c4e596d71 100644
--- a/Source/JavaScriptCore/runtime/ArrayStorage.h
+++ b/Source/JavaScriptCore/runtime/ArrayStorage.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,16 +23,16 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ArrayStorage_h
-#define ArrayStorage_h
+#pragma once
#include "ArrayConventions.h"
#include "Butterfly.h"
#include "IndexingHeader.h"
+#include "MarkedSpace.h"
#include "SparseArrayValueMap.h"
+#include "Structure.h"
#include "WriteBarrier.h"
#include <wtf/Noncopyable.h>
-#include <wtf/Platform.h>
namespace JSC {
@@ -54,11 +54,12 @@ public:
Butterfly* butterfly() { return reinterpret_cast<Butterfly*>(this); }
IndexingHeader* indexingHeader() { return IndexingHeader::from(this); }
+ const IndexingHeader* indexingHeader() const { return IndexingHeader::from(this); }
// We steal two fields from the indexing header: vectorLength and length.
- unsigned length() { return indexingHeader()->publicLength(); }
+ unsigned length() const { return indexingHeader()->publicLength(); }
void setLength(unsigned length) { indexingHeader()->setPublicLength(length); }
- unsigned vectorLength() { return indexingHeader()->vectorLength(); }
+ unsigned vectorLength() const { return indexingHeader()->vectorLength(); }
void setVectorLength(unsigned length) { indexingHeader()->setVectorLength(length); }
ALWAYS_INLINE void copyHeaderFromDuringGC(const ArrayStorage& other)
@@ -68,6 +69,11 @@ public:
m_numValuesInVector = other.m_numValuesInVector;
}
+ bool hasHoles() const
+ {
+ return m_numValuesInVector != length();
+ }
+
bool inSparseMode()
{
return m_sparseMap && m_sparseMap->sparseMode();
@@ -94,9 +100,66 @@ public:
{
return ArrayStorage::vectorOffset() + vectorLength * sizeof(WriteBarrier<Unknown>);
}
-};
+
+ static size_t totalSizeFor(unsigned indexBias, size_t propertyCapacity, unsigned vectorLength)
+ {
+ return Butterfly::totalSize(indexBias, propertyCapacity, true, sizeFor(vectorLength));
+ }
+
+ size_t totalSize(size_t propertyCapacity) const
+ {
+ return totalSizeFor(m_indexBias, propertyCapacity, vectorLength());
+ }
+
+ size_t totalSize(Structure* structure) const
+ {
+ return totalSize(structure->outOfLineCapacity());
+ }
+
+ static unsigned availableVectorLength(unsigned indexBias, size_t propertyCapacity, unsigned vectorLength)
+ {
+ size_t cellSize = MarkedSpace::optimalSizeFor(totalSizeFor(indexBias, propertyCapacity, vectorLength));
+
+ vectorLength = (cellSize - totalSizeFor(indexBias, propertyCapacity, 0)) / sizeof(WriteBarrier<Unknown>);
-} // namespace JSC
+ return vectorLength;
+ }
+
+ static unsigned availableVectorLength(unsigned indexBias, Structure* structure, unsigned vectorLength)
+ {
+ return availableVectorLength(indexBias, structure->outOfLineCapacity(), vectorLength);
+ }
+
+ unsigned availableVectorLength(size_t propertyCapacity, unsigned vectorLength)
+ {
+ return availableVectorLength(m_indexBias, propertyCapacity, vectorLength);
+ }
+
+ unsigned availableVectorLength(Structure* structure, unsigned vectorLength)
+ {
+ return availableVectorLength(structure->outOfLineCapacity(), vectorLength);
+ }
-#endif // ArrayStorage_h
+ static unsigned optimalVectorLength(unsigned indexBias, size_t propertyCapacity, unsigned vectorLength)
+ {
+ vectorLength = std::max(BASE_ARRAY_STORAGE_VECTOR_LEN, vectorLength);
+ return availableVectorLength(indexBias, propertyCapacity, vectorLength);
+ }
+
+ static unsigned optimalVectorLength(unsigned indexBias, Structure* structure, unsigned vectorLength)
+ {
+ return optimalVectorLength(indexBias, structure->outOfLineCapacity(), vectorLength);
+ }
+
+ unsigned optimalVectorLength(size_t propertyCapacity, unsigned vectorLength)
+ {
+ return optimalVectorLength(m_indexBias, propertyCapacity, vectorLength);
+ }
+
+ unsigned optimalVectorLength(Structure* structure, unsigned vectorLength)
+ {
+ return optimalVectorLength(structure->outOfLineCapacity(), vectorLength);
+ }
+};
+} // namespace JSC