Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Unified Diff: src/heap.cc

Issue 101413006: Implement in-heap backing store for typed arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Self-review Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index c42c445af9a33dc5d5026d009a74896f241de4b9..d664cba90e066c8b41c64adab006e8a8d0ec299b 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -2822,6 +2822,60 @@ bool Heap::CreateInitialMaps() {
}
set_external_float_array_map(Map::cast(obj));
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT8_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
Toon Verwaest 2013/12/23 10:40:32 Can we already change all these ToObject to To, on
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 Done (+ more boilerplate scratching) On 2013/12/23
+ }
+ set_fixed_uint8_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_INT8_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_int8_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT16_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_uint16_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_INT16_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_int16_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT32_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_uint32_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_INT32_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_int32_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_FLOAT32_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_float32_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_FLOAT64_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_float64_array_map(Map::cast(obj));
+
+ { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT8_CLAMPED_ARRAY_TYPE,
+ kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_fixed_uint8_clamped_array_map(Map::cast(obj));
+
{ MaybeObject* maybe_obj =
AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
if (!maybe_obj->ToObject(&obj)) return false;
@@ -3689,6 +3743,39 @@ Heap::RootListIndex Heap::RootIndexForExternalArrayType(
}
}
+
+Map* Heap::MapForFixedTypedArray(ExternalArrayType array_type) {
+ return Map::cast(roots_[RootIndexForFixedTypedArray(array_type)]);
+}
+
+
+Heap::RootListIndex Heap::RootIndexForFixedTypedArray(
+ ExternalArrayType array_type) {
+ switch (array_type) {
+ case kExternalByteArray:
+ return kFixedInt8ArrayMapRootIndex;
+ case kExternalUnsignedByteArray:
+ return kFixedUint8ArrayMapRootIndex;
+ case kExternalShortArray:
+ return kFixedInt16ArrayMapRootIndex;
+ case kExternalUnsignedShortArray:
+ return kFixedUint16ArrayMapRootIndex;
+ case kExternalIntArray:
+ return kFixedInt32ArrayMapRootIndex;
+ case kExternalUnsignedIntArray:
+ return kFixedUint32ArrayMapRootIndex;
+ case kExternalFloatArray:
+ return kFixedFloat32ArrayMapRootIndex;
+ case kExternalDoubleArray:
+ return kFixedFloat64ArrayMapRootIndex;
+ case kExternalPixelArray:
+ return kFixedUint8ClampedArrayMapRootIndex;
+ default:
+ UNREACHABLE();
+ return kUndefinedValueRootIndex;
+ }
+}
+
Heap::RootListIndex Heap::RootIndexForEmptyExternalArray(
ElementsKind elementsKind) {
switch (elementsKind) {
@@ -4210,6 +4297,72 @@ MaybeObject* Heap::AllocateExternalArray(int length,
return result;
}
+static void ForFixedTypedArray(ExternalArrayType array_type,
+ int* element_size,
+ ElementsKind* element_kind) {
+ switch (array_type) {
+ case kExternalUnsignedByteArray:
+ *element_size = 1;
+ *element_kind = UINT8_ELEMENTS;
+ return;
+ case kExternalByteArray:
+ *element_size = 1;
+ *element_kind = INT8_ELEMENTS;
+ return;
+ case kExternalUnsignedShortArray:
+ *element_size = 2;
+ *element_kind = UINT16_ELEMENTS;
+ return;
+ case kExternalShortArray:
+ *element_size = 2;
+ *element_kind = INT16_ELEMENTS;
+ return;
+ case kExternalUnsignedIntArray:
+ *element_size = 4;
+ *element_kind = UINT32_ELEMENTS;
+ return;
+ case kExternalIntArray:
+ *element_size = 4;
+ *element_kind = INT32_ELEMENTS;
+ return;
+ case kExternalFloatArray:
+ *element_size = 4;
+ *element_kind = FLOAT32_ELEMENTS;
+ return;
+ case kExternalDoubleArray:
+ *element_size = 8;
+ *element_kind = FLOAT64_ELEMENTS;
+ return;
+ case kExternalPixelArray:
+ *element_size = 1;
+ *element_kind = UINT8_CLAMPED_ELEMENTS;
+ return;
+ default:
+ UNREACHABLE();
+ }
+}
+
+
+MaybeObject* Heap::AllocateFixedTypedArray(int length,
+ ExternalArrayType array_type,
+ PretenureFlag pretenure) {
+ int element_size = 1; // Bogus.
Toon Verwaest 2013/12/23 10:40:32 Doesn't it work to set element_size and elements_k
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 Done.
+ ElementsKind elements_kind = UINT8_ELEMENTS; // Bogus.
+ ForFixedTypedArray(array_type, &element_size, &elements_kind);
+ int size = length * element_size + FixedTypedArrayBase::kDataOffset;
+ AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
+
+ HeapObject* object;
+ { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_DATA_SPACE);
Toon Verwaest 2013/12/23 10:40:32 Remove the { ... }.
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 Done.
+ if (!maybe_object->To<HeapObject>(&object)) return maybe_object;
Toon Verwaest 2013/12/23 10:40:32 Is the <HeapObject> really necessary? If not remov
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 No because FixedTypedArrayBase::cast checks map as
+ }
+ FixedTypedArrayBase* elements =
+ reinterpret_cast<FixedTypedArrayBase*>(object);
+ elements->set_map(MapForFixedTypedArray(array_type));
+ elements->set_length(length);
+ return elements;
+}
+
MaybeObject* Heap::CreateCode(const CodeDesc& desc,
Code::Flags flags,
@@ -6987,6 +7140,10 @@ void Heap::EnsureWeakObjectToCodeTable() {
}
+void Heap::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
+ v8::internal::V8::FatalProcessOutOfMemory(location, take_snapshot);
+}
+
#ifdef DEBUG
class PrintHandleVisitor: public ObjectVisitor {

Powered by Google App Engine
This is Rietveld 408576698