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

Side by Side Diff: src/heap.cc

Issue 3970005: Make Failure inherit from MaybeObject instead of Object. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap.h ('k') | src/heap-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 795
796 CompletelyClearInstanceofCache(); 796 CompletelyClearInstanceofCache();
797 797
798 if (is_compacting) FlushNumberStringCache(); 798 if (is_compacting) FlushNumberStringCache();
799 799
800 ClearNormalizedMapCaches(); 800 ClearNormalizedMapCaches();
801 } 801 }
802 802
803 803
804 Object* Heap::FindCodeObject(Address a) { 804 Object* Heap::FindCodeObject(Address a) {
805 Object* obj = code_space_->FindObject(a); 805 Object* obj = NULL; // Initialization to please compiler.
806 if (obj->IsFailure()) { 806 { MaybeObject* maybe_obj = code_space_->FindObject(a);
807 obj = lo_space_->FindObject(a); 807 if (!maybe_obj->ToObject(&obj)) {
808 obj = lo_space_->FindObject(a)->ToObjectUnchecked();
809 }
808 } 810 }
809 ASSERT(!obj->IsFailure());
810 return obj; 811 return obj;
811 } 812 }
812 813
813 814
814 // Helper class for copying HeapObjects 815 // Helper class for copying HeapObjects
815 class ScavengeVisitor: public ObjectVisitor { 816 class ScavengeVisitor: public ObjectVisitor {
816 public: 817 public:
817 818
818 void VisitPointer(Object** p) { ScavengePointer(p); } 819 void VisitPointer(Object** p) { ScavengePointer(p); }
819 820
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 template<ObjectContents object_contents, SizeRestriction size_restriction> 1254 template<ObjectContents object_contents, SizeRestriction size_restriction>
1254 static inline void EvacuateObject(Map* map, 1255 static inline void EvacuateObject(Map* map,
1255 HeapObject** slot, 1256 HeapObject** slot,
1256 HeapObject* object, 1257 HeapObject* object,
1257 int object_size) { 1258 int object_size) {
1258 ASSERT((size_restriction != SMALL) || 1259 ASSERT((size_restriction != SMALL) ||
1259 (object_size <= Page::kMaxHeapObjectSize)); 1260 (object_size <= Page::kMaxHeapObjectSize));
1260 ASSERT(object->Size() == object_size); 1261 ASSERT(object->Size() == object_size);
1261 1262
1262 if (Heap::ShouldBePromoted(object->address(), object_size)) { 1263 if (Heap::ShouldBePromoted(object->address(), object_size)) {
1263 Object* result; 1264 MaybeObject* maybe_result;
1264 1265
1265 if ((size_restriction != SMALL) && 1266 if ((size_restriction != SMALL) &&
1266 (object_size > Page::kMaxHeapObjectSize)) { 1267 (object_size > Page::kMaxHeapObjectSize)) {
1267 result = Heap::lo_space()->AllocateRawFixedArray(object_size); 1268 maybe_result = Heap::lo_space()->AllocateRawFixedArray(object_size);
1268 } else { 1269 } else {
1269 if (object_contents == DATA_OBJECT) { 1270 if (object_contents == DATA_OBJECT) {
1270 result = Heap::old_data_space()->AllocateRaw(object_size); 1271 maybe_result = Heap::old_data_space()->AllocateRaw(object_size);
1271 } else { 1272 } else {
1272 result = Heap::old_pointer_space()->AllocateRaw(object_size); 1273 maybe_result = Heap::old_pointer_space()->AllocateRaw(object_size);
1273 } 1274 }
1274 } 1275 }
1275 1276
1276 if (!result->IsFailure()) { 1277 Object* result = NULL; // Initialization to please compiler.
1278 if (maybe_result->ToObject(&result)) {
1277 HeapObject* target = HeapObject::cast(result); 1279 HeapObject* target = HeapObject::cast(result);
1278 *slot = MigrateObject(object, target, object_size); 1280 *slot = MigrateObject(object, target, object_size);
1279 1281
1280 if (object_contents == POINTER_OBJECT) { 1282 if (object_contents == POINTER_OBJECT) {
1281 promotion_queue.insert(target, object_size); 1283 promotion_queue.insert(target, object_size);
1282 } 1284 }
1283 1285
1284 Heap::tracer()->increment_promoted_objects_size(object_size); 1286 Heap::tracer()->increment_promoted_objects_size(object_size);
1285 return; 1287 return;
1286 } 1288 }
1287 } 1289 }
1288 Object* result = Heap::new_space()->AllocateRaw(object_size); 1290 Object* result =
1289 ASSERT(!result->IsFailure()); 1291 Heap::new_space()->AllocateRaw(object_size)->ToObjectUnchecked();
1290 *slot = MigrateObject(object, HeapObject::cast(result), object_size); 1292 *slot = MigrateObject(object, HeapObject::cast(result), object_size);
1291 return; 1293 return;
1292 } 1294 }
1293 1295
1294 1296
1295 static inline void EvacuateFixedArray(Map* map, 1297 static inline void EvacuateFixedArray(Map* map,
1296 HeapObject** slot, 1298 HeapObject** slot,
1297 HeapObject* object) { 1299 HeapObject* object) {
1298 int object_size = FixedArray::BodyDescriptor::SizeOf(map, object); 1300 int object_size = FixedArray::BodyDescriptor::SizeOf(map, object);
1299 EvacuateObject<POINTER_OBJECT, UNKNOWN_SIZE>(map, 1301 EvacuateObject<POINTER_OBJECT, UNKNOWN_SIZE>(map,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 Map* map = first_word.ToMap(); 1403 Map* map = first_word.ToMap();
1402 ScavengingVisitor::Scavenge(map, p, object); 1404 ScavengingVisitor::Scavenge(map, p, object);
1403 } 1405 }
1404 1406
1405 1407
1406 void Heap::ScavengePointer(HeapObject** p) { 1408 void Heap::ScavengePointer(HeapObject** p) {
1407 ScavengeObject(p, *p); 1409 ScavengeObject(p, *p);
1408 } 1410 }
1409 1411
1410 1412
1411 Object* Heap::AllocatePartialMap(InstanceType instance_type, 1413 MaybeObject* Heap::AllocatePartialMap(InstanceType instance_type,
1412 int instance_size) { 1414 int instance_size) {
1413 Object* result = AllocateRawMap(); 1415 Object* result;
1414 if (result->IsFailure()) return result; 1416 { MaybeObject* maybe_result = AllocateRawMap();
1417 if (!maybe_result->ToObject(&result)) return maybe_result;
1418 }
1415 1419
1416 // Map::cast cannot be used due to uninitialized map field. 1420 // Map::cast cannot be used due to uninitialized map field.
1417 reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map()); 1421 reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map());
1418 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); 1422 reinterpret_cast<Map*>(result)->set_instance_type(instance_type);
1419 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); 1423 reinterpret_cast<Map*>(result)->set_instance_size(instance_size);
1420 reinterpret_cast<Map*>(result)-> 1424 reinterpret_cast<Map*>(result)->
1421 set_visitor_id( 1425 set_visitor_id(
1422 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); 1426 StaticVisitorBase::GetVisitorId(instance_type, instance_size));
1423 reinterpret_cast<Map*>(result)->set_inobject_properties(0); 1427 reinterpret_cast<Map*>(result)->set_inobject_properties(0);
1424 reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0); 1428 reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0);
1425 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); 1429 reinterpret_cast<Map*>(result)->set_unused_property_fields(0);
1426 reinterpret_cast<Map*>(result)->set_bit_field(0); 1430 reinterpret_cast<Map*>(result)->set_bit_field(0);
1427 reinterpret_cast<Map*>(result)->set_bit_field2(0); 1431 reinterpret_cast<Map*>(result)->set_bit_field2(0);
1428 return result; 1432 return result;
1429 } 1433 }
1430 1434
1431 1435
1432 Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) { 1436 MaybeObject* Heap::AllocateMap(InstanceType instance_type, int instance_size) {
1433 Object* result = AllocateRawMap(); 1437 Object* result;
1434 if (result->IsFailure()) return result; 1438 { MaybeObject* maybe_result = AllocateRawMap();
1439 if (!maybe_result->ToObject(&result)) return maybe_result;
1440 }
1435 1441
1436 Map* map = reinterpret_cast<Map*>(result); 1442 Map* map = reinterpret_cast<Map*>(result);
1437 map->set_map(meta_map()); 1443 map->set_map(meta_map());
1438 map->set_instance_type(instance_type); 1444 map->set_instance_type(instance_type);
1439 map->set_visitor_id( 1445 map->set_visitor_id(
1440 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); 1446 StaticVisitorBase::GetVisitorId(instance_type, instance_size));
1441 map->set_prototype(null_value()); 1447 map->set_prototype(null_value());
1442 map->set_constructor(null_value()); 1448 map->set_constructor(null_value());
1443 map->set_instance_size(instance_size); 1449 map->set_instance_size(instance_size);
1444 map->set_inobject_properties(0); 1450 map->set_inobject_properties(0);
1445 map->set_pre_allocated_property_fields(0); 1451 map->set_pre_allocated_property_fields(0);
1446 map->set_instance_descriptors(empty_descriptor_array()); 1452 map->set_instance_descriptors(empty_descriptor_array());
1447 map->set_code_cache(empty_fixed_array()); 1453 map->set_code_cache(empty_fixed_array());
1448 map->set_unused_property_fields(0); 1454 map->set_unused_property_fields(0);
1449 map->set_bit_field(0); 1455 map->set_bit_field(0);
1450 map->set_bit_field2((1 << Map::kIsExtensible) | (1 << Map::kHasFastElements)); 1456 map->set_bit_field2((1 << Map::kIsExtensible) | (1 << Map::kHasFastElements));
1451 1457
1452 // If the map object is aligned fill the padding area with Smi 0 objects. 1458 // If the map object is aligned fill the padding area with Smi 0 objects.
1453 if (Map::kPadStart < Map::kSize) { 1459 if (Map::kPadStart < Map::kSize) {
1454 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag, 1460 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag,
1455 0, 1461 0,
1456 Map::kSize - Map::kPadStart); 1462 Map::kSize - Map::kPadStart);
1457 } 1463 }
1458 return map; 1464 return map;
1459 } 1465 }
1460 1466
1461 1467
1462 Object* Heap::AllocateCodeCache() { 1468 MaybeObject* Heap::AllocateCodeCache() {
1463 Object* result = AllocateStruct(CODE_CACHE_TYPE); 1469 Object* result;
1464 if (result->IsFailure()) return result; 1470 { MaybeObject* maybe_result = AllocateStruct(CODE_CACHE_TYPE);
1471 if (!maybe_result->ToObject(&result)) return maybe_result;
1472 }
1465 CodeCache* code_cache = CodeCache::cast(result); 1473 CodeCache* code_cache = CodeCache::cast(result);
1466 code_cache->set_default_cache(empty_fixed_array()); 1474 code_cache->set_default_cache(empty_fixed_array());
1467 code_cache->set_normal_type_cache(undefined_value()); 1475 code_cache->set_normal_type_cache(undefined_value());
1468 return code_cache; 1476 return code_cache;
1469 } 1477 }
1470 1478
1471 1479
1472 const Heap::StringTypeTable Heap::string_type_table[] = { 1480 const Heap::StringTypeTable Heap::string_type_table[] = {
1473 #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \ 1481 #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \
1474 {type, size, k##camel_name##MapRootIndex}, 1482 {type, size, k##camel_name##MapRootIndex},
(...skipping 12 matching lines...) Expand all
1487 1495
1488 const Heap::StructTable Heap::struct_table[] = { 1496 const Heap::StructTable Heap::struct_table[] = {
1489 #define STRUCT_TABLE_ELEMENT(NAME, Name, name) \ 1497 #define STRUCT_TABLE_ELEMENT(NAME, Name, name) \
1490 { NAME##_TYPE, Name::kSize, k##Name##MapRootIndex }, 1498 { NAME##_TYPE, Name::kSize, k##Name##MapRootIndex },
1491 STRUCT_LIST(STRUCT_TABLE_ELEMENT) 1499 STRUCT_LIST(STRUCT_TABLE_ELEMENT)
1492 #undef STRUCT_TABLE_ELEMENT 1500 #undef STRUCT_TABLE_ELEMENT
1493 }; 1501 };
1494 1502
1495 1503
1496 bool Heap::CreateInitialMaps() { 1504 bool Heap::CreateInitialMaps() {
1497 Object* obj = AllocatePartialMap(MAP_TYPE, Map::kSize); 1505 Object* obj;
1498 if (obj->IsFailure()) return false; 1506 { MaybeObject* maybe_obj = AllocatePartialMap(MAP_TYPE, Map::kSize);
1507 if (!maybe_obj->ToObject(&obj)) return false;
1508 }
1499 // Map::cast cannot be used due to uninitialized map field. 1509 // Map::cast cannot be used due to uninitialized map field.
1500 Map* new_meta_map = reinterpret_cast<Map*>(obj); 1510 Map* new_meta_map = reinterpret_cast<Map*>(obj);
1501 set_meta_map(new_meta_map); 1511 set_meta_map(new_meta_map);
1502 new_meta_map->set_map(new_meta_map); 1512 new_meta_map->set_map(new_meta_map);
1503 1513
1504 obj = AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1514 { MaybeObject* maybe_obj =
1505 if (obj->IsFailure()) return false; 1515 AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1516 if (!maybe_obj->ToObject(&obj)) return false;
1517 }
1506 set_fixed_array_map(Map::cast(obj)); 1518 set_fixed_array_map(Map::cast(obj));
1507 1519
1508 obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize); 1520 { MaybeObject* maybe_obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize);
1509 if (obj->IsFailure()) return false; 1521 if (!maybe_obj->ToObject(&obj)) return false;
1522 }
1510 set_oddball_map(Map::cast(obj)); 1523 set_oddball_map(Map::cast(obj));
1511 1524
1512 // Allocate the empty array. 1525 // Allocate the empty array.
1513 obj = AllocateEmptyFixedArray(); 1526 { MaybeObject* maybe_obj = AllocateEmptyFixedArray();
1514 if (obj->IsFailure()) return false; 1527 if (!maybe_obj->ToObject(&obj)) return false;
1528 }
1515 set_empty_fixed_array(FixedArray::cast(obj)); 1529 set_empty_fixed_array(FixedArray::cast(obj));
1516 1530
1517 obj = Allocate(oddball_map(), OLD_DATA_SPACE); 1531 { MaybeObject* maybe_obj = Allocate(oddball_map(), OLD_DATA_SPACE);
1518 if (obj->IsFailure()) return false; 1532 if (!maybe_obj->ToObject(&obj)) return false;
1533 }
1519 set_null_value(obj); 1534 set_null_value(obj);
1520 1535
1521 // Allocate the empty descriptor array. 1536 // Allocate the empty descriptor array.
1522 obj = AllocateEmptyFixedArray(); 1537 { MaybeObject* maybe_obj = AllocateEmptyFixedArray();
1523 if (obj->IsFailure()) return false; 1538 if (!maybe_obj->ToObject(&obj)) return false;
1539 }
1524 set_empty_descriptor_array(DescriptorArray::cast(obj)); 1540 set_empty_descriptor_array(DescriptorArray::cast(obj));
1525 1541
1526 // Fix the instance_descriptors for the existing maps. 1542 // Fix the instance_descriptors for the existing maps.
1527 meta_map()->set_instance_descriptors(empty_descriptor_array()); 1543 meta_map()->set_instance_descriptors(empty_descriptor_array());
1528 meta_map()->set_code_cache(empty_fixed_array()); 1544 meta_map()->set_code_cache(empty_fixed_array());
1529 1545
1530 fixed_array_map()->set_instance_descriptors(empty_descriptor_array()); 1546 fixed_array_map()->set_instance_descriptors(empty_descriptor_array());
1531 fixed_array_map()->set_code_cache(empty_fixed_array()); 1547 fixed_array_map()->set_code_cache(empty_fixed_array());
1532 1548
1533 oddball_map()->set_instance_descriptors(empty_descriptor_array()); 1549 oddball_map()->set_instance_descriptors(empty_descriptor_array());
1534 oddball_map()->set_code_cache(empty_fixed_array()); 1550 oddball_map()->set_code_cache(empty_fixed_array());
1535 1551
1536 // Fix prototype object for existing maps. 1552 // Fix prototype object for existing maps.
1537 meta_map()->set_prototype(null_value()); 1553 meta_map()->set_prototype(null_value());
1538 meta_map()->set_constructor(null_value()); 1554 meta_map()->set_constructor(null_value());
1539 1555
1540 fixed_array_map()->set_prototype(null_value()); 1556 fixed_array_map()->set_prototype(null_value());
1541 fixed_array_map()->set_constructor(null_value()); 1557 fixed_array_map()->set_constructor(null_value());
1542 1558
1543 oddball_map()->set_prototype(null_value()); 1559 oddball_map()->set_prototype(null_value());
1544 oddball_map()->set_constructor(null_value()); 1560 oddball_map()->set_constructor(null_value());
1545 1561
1546 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1562 { MaybeObject* maybe_obj =
1547 if (obj->IsFailure()) return false; 1563 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1564 if (!maybe_obj->ToObject(&obj)) return false;
1565 }
1548 set_fixed_cow_array_map(Map::cast(obj)); 1566 set_fixed_cow_array_map(Map::cast(obj));
1549 ASSERT(fixed_array_map() != fixed_cow_array_map()); 1567 ASSERT(fixed_array_map() != fixed_cow_array_map());
1550 1568
1551 obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize); 1569 { MaybeObject* maybe_obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
1552 if (obj->IsFailure()) return false; 1570 if (!maybe_obj->ToObject(&obj)) return false;
1571 }
1553 set_heap_number_map(Map::cast(obj)); 1572 set_heap_number_map(Map::cast(obj));
1554 1573
1555 obj = AllocateMap(PROXY_TYPE, Proxy::kSize); 1574 { MaybeObject* maybe_obj = AllocateMap(PROXY_TYPE, Proxy::kSize);
1556 if (obj->IsFailure()) return false; 1575 if (!maybe_obj->ToObject(&obj)) return false;
1576 }
1557 set_proxy_map(Map::cast(obj)); 1577 set_proxy_map(Map::cast(obj));
1558 1578
1559 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { 1579 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
1560 const StringTypeTable& entry = string_type_table[i]; 1580 const StringTypeTable& entry = string_type_table[i];
1561 obj = AllocateMap(entry.type, entry.size); 1581 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size);
1562 if (obj->IsFailure()) return false; 1582 if (!maybe_obj->ToObject(&obj)) return false;
1583 }
1563 roots_[entry.index] = Map::cast(obj); 1584 roots_[entry.index] = Map::cast(obj);
1564 } 1585 }
1565 1586
1566 obj = AllocateMap(STRING_TYPE, kVariableSizeSentinel); 1587 { MaybeObject* maybe_obj = AllocateMap(STRING_TYPE, kVariableSizeSentinel);
1567 if (obj->IsFailure()) return false; 1588 if (!maybe_obj->ToObject(&obj)) return false;
1589 }
1568 set_undetectable_string_map(Map::cast(obj)); 1590 set_undetectable_string_map(Map::cast(obj));
1569 Map::cast(obj)->set_is_undetectable(); 1591 Map::cast(obj)->set_is_undetectable();
1570 1592
1571 obj = AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel); 1593 { MaybeObject* maybe_obj =
1572 if (obj->IsFailure()) return false; 1594 AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel);
1595 if (!maybe_obj->ToObject(&obj)) return false;
1596 }
1573 set_undetectable_ascii_string_map(Map::cast(obj)); 1597 set_undetectable_ascii_string_map(Map::cast(obj));
1574 Map::cast(obj)->set_is_undetectable(); 1598 Map::cast(obj)->set_is_undetectable();
1575 1599
1576 obj = AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel); 1600 { MaybeObject* maybe_obj =
1577 if (obj->IsFailure()) return false; 1601 AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel);
1602 if (!maybe_obj->ToObject(&obj)) return false;
1603 }
1578 set_byte_array_map(Map::cast(obj)); 1604 set_byte_array_map(Map::cast(obj));
1579 1605
1580 obj = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize); 1606 { MaybeObject* maybe_obj =
1581 if (obj->IsFailure()) return false; 1607 AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize);
1608 if (!maybe_obj->ToObject(&obj)) return false;
1609 }
1582 set_pixel_array_map(Map::cast(obj)); 1610 set_pixel_array_map(Map::cast(obj));
1583 1611
1584 obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE, 1612 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE,
1585 ExternalArray::kAlignedSize); 1613 ExternalArray::kAlignedSize);
1586 if (obj->IsFailure()) return false; 1614 if (!maybe_obj->ToObject(&obj)) return false;
1615 }
1587 set_external_byte_array_map(Map::cast(obj)); 1616 set_external_byte_array_map(Map::cast(obj));
1588 1617
1589 obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, 1618 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
1590 ExternalArray::kAlignedSize); 1619 ExternalArray::kAlignedSize);
1591 if (obj->IsFailure()) return false; 1620 if (!maybe_obj->ToObject(&obj)) return false;
1621 }
1592 set_external_unsigned_byte_array_map(Map::cast(obj)); 1622 set_external_unsigned_byte_array_map(Map::cast(obj));
1593 1623
1594 obj = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE, 1624 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE,
1595 ExternalArray::kAlignedSize); 1625 ExternalArray::kAlignedSize);
1596 if (obj->IsFailure()) return false; 1626 if (!maybe_obj->ToObject(&obj)) return false;
1627 }
1597 set_external_short_array_map(Map::cast(obj)); 1628 set_external_short_array_map(Map::cast(obj));
1598 1629
1599 obj = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, 1630 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
1600 ExternalArray::kAlignedSize); 1631 ExternalArray::kAlignedSize);
1601 if (obj->IsFailure()) return false; 1632 if (!maybe_obj->ToObject(&obj)) return false;
1633 }
1602 set_external_unsigned_short_array_map(Map::cast(obj)); 1634 set_external_unsigned_short_array_map(Map::cast(obj));
1603 1635
1604 obj = AllocateMap(EXTERNAL_INT_ARRAY_TYPE, 1636 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_INT_ARRAY_TYPE,
1605 ExternalArray::kAlignedSize); 1637 ExternalArray::kAlignedSize);
1606 if (obj->IsFailure()) return false; 1638 if (!maybe_obj->ToObject(&obj)) return false;
1639 }
1607 set_external_int_array_map(Map::cast(obj)); 1640 set_external_int_array_map(Map::cast(obj));
1608 1641
1609 obj = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, 1642 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
1610 ExternalArray::kAlignedSize); 1643 ExternalArray::kAlignedSize);
1611 if (obj->IsFailure()) return false; 1644 if (!maybe_obj->ToObject(&obj)) return false;
1645 }
1612 set_external_unsigned_int_array_map(Map::cast(obj)); 1646 set_external_unsigned_int_array_map(Map::cast(obj));
1613 1647
1614 obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE, 1648 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE,
1615 ExternalArray::kAlignedSize); 1649 ExternalArray::kAlignedSize);
1616 if (obj->IsFailure()) return false; 1650 if (!maybe_obj->ToObject(&obj)) return false;
1651 }
1617 set_external_float_array_map(Map::cast(obj)); 1652 set_external_float_array_map(Map::cast(obj));
1618 1653
1619 obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel); 1654 { MaybeObject* maybe_obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel);
1620 if (obj->IsFailure()) return false; 1655 if (!maybe_obj->ToObject(&obj)) return false;
1656 }
1621 set_code_map(Map::cast(obj)); 1657 set_code_map(Map::cast(obj));
1622 1658
1623 obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE, 1659 { MaybeObject* maybe_obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE,
1624 JSGlobalPropertyCell::kSize); 1660 JSGlobalPropertyCell::kSize);
1625 if (obj->IsFailure()) return false; 1661 if (!maybe_obj->ToObject(&obj)) return false;
1662 }
1626 set_global_property_cell_map(Map::cast(obj)); 1663 set_global_property_cell_map(Map::cast(obj));
1627 1664
1628 obj = AllocateMap(FILLER_TYPE, kPointerSize); 1665 { MaybeObject* maybe_obj = AllocateMap(FILLER_TYPE, kPointerSize);
1629 if (obj->IsFailure()) return false; 1666 if (!maybe_obj->ToObject(&obj)) return false;
1667 }
1630 set_one_pointer_filler_map(Map::cast(obj)); 1668 set_one_pointer_filler_map(Map::cast(obj));
1631 1669
1632 obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize); 1670 { MaybeObject* maybe_obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize);
1633 if (obj->IsFailure()) return false; 1671 if (!maybe_obj->ToObject(&obj)) return false;
1672 }
1634 set_two_pointer_filler_map(Map::cast(obj)); 1673 set_two_pointer_filler_map(Map::cast(obj));
1635 1674
1636 for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) { 1675 for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) {
1637 const StructTable& entry = struct_table[i]; 1676 const StructTable& entry = struct_table[i];
1638 obj = AllocateMap(entry.type, entry.size); 1677 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size);
1639 if (obj->IsFailure()) return false; 1678 if (!maybe_obj->ToObject(&obj)) return false;
1679 }
1640 roots_[entry.index] = Map::cast(obj); 1680 roots_[entry.index] = Map::cast(obj);
1641 } 1681 }
1642 1682
1643 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1683 { MaybeObject* maybe_obj =
1644 if (obj->IsFailure()) return false; 1684 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1685 if (!maybe_obj->ToObject(&obj)) return false;
1686 }
1645 set_hash_table_map(Map::cast(obj)); 1687 set_hash_table_map(Map::cast(obj));
1646 1688
1647 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1689 { MaybeObject* maybe_obj =
1648 if (obj->IsFailure()) return false; 1690 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1691 if (!maybe_obj->ToObject(&obj)) return false;
1692 }
1649 set_context_map(Map::cast(obj)); 1693 set_context_map(Map::cast(obj));
1650 1694
1651 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1695 { MaybeObject* maybe_obj =
1652 if (obj->IsFailure()) return false; 1696 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1697 if (!maybe_obj->ToObject(&obj)) return false;
1698 }
1653 set_catch_context_map(Map::cast(obj)); 1699 set_catch_context_map(Map::cast(obj));
1654 1700
1655 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1701 { MaybeObject* maybe_obj =
1656 if (obj->IsFailure()) return false; 1702 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1703 if (!maybe_obj->ToObject(&obj)) return false;
1704 }
1657 Map* global_context_map = Map::cast(obj); 1705 Map* global_context_map = Map::cast(obj);
1658 global_context_map->set_visitor_id(StaticVisitorBase::kVisitGlobalContext); 1706 global_context_map->set_visitor_id(StaticVisitorBase::kVisitGlobalContext);
1659 set_global_context_map(global_context_map); 1707 set_global_context_map(global_context_map);
1660 1708
1661 obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE, 1709 { MaybeObject* maybe_obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE,
1662 SharedFunctionInfo::kAlignedSize); 1710 SharedFunctionInfo::kAlignedSize);
1663 if (obj->IsFailure()) return false; 1711 if (!maybe_obj->ToObject(&obj)) return false;
1712 }
1664 set_shared_function_info_map(Map::cast(obj)); 1713 set_shared_function_info_map(Map::cast(obj));
1665 1714
1666 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); 1715 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array()));
1667 return true; 1716 return true;
1668 } 1717 }
1669 1718
1670 1719
1671 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 1720 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
1672 // Statically ensure that it is safe to allocate heap numbers in paged 1721 // Statically ensure that it is safe to allocate heap numbers in paged
1673 // spaces. 1722 // spaces.
1674 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1723 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1675 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1724 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
1676 1725
1677 Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE); 1726 Object* result;
1678 if (result->IsFailure()) return result; 1727 { MaybeObject* maybe_result =
1728 AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
1729 if (!maybe_result->ToObject(&result)) return maybe_result;
1730 }
1679 1731
1680 HeapObject::cast(result)->set_map(heap_number_map()); 1732 HeapObject::cast(result)->set_map(heap_number_map());
1681 HeapNumber::cast(result)->set_value(value); 1733 HeapNumber::cast(result)->set_value(value);
1682 return result; 1734 return result;
1683 } 1735 }
1684 1736
1685 1737
1686 Object* Heap::AllocateHeapNumber(double value) { 1738 MaybeObject* Heap::AllocateHeapNumber(double value) {
1687 // Use general version, if we're forced to always allocate. 1739 // Use general version, if we're forced to always allocate.
1688 if (always_allocate()) return AllocateHeapNumber(value, TENURED); 1740 if (always_allocate()) return AllocateHeapNumber(value, TENURED);
1689 1741
1690 // This version of AllocateHeapNumber is optimized for 1742 // This version of AllocateHeapNumber is optimized for
1691 // allocation in new space. 1743 // allocation in new space.
1692 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1744 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1693 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 1745 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
1694 Object* result = new_space_.AllocateRaw(HeapNumber::kSize); 1746 Object* result;
1695 if (result->IsFailure()) return result; 1747 { MaybeObject* maybe_result = new_space_.AllocateRaw(HeapNumber::kSize);
1748 if (!maybe_result->ToObject(&result)) return maybe_result;
1749 }
1696 HeapObject::cast(result)->set_map(heap_number_map()); 1750 HeapObject::cast(result)->set_map(heap_number_map());
1697 HeapNumber::cast(result)->set_value(value); 1751 HeapNumber::cast(result)->set_value(value);
1698 return result; 1752 return result;
1699 } 1753 }
1700 1754
1701 1755
1702 Object* Heap::AllocateJSGlobalPropertyCell(Object* value) { 1756 MaybeObject* Heap::AllocateJSGlobalPropertyCell(Object* value) {
1703 Object* result = AllocateRawCell(); 1757 Object* result;
1704 if (result->IsFailure()) return result; 1758 { MaybeObject* maybe_result = AllocateRawCell();
1759 if (!maybe_result->ToObject(&result)) return maybe_result;
1760 }
1705 HeapObject::cast(result)->set_map(global_property_cell_map()); 1761 HeapObject::cast(result)->set_map(global_property_cell_map());
1706 JSGlobalPropertyCell::cast(result)->set_value(value); 1762 JSGlobalPropertyCell::cast(result)->set_value(value);
1707 return result; 1763 return result;
1708 } 1764 }
1709 1765
1710 1766
1711 Object* Heap::CreateOddball(const char* to_string, 1767 MaybeObject* Heap::CreateOddball(const char* to_string,
1712 Object* to_number) { 1768 Object* to_number) {
1713 Object* result = Allocate(oddball_map(), OLD_DATA_SPACE); 1769 Object* result;
1714 if (result->IsFailure()) return result; 1770 { MaybeObject* maybe_result = Allocate(oddball_map(), OLD_DATA_SPACE);
1771 if (!maybe_result->ToObject(&result)) return maybe_result;
1772 }
1715 return Oddball::cast(result)->Initialize(to_string, to_number); 1773 return Oddball::cast(result)->Initialize(to_string, to_number);
1716 } 1774 }
1717 1775
1718 1776
1719 bool Heap::CreateApiObjects() { 1777 bool Heap::CreateApiObjects() {
1720 Object* obj; 1778 Object* obj;
1721 1779
1722 obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 1780 { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
1723 if (obj->IsFailure()) return false; 1781 if (!maybe_obj->ToObject(&obj)) return false;
1782 }
1724 set_neander_map(Map::cast(obj)); 1783 set_neander_map(Map::cast(obj));
1725 1784
1726 obj = Heap::AllocateJSObjectFromMap(neander_map()); 1785 { MaybeObject* maybe_obj = Heap::AllocateJSObjectFromMap(neander_map());
1727 if (obj->IsFailure()) return false; 1786 if (!maybe_obj->ToObject(&obj)) return false;
1728 Object* elements = AllocateFixedArray(2); 1787 }
1729 if (elements->IsFailure()) return false; 1788 Object* elements;
1789 { MaybeObject* maybe_elements = AllocateFixedArray(2);
1790 if (!maybe_elements->ToObject(&elements)) return false;
1791 }
1730 FixedArray::cast(elements)->set(0, Smi::FromInt(0)); 1792 FixedArray::cast(elements)->set(0, Smi::FromInt(0));
1731 JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); 1793 JSObject::cast(obj)->set_elements(FixedArray::cast(elements));
1732 set_message_listeners(JSObject::cast(obj)); 1794 set_message_listeners(JSObject::cast(obj));
1733 1795
1734 return true; 1796 return true;
1735 } 1797 }
1736 1798
1737 1799
1738 void Heap::CreateCEntryStub() { 1800 void Heap::CreateCEntryStub() {
1739 CEntryStub stub(1); 1801 CEntryStub stub(1);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP 1843 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP
1782 Heap::CreateRegExpCEntryStub(); 1844 Heap::CreateRegExpCEntryStub();
1783 #endif 1845 #endif
1784 } 1846 }
1785 1847
1786 1848
1787 bool Heap::CreateInitialObjects() { 1849 bool Heap::CreateInitialObjects() {
1788 Object* obj; 1850 Object* obj;
1789 1851
1790 // The -0 value must be set before NumberFromDouble works. 1852 // The -0 value must be set before NumberFromDouble works.
1791 obj = AllocateHeapNumber(-0.0, TENURED); 1853 { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED);
1792 if (obj->IsFailure()) return false; 1854 if (!maybe_obj->ToObject(&obj)) return false;
1855 }
1793 set_minus_zero_value(obj); 1856 set_minus_zero_value(obj);
1794 ASSERT(signbit(minus_zero_value()->Number()) != 0); 1857 ASSERT(signbit(minus_zero_value()->Number()) != 0);
1795 1858
1796 obj = AllocateHeapNumber(OS::nan_value(), TENURED); 1859 { MaybeObject* maybe_obj = AllocateHeapNumber(OS::nan_value(), TENURED);
1797 if (obj->IsFailure()) return false; 1860 if (!maybe_obj->ToObject(&obj)) return false;
1861 }
1798 set_nan_value(obj); 1862 set_nan_value(obj);
1799 1863
1800 obj = Allocate(oddball_map(), OLD_DATA_SPACE); 1864 { MaybeObject* maybe_obj = Allocate(oddball_map(), OLD_DATA_SPACE);
1801 if (obj->IsFailure()) return false; 1865 if (!maybe_obj->ToObject(&obj)) return false;
1866 }
1802 set_undefined_value(obj); 1867 set_undefined_value(obj);
1803 ASSERT(!InNewSpace(undefined_value())); 1868 ASSERT(!InNewSpace(undefined_value()));
1804 1869
1805 // Allocate initial symbol table. 1870 // Allocate initial symbol table.
1806 obj = SymbolTable::Allocate(kInitialSymbolTableSize); 1871 { MaybeObject* maybe_obj = SymbolTable::Allocate(kInitialSymbolTableSize);
1807 if (obj->IsFailure()) return false; 1872 if (!maybe_obj->ToObject(&obj)) return false;
1873 }
1808 // Don't use set_symbol_table() due to asserts. 1874 // Don't use set_symbol_table() due to asserts.
1809 roots_[kSymbolTableRootIndex] = obj; 1875 roots_[kSymbolTableRootIndex] = obj;
1810 1876
1811 // Assign the print strings for oddballs after creating symboltable. 1877 // Assign the print strings for oddballs after creating symboltable.
1812 Object* symbol = LookupAsciiSymbol("undefined"); 1878 Object* symbol;
1813 if (symbol->IsFailure()) return false; 1879 { MaybeObject* maybe_symbol = LookupAsciiSymbol("undefined");
1880 if (!maybe_symbol->ToObject(&symbol)) return false;
1881 }
1814 Oddball::cast(undefined_value())->set_to_string(String::cast(symbol)); 1882 Oddball::cast(undefined_value())->set_to_string(String::cast(symbol));
1815 Oddball::cast(undefined_value())->set_to_number(nan_value()); 1883 Oddball::cast(undefined_value())->set_to_number(nan_value());
1816 1884
1817 // Allocate the null_value 1885 // Allocate the null_value
1818 obj = Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0)); 1886 { MaybeObject* maybe_obj =
1819 if (obj->IsFailure()) return false; 1887 Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0));
1888 if (!maybe_obj->ToObject(&obj)) return false;
1889 }
1820 1890
1821 obj = CreateOddball("true", Smi::FromInt(1)); 1891 { MaybeObject* maybe_obj = CreateOddball("true", Smi::FromInt(1));
1822 if (obj->IsFailure()) return false; 1892 if (!maybe_obj->ToObject(&obj)) return false;
1893 }
1823 set_true_value(obj); 1894 set_true_value(obj);
1824 1895
1825 obj = CreateOddball("false", Smi::FromInt(0)); 1896 { MaybeObject* maybe_obj = CreateOddball("false", Smi::FromInt(0));
1826 if (obj->IsFailure()) return false; 1897 if (!maybe_obj->ToObject(&obj)) return false;
1898 }
1827 set_false_value(obj); 1899 set_false_value(obj);
1828 1900
1829 obj = CreateOddball("hole", Smi::FromInt(-1)); 1901 { MaybeObject* maybe_obj = CreateOddball("hole", Smi::FromInt(-1));
1830 if (obj->IsFailure()) return false; 1902 if (!maybe_obj->ToObject(&obj)) return false;
1903 }
1831 set_the_hole_value(obj); 1904 set_the_hole_value(obj);
1832 1905
1833 obj = CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2)); 1906 { MaybeObject* maybe_obj =
1834 if (obj->IsFailure()) return false; 1907 CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2));
1908 if (!maybe_obj->ToObject(&obj)) return false;
1909 }
1835 set_no_interceptor_result_sentinel(obj); 1910 set_no_interceptor_result_sentinel(obj);
1836 1911
1837 obj = CreateOddball("termination_exception", Smi::FromInt(-3)); 1912 { MaybeObject* maybe_obj =
1838 if (obj->IsFailure()) return false; 1913 CreateOddball("termination_exception", Smi::FromInt(-3));
1914 if (!maybe_obj->ToObject(&obj)) return false;
1915 }
1839 set_termination_exception(obj); 1916 set_termination_exception(obj);
1840 1917
1841 // Allocate the empty string. 1918 // Allocate the empty string.
1842 obj = AllocateRawAsciiString(0, TENURED); 1919 { MaybeObject* maybe_obj = AllocateRawAsciiString(0, TENURED);
1843 if (obj->IsFailure()) return false; 1920 if (!maybe_obj->ToObject(&obj)) return false;
1921 }
1844 set_empty_string(String::cast(obj)); 1922 set_empty_string(String::cast(obj));
1845 1923
1846 for (unsigned i = 0; i < ARRAY_SIZE(constant_symbol_table); i++) { 1924 for (unsigned i = 0; i < ARRAY_SIZE(constant_symbol_table); i++) {
1847 obj = LookupAsciiSymbol(constant_symbol_table[i].contents); 1925 { MaybeObject* maybe_obj =
1848 if (obj->IsFailure()) return false; 1926 LookupAsciiSymbol(constant_symbol_table[i].contents);
1927 if (!maybe_obj->ToObject(&obj)) return false;
1928 }
1849 roots_[constant_symbol_table[i].index] = String::cast(obj); 1929 roots_[constant_symbol_table[i].index] = String::cast(obj);
1850 } 1930 }
1851 1931
1852 // Allocate the hidden symbol which is used to identify the hidden properties 1932 // Allocate the hidden symbol which is used to identify the hidden properties
1853 // in JSObjects. The hash code has a special value so that it will not match 1933 // in JSObjects. The hash code has a special value so that it will not match
1854 // the empty string when searching for the property. It cannot be part of the 1934 // the empty string when searching for the property. It cannot be part of the
1855 // loop above because it needs to be allocated manually with the special 1935 // loop above because it needs to be allocated manually with the special
1856 // hash code in place. The hash code for the hidden_symbol is zero to ensure 1936 // hash code in place. The hash code for the hidden_symbol is zero to ensure
1857 // that it will always be at the first entry in property descriptors. 1937 // that it will always be at the first entry in property descriptors.
1858 obj = AllocateSymbol(CStrVector(""), 0, String::kZeroHash); 1938 { MaybeObject* maybe_obj =
1859 if (obj->IsFailure()) return false; 1939 AllocateSymbol(CStrVector(""), 0, String::kZeroHash);
1940 if (!maybe_obj->ToObject(&obj)) return false;
1941 }
1860 hidden_symbol_ = String::cast(obj); 1942 hidden_symbol_ = String::cast(obj);
1861 1943
1862 // Allocate the proxy for __proto__. 1944 // Allocate the proxy for __proto__.
1863 obj = AllocateProxy((Address) &Accessors::ObjectPrototype); 1945 { MaybeObject* maybe_obj =
1864 if (obj->IsFailure()) return false; 1946 AllocateProxy((Address) &Accessors::ObjectPrototype);
1947 if (!maybe_obj->ToObject(&obj)) return false;
1948 }
1865 set_prototype_accessors(Proxy::cast(obj)); 1949 set_prototype_accessors(Proxy::cast(obj));
1866 1950
1867 // Allocate the code_stubs dictionary. The initial size is set to avoid 1951 // Allocate the code_stubs dictionary. The initial size is set to avoid
1868 // expanding the dictionary during bootstrapping. 1952 // expanding the dictionary during bootstrapping.
1869 obj = NumberDictionary::Allocate(128); 1953 { MaybeObject* maybe_obj = NumberDictionary::Allocate(128);
1870 if (obj->IsFailure()) return false; 1954 if (!maybe_obj->ToObject(&obj)) return false;
1955 }
1871 set_code_stubs(NumberDictionary::cast(obj)); 1956 set_code_stubs(NumberDictionary::cast(obj));
1872 1957
1873 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size 1958 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size
1874 // is set to avoid expanding the dictionary during bootstrapping. 1959 // is set to avoid expanding the dictionary during bootstrapping.
1875 obj = NumberDictionary::Allocate(64); 1960 { MaybeObject* maybe_obj = NumberDictionary::Allocate(64);
1876 if (obj->IsFailure()) return false; 1961 if (!maybe_obj->ToObject(&obj)) return false;
1962 }
1877 set_non_monomorphic_cache(NumberDictionary::cast(obj)); 1963 set_non_monomorphic_cache(NumberDictionary::cast(obj));
1878 1964
1879 set_instanceof_cache_function(Smi::FromInt(0)); 1965 set_instanceof_cache_function(Smi::FromInt(0));
1880 set_instanceof_cache_map(Smi::FromInt(0)); 1966 set_instanceof_cache_map(Smi::FromInt(0));
1881 set_instanceof_cache_answer(Smi::FromInt(0)); 1967 set_instanceof_cache_answer(Smi::FromInt(0));
1882 1968
1883 CreateFixedStubs(); 1969 CreateFixedStubs();
1884 1970
1885 // Allocate the dictionary of intrinsic function names. 1971 // Allocate the dictionary of intrinsic function names.
1886 obj = StringDictionary::Allocate(Runtime::kNumFunctions); 1972 { MaybeObject* maybe_obj = StringDictionary::Allocate(Runtime::kNumFunctions);
1887 if (obj->IsFailure()) return false; 1973 if (!maybe_obj->ToObject(&obj)) return false;
1888 obj = Runtime::InitializeIntrinsicFunctionNames(obj); 1974 }
1889 if (obj->IsFailure()) return false; 1975 { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(obj);
1976 if (!maybe_obj->ToObject(&obj)) return false;
1977 }
1890 set_intrinsic_function_names(StringDictionary::cast(obj)); 1978 set_intrinsic_function_names(StringDictionary::cast(obj));
1891 1979
1892 if (InitializeNumberStringCache()->IsFailure()) return false; 1980 if (InitializeNumberStringCache()->IsFailure()) return false;
1893 1981
1894 // Allocate cache for single character ASCII strings. 1982 // Allocate cache for single character ASCII strings.
1895 obj = AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED); 1983 { MaybeObject* maybe_obj =
1896 if (obj->IsFailure()) return false; 1984 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
1985 if (!maybe_obj->ToObject(&obj)) return false;
1986 }
1897 set_single_character_string_cache(FixedArray::cast(obj)); 1987 set_single_character_string_cache(FixedArray::cast(obj));
1898 1988
1899 // Allocate cache for external strings pointing to native source code. 1989 // Allocate cache for external strings pointing to native source code.
1900 obj = AllocateFixedArray(Natives::GetBuiltinsCount()); 1990 { MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount());
1901 if (obj->IsFailure()) return false; 1991 if (!maybe_obj->ToObject(&obj)) return false;
1992 }
1902 set_natives_source_cache(FixedArray::cast(obj)); 1993 set_natives_source_cache(FixedArray::cast(obj));
1903 1994
1904 // Handling of script id generation is in Factory::NewScript. 1995 // Handling of script id generation is in Factory::NewScript.
1905 set_last_script_id(undefined_value()); 1996 set_last_script_id(undefined_value());
1906 1997
1907 // Initialize keyed lookup cache. 1998 // Initialize keyed lookup cache.
1908 KeyedLookupCache::Clear(); 1999 KeyedLookupCache::Clear();
1909 2000
1910 // Initialize context slot cache. 2001 // Initialize context slot cache.
1911 ContextSlotCache::Clear(); 2002 ContextSlotCache::Clear();
1912 2003
1913 // Initialize descriptor cache. 2004 // Initialize descriptor cache.
1914 DescriptorLookupCache::Clear(); 2005 DescriptorLookupCache::Clear();
1915 2006
1916 // Initialize compilation cache. 2007 // Initialize compilation cache.
1917 CompilationCache::Clear(); 2008 CompilationCache::Clear();
1918 2009
1919 return true; 2010 return true;
1920 } 2011 }
1921 2012
1922 2013
1923 Object* Heap::InitializeNumberStringCache() { 2014 MaybeObject* Heap::InitializeNumberStringCache() {
1924 // Compute the size of the number string cache based on the max heap size. 2015 // Compute the size of the number string cache based on the max heap size.
1925 // max_semispace_size_ == 512 KB => number_string_cache_size = 32. 2016 // max_semispace_size_ == 512 KB => number_string_cache_size = 32.
1926 // max_semispace_size_ == 8 MB => number_string_cache_size = 16KB. 2017 // max_semispace_size_ == 8 MB => number_string_cache_size = 16KB.
1927 int number_string_cache_size = max_semispace_size_ / 512; 2018 int number_string_cache_size = max_semispace_size_ / 512;
1928 number_string_cache_size = Max(32, Min(16*KB, number_string_cache_size)); 2019 number_string_cache_size = Max(32, Min(16*KB, number_string_cache_size));
1929 Object* obj = AllocateFixedArray(number_string_cache_size * 2, TENURED); 2020 Object* obj;
1930 if (!obj->IsFailure()) set_number_string_cache(FixedArray::cast(obj)); 2021 MaybeObject* maybe_obj =
1931 return obj; 2022 AllocateFixedArray(number_string_cache_size * 2, TENURED);
2023 if (maybe_obj->ToObject(&obj)) set_number_string_cache(FixedArray::cast(obj));
2024 return maybe_obj;
1932 } 2025 }
1933 2026
1934 2027
1935 void Heap::FlushNumberStringCache() { 2028 void Heap::FlushNumberStringCache() {
1936 // Flush the number to string cache. 2029 // Flush the number to string cache.
1937 int len = number_string_cache()->length(); 2030 int len = number_string_cache()->length();
1938 for (int i = 0; i < len; i++) { 2031 for (int i = 0; i < len; i++) {
1939 number_string_cache()->set_undefined(i); 2032 number_string_cache()->set_undefined(i);
1940 } 2033 }
1941 } 2034 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 hash = smi_get_hash(Smi::cast(number)) & mask; 2072 hash = smi_get_hash(Smi::cast(number)) & mask;
1980 number_string_cache()->set(hash * 2, Smi::cast(number)); 2073 number_string_cache()->set(hash * 2, Smi::cast(number));
1981 } else { 2074 } else {
1982 hash = double_get_hash(number->Number()) & mask; 2075 hash = double_get_hash(number->Number()) & mask;
1983 number_string_cache()->set(hash * 2, number); 2076 number_string_cache()->set(hash * 2, number);
1984 } 2077 }
1985 number_string_cache()->set(hash * 2 + 1, string); 2078 number_string_cache()->set(hash * 2 + 1, string);
1986 } 2079 }
1987 2080
1988 2081
1989 Object* Heap::NumberToString(Object* number, bool check_number_string_cache) { 2082 MaybeObject* Heap::NumberToString(Object* number,
2083 bool check_number_string_cache) {
1990 Counters::number_to_string_runtime.Increment(); 2084 Counters::number_to_string_runtime.Increment();
1991 if (check_number_string_cache) { 2085 if (check_number_string_cache) {
1992 Object* cached = GetNumberStringCache(number); 2086 Object* cached = GetNumberStringCache(number);
1993 if (cached != undefined_value()) { 2087 if (cached != undefined_value()) {
1994 return cached; 2088 return cached;
1995 } 2089 }
1996 } 2090 }
1997 2091
1998 char arr[100]; 2092 char arr[100];
1999 Vector<char> buffer(arr, ARRAY_SIZE(arr)); 2093 Vector<char> buffer(arr, ARRAY_SIZE(arr));
2000 const char* str; 2094 const char* str;
2001 if (number->IsSmi()) { 2095 if (number->IsSmi()) {
2002 int num = Smi::cast(number)->value(); 2096 int num = Smi::cast(number)->value();
2003 str = IntToCString(num, buffer); 2097 str = IntToCString(num, buffer);
2004 } else { 2098 } else {
2005 double num = HeapNumber::cast(number)->value(); 2099 double num = HeapNumber::cast(number)->value();
2006 str = DoubleToCString(num, buffer); 2100 str = DoubleToCString(num, buffer);
2007 } 2101 }
2008 Object* result = AllocateStringFromAscii(CStrVector(str));
2009 2102
2010 if (!result->IsFailure()) { 2103 Object* js_string;
2011 SetNumberStringCache(number, String::cast(result)); 2104 MaybeObject* maybe_js_string = AllocateStringFromAscii(CStrVector(str));
2105 if (maybe_js_string->ToObject(&js_string)) {
2106 SetNumberStringCache(number, String::cast(js_string));
2012 } 2107 }
2013 return result; 2108 return maybe_js_string;
2014 } 2109 }
2015 2110
2016 2111
2017 Map* Heap::MapForExternalArrayType(ExternalArrayType array_type) { 2112 Map* Heap::MapForExternalArrayType(ExternalArrayType array_type) {
2018 return Map::cast(roots_[RootIndexForExternalArrayType(array_type)]); 2113 return Map::cast(roots_[RootIndexForExternalArrayType(array_type)]);
2019 } 2114 }
2020 2115
2021 2116
2022 Heap::RootListIndex Heap::RootIndexForExternalArrayType( 2117 Heap::RootListIndex Heap::RootIndexForExternalArrayType(
2023 ExternalArrayType array_type) { 2118 ExternalArrayType array_type) {
(...skipping 12 matching lines...) Expand all
2036 return kExternalUnsignedIntArrayMapRootIndex; 2131 return kExternalUnsignedIntArrayMapRootIndex;
2037 case kExternalFloatArray: 2132 case kExternalFloatArray:
2038 return kExternalFloatArrayMapRootIndex; 2133 return kExternalFloatArrayMapRootIndex;
2039 default: 2134 default:
2040 UNREACHABLE(); 2135 UNREACHABLE();
2041 return kUndefinedValueRootIndex; 2136 return kUndefinedValueRootIndex;
2042 } 2137 }
2043 } 2138 }
2044 2139
2045 2140
2046 Object* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { 2141 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) {
2047 // We need to distinguish the minus zero value and this cannot be 2142 // We need to distinguish the minus zero value and this cannot be
2048 // done after conversion to int. Doing this by comparing bit 2143 // done after conversion to int. Doing this by comparing bit
2049 // patterns is faster than using fpclassify() et al. 2144 // patterns is faster than using fpclassify() et al.
2050 static const DoubleRepresentation minus_zero(-0.0); 2145 static const DoubleRepresentation minus_zero(-0.0);
2051 2146
2052 DoubleRepresentation rep(value); 2147 DoubleRepresentation rep(value);
2053 if (rep.bits == minus_zero.bits) { 2148 if (rep.bits == minus_zero.bits) {
2054 return AllocateHeapNumber(-0.0, pretenure); 2149 return AllocateHeapNumber(-0.0, pretenure);
2055 } 2150 }
2056 2151
2057 int int_value = FastD2I(value); 2152 int int_value = FastD2I(value);
2058 if (value == int_value && Smi::IsValid(int_value)) { 2153 if (value == int_value && Smi::IsValid(int_value)) {
2059 return Smi::FromInt(int_value); 2154 return Smi::FromInt(int_value);
2060 } 2155 }
2061 2156
2062 // Materialize the value in the heap. 2157 // Materialize the value in the heap.
2063 return AllocateHeapNumber(value, pretenure); 2158 return AllocateHeapNumber(value, pretenure);
2064 } 2159 }
2065 2160
2066 2161
2067 Object* Heap::AllocateProxy(Address proxy, PretenureFlag pretenure) { 2162 MaybeObject* Heap::AllocateProxy(Address proxy, PretenureFlag pretenure) {
2068 // Statically ensure that it is safe to allocate proxies in paged spaces. 2163 // Statically ensure that it is safe to allocate proxies in paged spaces.
2069 STATIC_ASSERT(Proxy::kSize <= Page::kMaxHeapObjectSize); 2164 STATIC_ASSERT(Proxy::kSize <= Page::kMaxHeapObjectSize);
2070 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2165 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2071 Object* result = Allocate(proxy_map(), space); 2166 Object* result;
2072 if (result->IsFailure()) return result; 2167 { MaybeObject* maybe_result = Allocate(proxy_map(), space);
2168 if (!maybe_result->ToObject(&result)) return maybe_result;
2169 }
2073 2170
2074 Proxy::cast(result)->set_proxy(proxy); 2171 Proxy::cast(result)->set_proxy(proxy);
2075 return result; 2172 return result;
2076 } 2173 }
2077 2174
2078 2175
2079 Object* Heap::AllocateSharedFunctionInfo(Object* name) { 2176 MaybeObject* Heap::AllocateSharedFunctionInfo(Object* name) {
2080 Object* result = Allocate(shared_function_info_map(), OLD_POINTER_SPACE); 2177 Object* result;
2081 if (result->IsFailure()) return result; 2178 { MaybeObject* maybe_result =
2179 Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
2180 if (!maybe_result->ToObject(&result)) return maybe_result;
2181 }
2082 2182
2083 SharedFunctionInfo* share = SharedFunctionInfo::cast(result); 2183 SharedFunctionInfo* share = SharedFunctionInfo::cast(result);
2084 share->set_name(name); 2184 share->set_name(name);
2085 Code* illegal = Builtins::builtin(Builtins::Illegal); 2185 Code* illegal = Builtins::builtin(Builtins::Illegal);
2086 share->set_code(illegal); 2186 share->set_code(illegal);
2087 share->set_scope_info(SerializedScopeInfo::Empty()); 2187 share->set_scope_info(SerializedScopeInfo::Empty());
2088 Code* construct_stub = Builtins::builtin(Builtins::JSConstructStubGeneric); 2188 Code* construct_stub = Builtins::builtin(Builtins::JSConstructStubGeneric);
2089 share->set_construct_stub(construct_stub); 2189 share->set_construct_stub(construct_stub);
2090 share->set_expected_nof_properties(0); 2190 share->set_expected_nof_properties(0);
2091 share->set_length(0); 2191 share->set_length(0);
(...skipping 15 matching lines...) Expand all
2107 } 2207 }
2108 2208
2109 2209
2110 // Returns true for a character in a range. Both limits are inclusive. 2210 // Returns true for a character in a range. Both limits are inclusive.
2111 static inline bool Between(uint32_t character, uint32_t from, uint32_t to) { 2211 static inline bool Between(uint32_t character, uint32_t from, uint32_t to) {
2112 // This makes uses of the the unsigned wraparound. 2212 // This makes uses of the the unsigned wraparound.
2113 return character - from <= to - from; 2213 return character - from <= to - from;
2114 } 2214 }
2115 2215
2116 2216
2117 static inline Object* MakeOrFindTwoCharacterString(uint32_t c1, uint32_t c2) { 2217 MUST_USE_RESULT static inline MaybeObject* MakeOrFindTwoCharacterString(
2218 uint32_t c1,
2219 uint32_t c2) {
2118 String* symbol; 2220 String* symbol;
2119 // Numeric strings have a different hash algorithm not known by 2221 // Numeric strings have a different hash algorithm not known by
2120 // LookupTwoCharsSymbolIfExists, so we skip this step for such strings. 2222 // LookupTwoCharsSymbolIfExists, so we skip this step for such strings.
2121 if ((!Between(c1, '0', '9') || !Between(c2, '0', '9')) && 2223 if ((!Between(c1, '0', '9') || !Between(c2, '0', '9')) &&
2122 Heap::symbol_table()->LookupTwoCharsSymbolIfExists(c1, c2, &symbol)) { 2224 Heap::symbol_table()->LookupTwoCharsSymbolIfExists(c1, c2, &symbol)) {
2123 return symbol; 2225 return symbol;
2124 // Now we know the length is 2, we might as well make use of that fact 2226 // Now we know the length is 2, we might as well make use of that fact
2125 // when building the new string. 2227 // when building the new string.
2126 } else if ((c1 | c2) <= String::kMaxAsciiCharCodeU) { // We can do this 2228 } else if ((c1 | c2) <= String::kMaxAsciiCharCodeU) { // We can do this
2127 ASSERT(IsPowerOf2(String::kMaxAsciiCharCodeU + 1)); // because of this. 2229 ASSERT(IsPowerOf2(String::kMaxAsciiCharCodeU + 1)); // because of this.
2128 Object* result = Heap::AllocateRawAsciiString(2); 2230 Object* result;
2129 if (result->IsFailure()) return result; 2231 { MaybeObject* maybe_result = Heap::AllocateRawAsciiString(2);
2232 if (!maybe_result->ToObject(&result)) return maybe_result;
2233 }
2130 char* dest = SeqAsciiString::cast(result)->GetChars(); 2234 char* dest = SeqAsciiString::cast(result)->GetChars();
2131 dest[0] = c1; 2235 dest[0] = c1;
2132 dest[1] = c2; 2236 dest[1] = c2;
2133 return result; 2237 return result;
2134 } else { 2238 } else {
2135 Object* result = Heap::AllocateRawTwoByteString(2); 2239 Object* result;
2136 if (result->IsFailure()) return result; 2240 { MaybeObject* maybe_result = Heap::AllocateRawTwoByteString(2);
2241 if (!maybe_result->ToObject(&result)) return maybe_result;
2242 }
2137 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); 2243 uc16* dest = SeqTwoByteString::cast(result)->GetChars();
2138 dest[0] = c1; 2244 dest[0] = c1;
2139 dest[1] = c2; 2245 dest[1] = c2;
2140 return result; 2246 return result;
2141 } 2247 }
2142 } 2248 }
2143 2249
2144 2250
2145 Object* Heap::AllocateConsString(String* first, String* second) { 2251 MaybeObject* Heap::AllocateConsString(String* first, String* second) {
2146 int first_length = first->length(); 2252 int first_length = first->length();
2147 if (first_length == 0) { 2253 if (first_length == 0) {
2148 return second; 2254 return second;
2149 } 2255 }
2150 2256
2151 int second_length = second->length(); 2257 int second_length = second->length();
2152 if (second_length == 0) { 2258 if (second_length == 0) {
2153 return first; 2259 return first;
2154 } 2260 }
2155 2261
(...skipping 29 matching lines...) Expand all
2185 if (is_ascii_data_in_two_byte_string) { 2291 if (is_ascii_data_in_two_byte_string) {
2186 Counters::string_add_runtime_ext_to_ascii.Increment(); 2292 Counters::string_add_runtime_ext_to_ascii.Increment();
2187 } 2293 }
2188 } 2294 }
2189 2295
2190 // If the resulting string is small make a flat string. 2296 // If the resulting string is small make a flat string.
2191 if (length < String::kMinNonFlatLength) { 2297 if (length < String::kMinNonFlatLength) {
2192 ASSERT(first->IsFlat()); 2298 ASSERT(first->IsFlat());
2193 ASSERT(second->IsFlat()); 2299 ASSERT(second->IsFlat());
2194 if (is_ascii) { 2300 if (is_ascii) {
2195 Object* result = AllocateRawAsciiString(length); 2301 Object* result;
2196 if (result->IsFailure()) return result; 2302 { MaybeObject* maybe_result = AllocateRawAsciiString(length);
2303 if (!maybe_result->ToObject(&result)) return maybe_result;
2304 }
2197 // Copy the characters into the new object. 2305 // Copy the characters into the new object.
2198 char* dest = SeqAsciiString::cast(result)->GetChars(); 2306 char* dest = SeqAsciiString::cast(result)->GetChars();
2199 // Copy first part. 2307 // Copy first part.
2200 const char* src; 2308 const char* src;
2201 if (first->IsExternalString()) { 2309 if (first->IsExternalString()) {
2202 src = ExternalAsciiString::cast(first)->resource()->data(); 2310 src = ExternalAsciiString::cast(first)->resource()->data();
2203 } else { 2311 } else {
2204 src = SeqAsciiString::cast(first)->GetChars(); 2312 src = SeqAsciiString::cast(first)->GetChars();
2205 } 2313 }
2206 for (int i = 0; i < first_length; i++) *dest++ = src[i]; 2314 for (int i = 0; i < first_length; i++) *dest++ = src[i];
2207 // Copy second part. 2315 // Copy second part.
2208 if (second->IsExternalString()) { 2316 if (second->IsExternalString()) {
2209 src = ExternalAsciiString::cast(second)->resource()->data(); 2317 src = ExternalAsciiString::cast(second)->resource()->data();
2210 } else { 2318 } else {
2211 src = SeqAsciiString::cast(second)->GetChars(); 2319 src = SeqAsciiString::cast(second)->GetChars();
2212 } 2320 }
2213 for (int i = 0; i < second_length; i++) *dest++ = src[i]; 2321 for (int i = 0; i < second_length; i++) *dest++ = src[i];
2214 return result; 2322 return result;
2215 } else { 2323 } else {
2216 if (is_ascii_data_in_two_byte_string) { 2324 if (is_ascii_data_in_two_byte_string) {
2217 Object* result = AllocateRawAsciiString(length); 2325 Object* result;
2218 if (result->IsFailure()) return result; 2326 { MaybeObject* maybe_result = AllocateRawAsciiString(length);
2327 if (!maybe_result->ToObject(&result)) return maybe_result;
2328 }
2219 // Copy the characters into the new object. 2329 // Copy the characters into the new object.
2220 char* dest = SeqAsciiString::cast(result)->GetChars(); 2330 char* dest = SeqAsciiString::cast(result)->GetChars();
2221 String::WriteToFlat(first, dest, 0, first_length); 2331 String::WriteToFlat(first, dest, 0, first_length);
2222 String::WriteToFlat(second, dest + first_length, 0, second_length); 2332 String::WriteToFlat(second, dest + first_length, 0, second_length);
2223 return result; 2333 return result;
2224 } 2334 }
2225 2335
2226 Object* result = AllocateRawTwoByteString(length); 2336 Object* result;
2227 if (result->IsFailure()) return result; 2337 { MaybeObject* maybe_result = AllocateRawTwoByteString(length);
2338 if (!maybe_result->ToObject(&result)) return maybe_result;
2339 }
2228 // Copy the characters into the new object. 2340 // Copy the characters into the new object.
2229 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); 2341 uc16* dest = SeqTwoByteString::cast(result)->GetChars();
2230 String::WriteToFlat(first, dest, 0, first_length); 2342 String::WriteToFlat(first, dest, 0, first_length);
2231 String::WriteToFlat(second, dest + first_length, 0, second_length); 2343 String::WriteToFlat(second, dest + first_length, 0, second_length);
2232 return result; 2344 return result;
2233 } 2345 }
2234 } 2346 }
2235 2347
2236 Map* map = (is_ascii || is_ascii_data_in_two_byte_string) ? 2348 Map* map = (is_ascii || is_ascii_data_in_two_byte_string) ?
2237 cons_ascii_string_map() : cons_string_map(); 2349 cons_ascii_string_map() : cons_string_map();
2238 2350
2239 Object* result = Allocate(map, NEW_SPACE); 2351 Object* result;
2240 if (result->IsFailure()) return result; 2352 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
2353 if (!maybe_result->ToObject(&result)) return maybe_result;
2354 }
2241 2355
2242 AssertNoAllocation no_gc; 2356 AssertNoAllocation no_gc;
2243 ConsString* cons_string = ConsString::cast(result); 2357 ConsString* cons_string = ConsString::cast(result);
2244 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(no_gc); 2358 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(no_gc);
2245 cons_string->set_length(length); 2359 cons_string->set_length(length);
2246 cons_string->set_hash_field(String::kEmptyHashField); 2360 cons_string->set_hash_field(String::kEmptyHashField);
2247 cons_string->set_first(first, mode); 2361 cons_string->set_first(first, mode);
2248 cons_string->set_second(second, mode); 2362 cons_string->set_second(second, mode);
2249 return result; 2363 return result;
2250 } 2364 }
2251 2365
2252 2366
2253 Object* Heap::AllocateSubString(String* buffer, 2367 MaybeObject* Heap::AllocateSubString(String* buffer,
2254 int start, 2368 int start,
2255 int end, 2369 int end,
2256 PretenureFlag pretenure) { 2370 PretenureFlag pretenure) {
2257 int length = end - start; 2371 int length = end - start;
2258 2372
2259 if (length == 1) { 2373 if (length == 1) {
2260 return Heap::LookupSingleCharacterStringFromCode( 2374 return Heap::LookupSingleCharacterStringFromCode(
2261 buffer->Get(start)); 2375 buffer->Get(start));
2262 } else if (length == 2) { 2376 } else if (length == 2) {
2263 // Optimization for 2-byte strings often used as keys in a decompression 2377 // Optimization for 2-byte strings often used as keys in a decompression
2264 // dictionary. Check whether we already have the string in the symbol 2378 // dictionary. Check whether we already have the string in the symbol
2265 // table to prevent creation of many unneccesary strings. 2379 // table to prevent creation of many unneccesary strings.
2266 unsigned c1 = buffer->Get(start); 2380 unsigned c1 = buffer->Get(start);
2267 unsigned c2 = buffer->Get(start + 1); 2381 unsigned c2 = buffer->Get(start + 1);
2268 return MakeOrFindTwoCharacterString(c1, c2); 2382 return MakeOrFindTwoCharacterString(c1, c2);
2269 } 2383 }
2270 2384
2271 // Make an attempt to flatten the buffer to reduce access time. 2385 // Make an attempt to flatten the buffer to reduce access time.
2272 buffer = buffer->TryFlattenGetString(); 2386 buffer = buffer->TryFlattenGetString();
2273 2387
2274 Object* result = buffer->IsAsciiRepresentation() 2388 Object* result;
2275 ? AllocateRawAsciiString(length, pretenure ) 2389 { MaybeObject* maybe_result = buffer->IsAsciiRepresentation()
2276 : AllocateRawTwoByteString(length, pretenure); 2390 ? AllocateRawAsciiString(length, pretenure )
2277 if (result->IsFailure()) return result; 2391 : AllocateRawTwoByteString(length, pretenure);
2392 if (!maybe_result->ToObject(&result)) return maybe_result;
2393 }
2278 String* string_result = String::cast(result); 2394 String* string_result = String::cast(result);
2279 // Copy the characters into the new object. 2395 // Copy the characters into the new object.
2280 if (buffer->IsAsciiRepresentation()) { 2396 if (buffer->IsAsciiRepresentation()) {
2281 ASSERT(string_result->IsAsciiRepresentation()); 2397 ASSERT(string_result->IsAsciiRepresentation());
2282 char* dest = SeqAsciiString::cast(string_result)->GetChars(); 2398 char* dest = SeqAsciiString::cast(string_result)->GetChars();
2283 String::WriteToFlat(buffer, dest, start, end); 2399 String::WriteToFlat(buffer, dest, start, end);
2284 } else { 2400 } else {
2285 ASSERT(string_result->IsTwoByteRepresentation()); 2401 ASSERT(string_result->IsTwoByteRepresentation());
2286 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); 2402 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars();
2287 String::WriteToFlat(buffer, dest, start, end); 2403 String::WriteToFlat(buffer, dest, start, end);
2288 } 2404 }
2289 2405
2290 return result; 2406 return result;
2291 } 2407 }
2292 2408
2293 2409
2294 Object* Heap::AllocateExternalStringFromAscii( 2410 MaybeObject* Heap::AllocateExternalStringFromAscii(
2295 ExternalAsciiString::Resource* resource) { 2411 ExternalAsciiString::Resource* resource) {
2296 size_t length = resource->length(); 2412 size_t length = resource->length();
2297 if (length > static_cast<size_t>(String::kMaxLength)) { 2413 if (length > static_cast<size_t>(String::kMaxLength)) {
2298 Top::context()->mark_out_of_memory(); 2414 Top::context()->mark_out_of_memory();
2299 return Failure::OutOfMemoryException(); 2415 return Failure::OutOfMemoryException();
2300 } 2416 }
2301 2417
2302 Map* map = external_ascii_string_map(); 2418 Map* map = external_ascii_string_map();
2303 Object* result = Allocate(map, NEW_SPACE); 2419 Object* result;
2304 if (result->IsFailure()) return result; 2420 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
2421 if (!maybe_result->ToObject(&result)) return maybe_result;
2422 }
2305 2423
2306 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 2424 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
2307 external_string->set_length(static_cast<int>(length)); 2425 external_string->set_length(static_cast<int>(length));
2308 external_string->set_hash_field(String::kEmptyHashField); 2426 external_string->set_hash_field(String::kEmptyHashField);
2309 external_string->set_resource(resource); 2427 external_string->set_resource(resource);
2310 2428
2311 return result; 2429 return result;
2312 } 2430 }
2313 2431
2314 2432
2315 Object* Heap::AllocateExternalStringFromTwoByte( 2433 MaybeObject* Heap::AllocateExternalStringFromTwoByte(
2316 ExternalTwoByteString::Resource* resource) { 2434 ExternalTwoByteString::Resource* resource) {
2317 size_t length = resource->length(); 2435 size_t length = resource->length();
2318 if (length > static_cast<size_t>(String::kMaxLength)) { 2436 if (length > static_cast<size_t>(String::kMaxLength)) {
2319 Top::context()->mark_out_of_memory(); 2437 Top::context()->mark_out_of_memory();
2320 return Failure::OutOfMemoryException(); 2438 return Failure::OutOfMemoryException();
2321 } 2439 }
2322 2440
2323 // For small strings we check whether the resource contains only 2441 // For small strings we check whether the resource contains only
2324 // ascii characters. If yes, we use a different string map. 2442 // ascii characters. If yes, we use a different string map.
2325 bool is_ascii = true; 2443 bool is_ascii = true;
2326 if (length >= static_cast<size_t>(String::kMinNonFlatLength)) { 2444 if (length >= static_cast<size_t>(String::kMinNonFlatLength)) {
2327 is_ascii = false; 2445 is_ascii = false;
2328 } else { 2446 } else {
2329 const uc16* data = resource->data(); 2447 const uc16* data = resource->data();
2330 for (size_t i = 0; i < length; i++) { 2448 for (size_t i = 0; i < length; i++) {
2331 if (data[i] > String::kMaxAsciiCharCode) { 2449 if (data[i] > String::kMaxAsciiCharCode) {
2332 is_ascii = false; 2450 is_ascii = false;
2333 break; 2451 break;
2334 } 2452 }
2335 } 2453 }
2336 } 2454 }
2337 2455
2338 Map* map = is_ascii ? 2456 Map* map = is_ascii ?
2339 Heap::external_string_with_ascii_data_map() : Heap::external_string_map(); 2457 Heap::external_string_with_ascii_data_map() : Heap::external_string_map();
2340 Object* result = Allocate(map, NEW_SPACE); 2458 Object* result;
2341 if (result->IsFailure()) return result; 2459 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
2460 if (!maybe_result->ToObject(&result)) return maybe_result;
2461 }
2342 2462
2343 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); 2463 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result);
2344 external_string->set_length(static_cast<int>(length)); 2464 external_string->set_length(static_cast<int>(length));
2345 external_string->set_hash_field(String::kEmptyHashField); 2465 external_string->set_hash_field(String::kEmptyHashField);
2346 external_string->set_resource(resource); 2466 external_string->set_resource(resource);
2347 2467
2348 return result; 2468 return result;
2349 } 2469 }
2350 2470
2351 2471
2352 Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { 2472 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) {
2353 if (code <= String::kMaxAsciiCharCode) { 2473 if (code <= String::kMaxAsciiCharCode) {
2354 Object* value = Heap::single_character_string_cache()->get(code); 2474 Object* value = Heap::single_character_string_cache()->get(code);
2355 if (value != Heap::undefined_value()) return value; 2475 if (value != Heap::undefined_value()) return value;
2356 2476
2357 char buffer[1]; 2477 char buffer[1];
2358 buffer[0] = static_cast<char>(code); 2478 buffer[0] = static_cast<char>(code);
2359 Object* result = LookupSymbol(Vector<const char>(buffer, 1)); 2479 Object* result;
2480 MaybeObject* maybe_result = LookupSymbol(Vector<const char>(buffer, 1));
2360 2481
2361 if (result->IsFailure()) return result; 2482 if (!maybe_result->ToObject(&result)) return maybe_result;
2362 Heap::single_character_string_cache()->set(code, result); 2483 Heap::single_character_string_cache()->set(code, result);
2363 return result; 2484 return result;
2364 } 2485 }
2365 2486
2366 Object* result = Heap::AllocateRawTwoByteString(1); 2487 Object* result;
2367 if (result->IsFailure()) return result; 2488 { MaybeObject* maybe_result = Heap::AllocateRawTwoByteString(1);
2489 if (!maybe_result->ToObject(&result)) return maybe_result;
2490 }
2368 String* answer = String::cast(result); 2491 String* answer = String::cast(result);
2369 answer->Set(0, code); 2492 answer->Set(0, code);
2370 return answer; 2493 return answer;
2371 } 2494 }
2372 2495
2373 2496
2374 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 2497 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
2375 if (length < 0 || length > ByteArray::kMaxLength) { 2498 if (length < 0 || length > ByteArray::kMaxLength) {
2376 return Failure::OutOfMemoryException(); 2499 return Failure::OutOfMemoryException();
2377 } 2500 }
2378 if (pretenure == NOT_TENURED) { 2501 if (pretenure == NOT_TENURED) {
2379 return AllocateByteArray(length); 2502 return AllocateByteArray(length);
2380 } 2503 }
2381 int size = ByteArray::SizeFor(length); 2504 int size = ByteArray::SizeFor(length);
2382 Object* result = (size <= MaxObjectSizeInPagedSpace()) 2505 Object* result;
2383 ? old_data_space_->AllocateRaw(size) 2506 { MaybeObject* maybe_result = (size <= MaxObjectSizeInPagedSpace())
2384 : lo_space_->AllocateRaw(size); 2507 ? old_data_space_->AllocateRaw(size)
2385 if (result->IsFailure()) return result; 2508 : lo_space_->AllocateRaw(size);
2509 if (!maybe_result->ToObject(&result)) return maybe_result;
2510 }
2386 2511
2387 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map()); 2512 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map());
2388 reinterpret_cast<ByteArray*>(result)->set_length(length); 2513 reinterpret_cast<ByteArray*>(result)->set_length(length);
2389 return result; 2514 return result;
2390 } 2515 }
2391 2516
2392 2517
2393 Object* Heap::AllocateByteArray(int length) { 2518 MaybeObject* Heap::AllocateByteArray(int length) {
2394 if (length < 0 || length > ByteArray::kMaxLength) { 2519 if (length < 0 || length > ByteArray::kMaxLength) {
2395 return Failure::OutOfMemoryException(); 2520 return Failure::OutOfMemoryException();
2396 } 2521 }
2397 int size = ByteArray::SizeFor(length); 2522 int size = ByteArray::SizeFor(length);
2398 AllocationSpace space = 2523 AllocationSpace space =
2399 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE; 2524 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE;
2400 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); 2525 Object* result;
2401 if (result->IsFailure()) return result; 2526 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
2527 if (!maybe_result->ToObject(&result)) return maybe_result;
2528 }
2402 2529
2403 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map()); 2530 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map());
2404 reinterpret_cast<ByteArray*>(result)->set_length(length); 2531 reinterpret_cast<ByteArray*>(result)->set_length(length);
2405 return result; 2532 return result;
2406 } 2533 }
2407 2534
2408 2535
2409 void Heap::CreateFillerObjectAt(Address addr, int size) { 2536 void Heap::CreateFillerObjectAt(Address addr, int size) {
2410 if (size == 0) return; 2537 if (size == 0) return;
2411 HeapObject* filler = HeapObject::FromAddress(addr); 2538 HeapObject* filler = HeapObject::FromAddress(addr);
2412 if (size == kPointerSize) { 2539 if (size == kPointerSize) {
2413 filler->set_map(one_pointer_filler_map()); 2540 filler->set_map(one_pointer_filler_map());
2414 } else if (size == 2 * kPointerSize) { 2541 } else if (size == 2 * kPointerSize) {
2415 filler->set_map(two_pointer_filler_map()); 2542 filler->set_map(two_pointer_filler_map());
2416 } else { 2543 } else {
2417 filler->set_map(byte_array_map()); 2544 filler->set_map(byte_array_map());
2418 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size)); 2545 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size));
2419 } 2546 }
2420 } 2547 }
2421 2548
2422 2549
2423 Object* Heap::AllocatePixelArray(int length, 2550 MaybeObject* Heap::AllocatePixelArray(int length,
2424 uint8_t* external_pointer, 2551 uint8_t* external_pointer,
2425 PretenureFlag pretenure) { 2552 PretenureFlag pretenure) {
2426 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2553 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2427 Object* result = AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE); 2554 Object* result;
2428 if (result->IsFailure()) return result; 2555 { MaybeObject* maybe_result =
2556 AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE);
2557 if (!maybe_result->ToObject(&result)) return maybe_result;
2558 }
2429 2559
2430 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map()); 2560 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map());
2431 reinterpret_cast<PixelArray*>(result)->set_length(length); 2561 reinterpret_cast<PixelArray*>(result)->set_length(length);
2432 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer); 2562 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer);
2433 2563
2434 return result; 2564 return result;
2435 } 2565 }
2436 2566
2437 2567
2438 Object* Heap::AllocateExternalArray(int length, 2568 MaybeObject* Heap::AllocateExternalArray(int length,
2439 ExternalArrayType array_type, 2569 ExternalArrayType array_type,
2440 void* external_pointer, 2570 void* external_pointer,
2441 PretenureFlag pretenure) { 2571 PretenureFlag pretenure) {
2442 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2572 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2443 Object* result = AllocateRaw(ExternalArray::kAlignedSize, 2573 Object* result;
2444 space, 2574 { MaybeObject* maybe_result = AllocateRaw(ExternalArray::kAlignedSize,
2445 OLD_DATA_SPACE); 2575 space,
2446 if (result->IsFailure()) return result; 2576 OLD_DATA_SPACE);
2577 if (!maybe_result->ToObject(&result)) return maybe_result;
2578 }
2447 2579
2448 reinterpret_cast<ExternalArray*>(result)->set_map( 2580 reinterpret_cast<ExternalArray*>(result)->set_map(
2449 MapForExternalArrayType(array_type)); 2581 MapForExternalArrayType(array_type));
2450 reinterpret_cast<ExternalArray*>(result)->set_length(length); 2582 reinterpret_cast<ExternalArray*>(result)->set_length(length);
2451 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( 2583 reinterpret_cast<ExternalArray*>(result)->set_external_pointer(
2452 external_pointer); 2584 external_pointer);
2453 2585
2454 return result; 2586 return result;
2455 } 2587 }
2456 2588
2457 2589
2458 Object* Heap::CreateCode(const CodeDesc& desc, 2590 MaybeObject* Heap::CreateCode(const CodeDesc& desc,
2459 Code::Flags flags, 2591 Code::Flags flags,
2460 Handle<Object> self_reference) { 2592 Handle<Object> self_reference) {
2461 // Allocate ByteArray before the Code object, so that we do not risk 2593 // Allocate ByteArray before the Code object, so that we do not risk
2462 // leaving uninitialized Code object (and breaking the heap). 2594 // leaving uninitialized Code object (and breaking the heap).
2463 Object* reloc_info = AllocateByteArray(desc.reloc_size, TENURED); 2595 Object* reloc_info;
2464 if (reloc_info->IsFailure()) return reloc_info; 2596 { MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED);
2597 if (!maybe_reloc_info->ToObject(&reloc_info)) return maybe_reloc_info;
2598 }
2465 2599
2466 // Compute size 2600 // Compute size
2467 int body_size = RoundUp(desc.instr_size, kObjectAlignment); 2601 int body_size = RoundUp(desc.instr_size, kObjectAlignment);
2468 int obj_size = Code::SizeFor(body_size); 2602 int obj_size = Code::SizeFor(body_size);
2469 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); 2603 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment));
2470 Object* result; 2604 MaybeObject* maybe_result;
2471 if (obj_size > MaxObjectSizeInPagedSpace()) { 2605 if (obj_size > MaxObjectSizeInPagedSpace()) {
2472 result = lo_space_->AllocateRawCode(obj_size); 2606 maybe_result = lo_space_->AllocateRawCode(obj_size);
2473 } else { 2607 } else {
2474 result = code_space_->AllocateRaw(obj_size); 2608 maybe_result = code_space_->AllocateRaw(obj_size);
2475 } 2609 }
2476 2610
2477 if (result->IsFailure()) return result; 2611 Object* result;
2612 if (!maybe_result->ToObject(&result)) return maybe_result;
2478 2613
2479 // Initialize the object 2614 // Initialize the object
2480 HeapObject::cast(result)->set_map(code_map()); 2615 HeapObject::cast(result)->set_map(code_map());
2481 Code* code = Code::cast(result); 2616 Code* code = Code::cast(result);
2482 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2617 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2483 code->set_instruction_size(desc.instr_size); 2618 code->set_instruction_size(desc.instr_size);
2484 code->set_relocation_info(ByteArray::cast(reloc_info)); 2619 code->set_relocation_info(ByteArray::cast(reloc_info));
2485 code->set_flags(flags); 2620 code->set_flags(flags);
2486 // Allow self references to created code object by patching the handle to 2621 // Allow self references to created code object by patching the handle to
2487 // point to the newly allocated Code object. 2622 // point to the newly allocated Code object.
2488 if (!self_reference.is_null()) { 2623 if (!self_reference.is_null()) {
2489 *(self_reference.location()) = code; 2624 *(self_reference.location()) = code;
2490 } 2625 }
2491 // Migrate generated code. 2626 // Migrate generated code.
2492 // The generated code can contain Object** values (typically from handles) 2627 // The generated code can contain Object** values (typically from handles)
2493 // that are dereferenced during the copy to point directly to the actual heap 2628 // that are dereferenced during the copy to point directly to the actual heap
2494 // objects. These pointers can include references to the code object itself, 2629 // objects. These pointers can include references to the code object itself,
2495 // through the self_reference parameter. 2630 // through the self_reference parameter.
2496 code->CopyFrom(desc); 2631 code->CopyFrom(desc);
2497 2632
2498 #ifdef DEBUG 2633 #ifdef DEBUG
2499 code->Verify(); 2634 code->Verify();
2500 #endif 2635 #endif
2501 return code; 2636 return code;
2502 } 2637 }
2503 2638
2504 2639
2505 Object* Heap::CopyCode(Code* code) { 2640 MaybeObject* Heap::CopyCode(Code* code) {
2506 // Allocate an object the same size as the code object. 2641 // Allocate an object the same size as the code object.
2507 int obj_size = code->Size(); 2642 int obj_size = code->Size();
2508 Object* result; 2643 MaybeObject* maybe_result;
2509 if (obj_size > MaxObjectSizeInPagedSpace()) { 2644 if (obj_size > MaxObjectSizeInPagedSpace()) {
2510 result = lo_space_->AllocateRawCode(obj_size); 2645 maybe_result = lo_space_->AllocateRawCode(obj_size);
2511 } else { 2646 } else {
2512 result = code_space_->AllocateRaw(obj_size); 2647 maybe_result = code_space_->AllocateRaw(obj_size);
2513 } 2648 }
2514 2649
2515 if (result->IsFailure()) return result; 2650 Object* result;
2651 if (!maybe_result->ToObject(&result)) return maybe_result;
2516 2652
2517 // Copy code object. 2653 // Copy code object.
2518 Address old_addr = code->address(); 2654 Address old_addr = code->address();
2519 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); 2655 Address new_addr = reinterpret_cast<HeapObject*>(result)->address();
2520 CopyBlock(new_addr, old_addr, obj_size); 2656 CopyBlock(new_addr, old_addr, obj_size);
2521 // Relocate the copy. 2657 // Relocate the copy.
2522 Code* new_code = Code::cast(result); 2658 Code* new_code = Code::cast(result);
2523 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2659 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2524 new_code->Relocate(new_addr - old_addr); 2660 new_code->Relocate(new_addr - old_addr);
2525 return new_code; 2661 return new_code;
2526 } 2662 }
2527 2663
2528 2664
2529 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { 2665 MaybeObject* Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
2530 // Allocate ByteArray before the Code object, so that we do not risk 2666 // Allocate ByteArray before the Code object, so that we do not risk
2531 // leaving uninitialized Code object (and breaking the heap). 2667 // leaving uninitialized Code object (and breaking the heap).
2532 Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED); 2668 Object* reloc_info_array;
2533 if (reloc_info_array->IsFailure()) return reloc_info_array; 2669 { MaybeObject* maybe_reloc_info_array =
2670 AllocateByteArray(reloc_info.length(), TENURED);
2671 if (!maybe_reloc_info_array->ToObject(&reloc_info_array)) {
2672 return maybe_reloc_info_array;
2673 }
2674 }
2534 2675
2535 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); 2676 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment);
2536 2677
2537 int new_obj_size = Code::SizeFor(new_body_size); 2678 int new_obj_size = Code::SizeFor(new_body_size);
2538 2679
2539 Address old_addr = code->address(); 2680 Address old_addr = code->address();
2540 2681
2541 size_t relocation_offset = 2682 size_t relocation_offset =
2542 static_cast<size_t>(code->instruction_end() - old_addr); 2683 static_cast<size_t>(code->instruction_end() - old_addr);
2543 2684
2544 Object* result; 2685 MaybeObject* maybe_result;
2545 if (new_obj_size > MaxObjectSizeInPagedSpace()) { 2686 if (new_obj_size > MaxObjectSizeInPagedSpace()) {
2546 result = lo_space_->AllocateRawCode(new_obj_size); 2687 maybe_result = lo_space_->AllocateRawCode(new_obj_size);
2547 } else { 2688 } else {
2548 result = code_space_->AllocateRaw(new_obj_size); 2689 maybe_result = code_space_->AllocateRaw(new_obj_size);
2549 } 2690 }
2550 2691
2551 if (result->IsFailure()) return result; 2692 Object* result;
2693 if (!maybe_result->ToObject(&result)) return maybe_result;
2552 2694
2553 // Copy code object. 2695 // Copy code object.
2554 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); 2696 Address new_addr = reinterpret_cast<HeapObject*>(result)->address();
2555 2697
2556 // Copy header and instructions. 2698 // Copy header and instructions.
2557 memcpy(new_addr, old_addr, relocation_offset); 2699 memcpy(new_addr, old_addr, relocation_offset);
2558 2700
2559 Code* new_code = Code::cast(result); 2701 Code* new_code = Code::cast(result);
2560 new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); 2702 new_code->set_relocation_info(ByteArray::cast(reloc_info_array));
2561 2703
2562 // Copy patched rinfo. 2704 // Copy patched rinfo.
2563 memcpy(new_code->relocation_start(), reloc_info.start(), reloc_info.length()); 2705 memcpy(new_code->relocation_start(), reloc_info.start(), reloc_info.length());
2564 2706
2565 // Relocate the copy. 2707 // Relocate the copy.
2566 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2708 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2567 new_code->Relocate(new_addr - old_addr); 2709 new_code->Relocate(new_addr - old_addr);
2568 2710
2569 #ifdef DEBUG 2711 #ifdef DEBUG
2570 code->Verify(); 2712 code->Verify();
2571 #endif 2713 #endif
2572 return new_code; 2714 return new_code;
2573 } 2715 }
2574 2716
2575 2717
2576 Object* Heap::Allocate(Map* map, AllocationSpace space) { 2718 MaybeObject* Heap::Allocate(Map* map, AllocationSpace space) {
2577 ASSERT(gc_state_ == NOT_IN_GC); 2719 ASSERT(gc_state_ == NOT_IN_GC);
2578 ASSERT(map->instance_type() != MAP_TYPE); 2720 ASSERT(map->instance_type() != MAP_TYPE);
2579 // If allocation failures are disallowed, we may allocate in a different 2721 // If allocation failures are disallowed, we may allocate in a different
2580 // space when new space is full and the object is not a large object. 2722 // space when new space is full and the object is not a large object.
2581 AllocationSpace retry_space = 2723 AllocationSpace retry_space =
2582 (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type()); 2724 (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type());
2583 Object* result = 2725 Object* result;
2584 AllocateRaw(map->instance_size(), space, retry_space); 2726 { MaybeObject* maybe_result =
2585 if (result->IsFailure()) return result; 2727 AllocateRaw(map->instance_size(), space, retry_space);
2728 if (!maybe_result->ToObject(&result)) return maybe_result;
2729 }
2586 HeapObject::cast(result)->set_map(map); 2730 HeapObject::cast(result)->set_map(map);
2587 #ifdef ENABLE_LOGGING_AND_PROFILING 2731 #ifdef ENABLE_LOGGING_AND_PROFILING
2588 ProducerHeapProfile::RecordJSObjectAllocation(result); 2732 ProducerHeapProfile::RecordJSObjectAllocation(result);
2589 #endif 2733 #endif
2590 return result; 2734 return result;
2591 } 2735 }
2592 2736
2593 2737
2594 Object* Heap::InitializeFunction(JSFunction* function, 2738 MaybeObject* Heap::InitializeFunction(JSFunction* function,
2595 SharedFunctionInfo* shared, 2739 SharedFunctionInfo* shared,
2596 Object* prototype) { 2740 Object* prototype) {
2597 ASSERT(!prototype->IsMap()); 2741 ASSERT(!prototype->IsMap());
2598 function->initialize_properties(); 2742 function->initialize_properties();
2599 function->initialize_elements(); 2743 function->initialize_elements();
2600 function->set_shared(shared); 2744 function->set_shared(shared);
2601 function->set_code(shared->code()); 2745 function->set_code(shared->code());
2602 function->set_prototype_or_initial_map(prototype); 2746 function->set_prototype_or_initial_map(prototype);
2603 function->set_context(undefined_value()); 2747 function->set_context(undefined_value());
2604 function->set_literals(empty_fixed_array()); 2748 function->set_literals(empty_fixed_array());
2605 return function; 2749 return function;
2606 } 2750 }
2607 2751
2608 2752
2609 Object* Heap::AllocateFunctionPrototype(JSFunction* function) { 2753 MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) {
2610 // Allocate the prototype. Make sure to use the object function 2754 // Allocate the prototype. Make sure to use the object function
2611 // from the function's context, since the function can be from a 2755 // from the function's context, since the function can be from a
2612 // different context. 2756 // different context.
2613 JSFunction* object_function = 2757 JSFunction* object_function =
2614 function->context()->global_context()->object_function(); 2758 function->context()->global_context()->object_function();
2615 Object* prototype = AllocateJSObject(object_function); 2759 Object* prototype;
2616 if (prototype->IsFailure()) return prototype; 2760 { MaybeObject* maybe_prototype = AllocateJSObject(object_function);
2761 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype;
2762 }
2617 // When creating the prototype for the function we must set its 2763 // When creating the prototype for the function we must set its
2618 // constructor to the function. 2764 // constructor to the function.
2619 Object* result = 2765 Object* result;
2620 JSObject::cast(prototype)->SetProperty(constructor_symbol(), 2766 { MaybeObject* maybe_result =
2621 function, 2767 JSObject::cast(prototype)->SetProperty(constructor_symbol(),
2622 DONT_ENUM); 2768 function,
2623 if (result->IsFailure()) return result; 2769 DONT_ENUM);
2770 if (!maybe_result->ToObject(&result)) return maybe_result;
2771 }
2624 return prototype; 2772 return prototype;
2625 } 2773 }
2626 2774
2627 2775
2628 Object* Heap::AllocateFunction(Map* function_map, 2776 MaybeObject* Heap::AllocateFunction(Map* function_map,
2629 SharedFunctionInfo* shared, 2777 SharedFunctionInfo* shared,
2630 Object* prototype, 2778 Object* prototype,
2631 PretenureFlag pretenure) { 2779 PretenureFlag pretenure) {
2632 AllocationSpace space = 2780 AllocationSpace space =
2633 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2781 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2634 Object* result = Allocate(function_map, space); 2782 Object* result;
2635 if (result->IsFailure()) return result; 2783 { MaybeObject* maybe_result = Allocate(function_map, space);
2784 if (!maybe_result->ToObject(&result)) return maybe_result;
2785 }
2636 return InitializeFunction(JSFunction::cast(result), shared, prototype); 2786 return InitializeFunction(JSFunction::cast(result), shared, prototype);
2637 } 2787 }
2638 2788
2639 2789
2640 Object* Heap::AllocateArgumentsObject(Object* callee, int length) { 2790 MaybeObject* Heap::AllocateArgumentsObject(Object* callee, int length) {
2641 // To get fast allocation and map sharing for arguments objects we 2791 // To get fast allocation and map sharing for arguments objects we
2642 // allocate them based on an arguments boilerplate. 2792 // allocate them based on an arguments boilerplate.
2643 2793
2644 // This calls Copy directly rather than using Heap::AllocateRaw so we 2794 // This calls Copy directly rather than using Heap::AllocateRaw so we
2645 // duplicate the check here. 2795 // duplicate the check here.
2646 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 2796 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
2647 2797
2648 JSObject* boilerplate = 2798 JSObject* boilerplate =
2649 Top::context()->global_context()->arguments_boilerplate(); 2799 Top::context()->global_context()->arguments_boilerplate();
2650 2800
2651 // Check that the size of the boilerplate matches our 2801 // Check that the size of the boilerplate matches our
2652 // expectations. The ArgumentsAccessStub::GenerateNewObject relies 2802 // expectations. The ArgumentsAccessStub::GenerateNewObject relies
2653 // on the size being a known constant. 2803 // on the size being a known constant.
2654 ASSERT(kArgumentsObjectSize == boilerplate->map()->instance_size()); 2804 ASSERT(kArgumentsObjectSize == boilerplate->map()->instance_size());
2655 2805
2656 // Do the allocation. 2806 // Do the allocation.
2657 Object* result = 2807 Object* result;
2658 AllocateRaw(kArgumentsObjectSize, NEW_SPACE, OLD_POINTER_SPACE); 2808 { MaybeObject* maybe_result =
2659 if (result->IsFailure()) return result; 2809 AllocateRaw(kArgumentsObjectSize, NEW_SPACE, OLD_POINTER_SPACE);
2810 if (!maybe_result->ToObject(&result)) return maybe_result;
2811 }
2660 2812
2661 // Copy the content. The arguments boilerplate doesn't have any 2813 // Copy the content. The arguments boilerplate doesn't have any
2662 // fields that point to new space so it's safe to skip the write 2814 // fields that point to new space so it's safe to skip the write
2663 // barrier here. 2815 // barrier here.
2664 CopyBlock(HeapObject::cast(result)->address(), 2816 CopyBlock(HeapObject::cast(result)->address(),
2665 boilerplate->address(), 2817 boilerplate->address(),
2666 kArgumentsObjectSize); 2818 kArgumentsObjectSize);
2667 2819
2668 // Set the two properties. 2820 // Set the two properties.
2669 JSObject::cast(result)->InObjectPropertyAtPut(arguments_callee_index, 2821 JSObject::cast(result)->InObjectPropertyAtPut(arguments_callee_index,
(...skipping 17 matching lines...) Expand all
2687 for (int i = 1; i != count; i++) { 2839 for (int i = 1; i != count; i++) {
2688 String* current_key = descriptors->GetKey(i); 2840 String* current_key = descriptors->GetKey(i);
2689 if (prev_key == current_key) return true; 2841 if (prev_key == current_key) return true;
2690 prev_key = current_key; 2842 prev_key = current_key;
2691 } 2843 }
2692 } 2844 }
2693 return false; 2845 return false;
2694 } 2846 }
2695 2847
2696 2848
2697 Object* Heap::AllocateInitialMap(JSFunction* fun) { 2849 MaybeObject* Heap::AllocateInitialMap(JSFunction* fun) {
2698 ASSERT(!fun->has_initial_map()); 2850 ASSERT(!fun->has_initial_map());
2699 2851
2700 // First create a new map with the size and number of in-object properties 2852 // First create a new map with the size and number of in-object properties
2701 // suggested by the function. 2853 // suggested by the function.
2702 int instance_size = fun->shared()->CalculateInstanceSize(); 2854 int instance_size = fun->shared()->CalculateInstanceSize();
2703 int in_object_properties = fun->shared()->CalculateInObjectProperties(); 2855 int in_object_properties = fun->shared()->CalculateInObjectProperties();
2704 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size); 2856 Object* map_obj;
2705 if (map_obj->IsFailure()) return map_obj; 2857 { MaybeObject* maybe_map_obj =
2858 Heap::AllocateMap(JS_OBJECT_TYPE, instance_size);
2859 if (!maybe_map_obj->ToObject(&map_obj)) return maybe_map_obj;
2860 }
2706 2861
2707 // Fetch or allocate prototype. 2862 // Fetch or allocate prototype.
2708 Object* prototype; 2863 Object* prototype;
2709 if (fun->has_instance_prototype()) { 2864 if (fun->has_instance_prototype()) {
2710 prototype = fun->instance_prototype(); 2865 prototype = fun->instance_prototype();
2711 } else { 2866 } else {
2712 prototype = AllocateFunctionPrototype(fun); 2867 { MaybeObject* maybe_prototype = AllocateFunctionPrototype(fun);
2713 if (prototype->IsFailure()) return prototype; 2868 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype;
2869 }
2714 } 2870 }
2715 Map* map = Map::cast(map_obj); 2871 Map* map = Map::cast(map_obj);
2716 map->set_inobject_properties(in_object_properties); 2872 map->set_inobject_properties(in_object_properties);
2717 map->set_unused_property_fields(in_object_properties); 2873 map->set_unused_property_fields(in_object_properties);
2718 map->set_prototype(prototype); 2874 map->set_prototype(prototype);
2719 ASSERT(map->has_fast_elements()); 2875 ASSERT(map->has_fast_elements());
2720 2876
2721 // If the function has only simple this property assignments add 2877 // If the function has only simple this property assignments add
2722 // field descriptors for these to the initial map as the object 2878 // field descriptors for these to the initial map as the object
2723 // cannot be constructed without having these properties. Guard by 2879 // cannot be constructed without having these properties. Guard by
2724 // the inline_new flag so we only change the map if we generate a 2880 // the inline_new flag so we only change the map if we generate a
2725 // specialized construct stub. 2881 // specialized construct stub.
2726 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); 2882 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields);
2727 if (fun->shared()->CanGenerateInlineConstructor(prototype)) { 2883 if (fun->shared()->CanGenerateInlineConstructor(prototype)) {
2728 int count = fun->shared()->this_property_assignments_count(); 2884 int count = fun->shared()->this_property_assignments_count();
2729 if (count > in_object_properties) { 2885 if (count > in_object_properties) {
2730 // Inline constructor can only handle inobject properties. 2886 // Inline constructor can only handle inobject properties.
2731 fun->shared()->ForbidInlineConstructor(); 2887 fun->shared()->ForbidInlineConstructor();
2732 } else { 2888 } else {
2733 Object* descriptors_obj = DescriptorArray::Allocate(count); 2889 Object* descriptors_obj;
2734 if (descriptors_obj->IsFailure()) return descriptors_obj; 2890 { MaybeObject* maybe_descriptors_obj = DescriptorArray::Allocate(count);
2891 if (!maybe_descriptors_obj->ToObject(&descriptors_obj)) {
2892 return maybe_descriptors_obj;
2893 }
2894 }
2735 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj); 2895 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj);
2736 for (int i = 0; i < count; i++) { 2896 for (int i = 0; i < count; i++) {
2737 String* name = fun->shared()->GetThisPropertyAssignmentName(i); 2897 String* name = fun->shared()->GetThisPropertyAssignmentName(i);
2738 ASSERT(name->IsSymbol()); 2898 ASSERT(name->IsSymbol());
2739 FieldDescriptor field(name, i, NONE); 2899 FieldDescriptor field(name, i, NONE);
2740 field.SetEnumerationIndex(i); 2900 field.SetEnumerationIndex(i);
2741 descriptors->Set(i, &field); 2901 descriptors->Set(i, &field);
2742 } 2902 }
2743 descriptors->SetNextEnumerationIndex(count); 2903 descriptors->SetNextEnumerationIndex(count);
2744 descriptors->SortUnchecked(); 2904 descriptors->SortUnchecked();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 // We might want to shrink the object later. 2945 // We might want to shrink the object later.
2786 ASSERT(obj->GetInternalFieldCount() == 0); 2946 ASSERT(obj->GetInternalFieldCount() == 0);
2787 filler = Heap::one_pointer_filler_map(); 2947 filler = Heap::one_pointer_filler_map();
2788 } else { 2948 } else {
2789 filler = Heap::undefined_value(); 2949 filler = Heap::undefined_value();
2790 } 2950 }
2791 obj->InitializeBody(map->instance_size(), filler); 2951 obj->InitializeBody(map->instance_size(), filler);
2792 } 2952 }
2793 2953
2794 2954
2795 Object* Heap::AllocateJSObjectFromMap(Map* map, PretenureFlag pretenure) { 2955 MaybeObject* Heap::AllocateJSObjectFromMap(Map* map, PretenureFlag pretenure) {
2796 // JSFunctions should be allocated using AllocateFunction to be 2956 // JSFunctions should be allocated using AllocateFunction to be
2797 // properly initialized. 2957 // properly initialized.
2798 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); 2958 ASSERT(map->instance_type() != JS_FUNCTION_TYPE);
2799 2959
2800 // Both types of global objects should be allocated using 2960 // Both types of global objects should be allocated using
2801 // AllocateGlobalObject to be properly initialized. 2961 // AllocateGlobalObject to be properly initialized.
2802 ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); 2962 ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE);
2803 ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); 2963 ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE);
2804 2964
2805 // Allocate the backing storage for the properties. 2965 // Allocate the backing storage for the properties.
2806 int prop_size = 2966 int prop_size =
2807 map->pre_allocated_property_fields() + 2967 map->pre_allocated_property_fields() +
2808 map->unused_property_fields() - 2968 map->unused_property_fields() -
2809 map->inobject_properties(); 2969 map->inobject_properties();
2810 ASSERT(prop_size >= 0); 2970 ASSERT(prop_size >= 0);
2811 Object* properties = AllocateFixedArray(prop_size, pretenure); 2971 Object* properties;
2812 if (properties->IsFailure()) return properties; 2972 { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, pretenure);
2973 if (!maybe_properties->ToObject(&properties)) return maybe_properties;
2974 }
2813 2975
2814 // Allocate the JSObject. 2976 // Allocate the JSObject.
2815 AllocationSpace space = 2977 AllocationSpace space =
2816 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2978 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2817 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2979 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
2818 Object* obj = Allocate(map, space); 2980 Object* obj;
2819 if (obj->IsFailure()) return obj; 2981 { MaybeObject* maybe_obj = Allocate(map, space);
2982 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
2983 }
2820 2984
2821 // Initialize the JSObject. 2985 // Initialize the JSObject.
2822 InitializeJSObjectFromMap(JSObject::cast(obj), 2986 InitializeJSObjectFromMap(JSObject::cast(obj),
2823 FixedArray::cast(properties), 2987 FixedArray::cast(properties),
2824 map); 2988 map);
2825 ASSERT(JSObject::cast(obj)->HasFastElements()); 2989 ASSERT(JSObject::cast(obj)->HasFastElements());
2826 return obj; 2990 return obj;
2827 } 2991 }
2828 2992
2829 2993
2830 Object* Heap::AllocateJSObject(JSFunction* constructor, 2994 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor,
2831 PretenureFlag pretenure) { 2995 PretenureFlag pretenure) {
2832 // Allocate the initial map if absent. 2996 // Allocate the initial map if absent.
2833 if (!constructor->has_initial_map()) { 2997 if (!constructor->has_initial_map()) {
2834 Object* initial_map = AllocateInitialMap(constructor); 2998 Object* initial_map;
2835 if (initial_map->IsFailure()) return initial_map; 2999 { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor);
3000 if (!maybe_initial_map->ToObject(&initial_map)) return maybe_initial_map;
3001 }
2836 constructor->set_initial_map(Map::cast(initial_map)); 3002 constructor->set_initial_map(Map::cast(initial_map));
2837 Map::cast(initial_map)->set_constructor(constructor); 3003 Map::cast(initial_map)->set_constructor(constructor);
2838 } 3004 }
2839 // Allocate the object based on the constructors initial map. 3005 // Allocate the object based on the constructors initial map.
2840 Object* result = 3006 MaybeObject* result =
2841 AllocateJSObjectFromMap(constructor->initial_map(), pretenure); 3007 AllocateJSObjectFromMap(constructor->initial_map(), pretenure);
3008 #ifdef DEBUG
2842 // Make sure result is NOT a global object if valid. 3009 // Make sure result is NOT a global object if valid.
2843 ASSERT(result->IsFailure() || !result->IsGlobalObject()); 3010 Object* non_failure;
3011 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject());
3012 #endif
2844 return result; 3013 return result;
2845 } 3014 }
2846 3015
2847 3016
2848 Object* Heap::AllocateGlobalObject(JSFunction* constructor) { 3017 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) {
2849 ASSERT(constructor->has_initial_map()); 3018 ASSERT(constructor->has_initial_map());
2850 Map* map = constructor->initial_map(); 3019 Map* map = constructor->initial_map();
2851 3020
2852 // Make sure no field properties are described in the initial map. 3021 // Make sure no field properties are described in the initial map.
2853 // This guarantees us that normalizing the properties does not 3022 // This guarantees us that normalizing the properties does not
2854 // require us to change property values to JSGlobalPropertyCells. 3023 // require us to change property values to JSGlobalPropertyCells.
2855 ASSERT(map->NextFreePropertyIndex() == 0); 3024 ASSERT(map->NextFreePropertyIndex() == 0);
2856 3025
2857 // Make sure we don't have a ton of pre-allocated slots in the 3026 // Make sure we don't have a ton of pre-allocated slots in the
2858 // global objects. They will be unused once we normalize the object. 3027 // global objects. They will be unused once we normalize the object.
2859 ASSERT(map->unused_property_fields() == 0); 3028 ASSERT(map->unused_property_fields() == 0);
2860 ASSERT(map->inobject_properties() == 0); 3029 ASSERT(map->inobject_properties() == 0);
2861 3030
2862 // Initial size of the backing store to avoid resize of the storage during 3031 // Initial size of the backing store to avoid resize of the storage during
2863 // bootstrapping. The size differs between the JS global object ad the 3032 // bootstrapping. The size differs between the JS global object ad the
2864 // builtins object. 3033 // builtins object.
2865 int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512; 3034 int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512;
2866 3035
2867 // Allocate a dictionary object for backing storage. 3036 // Allocate a dictionary object for backing storage.
2868 Object* obj = 3037 Object* obj;
2869 StringDictionary::Allocate( 3038 { MaybeObject* maybe_obj =
2870 map->NumberOfDescribedProperties() * 2 + initial_size); 3039 StringDictionary::Allocate(
2871 if (obj->IsFailure()) return obj; 3040 map->NumberOfDescribedProperties() * 2 + initial_size);
3041 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
3042 }
2872 StringDictionary* dictionary = StringDictionary::cast(obj); 3043 StringDictionary* dictionary = StringDictionary::cast(obj);
2873 3044
2874 // The global object might be created from an object template with accessors. 3045 // The global object might be created from an object template with accessors.
2875 // Fill these accessors into the dictionary. 3046 // Fill these accessors into the dictionary.
2876 DescriptorArray* descs = map->instance_descriptors(); 3047 DescriptorArray* descs = map->instance_descriptors();
2877 for (int i = 0; i < descs->number_of_descriptors(); i++) { 3048 for (int i = 0; i < descs->number_of_descriptors(); i++) {
2878 PropertyDetails details = descs->GetDetails(i); 3049 PropertyDetails details = descs->GetDetails(i);
2879 ASSERT(details.type() == CALLBACKS); // Only accessors are expected. 3050 ASSERT(details.type() == CALLBACKS); // Only accessors are expected.
2880 PropertyDetails d = 3051 PropertyDetails d =
2881 PropertyDetails(details.attributes(), CALLBACKS, details.index()); 3052 PropertyDetails(details.attributes(), CALLBACKS, details.index());
2882 Object* value = descs->GetCallbacksObject(i); 3053 Object* value = descs->GetCallbacksObject(i);
2883 value = Heap::AllocateJSGlobalPropertyCell(value); 3054 { MaybeObject* maybe_value = Heap::AllocateJSGlobalPropertyCell(value);
2884 if (value->IsFailure()) return value; 3055 if (!maybe_value->ToObject(&value)) return maybe_value;
3056 }
2885 3057
2886 Object* result = dictionary->Add(descs->GetKey(i), value, d); 3058 Object* result;
2887 if (result->IsFailure()) return result; 3059 { MaybeObject* maybe_result = dictionary->Add(descs->GetKey(i), value, d);
3060 if (!maybe_result->ToObject(&result)) return maybe_result;
3061 }
2888 dictionary = StringDictionary::cast(result); 3062 dictionary = StringDictionary::cast(result);
2889 } 3063 }
2890 3064
2891 // Allocate the global object and initialize it with the backing store. 3065 // Allocate the global object and initialize it with the backing store.
2892 obj = Allocate(map, OLD_POINTER_SPACE); 3066 { MaybeObject* maybe_obj = Allocate(map, OLD_POINTER_SPACE);
2893 if (obj->IsFailure()) return obj; 3067 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
3068 }
2894 JSObject* global = JSObject::cast(obj); 3069 JSObject* global = JSObject::cast(obj);
2895 InitializeJSObjectFromMap(global, dictionary, map); 3070 InitializeJSObjectFromMap(global, dictionary, map);
2896 3071
2897 // Create a new map for the global object. 3072 // Create a new map for the global object.
2898 obj = map->CopyDropDescriptors(); 3073 { MaybeObject* maybe_obj = map->CopyDropDescriptors();
2899 if (obj->IsFailure()) return obj; 3074 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
3075 }
2900 Map* new_map = Map::cast(obj); 3076 Map* new_map = Map::cast(obj);
2901 3077
2902 // Setup the global object as a normalized object. 3078 // Setup the global object as a normalized object.
2903 global->set_map(new_map); 3079 global->set_map(new_map);
2904 global->map()->set_instance_descriptors(Heap::empty_descriptor_array()); 3080 global->map()->set_instance_descriptors(Heap::empty_descriptor_array());
2905 global->set_properties(dictionary); 3081 global->set_properties(dictionary);
2906 3082
2907 // Make sure result is a global object with properties in dictionary. 3083 // Make sure result is a global object with properties in dictionary.
2908 ASSERT(global->IsGlobalObject()); 3084 ASSERT(global->IsGlobalObject());
2909 ASSERT(!global->HasFastProperties()); 3085 ASSERT(!global->HasFastProperties());
2910 return global; 3086 return global;
2911 } 3087 }
2912 3088
2913 3089
2914 Object* Heap::CopyJSObject(JSObject* source) { 3090 MaybeObject* Heap::CopyJSObject(JSObject* source) {
2915 // Never used to copy functions. If functions need to be copied we 3091 // Never used to copy functions. If functions need to be copied we
2916 // have to be careful to clear the literals array. 3092 // have to be careful to clear the literals array.
2917 ASSERT(!source->IsJSFunction()); 3093 ASSERT(!source->IsJSFunction());
2918 3094
2919 // Make the clone. 3095 // Make the clone.
2920 Map* map = source->map(); 3096 Map* map = source->map();
2921 int object_size = map->instance_size(); 3097 int object_size = map->instance_size();
2922 Object* clone; 3098 Object* clone;
2923 3099
2924 // If we're forced to always allocate, we use the general allocation 3100 // If we're forced to always allocate, we use the general allocation
2925 // functions which may leave us with an object in old space. 3101 // functions which may leave us with an object in old space.
2926 if (always_allocate()) { 3102 if (always_allocate()) {
2927 clone = AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE); 3103 { MaybeObject* maybe_clone =
2928 if (clone->IsFailure()) return clone; 3104 AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE);
3105 if (!maybe_clone->ToObject(&clone)) return maybe_clone;
3106 }
2929 Address clone_address = HeapObject::cast(clone)->address(); 3107 Address clone_address = HeapObject::cast(clone)->address();
2930 CopyBlock(clone_address, 3108 CopyBlock(clone_address,
2931 source->address(), 3109 source->address(),
2932 object_size); 3110 object_size);
2933 // Update write barrier for all fields that lie beyond the header. 3111 // Update write barrier for all fields that lie beyond the header.
2934 RecordWrites(clone_address, 3112 RecordWrites(clone_address,
2935 JSObject::kHeaderSize, 3113 JSObject::kHeaderSize,
2936 (object_size - JSObject::kHeaderSize) / kPointerSize); 3114 (object_size - JSObject::kHeaderSize) / kPointerSize);
2937 } else { 3115 } else {
2938 clone = new_space_.AllocateRaw(object_size); 3116 { MaybeObject* maybe_clone = new_space_.AllocateRaw(object_size);
2939 if (clone->IsFailure()) return clone; 3117 if (!maybe_clone->ToObject(&clone)) return maybe_clone;
3118 }
2940 ASSERT(Heap::InNewSpace(clone)); 3119 ASSERT(Heap::InNewSpace(clone));
2941 // Since we know the clone is allocated in new space, we can copy 3120 // Since we know the clone is allocated in new space, we can copy
2942 // the contents without worrying about updating the write barrier. 3121 // the contents without worrying about updating the write barrier.
2943 CopyBlock(HeapObject::cast(clone)->address(), 3122 CopyBlock(HeapObject::cast(clone)->address(),
2944 source->address(), 3123 source->address(),
2945 object_size); 3124 object_size);
2946 } 3125 }
2947 3126
2948 FixedArray* elements = FixedArray::cast(source->elements()); 3127 FixedArray* elements = FixedArray::cast(source->elements());
2949 FixedArray* properties = FixedArray::cast(source->properties()); 3128 FixedArray* properties = FixedArray::cast(source->properties());
2950 // Update elements if necessary. 3129 // Update elements if necessary.
2951 if (elements->length() > 0) { 3130 if (elements->length() > 0) {
2952 Object* elem = 3131 Object* elem;
2953 (elements->map() == fixed_cow_array_map()) ? 3132 { MaybeObject* maybe_elem =
2954 elements : CopyFixedArray(elements); 3133 (elements->map() == fixed_cow_array_map()) ?
2955 if (elem->IsFailure()) return elem; 3134 elements : CopyFixedArray(elements);
3135 if (!maybe_elem->ToObject(&elem)) return maybe_elem;
3136 }
2956 JSObject::cast(clone)->set_elements(FixedArray::cast(elem)); 3137 JSObject::cast(clone)->set_elements(FixedArray::cast(elem));
2957 } 3138 }
2958 // Update properties if necessary. 3139 // Update properties if necessary.
2959 if (properties->length() > 0) { 3140 if (properties->length() > 0) {
2960 Object* prop = CopyFixedArray(properties); 3141 Object* prop;
2961 if (prop->IsFailure()) return prop; 3142 { MaybeObject* maybe_prop = CopyFixedArray(properties);
3143 if (!maybe_prop->ToObject(&prop)) return maybe_prop;
3144 }
2962 JSObject::cast(clone)->set_properties(FixedArray::cast(prop)); 3145 JSObject::cast(clone)->set_properties(FixedArray::cast(prop));
2963 } 3146 }
2964 // Return the new clone. 3147 // Return the new clone.
2965 #ifdef ENABLE_LOGGING_AND_PROFILING 3148 #ifdef ENABLE_LOGGING_AND_PROFILING
2966 ProducerHeapProfile::RecordJSObjectAllocation(clone); 3149 ProducerHeapProfile::RecordJSObjectAllocation(clone);
2967 #endif 3150 #endif
2968 return clone; 3151 return clone;
2969 } 3152 }
2970 3153
2971 3154
2972 Object* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, 3155 MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor,
2973 JSGlobalProxy* object) { 3156 JSGlobalProxy* object) {
2974 ASSERT(constructor->has_initial_map()); 3157 ASSERT(constructor->has_initial_map());
2975 Map* map = constructor->initial_map(); 3158 Map* map = constructor->initial_map();
2976 3159
2977 // Check that the already allocated object has the same size and type as 3160 // Check that the already allocated object has the same size and type as
2978 // objects allocated using the constructor. 3161 // objects allocated using the constructor.
2979 ASSERT(map->instance_size() == object->map()->instance_size()); 3162 ASSERT(map->instance_size() == object->map()->instance_size());
2980 ASSERT(map->instance_type() == object->map()->instance_type()); 3163 ASSERT(map->instance_type() == object->map()->instance_type());
2981 3164
2982 // Allocate the backing storage for the properties. 3165 // Allocate the backing storage for the properties.
2983 int prop_size = map->unused_property_fields() - map->inobject_properties(); 3166 int prop_size = map->unused_property_fields() - map->inobject_properties();
2984 Object* properties = AllocateFixedArray(prop_size, TENURED); 3167 Object* properties;
2985 if (properties->IsFailure()) return properties; 3168 { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, TENURED);
3169 if (!maybe_properties->ToObject(&properties)) return maybe_properties;
3170 }
2986 3171
2987 // Reset the map for the object. 3172 // Reset the map for the object.
2988 object->set_map(constructor->initial_map()); 3173 object->set_map(constructor->initial_map());
2989 3174
2990 // Reinitialize the object from the constructor map. 3175 // Reinitialize the object from the constructor map.
2991 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); 3176 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map);
2992 return object; 3177 return object;
2993 } 3178 }
2994 3179
2995 3180
2996 Object* Heap::AllocateStringFromAscii(Vector<const char> string, 3181 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string,
2997 PretenureFlag pretenure) { 3182 PretenureFlag pretenure) {
2998 Object* result = AllocateRawAsciiString(string.length(), pretenure); 3183 Object* result;
2999 if (result->IsFailure()) return result; 3184 { MaybeObject* maybe_result =
3185 AllocateRawAsciiString(string.length(), pretenure);
3186 if (!maybe_result->ToObject(&result)) return maybe_result;
3187 }
3000 3188
3001 // Copy the characters into the new object. 3189 // Copy the characters into the new object.
3002 SeqAsciiString* string_result = SeqAsciiString::cast(result); 3190 SeqAsciiString* string_result = SeqAsciiString::cast(result);
3003 for (int i = 0; i < string.length(); i++) { 3191 for (int i = 0; i < string.length(); i++) {
3004 string_result->SeqAsciiStringSet(i, string[i]); 3192 string_result->SeqAsciiStringSet(i, string[i]);
3005 } 3193 }
3006 return result; 3194 return result;
3007 } 3195 }
3008 3196
3009 3197
3010 Object* Heap::AllocateStringFromUtf8(Vector<const char> string, 3198 MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> string,
3011 PretenureFlag pretenure) { 3199 PretenureFlag pretenure) {
3012 // V8 only supports characters in the Basic Multilingual Plane. 3200 // V8 only supports characters in the Basic Multilingual Plane.
3013 const uc32 kMaxSupportedChar = 0xFFFF; 3201 const uc32 kMaxSupportedChar = 0xFFFF;
3014 // Count the number of characters in the UTF-8 string and check if 3202 // Count the number of characters in the UTF-8 string and check if
3015 // it is an ASCII string. 3203 // it is an ASCII string.
3016 Access<Scanner::Utf8Decoder> decoder(Scanner::utf8_decoder()); 3204 Access<Scanner::Utf8Decoder> decoder(Scanner::utf8_decoder());
3017 decoder->Reset(string.start(), string.length()); 3205 decoder->Reset(string.start(), string.length());
3018 int chars = 0; 3206 int chars = 0;
3019 bool is_ascii = true; 3207 bool is_ascii = true;
3020 while (decoder->has_more()) { 3208 while (decoder->has_more()) {
3021 uc32 r = decoder->GetNext(); 3209 uc32 r = decoder->GetNext();
3022 if (r > String::kMaxAsciiCharCode) is_ascii = false; 3210 if (r > String::kMaxAsciiCharCode) is_ascii = false;
3023 chars++; 3211 chars++;
3024 } 3212 }
3025 3213
3026 // If the string is ascii, we do not need to convert the characters 3214 // If the string is ascii, we do not need to convert the characters
3027 // since UTF8 is backwards compatible with ascii. 3215 // since UTF8 is backwards compatible with ascii.
3028 if (is_ascii) return AllocateStringFromAscii(string, pretenure); 3216 if (is_ascii) return AllocateStringFromAscii(string, pretenure);
3029 3217
3030 Object* result = AllocateRawTwoByteString(chars, pretenure); 3218 Object* result;
3031 if (result->IsFailure()) return result; 3219 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure);
3220 if (!maybe_result->ToObject(&result)) return maybe_result;
3221 }
3032 3222
3033 // Convert and copy the characters into the new object. 3223 // Convert and copy the characters into the new object.
3034 String* string_result = String::cast(result); 3224 String* string_result = String::cast(result);
3035 decoder->Reset(string.start(), string.length()); 3225 decoder->Reset(string.start(), string.length());
3036 for (int i = 0; i < chars; i++) { 3226 for (int i = 0; i < chars; i++) {
3037 uc32 r = decoder->GetNext(); 3227 uc32 r = decoder->GetNext();
3038 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; } 3228 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; }
3039 string_result->Set(i, r); 3229 string_result->Set(i, r);
3040 } 3230 }
3041 return result; 3231 return result;
3042 } 3232 }
3043 3233
3044 3234
3045 Object* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, 3235 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
3046 PretenureFlag pretenure) { 3236 PretenureFlag pretenure) {
3047 // Check if the string is an ASCII string. 3237 // Check if the string is an ASCII string.
3048 int i = 0; 3238 int i = 0;
3049 while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++; 3239 while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++;
3050 3240
3241 MaybeObject* maybe_result;
3242 if (i == string.length()) { // It's an ASCII string.
3243 maybe_result = AllocateRawAsciiString(string.length(), pretenure);
3244 } else { // It's not an ASCII string.
3245 maybe_result = AllocateRawTwoByteString(string.length(), pretenure);
3246 }
3051 Object* result; 3247 Object* result;
3052 if (i == string.length()) { // It's an ASCII string. 3248 if (!maybe_result->ToObject(&result)) return maybe_result;
3053 result = AllocateRawAsciiString(string.length(), pretenure);
3054 } else { // It's not an ASCII string.
3055 result = AllocateRawTwoByteString(string.length(), pretenure);
3056 }
3057 if (result->IsFailure()) return result;
3058 3249
3059 // Copy the characters into the new object, which may be either ASCII or 3250 // Copy the characters into the new object, which may be either ASCII or
3060 // UTF-16. 3251 // UTF-16.
3061 String* string_result = String::cast(result); 3252 String* string_result = String::cast(result);
3062 for (int i = 0; i < string.length(); i++) { 3253 for (int i = 0; i < string.length(); i++) {
3063 string_result->Set(i, string[i]); 3254 string_result->Set(i, string[i]);
3064 } 3255 }
3065 return result; 3256 return result;
3066 } 3257 }
3067 3258
(...skipping 12 matching lines...) Expand all
3080 if (map == external_ascii_string_map()) return external_ascii_symbol_map(); 3271 if (map == external_ascii_string_map()) return external_ascii_symbol_map();
3081 if (map == external_string_with_ascii_data_map()) { 3272 if (map == external_string_with_ascii_data_map()) {
3082 return external_symbol_with_ascii_data_map(); 3273 return external_symbol_with_ascii_data_map();
3083 } 3274 }
3084 3275
3085 // No match found. 3276 // No match found.
3086 return NULL; 3277 return NULL;
3087 } 3278 }
3088 3279
3089 3280
3090 Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, 3281 MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer,
3091 int chars, 3282 int chars,
3092 uint32_t hash_field) { 3283 uint32_t hash_field) {
3093 ASSERT(chars >= 0); 3284 ASSERT(chars >= 0);
3094 // Ensure the chars matches the number of characters in the buffer. 3285 // Ensure the chars matches the number of characters in the buffer.
3095 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); 3286 ASSERT(static_cast<unsigned>(chars) == buffer->Length());
3096 // Determine whether the string is ascii. 3287 // Determine whether the string is ascii.
3097 bool is_ascii = true; 3288 bool is_ascii = true;
3098 while (buffer->has_more()) { 3289 while (buffer->has_more()) {
3099 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) { 3290 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) {
3100 is_ascii = false; 3291 is_ascii = false;
3101 break; 3292 break;
3102 } 3293 }
(...skipping 12 matching lines...) Expand all
3115 size = SeqAsciiString::SizeFor(chars); 3306 size = SeqAsciiString::SizeFor(chars);
3116 } else { 3307 } else {
3117 if (chars > SeqTwoByteString::kMaxLength) { 3308 if (chars > SeqTwoByteString::kMaxLength) {
3118 return Failure::OutOfMemoryException(); 3309 return Failure::OutOfMemoryException();
3119 } 3310 }
3120 map = symbol_map(); 3311 map = symbol_map();
3121 size = SeqTwoByteString::SizeFor(chars); 3312 size = SeqTwoByteString::SizeFor(chars);
3122 } 3313 }
3123 3314
3124 // Allocate string. 3315 // Allocate string.
3125 Object* result = (size > MaxObjectSizeInPagedSpace()) 3316 Object* result;
3126 ? lo_space_->AllocateRaw(size) 3317 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace())
3127 : old_data_space_->AllocateRaw(size); 3318 ? lo_space_->AllocateRaw(size)
3128 if (result->IsFailure()) return result; 3319 : old_data_space_->AllocateRaw(size);
3320 if (!maybe_result->ToObject(&result)) return maybe_result;
3321 }
3129 3322
3130 reinterpret_cast<HeapObject*>(result)->set_map(map); 3323 reinterpret_cast<HeapObject*>(result)->set_map(map);
3131 // Set length and hash fields of the allocated string. 3324 // Set length and hash fields of the allocated string.
3132 String* answer = String::cast(result); 3325 String* answer = String::cast(result);
3133 answer->set_length(chars); 3326 answer->set_length(chars);
3134 answer->set_hash_field(hash_field); 3327 answer->set_hash_field(hash_field);
3135 3328
3136 ASSERT_EQ(size, answer->Size()); 3329 ASSERT_EQ(size, answer->Size());
3137 3330
3138 // Fill in the characters. 3331 // Fill in the characters.
3139 for (int i = 0; i < chars; i++) { 3332 for (int i = 0; i < chars; i++) {
3140 answer->Set(i, buffer->GetNext()); 3333 answer->Set(i, buffer->GetNext());
3141 } 3334 }
3142 return answer; 3335 return answer;
3143 } 3336 }
3144 3337
3145 3338
3146 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { 3339 MaybeObject* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) {
3147 if (length < 0 || length > SeqAsciiString::kMaxLength) { 3340 if (length < 0 || length > SeqAsciiString::kMaxLength) {
3148 return Failure::OutOfMemoryException(); 3341 return Failure::OutOfMemoryException();
3149 } 3342 }
3150 3343
3151 int size = SeqAsciiString::SizeFor(length); 3344 int size = SeqAsciiString::SizeFor(length);
3152 ASSERT(size <= SeqAsciiString::kMaxSize); 3345 ASSERT(size <= SeqAsciiString::kMaxSize);
3153 3346
3154 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 3347 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
3155 AllocationSpace retry_space = OLD_DATA_SPACE; 3348 AllocationSpace retry_space = OLD_DATA_SPACE;
3156 3349
3157 if (space == NEW_SPACE) { 3350 if (space == NEW_SPACE) {
3158 if (size > kMaxObjectSizeInNewSpace) { 3351 if (size > kMaxObjectSizeInNewSpace) {
3159 // Allocate in large object space, retry space will be ignored. 3352 // Allocate in large object space, retry space will be ignored.
3160 space = LO_SPACE; 3353 space = LO_SPACE;
3161 } else if (size > MaxObjectSizeInPagedSpace()) { 3354 } else if (size > MaxObjectSizeInPagedSpace()) {
3162 // Allocate in new space, retry in large object space. 3355 // Allocate in new space, retry in large object space.
3163 retry_space = LO_SPACE; 3356 retry_space = LO_SPACE;
3164 } 3357 }
3165 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { 3358 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
3166 space = LO_SPACE; 3359 space = LO_SPACE;
3167 } 3360 }
3168 Object* result = AllocateRaw(size, space, retry_space); 3361 Object* result;
3169 if (result->IsFailure()) return result; 3362 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space);
3363 if (!maybe_result->ToObject(&result)) return maybe_result;
3364 }
3170 3365
3171 // Partially initialize the object. 3366 // Partially initialize the object.
3172 HeapObject::cast(result)->set_map(ascii_string_map()); 3367 HeapObject::cast(result)->set_map(ascii_string_map());
3173 String::cast(result)->set_length(length); 3368 String::cast(result)->set_length(length);
3174 String::cast(result)->set_hash_field(String::kEmptyHashField); 3369 String::cast(result)->set_hash_field(String::kEmptyHashField);
3175 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 3370 ASSERT_EQ(size, HeapObject::cast(result)->Size());
3176 return result; 3371 return result;
3177 } 3372 }
3178 3373
3179 3374
3180 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { 3375 MaybeObject* Heap::AllocateRawTwoByteString(int length,
3376 PretenureFlag pretenure) {
3181 if (length < 0 || length > SeqTwoByteString::kMaxLength) { 3377 if (length < 0 || length > SeqTwoByteString::kMaxLength) {
3182 return Failure::OutOfMemoryException(); 3378 return Failure::OutOfMemoryException();
3183 } 3379 }
3184 int size = SeqTwoByteString::SizeFor(length); 3380 int size = SeqTwoByteString::SizeFor(length);
3185 ASSERT(size <= SeqTwoByteString::kMaxSize); 3381 ASSERT(size <= SeqTwoByteString::kMaxSize);
3186 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 3382 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
3187 AllocationSpace retry_space = OLD_DATA_SPACE; 3383 AllocationSpace retry_space = OLD_DATA_SPACE;
3188 3384
3189 if (space == NEW_SPACE) { 3385 if (space == NEW_SPACE) {
3190 if (size > kMaxObjectSizeInNewSpace) { 3386 if (size > kMaxObjectSizeInNewSpace) {
3191 // Allocate in large object space, retry space will be ignored. 3387 // Allocate in large object space, retry space will be ignored.
3192 space = LO_SPACE; 3388 space = LO_SPACE;
3193 } else if (size > MaxObjectSizeInPagedSpace()) { 3389 } else if (size > MaxObjectSizeInPagedSpace()) {
3194 // Allocate in new space, retry in large object space. 3390 // Allocate in new space, retry in large object space.
3195 retry_space = LO_SPACE; 3391 retry_space = LO_SPACE;
3196 } 3392 }
3197 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { 3393 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
3198 space = LO_SPACE; 3394 space = LO_SPACE;
3199 } 3395 }
3200 Object* result = AllocateRaw(size, space, retry_space); 3396 Object* result;
3201 if (result->IsFailure()) return result; 3397 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space);
3398 if (!maybe_result->ToObject(&result)) return maybe_result;
3399 }
3202 3400
3203 // Partially initialize the object. 3401 // Partially initialize the object.
3204 HeapObject::cast(result)->set_map(string_map()); 3402 HeapObject::cast(result)->set_map(string_map());
3205 String::cast(result)->set_length(length); 3403 String::cast(result)->set_length(length);
3206 String::cast(result)->set_hash_field(String::kEmptyHashField); 3404 String::cast(result)->set_hash_field(String::kEmptyHashField);
3207 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 3405 ASSERT_EQ(size, HeapObject::cast(result)->Size());
3208 return result; 3406 return result;
3209 } 3407 }
3210 3408
3211 3409
3212 Object* Heap::AllocateEmptyFixedArray() { 3410 MaybeObject* Heap::AllocateEmptyFixedArray() {
3213 int size = FixedArray::SizeFor(0); 3411 int size = FixedArray::SizeFor(0);
3214 Object* result = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); 3412 Object* result;
3215 if (result->IsFailure()) return result; 3413 { MaybeObject* maybe_result =
3414 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
3415 if (!maybe_result->ToObject(&result)) return maybe_result;
3416 }
3216 // Initialize the object. 3417 // Initialize the object.
3217 reinterpret_cast<FixedArray*>(result)->set_map(fixed_array_map()); 3418 reinterpret_cast<FixedArray*>(result)->set_map(fixed_array_map());
3218 reinterpret_cast<FixedArray*>(result)->set_length(0); 3419 reinterpret_cast<FixedArray*>(result)->set_length(0);
3219 return result; 3420 return result;
3220 } 3421 }
3221 3422
3222 3423
3223 Object* Heap::AllocateRawFixedArray(int length) { 3424 MaybeObject* Heap::AllocateRawFixedArray(int length) {
3224 if (length < 0 || length > FixedArray::kMaxLength) { 3425 if (length < 0 || length > FixedArray::kMaxLength) {
3225 return Failure::OutOfMemoryException(); 3426 return Failure::OutOfMemoryException();
3226 } 3427 }
3227 ASSERT(length > 0); 3428 ASSERT(length > 0);
3228 // Use the general function if we're forced to always allocate. 3429 // Use the general function if we're forced to always allocate.
3229 if (always_allocate()) return AllocateFixedArray(length, TENURED); 3430 if (always_allocate()) return AllocateFixedArray(length, TENURED);
3230 // Allocate the raw data for a fixed array. 3431 // Allocate the raw data for a fixed array.
3231 int size = FixedArray::SizeFor(length); 3432 int size = FixedArray::SizeFor(length);
3232 return size <= kMaxObjectSizeInNewSpace 3433 return size <= kMaxObjectSizeInNewSpace
3233 ? new_space_.AllocateRaw(size) 3434 ? new_space_.AllocateRaw(size)
3234 : lo_space_->AllocateRawFixedArray(size); 3435 : lo_space_->AllocateRawFixedArray(size);
3235 } 3436 }
3236 3437
3237 3438
3238 Object* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { 3439 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
3239 int len = src->length(); 3440 int len = src->length();
3240 Object* obj = AllocateRawFixedArray(len); 3441 Object* obj;
3241 if (obj->IsFailure()) return obj; 3442 { MaybeObject* maybe_obj = AllocateRawFixedArray(len);
3443 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
3444 }
3242 if (Heap::InNewSpace(obj)) { 3445 if (Heap::InNewSpace(obj)) {
3243 HeapObject* dst = HeapObject::cast(obj); 3446 HeapObject* dst = HeapObject::cast(obj);
3244 dst->set_map(map); 3447 dst->set_map(map);
3245 CopyBlock(dst->address() + kPointerSize, 3448 CopyBlock(dst->address() + kPointerSize,
3246 src->address() + kPointerSize, 3449 src->address() + kPointerSize,
3247 FixedArray::SizeFor(len) - kPointerSize); 3450 FixedArray::SizeFor(len) - kPointerSize);
3248 return obj; 3451 return obj;
3249 } 3452 }
3250 HeapObject::cast(obj)->set_map(map); 3453 HeapObject::cast(obj)->set_map(map);
3251 FixedArray* result = FixedArray::cast(obj); 3454 FixedArray* result = FixedArray::cast(obj);
3252 result->set_length(len); 3455 result->set_length(len);
3253 3456
3254 // Copy the content 3457 // Copy the content
3255 AssertNoAllocation no_gc; 3458 AssertNoAllocation no_gc;
3256 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); 3459 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
3257 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); 3460 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
3258 return result; 3461 return result;
3259 } 3462 }
3260 3463
3261 3464
3262 Object* Heap::AllocateFixedArray(int length) { 3465 MaybeObject* Heap::AllocateFixedArray(int length) {
3263 ASSERT(length >= 0); 3466 ASSERT(length >= 0);
3264 if (length == 0) return empty_fixed_array(); 3467 if (length == 0) return empty_fixed_array();
3265 Object* result = AllocateRawFixedArray(length); 3468 Object* result;
3266 if (!result->IsFailure()) { 3469 { MaybeObject* maybe_result = AllocateRawFixedArray(length);
3267 // Initialize header. 3470 if (!maybe_result->ToObject(&result)) return maybe_result;
3268 FixedArray* array = reinterpret_cast<FixedArray*>(result);
3269 array->set_map(fixed_array_map());
3270 array->set_length(length);
3271 // Initialize body.
3272 ASSERT(!Heap::InNewSpace(undefined_value()));
3273 MemsetPointer(array->data_start(), undefined_value(), length);
3274 } 3471 }
3472 // Initialize header.
3473 FixedArray* array = reinterpret_cast<FixedArray*>(result);
3474 array->set_map(fixed_array_map());
3475 array->set_length(length);
3476 // Initialize body.
3477 ASSERT(!Heap::InNewSpace(undefined_value()));
3478 MemsetPointer(array->data_start(), undefined_value(), length);
3275 return result; 3479 return result;
3276 } 3480 }
3277 3481
3278 3482
3279 Object* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { 3483 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) {
3280 if (length < 0 || length > FixedArray::kMaxLength) { 3484 if (length < 0 || length > FixedArray::kMaxLength) {
3281 return Failure::OutOfMemoryException(); 3485 return Failure::OutOfMemoryException();
3282 } 3486 }
3283 3487
3284 AllocationSpace space = 3488 AllocationSpace space =
3285 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 3489 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
3286 int size = FixedArray::SizeFor(length); 3490 int size = FixedArray::SizeFor(length);
3287 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) { 3491 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) {
3288 // Too big for new space. 3492 // Too big for new space.
3289 space = LO_SPACE; 3493 space = LO_SPACE;
3290 } else if (space == OLD_POINTER_SPACE && 3494 } else if (space == OLD_POINTER_SPACE &&
3291 size > MaxObjectSizeInPagedSpace()) { 3495 size > MaxObjectSizeInPagedSpace()) {
3292 // Too big for old pointer space. 3496 // Too big for old pointer space.
3293 space = LO_SPACE; 3497 space = LO_SPACE;
3294 } 3498 }
3295 3499
3296 AllocationSpace retry_space = 3500 AllocationSpace retry_space =
3297 (size <= MaxObjectSizeInPagedSpace()) ? OLD_POINTER_SPACE : LO_SPACE; 3501 (size <= MaxObjectSizeInPagedSpace()) ? OLD_POINTER_SPACE : LO_SPACE;
3298 3502
3299 return AllocateRaw(size, space, retry_space); 3503 return AllocateRaw(size, space, retry_space);
3300 } 3504 }
3301 3505
3302 3506
3303 static Object* AllocateFixedArrayWithFiller(int length, 3507 MUST_USE_RESULT static MaybeObject* AllocateFixedArrayWithFiller(
3304 PretenureFlag pretenure, 3508 int length,
3305 Object* filler) { 3509 PretenureFlag pretenure,
3510 Object* filler) {
3306 ASSERT(length >= 0); 3511 ASSERT(length >= 0);
3307 ASSERT(Heap::empty_fixed_array()->IsFixedArray()); 3512 ASSERT(Heap::empty_fixed_array()->IsFixedArray());
3308 if (length == 0) return Heap::empty_fixed_array(); 3513 if (length == 0) return Heap::empty_fixed_array();
3309 3514
3310 ASSERT(!Heap::InNewSpace(filler)); 3515 ASSERT(!Heap::InNewSpace(filler));
3311 Object* result = Heap::AllocateRawFixedArray(length, pretenure); 3516 Object* result;
3312 if (result->IsFailure()) return result; 3517 { MaybeObject* maybe_result = Heap::AllocateRawFixedArray(length, pretenure);
3518 if (!maybe_result->ToObject(&result)) return maybe_result;
3519 }
3313 3520
3314 HeapObject::cast(result)->set_map(Heap::fixed_array_map()); 3521 HeapObject::cast(result)->set_map(Heap::fixed_array_map());
3315 FixedArray* array = FixedArray::cast(result); 3522 FixedArray* array = FixedArray::cast(result);
3316 array->set_length(length); 3523 array->set_length(length);
3317 MemsetPointer(array->data_start(), filler, length); 3524 MemsetPointer(array->data_start(), filler, length);
3318 return array; 3525 return array;
3319 } 3526 }
3320 3527
3321 3528
3322 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 3529 MaybeObject* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
3323 return AllocateFixedArrayWithFiller(length, pretenure, undefined_value()); 3530 return AllocateFixedArrayWithFiller(length, pretenure, undefined_value());
3324 } 3531 }
3325 3532
3326 3533
3327 Object* Heap::AllocateFixedArrayWithHoles(int length, PretenureFlag pretenure) { 3534 MaybeObject* Heap::AllocateFixedArrayWithHoles(int length,
3535 PretenureFlag pretenure) {
3328 return AllocateFixedArrayWithFiller(length, pretenure, the_hole_value()); 3536 return AllocateFixedArrayWithFiller(length, pretenure, the_hole_value());
3329 } 3537 }
3330 3538
3331 3539
3332 Object* Heap::AllocateUninitializedFixedArray(int length) { 3540 MaybeObject* Heap::AllocateUninitializedFixedArray(int length) {
3333 if (length == 0) return empty_fixed_array(); 3541 if (length == 0) return empty_fixed_array();
3334 3542
3335 Object* obj = AllocateRawFixedArray(length); 3543 Object* obj;
3336 if (obj->IsFailure()) return obj; 3544 { MaybeObject* maybe_obj = AllocateRawFixedArray(length);
3545 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
3546 }
3337 3547
3338 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map()); 3548 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map());
3339 FixedArray::cast(obj)->set_length(length); 3549 FixedArray::cast(obj)->set_length(length);
3340 return obj; 3550 return obj;
3341 } 3551 }
3342 3552
3343 3553
3344 Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { 3554 MaybeObject* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
3345 Object* result = Heap::AllocateFixedArray(length, pretenure); 3555 Object* result;
3346 if (result->IsFailure()) return result; 3556 { MaybeObject* maybe_result = Heap::AllocateFixedArray(length, pretenure);
3557 if (!maybe_result->ToObject(&result)) return maybe_result;
3558 }
3347 reinterpret_cast<HeapObject*>(result)->set_map(hash_table_map()); 3559 reinterpret_cast<HeapObject*>(result)->set_map(hash_table_map());
3348 ASSERT(result->IsHashTable()); 3560 ASSERT(result->IsHashTable());
3349 return result; 3561 return result;
3350 } 3562 }
3351 3563
3352 3564
3353 Object* Heap::AllocateGlobalContext() { 3565 MaybeObject* Heap::AllocateGlobalContext() {
3354 Object* result = Heap::AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS); 3566 Object* result;
3355 if (result->IsFailure()) return result; 3567 { MaybeObject* maybe_result =
3568 Heap::AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS);
3569 if (!maybe_result->ToObject(&result)) return maybe_result;
3570 }
3356 Context* context = reinterpret_cast<Context*>(result); 3571 Context* context = reinterpret_cast<Context*>(result);
3357 context->set_map(global_context_map()); 3572 context->set_map(global_context_map());
3358 ASSERT(context->IsGlobalContext()); 3573 ASSERT(context->IsGlobalContext());
3359 ASSERT(result->IsContext()); 3574 ASSERT(result->IsContext());
3360 return result; 3575 return result;
3361 } 3576 }
3362 3577
3363 3578
3364 Object* Heap::AllocateFunctionContext(int length, JSFunction* function) { 3579 MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) {
3365 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); 3580 ASSERT(length >= Context::MIN_CONTEXT_SLOTS);
3366 Object* result = Heap::AllocateFixedArray(length); 3581 Object* result;
3367 if (result->IsFailure()) return result; 3582 { MaybeObject* maybe_result = Heap::AllocateFixedArray(length);
3583 if (!maybe_result->ToObject(&result)) return maybe_result;
3584 }
3368 Context* context = reinterpret_cast<Context*>(result); 3585 Context* context = reinterpret_cast<Context*>(result);
3369 context->set_map(context_map()); 3586 context->set_map(context_map());
3370 context->set_closure(function); 3587 context->set_closure(function);
3371 context->set_fcontext(context); 3588 context->set_fcontext(context);
3372 context->set_previous(NULL); 3589 context->set_previous(NULL);
3373 context->set_extension(NULL); 3590 context->set_extension(NULL);
3374 context->set_global(function->context()->global()); 3591 context->set_global(function->context()->global());
3375 ASSERT(!context->IsGlobalContext()); 3592 ASSERT(!context->IsGlobalContext());
3376 ASSERT(context->is_function_context()); 3593 ASSERT(context->is_function_context());
3377 ASSERT(result->IsContext()); 3594 ASSERT(result->IsContext());
3378 return result; 3595 return result;
3379 } 3596 }
3380 3597
3381 3598
3382 Object* Heap::AllocateWithContext(Context* previous, 3599 MaybeObject* Heap::AllocateWithContext(Context* previous,
3383 JSObject* extension, 3600 JSObject* extension,
3384 bool is_catch_context) { 3601 bool is_catch_context) {
3385 Object* result = Heap::AllocateFixedArray(Context::MIN_CONTEXT_SLOTS); 3602 Object* result;
3386 if (result->IsFailure()) return result; 3603 { MaybeObject* maybe_result =
3604 Heap::AllocateFixedArray(Context::MIN_CONTEXT_SLOTS);
3605 if (!maybe_result->ToObject(&result)) return maybe_result;
3606 }
3387 Context* context = reinterpret_cast<Context*>(result); 3607 Context* context = reinterpret_cast<Context*>(result);
3388 context->set_map(is_catch_context ? catch_context_map() : context_map()); 3608 context->set_map(is_catch_context ? catch_context_map() : context_map());
3389 context->set_closure(previous->closure()); 3609 context->set_closure(previous->closure());
3390 context->set_fcontext(previous->fcontext()); 3610 context->set_fcontext(previous->fcontext());
3391 context->set_previous(previous); 3611 context->set_previous(previous);
3392 context->set_extension(extension); 3612 context->set_extension(extension);
3393 context->set_global(previous->global()); 3613 context->set_global(previous->global());
3394 ASSERT(!context->IsGlobalContext()); 3614 ASSERT(!context->IsGlobalContext());
3395 ASSERT(!context->is_function_context()); 3615 ASSERT(!context->is_function_context());
3396 ASSERT(result->IsContext()); 3616 ASSERT(result->IsContext());
3397 return result; 3617 return result;
3398 } 3618 }
3399 3619
3400 3620
3401 Object* Heap::AllocateStruct(InstanceType type) { 3621 MaybeObject* Heap::AllocateStruct(InstanceType type) {
3402 Map* map; 3622 Map* map;
3403 switch (type) { 3623 switch (type) {
3404 #define MAKE_CASE(NAME, Name, name) case NAME##_TYPE: map = name##_map(); break; 3624 #define MAKE_CASE(NAME, Name, name) case NAME##_TYPE: map = name##_map(); break;
3405 STRUCT_LIST(MAKE_CASE) 3625 STRUCT_LIST(MAKE_CASE)
3406 #undef MAKE_CASE 3626 #undef MAKE_CASE
3407 default: 3627 default:
3408 UNREACHABLE(); 3628 UNREACHABLE();
3409 return Failure::InternalError(); 3629 return Failure::InternalError();
3410 } 3630 }
3411 int size = map->instance_size(); 3631 int size = map->instance_size();
3412 AllocationSpace space = 3632 AllocationSpace space =
3413 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_POINTER_SPACE; 3633 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_POINTER_SPACE;
3414 Object* result = Heap::Allocate(map, space); 3634 Object* result;
3415 if (result->IsFailure()) return result; 3635 { MaybeObject* maybe_result = Heap::Allocate(map, space);
3636 if (!maybe_result->ToObject(&result)) return maybe_result;
3637 }
3416 Struct::cast(result)->InitializeBody(size); 3638 Struct::cast(result)->InitializeBody(size);
3417 return result; 3639 return result;
3418 } 3640 }
3419 3641
3420 3642
3421 bool Heap::IdleNotification() { 3643 bool Heap::IdleNotification() {
3422 static const int kIdlesBeforeScavenge = 4; 3644 static const int kIdlesBeforeScavenge = 4;
3423 static const int kIdlesBeforeMarkSweep = 7; 3645 static const int kIdlesBeforeMarkSweep = 7;
3424 static const int kIdlesBeforeMarkCompact = 8; 3646 static const int kIdlesBeforeMarkCompact = 8;
3425 static int number_idle_notifications = 0; 3647 static int number_idle_notifications = 0;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 VerifyPointersVisitor no_dirty_regions_visitor; 3887 VerifyPointersVisitor no_dirty_regions_visitor;
3666 old_data_space_->Verify(&no_dirty_regions_visitor); 3888 old_data_space_->Verify(&no_dirty_regions_visitor);
3667 code_space_->Verify(&no_dirty_regions_visitor); 3889 code_space_->Verify(&no_dirty_regions_visitor);
3668 cell_space_->Verify(&no_dirty_regions_visitor); 3890 cell_space_->Verify(&no_dirty_regions_visitor);
3669 3891
3670 lo_space_->Verify(); 3892 lo_space_->Verify();
3671 } 3893 }
3672 #endif // DEBUG 3894 #endif // DEBUG
3673 3895
3674 3896
3675 Object* Heap::LookupSymbol(Vector<const char> string) { 3897 MaybeObject* Heap::LookupSymbol(Vector<const char> string) {
3676 Object* symbol = NULL; 3898 Object* symbol = NULL;
3677 Object* new_table = symbol_table()->LookupSymbol(string, &symbol); 3899 Object* new_table;
3678 if (new_table->IsFailure()) return new_table; 3900 { MaybeObject* maybe_new_table =
3901 symbol_table()->LookupSymbol(string, &symbol);
3902 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
3903 }
3679 // Can't use set_symbol_table because SymbolTable::cast knows that 3904 // Can't use set_symbol_table because SymbolTable::cast knows that
3680 // SymbolTable is a singleton and checks for identity. 3905 // SymbolTable is a singleton and checks for identity.
3681 roots_[kSymbolTableRootIndex] = new_table; 3906 roots_[kSymbolTableRootIndex] = new_table;
3682 ASSERT(symbol != NULL); 3907 ASSERT(symbol != NULL);
3683 return symbol; 3908 return symbol;
3684 } 3909 }
3685 3910
3686 3911
3687 Object* Heap::LookupSymbol(String* string) { 3912 MaybeObject* Heap::LookupSymbol(String* string) {
3688 if (string->IsSymbol()) return string; 3913 if (string->IsSymbol()) return string;
3689 Object* symbol = NULL; 3914 Object* symbol = NULL;
3690 Object* new_table = symbol_table()->LookupString(string, &symbol); 3915 Object* new_table;
3691 if (new_table->IsFailure()) return new_table; 3916 { MaybeObject* maybe_new_table =
3917 symbol_table()->LookupString(string, &symbol);
3918 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
3919 }
3692 // Can't use set_symbol_table because SymbolTable::cast knows that 3920 // Can't use set_symbol_table because SymbolTable::cast knows that
3693 // SymbolTable is a singleton and checks for identity. 3921 // SymbolTable is a singleton and checks for identity.
3694 roots_[kSymbolTableRootIndex] = new_table; 3922 roots_[kSymbolTableRootIndex] = new_table;
3695 ASSERT(symbol != NULL); 3923 ASSERT(symbol != NULL);
3696 return symbol; 3924 return symbol;
3697 } 3925 }
3698 3926
3699 3927
3700 bool Heap::LookupSymbolIfExists(String* string, String** symbol) { 3928 bool Heap::LookupSymbolIfExists(String* string, String** symbol) {
3701 if (string->IsSymbol()) { 3929 if (string->IsSymbol()) {
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
5007 void ExternalStringTable::TearDown() { 5235 void ExternalStringTable::TearDown() {
5008 new_space_strings_.Free(); 5236 new_space_strings_.Free();
5009 old_space_strings_.Free(); 5237 old_space_strings_.Free();
5010 } 5238 }
5011 5239
5012 5240
5013 List<Object*> ExternalStringTable::new_space_strings_; 5241 List<Object*> ExternalStringTable::new_space_strings_;
5014 List<Object*> ExternalStringTable::old_space_strings_; 5242 List<Object*> ExternalStringTable::old_space_strings_;
5015 5243
5016 } } // namespace v8::internal 5244 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698