}
+Object* Heap::AllocateRawFixedArray(int length) {
+ // Allocate the raw data for a fixed array.
+ int size = FixedArray::SizeFor(length);
+ return (size > MaxHeapObjectSize())
+ ? lo_space_->AllocateRawFixedArray(size)
+ : new_space_.AllocateRaw(size);
+}
+
+
+Object* Heap::CopyFixedArray(FixedArray* src) {
+ int len = src->length();
+ Object* obj = Heap::AllocateRawFixedArray(len);
+ if (obj->IsFailure()) return obj;
+ HeapObject::cast(obj)->set_map(src->map());
+ FixedArray* result = FixedArray::cast(obj);
+ result->set_length(len);
+ FixedArray::WriteBarrierMode mode = result->GetWriteBarrierMode();
+ // Copy the content
+ for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
+ return result;
+}
+
+
+Object* Heap::AllocateFixedArray(int length) {
+ Object* result = AllocateRawFixedArray(length);
+ if (!result->IsFailure()) {
+ // Initialize header.
+ reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
+ FixedArray* array = FixedArray::cast(result);
+ array->set_length(length);
+ // Initialize body.
+ for (int index = 0; index < length; index++) array->set_undefined(index);
+ }
+ return result;
+}
+
+
Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
ASSERT(empty_fixed_array()->IsFixedArray());
if (length == 0) return empty_fixed_array();
Object* Heap::AllocateFixedArrayWithHoles(int length) {
if (length == 0) return empty_fixed_array();
- int size = FixedArray::SizeFor(length);
- Object* result = size > MaxHeapObjectSize()
- ? lo_space_->AllocateRawFixedArray(size)
- : AllocateRaw(size, NEW_SPACE);
- if (result->IsFailure()) return result;
-
- // Initialize the object.
- reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
- FixedArray* array = FixedArray::cast(result);
- array->set_length(length);
- for (int index = 0; index < length; index++) array->set_the_hole(index);
- return array;
+ Object* result = AllocateRawFixedArray(length);
+ if (!result->IsFailure()) {
+ // Initialize header.
+ reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
+ FixedArray* array = FixedArray::cast(result);
+ array->set_length(length);
+ // Initialize body.
+ for (int index = 0; index < length; index++) array->set_the_hole(index);
+ }
+ return result;
}
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
// failed.
// Please note this does not perform a garbage collection.
- static Object* AllocateFixedArray(int length,
- PretenureFlag pretenure = NOT_TENURED);
+ static Object* AllocateFixedArray(int length, PretenureFlag pretenure);
+ // Allocate uninitialized, non-tenured fixed array with length elements.
+ static Object* AllocateFixedArray(int length);
+ // Make a copy of src and return it. Returns
+ // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
+ static Object* CopyFixedArray(FixedArray* src);
// Allocates a fixed array initialized with the hole values.
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
// (since both AllocateRaw and AllocateRawMap are inlined).
static inline Object* AllocateRawMap(int size_in_bytes);
+ // Allocate unitialized fixed array (pretenure == NON_TENURE).
+ static Object* AllocateRawFixedArray(int length);
// Initializes a JSObject based on its map.
static void InitializeJSObjectFromMap(JSObject* obj,
}
+Object* FixedArray::Copy() {
+ if (length() == 0) return this;
+ return Heap::CopyFixedArray(this);
+}
+
+
#undef CAST_ACCESSOR
#undef INT_ACCESSORS
#undef SMI_ACCESSORS
String* JSObject::class_name() {
if (IsJSFunction()) return Heap::function_class_symbol();
- // If the constructor is not present "Object" is returned.
- String* result = Heap::Object_symbol();
if (map()->constructor()->IsJSFunction()) {
JSFunction* constructor = JSFunction::cast(map()->constructor());
return String::cast(constructor->shared()->instance_class_name());
}
- return result;
+ // If the constructor is not present, return "Object".
+ return Heap::Object_symbol();
}
}
-Object* FixedArray::Copy() {
- int len = length();
- if (len == 0) return this;
- Object* obj = Heap::AllocateFixedArray(len);
- if (obj->IsFailure()) return obj;
- FixedArray* result = FixedArray::cast(obj);
- WriteBarrierMode mode = result->GetWriteBarrierMode();
- // Copy the content
- for (int i = 0; i < len; i++) {
- result->set(i, get(i), mode);
- }
- result->set_map(map());
- return result;
-}
-
Object* FixedArray::CopySize(int new_length) {
if (new_length == 0) return Heap::empty_fixed_array();
Object* obj = Heap::AllocateFixedArray(new_length);
inline WriteBarrierMode GetWriteBarrierMode();
// Copy operations.
- Object* Copy();
+ inline Object* Copy();
Object* CopySize(int new_length);
// Add the elements of a JSArray to this FixedArray.