| Index: src/heap.cc
|
| ===================================================================
|
| --- src/heap.cc (revision 5559)
|
| +++ src/heap.cc (working copy)
|
| @@ -1402,9 +1402,11 @@
|
|
|
|
|
| Object* Heap::AllocatePartialMap(InstanceType instance_type,
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawMap();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| int instance_size) {
|
| - Object* result = AllocateRawMap();
|
| - if (result->IsFailure()) return result;
|
|
|
| // Map::cast cannot be used due to uninitialized map field.
|
| reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map());
|
| @@ -1422,9 +1424,11 @@
|
| }
|
|
|
|
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawMap();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) {
|
| - Object* result = AllocateRawMap();
|
| - if (result->IsFailure()) return result;
|
|
|
| Map* map = reinterpret_cast<Map*>(result);
|
| map->set_map(meta_map());
|
| @@ -1452,9 +1456,11 @@
|
| }
|
|
|
|
|
| + Object* result;
|
| + { TryAllocation t = AllocateStruct(CODE_CACHE_TYPE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Object* Heap::AllocateCodeCache() {
|
| - Object* result = AllocateStruct(CODE_CACHE_TYPE);
|
| - if (result->IsFailure()) return result;
|
| CodeCache* code_cache = CodeCache::cast(result);
|
| code_cache->set_default_cache(empty_fixed_array());
|
| code_cache->set_normal_type_cache(undefined_value());
|
| @@ -1486,34 +1492,42 @@
|
| };
|
|
|
|
|
| + Object* obj;
|
| + { TryAllocation t = AllocatePartialMap(MAP_TYPE, Map::kSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| bool Heap::CreateInitialMaps() {
|
| - Object* obj = AllocatePartialMap(MAP_TYPE, Map::kSize);
|
| - if (obj->IsFailure()) return false;
|
| // Map::cast cannot be used due to uninitialized map field.
|
| Map* new_meta_map = reinterpret_cast<Map*>(obj);
|
| set_meta_map(new_meta_map);
|
| new_meta_map->set_map(new_meta_map);
|
| + { TryAllocation t =
|
| + AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_fixed_array_map(Map::cast(obj));
|
| + { TryAllocation t = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize);
|
| - if (obj->IsFailure()) return false;
|
| set_oddball_map(Map::cast(obj));
|
|
|
| + { TryAllocation t = AllocateEmptyFixedArray();
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate the empty array.
|
| - obj = AllocateEmptyFixedArray();
|
| - if (obj->IsFailure()) return false;
|
| set_empty_fixed_array(FixedArray::cast(obj));
|
| + { TryAllocation t = Allocate(oddball_map(), OLD_DATA_SPACE);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = Allocate(oddball_map(), OLD_DATA_SPACE);
|
| - if (obj->IsFailure()) return false;
|
| set_null_value(obj);
|
|
|
| + { TryAllocation t = AllocateEmptyFixedArray();
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate the empty descriptor array.
|
| - obj = AllocateEmptyFixedArray();
|
| - if (obj->IsFailure()) return false;
|
| set_empty_descriptor_array(DescriptorArray::cast(obj));
|
|
|
| // Fix the instance_descriptors for the existing maps.
|
| @@ -1535,123 +1549,148 @@
|
|
|
| oddball_map()->set_prototype(null_value());
|
| oddball_map()->set_constructor(null_value());
|
| + { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_fixed_cow_array_map(Map::cast(obj));
|
| ASSERT(fixed_array_map() != fixed_cow_array_map());
|
| + { TryAllocation t = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
|
| - if (obj->IsFailure()) return false;
|
| set_heap_number_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(PROXY_TYPE, Proxy::kSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(PROXY_TYPE, Proxy::kSize);
|
| - if (obj->IsFailure()) return false;
|
| set_proxy_map(Map::cast(obj));
|
|
|
| for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
|
| + { TryAllocation t = AllocateMap(entry.type, entry.size);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| const StringTypeTable& entry = string_type_table[i];
|
| - obj = AllocateMap(entry.type, entry.size);
|
| - if (obj->IsFailure()) return false;
|
| roots_[entry.index] = Map::cast(obj);
|
| }
|
| + { TryAllocation t = AllocateMap(STRING_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(STRING_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_undetectable_string_map(Map::cast(obj));
|
| Map::cast(obj)->set_is_undetectable();
|
| + { TryAllocation t = AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_undetectable_ascii_string_map(Map::cast(obj));
|
| Map::cast(obj)->set_is_undetectable();
|
| + { TryAllocation t = AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_byte_array_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| set_pixel_array_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE,
|
| - ExternalArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE,
|
| + ExternalArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_external_byte_array_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
|
| - ExternalArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
|
| + ExternalArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_external_unsigned_byte_array_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE,
|
| - ExternalArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE,
|
| + ExternalArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_external_short_array_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
|
| - ExternalArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
|
| + ExternalArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_external_unsigned_short_array_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(EXTERNAL_INT_ARRAY_TYPE,
|
| - ExternalArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(EXTERNAL_INT_ARRAY_TYPE,
|
| + ExternalArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_external_int_array_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
|
| - ExternalArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
|
| + ExternalArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_external_unsigned_int_array_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE,
|
| - ExternalArray::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE,
|
| + ExternalArray::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_external_float_array_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(CODE_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_code_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE,
|
| - JSGlobalPropertyCell::kSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE,
|
| + JSGlobalPropertyCell::kSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_global_property_cell_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(FILLER_TYPE, kPointerSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(FILLER_TYPE, kPointerSize);
|
| - if (obj->IsFailure()) return false;
|
| set_one_pointer_filler_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(FILLER_TYPE, 2 * kPointerSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize);
|
| - if (obj->IsFailure()) return false;
|
| set_two_pointer_filler_map(Map::cast(obj));
|
|
|
| for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) {
|
| + { TryAllocation t = AllocateMap(entry.type, entry.size);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| const StructTable& entry = struct_table[i];
|
| - obj = AllocateMap(entry.type, entry.size);
|
| - if (obj->IsFailure()) return false;
|
| roots_[entry.index] = Map::cast(obj);
|
| }
|
| + { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_hash_table_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_context_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_catch_context_map(Map::cast(obj));
|
| + { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
| - if (obj->IsFailure()) return false;
|
| set_global_context_map(Map::cast(obj));
|
|
|
| - obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE,
|
| - SharedFunctionInfo::kAlignedSize);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = AllocateMap(SHARED_FUNCTION_INFO_TYPE,
|
| + SharedFunctionInfo::kAlignedSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_shared_function_info_map(Map::cast(obj));
|
|
|
| ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array()));
|
| @@ -1664,9 +1703,11 @@
|
| // spaces.
|
| STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
|
| AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
|
| + Object* result;
|
| + { TryAllocation t = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
|
| - if (result->IsFailure()) return result;
|
|
|
| HeapObject::cast(result)->set_map(heap_number_map());
|
| HeapNumber::cast(result)->set_value(value);
|
| @@ -1681,18 +1722,22 @@
|
| // This version of AllocateHeapNumber is optimized for
|
| // allocation in new space.
|
| STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
|
| + Object* result;
|
| + { TryAllocation t = new_space_.AllocateRaw(HeapNumber::kSize);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
|
| - Object* result = new_space_.AllocateRaw(HeapNumber::kSize);
|
| - if (result->IsFailure()) return result;
|
| HeapObject::cast(result)->set_map(heap_number_map());
|
| HeapNumber::cast(result)->set_value(value);
|
| return result;
|
| }
|
|
|
|
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawCell();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Object* Heap::AllocateJSGlobalPropertyCell(Object* value) {
|
| - Object* result = AllocateRawCell();
|
| - if (result->IsFailure()) return result;
|
| HeapObject::cast(result)->set_map(global_property_cell_map());
|
| JSGlobalPropertyCell::cast(result)->set_value(value);
|
| return result;
|
| @@ -1700,24 +1745,30 @@
|
|
|
|
|
| Object* Heap::CreateOddball(const char* to_string,
|
| + Object* result;
|
| + { TryAllocation t = Allocate(oddball_map(), OLD_DATA_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Object* to_number) {
|
| - Object* result = Allocate(oddball_map(), OLD_DATA_SPACE);
|
| - if (result->IsFailure()) return result;
|
| return Oddball::cast(result)->Initialize(to_string, to_number);
|
| }
|
|
|
|
|
| bool Heap::CreateApiObjects() {
|
| Object* obj;
|
| + { TryAllocation t = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
| - if (obj->IsFailure()) return false;
|
| set_neander_map(Map::cast(obj));
|
| + { TryAllocation t = Heap::AllocateJSObjectFromMap(neander_map());
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = Heap::AllocateJSObjectFromMap(neander_map());
|
| - if (obj->IsFailure()) return false;
|
| - Object* elements = AllocateFixedArray(2);
|
| - if (elements->IsFailure()) return false;
|
| + Object* elements;
|
| + { TryAllocation t = AllocateFixedArray(2);
|
| + if (!t->ToObject(&elements)) return false;
|
| + }
|
| FixedArray::cast(elements)->set(0, Smi::FromInt(0));
|
| JSObject::cast(obj)->set_elements(FixedArray::cast(elements));
|
| set_message_listeners(JSObject::cast(obj));
|
| @@ -1778,65 +1829,81 @@
|
| bool Heap::CreateInitialObjects() {
|
| Object* obj;
|
|
|
| + { TryAllocation t = AllocateHeapNumber(-0.0, TENURED);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // The -0 value must be set before NumberFromDouble works.
|
| - obj = AllocateHeapNumber(-0.0, TENURED);
|
| - if (obj->IsFailure()) return false;
|
| set_minus_zero_value(obj);
|
| ASSERT(signbit(minus_zero_value()->Number()) != 0);
|
| + { TryAllocation t = AllocateHeapNumber(OS::nan_value(), TENURED);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = AllocateHeapNumber(OS::nan_value(), TENURED);
|
| - if (obj->IsFailure()) return false;
|
| set_nan_value(obj);
|
| + { TryAllocation t = Allocate(oddball_map(), OLD_DATA_SPACE);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = Allocate(oddball_map(), OLD_DATA_SPACE);
|
| - if (obj->IsFailure()) return false;
|
| set_undefined_value(obj);
|
| ASSERT(!InNewSpace(undefined_value()));
|
|
|
| + { TryAllocation t = SymbolTable::Allocate(kInitialSymbolTableSize);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate initial symbol table.
|
| - obj = SymbolTable::Allocate(kInitialSymbolTableSize);
|
| - if (obj->IsFailure()) return false;
|
| // Don't use set_symbol_table() due to asserts.
|
| roots_[kSymbolTableRootIndex] = obj;
|
|
|
| + Object* symbol;
|
| + { TryAllocation t = LookupAsciiSymbol("undefined");
|
| + if (!t->ToObject(&symbol)) return false;
|
| + }
|
| // Assign the print strings for oddballs after creating symboltable.
|
| - Object* symbol = LookupAsciiSymbol("undefined");
|
| - if (symbol->IsFailure()) return false;
|
| Oddball::cast(undefined_value())->set_to_string(String::cast(symbol));
|
| Oddball::cast(undefined_value())->set_to_number(nan_value());
|
|
|
| + { TryAllocation t =
|
| + Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0));
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate the null_value
|
| - obj = Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0));
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = CreateOddball("true", Smi::FromInt(1));
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = CreateOddball("true", Smi::FromInt(1));
|
| - if (obj->IsFailure()) return false;
|
| set_true_value(obj);
|
| + { TryAllocation t = CreateOddball("false", Smi::FromInt(0));
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = CreateOddball("false", Smi::FromInt(0));
|
| - if (obj->IsFailure()) return false;
|
| set_false_value(obj);
|
| + { TryAllocation t = CreateOddball("hole", Smi::FromInt(-1));
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = CreateOddball("hole", Smi::FromInt(-1));
|
| - if (obj->IsFailure()) return false;
|
| set_the_hole_value(obj);
|
| + { TryAllocation t =
|
| + CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2));
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2));
|
| - if (obj->IsFailure()) return false;
|
| set_no_interceptor_result_sentinel(obj);
|
| + { TryAllocation t = CreateOddball("termination_exception", Smi::FromInt(-3));
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
|
|
| - obj = CreateOddball("termination_exception", Smi::FromInt(-3));
|
| - if (obj->IsFailure()) return false;
|
| set_termination_exception(obj);
|
|
|
| + { TryAllocation t = AllocateRawAsciiString(0, TENURED);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate the empty string.
|
| - obj = AllocateRawAsciiString(0, TENURED);
|
| - if (obj->IsFailure()) return false;
|
| set_empty_string(String::cast(obj));
|
|
|
| + { TryAllocation t = LookupAsciiSymbol(constant_symbol_table[i].contents);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| for (unsigned i = 0; i < ARRAY_SIZE(constant_symbol_table); i++) {
|
| - obj = LookupAsciiSymbol(constant_symbol_table[i].contents);
|
| - if (obj->IsFailure()) return false;
|
| roots_[constant_symbol_table[i].index] = String::cast(obj);
|
| }
|
|
|
| @@ -1845,26 +1912,30 @@
|
| // the empty string when searching for the property. It cannot be part of the
|
| // loop above because it needs to be allocated manually with the special
|
| // hash code in place. The hash code for the hidden_symbol is zero to ensure
|
| + { TryAllocation t = AllocateSymbol(CStrVector(""), 0, String::kZeroHash);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // that it will always be at the first entry in property descriptors.
|
| - obj = AllocateSymbol(CStrVector(""), 0, String::kZeroHash);
|
| - if (obj->IsFailure()) return false;
|
| hidden_symbol_ = String::cast(obj);
|
|
|
| + { TryAllocation t = AllocateProxy((Address) &Accessors::ObjectPrototype);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate the proxy for __proto__.
|
| - obj = AllocateProxy((Address) &Accessors::ObjectPrototype);
|
| - if (obj->IsFailure()) return false;
|
| set_prototype_accessors(Proxy::cast(obj));
|
|
|
| // Allocate the code_stubs dictionary. The initial size is set to avoid
|
| + { TryAllocation t = NumberDictionary::Allocate(128);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // expanding the dictionary during bootstrapping.
|
| - obj = NumberDictionary::Allocate(128);
|
| - if (obj->IsFailure()) return false;
|
| set_code_stubs(NumberDictionary::cast(obj));
|
|
|
| // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size
|
| + { TryAllocation t = NumberDictionary::Allocate(64);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // is set to avoid expanding the dictionary during bootstrapping.
|
| - obj = NumberDictionary::Allocate(64);
|
| - if (obj->IsFailure()) return false;
|
| set_non_monomorphic_cache(NumberDictionary::cast(obj));
|
|
|
| set_instanceof_cache_function(Smi::FromInt(0));
|
| @@ -1873,23 +1944,28 @@
|
|
|
| CreateFixedStubs();
|
|
|
| + { TryAllocation t = StringDictionary::Allocate(Runtime::kNumFunctions);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate the dictionary of intrinsic function names.
|
| - obj = StringDictionary::Allocate(Runtime::kNumFunctions);
|
| - if (obj->IsFailure()) return false;
|
| - obj = Runtime::InitializeIntrinsicFunctionNames(obj);
|
| - if (obj->IsFailure()) return false;
|
| + { TryAllocation t = Runtime::InitializeIntrinsicFunctionNames(obj);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| set_intrinsic_function_names(StringDictionary::cast(obj));
|
|
|
| if (InitializeNumberStringCache()->IsFailure()) return false;
|
|
|
| + { TryAllocation t =
|
| + AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate cache for single character ASCII strings.
|
| - obj = AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
|
| - if (obj->IsFailure()) return false;
|
| set_single_character_string_cache(FixedArray::cast(obj));
|
|
|
| + { TryAllocation t = AllocateFixedArray(Natives::GetBuiltinsCount());
|
| + if (!t->ToObject(&obj)) return false;
|
| + }
|
| // Allocate cache for external strings pointing to native source code.
|
| - obj = AllocateFixedArray(Natives::GetBuiltinsCount());
|
| - if (obj->IsFailure()) return false;
|
| set_natives_source_cache(FixedArray::cast(obj));
|
|
|
| // Handling of script id generation is in Factory::NewScript.
|
| @@ -2058,18 +2134,22 @@
|
| Object* Heap::AllocateProxy(Address proxy, PretenureFlag pretenure) {
|
| // Statically ensure that it is safe to allocate proxies in paged spaces.
|
| STATIC_ASSERT(Proxy::kSize <= Page::kMaxHeapObjectSize);
|
| + Object* result;
|
| + { TryAllocation t = Allocate(proxy_map(), space);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
|
| - Object* result = Allocate(proxy_map(), space);
|
| - if (result->IsFailure()) return result;
|
|
|
| Proxy::cast(result)->set_proxy(proxy);
|
| return result;
|
| }
|
|
|
|
|
| + Object* result;
|
| + { TryAllocation t = Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Object* Heap::AllocateSharedFunctionInfo(Object* name) {
|
| - Object* result = Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
|
| - if (result->IsFailure()) return result;
|
|
|
| SharedFunctionInfo* share = SharedFunctionInfo::cast(result);
|
| share->set_name(name);
|
| @@ -2115,16 +2195,20 @@
|
| // Now we know the length is 2, we might as well make use of that fact
|
| // when building the new string.
|
| } else if ((c1 | c2) <= String::kMaxAsciiCharCodeU) { // We can do this
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateRawAsciiString(2);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| ASSERT(IsPowerOf2(String::kMaxAsciiCharCodeU + 1)); // because of this.
|
| - Object* result = Heap::AllocateRawAsciiString(2);
|
| - if (result->IsFailure()) return result;
|
| char* dest = SeqAsciiString::cast(result)->GetChars();
|
| dest[0] = c1;
|
| dest[1] = c2;
|
| return result;
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateRawTwoByteString(2);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| } else {
|
| - Object* result = Heap::AllocateRawTwoByteString(2);
|
| - if (result->IsFailure()) return result;
|
| uc16* dest = SeqTwoByteString::cast(result)->GetChars();
|
| dest[0] = c1;
|
| dest[1] = c2;
|
| @@ -2182,9 +2266,11 @@
|
| if (length < String::kMinNonFlatLength) {
|
| ASSERT(first->IsFlat());
|
| ASSERT(second->IsFlat());
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawAsciiString(length);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| if (is_ascii) {
|
| - Object* result = AllocateRawAsciiString(length);
|
| - if (result->IsFailure()) return result;
|
| // Copy the characters into the new object.
|
| char* dest = SeqAsciiString::cast(result)->GetChars();
|
| // Copy first part.
|
| @@ -2204,18 +2290,22 @@
|
| for (int i = 0; i < second_length; i++) *dest++ = src[i];
|
| return result;
|
| } else {
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawAsciiString(length);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| if (is_ascii_data_in_two_byte_string) {
|
| - Object* result = AllocateRawAsciiString(length);
|
| - if (result->IsFailure()) return result;
|
| // Copy the characters into the new object.
|
| char* dest = SeqAsciiString::cast(result)->GetChars();
|
| String::WriteToFlat(first, dest, 0, first_length);
|
| String::WriteToFlat(second, dest + first_length, 0, second_length);
|
| return result;
|
| }
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawTwoByteString(length);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - Object* result = AllocateRawTwoByteString(length);
|
| - if (result->IsFailure()) return result;
|
| // Copy the characters into the new object.
|
| uc16* dest = SeqTwoByteString::cast(result)->GetChars();
|
| String::WriteToFlat(first, dest, 0, first_length);
|
| @@ -2226,9 +2316,11 @@
|
|
|
| Map* map = (is_ascii || is_ascii_data_in_two_byte_string) ?
|
| cons_ascii_string_map() : cons_string_map();
|
| + Object* result;
|
| + { TryAllocation t = Allocate(map, NEW_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - Object* result = Allocate(map, NEW_SPACE);
|
| - if (result->IsFailure()) return result;
|
|
|
| AssertNoAllocation no_gc;
|
| ConsString* cons_string = ConsString::cast(result);
|
| @@ -2290,9 +2382,11 @@
|
| return Failure::OutOfMemoryException();
|
| }
|
|
|
| + Object* result;
|
| + { TryAllocation t = Allocate(map, NEW_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Map* map = external_ascii_string_map();
|
| - Object* result = Allocate(map, NEW_SPACE);
|
| - if (result->IsFailure()) return result;
|
|
|
| ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
|
| external_string->set_length(static_cast<int>(length));
|
| @@ -2327,9 +2421,11 @@
|
| }
|
|
|
| Map* map = is_ascii ?
|
| + Object* result;
|
| + { TryAllocation t = Allocate(map, NEW_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Heap::external_string_with_ascii_data_map() : Heap::external_string_map();
|
| - Object* result = Allocate(map, NEW_SPACE);
|
| - if (result->IsFailure()) return result;
|
|
|
| ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result);
|
| external_string->set_length(static_cast<int>(length));
|
| @@ -2353,9 +2449,11 @@
|
| Heap::single_character_string_cache()->set(code, result);
|
| return result;
|
| }
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateRawTwoByteString(1);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - Object* result = Heap::AllocateRawTwoByteString(1);
|
| - if (result->IsFailure()) return result;
|
| String* answer = String::cast(result);
|
| answer->Set(0, code);
|
| return answer;
|
| @@ -2387,9 +2485,11 @@
|
| }
|
| int size = ByteArray::SizeFor(length);
|
| AllocationSpace space =
|
| + Object* result;
|
| + { TryAllocation t = AllocateRaw(size, space, OLD_DATA_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE;
|
| - Object* result = AllocateRaw(size, space, OLD_DATA_SPACE);
|
| - if (result->IsFailure()) return result;
|
|
|
| reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map());
|
| reinterpret_cast<ByteArray*>(result)->set_length(length);
|
| @@ -2414,9 +2514,12 @@
|
| Object* Heap::AllocatePixelArray(int length,
|
| uint8_t* external_pointer,
|
| PretenureFlag pretenure) {
|
| + Object* result;
|
| + { TryAllocation t =
|
| + AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
|
| - Object* result = AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE);
|
| - if (result->IsFailure()) return result;
|
|
|
| reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map());
|
| reinterpret_cast<PixelArray*>(result)->set_length(length);
|
| @@ -2450,9 +2553,11 @@
|
| Code::Flags flags,
|
| Handle<Object> self_reference) {
|
| // Allocate ByteArray before the Code object, so that we do not risk
|
| + Object* reloc_info;
|
| + { TryAllocation t = AllocateByteArray(desc.reloc_size, TENURED);
|
| + if (!t->ToObject(&reloc_info)) return t;
|
| + }
|
| // leaving uninitialized Code object (and breaking the heap).
|
| - Object* reloc_info = AllocateByteArray(desc.reloc_size, TENURED);
|
| - if (reloc_info->IsFailure()) return reloc_info;
|
|
|
| // Compute size
|
| int body_size = RoundUp(desc.instr_size, kObjectAlignment);
|
| @@ -2519,9 +2624,11 @@
|
|
|
| Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
|
| // Allocate ByteArray before the Code object, so that we do not risk
|
| + Object* reloc_info_array;
|
| + { TryAllocation t = AllocateByteArray(reloc_info.length(), TENURED);
|
| + if (!t->ToObject(&reloc_info_array)) return t;
|
| + }
|
| // leaving uninitialized Code object (and breaking the heap).
|
| - Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED);
|
| - if (reloc_info_array->IsFailure()) return reloc_info_array;
|
|
|
| int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment);
|
|
|
| @@ -2571,9 +2678,11 @@
|
| // space when new space is full and the object is not a large object.
|
| AllocationSpace retry_space =
|
| (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type());
|
| - Object* result =
|
| - AllocateRaw(map->instance_size(), space, retry_space);
|
| - if (result->IsFailure()) return result;
|
| + Object* result;
|
| + { TryAllocation t =
|
| + AllocateRaw(map->instance_size(), space, retry_space);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| HeapObject::cast(result)->set_map(map);
|
| #ifdef ENABLE_LOGGING_AND_PROFILING
|
| ProducerHeapProfile::RecordJSObjectAllocation(result);
|
| @@ -2602,9 +2711,11 @@
|
| // from the function's context, since the function can be from a
|
| // different context.
|
| JSFunction* object_function =
|
| + Object* prototype;
|
| + { TryAllocation t = AllocateJSObject(object_function);
|
| + if (!t->ToObject(&prototype)) return t;
|
| + }
|
| function->context()->global_context()->object_function();
|
| - Object* prototype = AllocateJSObject(object_function);
|
| - if (prototype->IsFailure()) return prototype;
|
| // When creating the prototype for the function we must set its
|
| // constructor to the function.
|
| Object* result =
|
| @@ -2621,9 +2732,11 @@
|
| Object* prototype,
|
| PretenureFlag pretenure) {
|
| AllocationSpace space =
|
| + Object* result;
|
| + { TryAllocation t = Allocate(function_map, space);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
|
| - Object* result = Allocate(function_map, space);
|
| - if (result->IsFailure()) return result;
|
| return InitializeFunction(JSFunction::cast(result), shared, prototype);
|
| }
|
|
|
| @@ -2645,9 +2758,11 @@
|
| ASSERT(kArgumentsObjectSize == boilerplate->map()->instance_size());
|
|
|
| // Do the allocation.
|
| - Object* result =
|
| - AllocateRaw(kArgumentsObjectSize, NEW_SPACE, OLD_POINTER_SPACE);
|
| - if (result->IsFailure()) return result;
|
| + Object* result;
|
| + { TryAllocation t =
|
| + AllocateRaw(kArgumentsObjectSize, NEW_SPACE, OLD_POINTER_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| // Copy the content. The arguments boilerplate doesn't have any
|
| // fields that point to new space so it's safe to skip the write
|
| @@ -2691,17 +2806,20 @@
|
| // First create a new map with the size and number of in-object properties
|
| // suggested by the function.
|
| int instance_size = fun->shared()->CalculateInstanceSize();
|
| + Object* map_obj;
|
| + { TryAllocation t = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size);
|
| + if (!t->ToObject(&map_obj)) return t;
|
| + }
|
| int in_object_properties = fun->shared()->CalculateInObjectProperties();
|
| - Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size);
|
| - if (map_obj->IsFailure()) return map_obj;
|
|
|
| // Fetch or allocate prototype.
|
| Object* prototype;
|
| if (fun->has_instance_prototype()) {
|
| prototype = fun->instance_prototype();
|
| + { TryAllocation t = AllocateFunctionPrototype(fun);
|
| + if (!t->ToObject(&prototype)) return t;
|
| + }
|
| } else {
|
| - prototype = AllocateFunctionPrototype(fun);
|
| - if (prototype->IsFailure()) return prototype;
|
| }
|
| Map* map = Map::cast(map_obj);
|
| map->set_inobject_properties(in_object_properties);
|
| @@ -2720,9 +2838,11 @@
|
| if (count > in_object_properties) {
|
| // Inline constructor can only handle inobject properties.
|
| fun->shared()->ForbidInlineConstructor();
|
| + Object* descriptors_obj;
|
| + { TryAllocation t = DescriptorArray::Allocate(count);
|
| + if (!t->ToObject(&descriptors_obj)) return t;
|
| + }
|
| } else {
|
| - Object* descriptors_obj = DescriptorArray::Allocate(count);
|
| - if (descriptors_obj->IsFailure()) return descriptors_obj;
|
| DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj);
|
| for (int i = 0; i < count; i++) {
|
| String* name = fun->shared()->GetThisPropertyAssignmentName(i);
|
| @@ -2798,16 +2918,20 @@
|
| map->pre_allocated_property_fields() +
|
| map->unused_property_fields() -
|
| map->inobject_properties();
|
| + Object* properties;
|
| + { TryAllocation t = AllocateFixedArray(prop_size, pretenure);
|
| + if (!t->ToObject(&properties)) return t;
|
| + }
|
| ASSERT(prop_size >= 0);
|
| - Object* properties = AllocateFixedArray(prop_size, pretenure);
|
| - if (properties->IsFailure()) return properties;
|
|
|
| // Allocate the JSObject.
|
| AllocationSpace space =
|
| (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
|
| + Object* obj;
|
| + { TryAllocation t = Allocate(map, space);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
|
| - Object* obj = Allocate(map, space);
|
| - if (obj->IsFailure()) return obj;
|
|
|
| // Initialize the JSObject.
|
| InitializeJSObjectFromMap(JSObject::cast(obj),
|
| @@ -2821,9 +2945,11 @@
|
| Object* Heap::AllocateJSObject(JSFunction* constructor,
|
| PretenureFlag pretenure) {
|
| // Allocate the initial map if absent.
|
| + Object* initial_map;
|
| + { TryAllocation t = AllocateInitialMap(constructor);
|
| + if (!t->ToObject(&initial_map)) return t;
|
| + }
|
| if (!constructor->has_initial_map()) {
|
| - Object* initial_map = AllocateInitialMap(constructor);
|
| - if (initial_map->IsFailure()) return initial_map;
|
| constructor->set_initial_map(Map::cast(initial_map));
|
| Map::cast(initial_map)->set_constructor(constructor);
|
| }
|
| @@ -2870,24 +2996,29 @@
|
| ASSERT(details.type() == CALLBACKS); // Only accessors are expected.
|
| PropertyDetails d =
|
| PropertyDetails(details.attributes(), CALLBACKS, details.index());
|
| + { TryAllocation t = Heap::AllocateJSGlobalPropertyCell(value);
|
| + if (!t->ToObject(&value)) return t;
|
| + }
|
| Object* value = descs->GetCallbacksObject(i);
|
| - value = Heap::AllocateJSGlobalPropertyCell(value);
|
| - if (value->IsFailure()) return value;
|
| + Object* result;
|
| + { TryAllocation t = dictionary->Add(descs->GetKey(i), value, d);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - Object* result = dictionary->Add(descs->GetKey(i), value, d);
|
| - if (result->IsFailure()) return result;
|
| dictionary = StringDictionary::cast(result);
|
| }
|
|
|
| + { TryAllocation t = Allocate(map, OLD_POINTER_SPACE);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| // Allocate the global object and initialize it with the backing store.
|
| - obj = Allocate(map, OLD_POINTER_SPACE);
|
| - if (obj->IsFailure()) return obj;
|
| JSObject* global = JSObject::cast(obj);
|
| InitializeJSObjectFromMap(global, dictionary, map);
|
|
|
| + { TryAllocation t = map->CopyDropDescriptors();
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| // Create a new map for the global object.
|
| - obj = map->CopyDropDescriptors();
|
| - if (obj->IsFailure()) return obj;
|
| Map* new_map = Map::cast(obj);
|
|
|
| // Setup the global object as a normalized object.
|
| @@ -2914,9 +3045,10 @@
|
|
|
| // If we're forced to always allocate, we use the general allocation
|
| // functions which may leave us with an object in old space.
|
| + { TryAllocation t = AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE);
|
| + if (!t->ToObject(&clone)) return t;
|
| + }
|
| if (always_allocate()) {
|
| - clone = AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE);
|
| - if (clone->IsFailure()) return clone;
|
| Address clone_address = HeapObject::cast(clone)->address();
|
| CopyBlock(clone_address,
|
| source->address(),
|
| @@ -2925,9 +3057,10 @@
|
| RecordWrites(clone_address,
|
| JSObject::kHeaderSize,
|
| (object_size - JSObject::kHeaderSize) / kPointerSize);
|
| + { TryAllocation t = new_space_.AllocateRaw(object_size);
|
| + if (!t->ToObject(&clone)) return t;
|
| + }
|
| } else {
|
| - clone = new_space_.AllocateRaw(object_size);
|
| - if (clone->IsFailure()) return clone;
|
| ASSERT(Heap::InNewSpace(clone));
|
| // Since we know the clone is allocated in new space, we can copy
|
| // the contents without worrying about updating the write barrier.
|
| @@ -2947,9 +3080,11 @@
|
| JSObject::cast(clone)->set_elements(FixedArray::cast(elem));
|
| }
|
| // Update properties if necessary.
|
| + Object* prop;
|
| + { TryAllocation t = CopyFixedArray(properties);
|
| + if (!t->ToObject(&prop)) return t;
|
| + }
|
| if (properties->length() > 0) {
|
| - Object* prop = CopyFixedArray(properties);
|
| - if (prop->IsFailure()) return prop;
|
| JSObject::cast(clone)->set_properties(FixedArray::cast(prop));
|
| }
|
| // Return the new clone.
|
| @@ -2971,9 +3106,11 @@
|
| ASSERT(map->instance_type() == object->map()->instance_type());
|
|
|
| // Allocate the backing storage for the properties.
|
| + Object* properties;
|
| + { TryAllocation t = AllocateFixedArray(prop_size, TENURED);
|
| + if (!t->ToObject(&properties)) return t;
|
| + }
|
| int prop_size = map->unused_property_fields() - map->inobject_properties();
|
| - Object* properties = AllocateFixedArray(prop_size, TENURED);
|
| - if (properties->IsFailure()) return properties;
|
|
|
| // Reset the map for the object.
|
| object->set_map(constructor->initial_map());
|
| @@ -2985,9 +3122,11 @@
|
|
|
|
|
| Object* Heap::AllocateStringFromAscii(Vector<const char> string,
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawAsciiString(string.length(), pretenure);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| PretenureFlag pretenure) {
|
| - Object* result = AllocateRawAsciiString(string.length(), pretenure);
|
| - if (result->IsFailure()) return result;
|
|
|
| // Copy the characters into the new object.
|
| SeqAsciiString* string_result = SeqAsciiString::cast(result);
|
| @@ -3017,9 +3156,11 @@
|
| // If the string is ascii, we do not need to convert the characters
|
| // since UTF8 is backwards compatible with ascii.
|
| if (is_ascii) return AllocateStringFromAscii(string, pretenure);
|
| + Object* result;
|
| + { TryAllocation t = AllocateRawTwoByteString(chars, pretenure);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - Object* result = AllocateRawTwoByteString(chars, pretenure);
|
| - if (result->IsFailure()) return result;
|
|
|
| // Convert and copy the characters into the new object.
|
| String* string_result = String::cast(result);
|
| @@ -3155,9 +3296,11 @@
|
| }
|
| } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
|
| space = LO_SPACE;
|
| + Object* result;
|
| + { TryAllocation t = AllocateRaw(size, space, retry_space);
|
| + if (!t->ToObject(&result)) return t;
|
| }
|
| - Object* result = AllocateRaw(size, space, retry_space);
|
| - if (result->IsFailure()) return result;
|
| + }
|
|
|
| // Partially initialize the object.
|
| HeapObject::cast(result)->set_map(ascii_string_map());
|
| @@ -3187,9 +3330,11 @@
|
| }
|
| } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
|
| space = LO_SPACE;
|
| + Object* result;
|
| + { TryAllocation t = AllocateRaw(size, space, retry_space);
|
| + if (!t->ToObject(&result)) return t;
|
| }
|
| - Object* result = AllocateRaw(size, space, retry_space);
|
| - if (result->IsFailure()) return result;
|
| + }
|
|
|
| // Partially initialize the object.
|
| HeapObject::cast(result)->set_map(string_map());
|
| @@ -3201,9 +3346,11 @@
|
|
|
|
|
| Object* Heap::AllocateEmptyFixedArray() {
|
| + Object* result;
|
| + { TryAllocation t = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| int size = FixedArray::SizeFor(0);
|
| - Object* result = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
|
| - if (result->IsFailure()) return result;
|
| // Initialize the object.
|
| reinterpret_cast<FixedArray*>(result)->set_map(fixed_array_map());
|
| reinterpret_cast<FixedArray*>(result)->set_length(0);
|
| @@ -3227,9 +3374,11 @@
|
|
|
|
|
| Object* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
|
| + Object* obj;
|
| + { TryAllocation t = AllocateRawFixedArray(len);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| int len = src->length();
|
| - Object* obj = AllocateRawFixedArray(len);
|
| - if (obj->IsFailure()) return obj;
|
| if (Heap::InNewSpace(obj)) {
|
| HeapObject* dst = HeapObject::cast(obj);
|
| dst->set_map(map);
|
| @@ -3298,9 +3447,11 @@
|
| ASSERT(Heap::empty_fixed_array()->IsFixedArray());
|
| if (length == 0) return Heap::empty_fixed_array();
|
|
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateRawFixedArray(length, pretenure);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| ASSERT(!Heap::InNewSpace(filler));
|
| - Object* result = Heap::AllocateRawFixedArray(length, pretenure);
|
| - if (result->IsFailure()) return result;
|
|
|
| HeapObject::cast(result)->set_map(Heap::fixed_array_map());
|
| FixedArray* array = FixedArray::cast(result);
|
| @@ -3322,9 +3473,11 @@
|
|
|
| Object* Heap::AllocateUninitializedFixedArray(int length) {
|
| if (length == 0) return empty_fixed_array();
|
| + Object* obj;
|
| + { TryAllocation t = AllocateRawFixedArray(length);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
|
|
| - Object* obj = AllocateRawFixedArray(length);
|
| - if (obj->IsFailure()) return obj;
|
|
|
| reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map());
|
| FixedArray::cast(obj)->set_length(length);
|
| @@ -3332,18 +3485,22 @@
|
| }
|
|
|
|
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateFixedArray(length, pretenure);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
|
| - Object* result = Heap::AllocateFixedArray(length, pretenure);
|
| - if (result->IsFailure()) return result;
|
| reinterpret_cast<HeapObject*>(result)->set_map(hash_table_map());
|
| ASSERT(result->IsHashTable());
|
| return result;
|
| }
|
|
|
|
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Object* Heap::AllocateGlobalContext() {
|
| - Object* result = Heap::AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS);
|
| - if (result->IsFailure()) return result;
|
| Context* context = reinterpret_cast<Context*>(result);
|
| context->set_map(global_context_map());
|
| ASSERT(context->IsGlobalContext());
|
| @@ -3353,9 +3510,11 @@
|
|
|
|
|
| Object* Heap::AllocateFunctionContext(int length, JSFunction* function) {
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateFixedArray(length);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| ASSERT(length >= Context::MIN_CONTEXT_SLOTS);
|
| - Object* result = Heap::AllocateFixedArray(length);
|
| - if (result->IsFailure()) return result;
|
| Context* context = reinterpret_cast<Context*>(result);
|
| context->set_map(context_map());
|
| context->set_closure(function);
|
| @@ -3372,9 +3531,11 @@
|
|
|
| Object* Heap::AllocateWithContext(Context* previous,
|
| JSObject* extension,
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateFixedArray(Context::MIN_CONTEXT_SLOTS);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| bool is_catch_context) {
|
| - Object* result = Heap::AllocateFixedArray(Context::MIN_CONTEXT_SLOTS);
|
| - if (result->IsFailure()) return result;
|
| Context* context = reinterpret_cast<Context*>(result);
|
| context->set_map(is_catch_context ? catch_context_map() : context_map());
|
| context->set_closure(previous->closure());
|
| @@ -3401,9 +3562,11 @@
|
| }
|
| int size = map->instance_size();
|
| AllocationSpace space =
|
| + Object* result;
|
| + { TryAllocation t = Heap::Allocate(map, space);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_POINTER_SPACE;
|
| - Object* result = Heap::Allocate(map, space);
|
| - if (result->IsFailure()) return result;
|
| Struct::cast(result)->InitializeBody(size);
|
| return result;
|
| }
|
| @@ -3664,9 +3827,11 @@
|
|
|
|
|
| Object* Heap::LookupSymbol(Vector<const char> string) {
|
| + Object* new_table;
|
| + { TryAllocation t = symbol_table()->LookupSymbol(string, &symbol);
|
| + if (!t->ToObject(&new_table)) return t;
|
| + }
|
| Object* symbol = NULL;
|
| - Object* new_table = symbol_table()->LookupSymbol(string, &symbol);
|
| - if (new_table->IsFailure()) return new_table;
|
| // Can't use set_symbol_table because SymbolTable::cast knows that
|
| // SymbolTable is a singleton and checks for identity.
|
| roots_[kSymbolTableRootIndex] = new_table;
|
| @@ -3677,9 +3842,11 @@
|
|
|
| Object* Heap::LookupSymbol(String* string) {
|
| if (string->IsSymbol()) return string;
|
| + Object* new_table;
|
| + { TryAllocation t = symbol_table()->LookupString(string, &symbol);
|
| + if (!t->ToObject(&new_table)) return t;
|
| + }
|
| Object* symbol = NULL;
|
| - Object* new_table = symbol_table()->LookupString(string, &symbol);
|
| - if (new_table->IsFailure()) return new_table;
|
| // Can't use set_symbol_table because SymbolTable::cast knows that
|
| // SymbolTable is a singleton and checks for identity.
|
| roots_[kSymbolTableRootIndex] = new_table;
|
|
|