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

Side by Side Diff: src/heap.cc

Issue 3522008: This is a little experiment to move Failure to a superclass above 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/code-stubs.cc ('k') | src/ia32/macro-assembler-ia32.cc » ('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 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 ScavengingVisitor::Scavenge(map, p, object); 1395 ScavengingVisitor::Scavenge(map, p, object);
1396 } 1396 }
1397 1397
1398 1398
1399 void Heap::ScavengePointer(HeapObject** p) { 1399 void Heap::ScavengePointer(HeapObject** p) {
1400 ScavengeObject(p, *p); 1400 ScavengeObject(p, *p);
1401 } 1401 }
1402 1402
1403 1403
1404 Object* Heap::AllocatePartialMap(InstanceType instance_type, 1404 Object* Heap::AllocatePartialMap(InstanceType instance_type,
1405 Object* result;
1406 { TryAllocation t = AllocateRawMap();
1407 if (!t->ToObject(&result)) return t;
1408 }
1405 int instance_size) { 1409 int instance_size) {
1406 Object* result = AllocateRawMap();
1407 if (result->IsFailure()) return result;
1408 1410
1409 // Map::cast cannot be used due to uninitialized map field. 1411 // Map::cast cannot be used due to uninitialized map field.
1410 reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map()); 1412 reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map());
1411 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); 1413 reinterpret_cast<Map*>(result)->set_instance_type(instance_type);
1412 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); 1414 reinterpret_cast<Map*>(result)->set_instance_size(instance_size);
1413 reinterpret_cast<Map*>(result)-> 1415 reinterpret_cast<Map*>(result)->
1414 set_visitor_id( 1416 set_visitor_id(
1415 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); 1417 StaticVisitorBase::GetVisitorId(instance_type, instance_size));
1416 reinterpret_cast<Map*>(result)->set_inobject_properties(0); 1418 reinterpret_cast<Map*>(result)->set_inobject_properties(0);
1417 reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0); 1419 reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0);
1418 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); 1420 reinterpret_cast<Map*>(result)->set_unused_property_fields(0);
1419 reinterpret_cast<Map*>(result)->set_bit_field(0); 1421 reinterpret_cast<Map*>(result)->set_bit_field(0);
1420 reinterpret_cast<Map*>(result)->set_bit_field2(0); 1422 reinterpret_cast<Map*>(result)->set_bit_field2(0);
1421 return result; 1423 return result;
1422 } 1424 }
1423 1425
1424 1426
1427 Object* result;
1428 { TryAllocation t = AllocateRawMap();
1429 if (!t->ToObject(&result)) return t;
1430 }
1425 Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) { 1431 Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) {
1426 Object* result = AllocateRawMap();
1427 if (result->IsFailure()) return result;
1428 1432
1429 Map* map = reinterpret_cast<Map*>(result); 1433 Map* map = reinterpret_cast<Map*>(result);
1430 map->set_map(meta_map()); 1434 map->set_map(meta_map());
1431 map->set_instance_type(instance_type); 1435 map->set_instance_type(instance_type);
1432 map->set_visitor_id( 1436 map->set_visitor_id(
1433 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); 1437 StaticVisitorBase::GetVisitorId(instance_type, instance_size));
1434 map->set_prototype(null_value()); 1438 map->set_prototype(null_value());
1435 map->set_constructor(null_value()); 1439 map->set_constructor(null_value());
1436 map->set_instance_size(instance_size); 1440 map->set_instance_size(instance_size);
1437 map->set_inobject_properties(0); 1441 map->set_inobject_properties(0);
1438 map->set_pre_allocated_property_fields(0); 1442 map->set_pre_allocated_property_fields(0);
1439 map->set_instance_descriptors(empty_descriptor_array()); 1443 map->set_instance_descriptors(empty_descriptor_array());
1440 map->set_code_cache(empty_fixed_array()); 1444 map->set_code_cache(empty_fixed_array());
1441 map->set_unused_property_fields(0); 1445 map->set_unused_property_fields(0);
1442 map->set_bit_field(0); 1446 map->set_bit_field(0);
1443 map->set_bit_field2((1 << Map::kIsExtensible) | (1 << Map::kHasFastElements)); 1447 map->set_bit_field2((1 << Map::kIsExtensible) | (1 << Map::kHasFastElements));
1444 1448
1445 // If the map object is aligned fill the padding area with Smi 0 objects. 1449 // If the map object is aligned fill the padding area with Smi 0 objects.
1446 if (Map::kPadStart < Map::kSize) { 1450 if (Map::kPadStart < Map::kSize) {
1447 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag, 1451 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag,
1448 0, 1452 0,
1449 Map::kSize - Map::kPadStart); 1453 Map::kSize - Map::kPadStart);
1450 } 1454 }
1451 return map; 1455 return map;
1452 } 1456 }
1453 1457
1454 1458
1459 Object* result;
1460 { TryAllocation t = AllocateStruct(CODE_CACHE_TYPE);
1461 if (!t->ToObject(&result)) return t;
1462 }
1455 Object* Heap::AllocateCodeCache() { 1463 Object* Heap::AllocateCodeCache() {
1456 Object* result = AllocateStruct(CODE_CACHE_TYPE);
1457 if (result->IsFailure()) return result;
1458 CodeCache* code_cache = CodeCache::cast(result); 1464 CodeCache* code_cache = CodeCache::cast(result);
1459 code_cache->set_default_cache(empty_fixed_array()); 1465 code_cache->set_default_cache(empty_fixed_array());
1460 code_cache->set_normal_type_cache(undefined_value()); 1466 code_cache->set_normal_type_cache(undefined_value());
1461 return code_cache; 1467 return code_cache;
1462 } 1468 }
1463 1469
1464 1470
1465 const Heap::StringTypeTable Heap::string_type_table[] = { 1471 const Heap::StringTypeTable Heap::string_type_table[] = {
1466 #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \ 1472 #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \
1467 {type, size, k##camel_name##MapRootIndex}, 1473 {type, size, k##camel_name##MapRootIndex},
(...skipping 11 matching lines...) Expand all
1479 1485
1480 1486
1481 const Heap::StructTable Heap::struct_table[] = { 1487 const Heap::StructTable Heap::struct_table[] = {
1482 #define STRUCT_TABLE_ELEMENT(NAME, Name, name) \ 1488 #define STRUCT_TABLE_ELEMENT(NAME, Name, name) \
1483 { NAME##_TYPE, Name::kSize, k##Name##MapRootIndex }, 1489 { NAME##_TYPE, Name::kSize, k##Name##MapRootIndex },
1484 STRUCT_LIST(STRUCT_TABLE_ELEMENT) 1490 STRUCT_LIST(STRUCT_TABLE_ELEMENT)
1485 #undef STRUCT_TABLE_ELEMENT 1491 #undef STRUCT_TABLE_ELEMENT
1486 }; 1492 };
1487 1493
1488 1494
1495 Object* obj;
1496 { TryAllocation t = AllocatePartialMap(MAP_TYPE, Map::kSize);
1497 if (!t->ToObject(&obj)) return false;
1498 }
1489 bool Heap::CreateInitialMaps() { 1499 bool Heap::CreateInitialMaps() {
1490 Object* obj = AllocatePartialMap(MAP_TYPE, Map::kSize);
1491 if (obj->IsFailure()) return false;
1492 // Map::cast cannot be used due to uninitialized map field. 1500 // Map::cast cannot be used due to uninitialized map field.
1493 Map* new_meta_map = reinterpret_cast<Map*>(obj); 1501 Map* new_meta_map = reinterpret_cast<Map*>(obj);
1494 set_meta_map(new_meta_map); 1502 set_meta_map(new_meta_map);
1495 new_meta_map->set_map(new_meta_map); 1503 new_meta_map->set_map(new_meta_map);
1504 { TryAllocation t =
1505 AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1506 if (!t->ToObject(&obj)) return false;
1507 }
1496 1508
1497 obj = AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1498 if (obj->IsFailure()) return false;
1499 set_fixed_array_map(Map::cast(obj)); 1509 set_fixed_array_map(Map::cast(obj));
1510 { TryAllocation t = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize);
1511 if (!t->ToObject(&obj)) return false;
1512 }
1500 1513
1501 obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize);
1502 if (obj->IsFailure()) return false;
1503 set_oddball_map(Map::cast(obj)); 1514 set_oddball_map(Map::cast(obj));
1504 1515
1516 { TryAllocation t = AllocateEmptyFixedArray();
1517 if (!t->ToObject(&obj)) return false;
1518 }
1505 // Allocate the empty array. 1519 // Allocate the empty array.
1506 obj = AllocateEmptyFixedArray();
1507 if (obj->IsFailure()) return false;
1508 set_empty_fixed_array(FixedArray::cast(obj)); 1520 set_empty_fixed_array(FixedArray::cast(obj));
1521 { TryAllocation t = Allocate(oddball_map(), OLD_DATA_SPACE);
1522 if (!t->ToObject(&obj)) return false;
1523 }
1509 1524
1510 obj = Allocate(oddball_map(), OLD_DATA_SPACE);
1511 if (obj->IsFailure()) return false;
1512 set_null_value(obj); 1525 set_null_value(obj);
1513 1526
1527 { TryAllocation t = AllocateEmptyFixedArray();
1528 if (!t->ToObject(&obj)) return false;
1529 }
1514 // Allocate the empty descriptor array. 1530 // Allocate the empty descriptor array.
1515 obj = AllocateEmptyFixedArray();
1516 if (obj->IsFailure()) return false;
1517 set_empty_descriptor_array(DescriptorArray::cast(obj)); 1531 set_empty_descriptor_array(DescriptorArray::cast(obj));
1518 1532
1519 // Fix the instance_descriptors for the existing maps. 1533 // Fix the instance_descriptors for the existing maps.
1520 meta_map()->set_instance_descriptors(empty_descriptor_array()); 1534 meta_map()->set_instance_descriptors(empty_descriptor_array());
1521 meta_map()->set_code_cache(empty_fixed_array()); 1535 meta_map()->set_code_cache(empty_fixed_array());
1522 1536
1523 fixed_array_map()->set_instance_descriptors(empty_descriptor_array()); 1537 fixed_array_map()->set_instance_descriptors(empty_descriptor_array());
1524 fixed_array_map()->set_code_cache(empty_fixed_array()); 1538 fixed_array_map()->set_code_cache(empty_fixed_array());
1525 1539
1526 oddball_map()->set_instance_descriptors(empty_descriptor_array()); 1540 oddball_map()->set_instance_descriptors(empty_descriptor_array());
1527 oddball_map()->set_code_cache(empty_fixed_array()); 1541 oddball_map()->set_code_cache(empty_fixed_array());
1528 1542
1529 // Fix prototype object for existing maps. 1543 // Fix prototype object for existing maps.
1530 meta_map()->set_prototype(null_value()); 1544 meta_map()->set_prototype(null_value());
1531 meta_map()->set_constructor(null_value()); 1545 meta_map()->set_constructor(null_value());
1532 1546
1533 fixed_array_map()->set_prototype(null_value()); 1547 fixed_array_map()->set_prototype(null_value());
1534 fixed_array_map()->set_constructor(null_value()); 1548 fixed_array_map()->set_constructor(null_value());
1535 1549
1536 oddball_map()->set_prototype(null_value()); 1550 oddball_map()->set_prototype(null_value());
1537 oddball_map()->set_constructor(null_value()); 1551 oddball_map()->set_constructor(null_value());
1552 { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1553 if (!t->ToObject(&obj)) return false;
1554 }
1538 1555
1539 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1540 if (obj->IsFailure()) return false;
1541 set_fixed_cow_array_map(Map::cast(obj)); 1556 set_fixed_cow_array_map(Map::cast(obj));
1542 ASSERT(fixed_array_map() != fixed_cow_array_map()); 1557 ASSERT(fixed_array_map() != fixed_cow_array_map());
1558 { TryAllocation t = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
1559 if (!t->ToObject(&obj)) return false;
1560 }
1543 1561
1544 obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
1545 if (obj->IsFailure()) return false;
1546 set_heap_number_map(Map::cast(obj)); 1562 set_heap_number_map(Map::cast(obj));
1563 { TryAllocation t = AllocateMap(PROXY_TYPE, Proxy::kSize);
1564 if (!t->ToObject(&obj)) return false;
1565 }
1547 1566
1548 obj = AllocateMap(PROXY_TYPE, Proxy::kSize);
1549 if (obj->IsFailure()) return false;
1550 set_proxy_map(Map::cast(obj)); 1567 set_proxy_map(Map::cast(obj));
1551 1568
1552 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { 1569 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
1570 { TryAllocation t = AllocateMap(entry.type, entry.size);
1571 if (!t->ToObject(&obj)) return false;
1572 }
1553 const StringTypeTable& entry = string_type_table[i]; 1573 const StringTypeTable& entry = string_type_table[i];
1554 obj = AllocateMap(entry.type, entry.size);
1555 if (obj->IsFailure()) return false;
1556 roots_[entry.index] = Map::cast(obj); 1574 roots_[entry.index] = Map::cast(obj);
1557 } 1575 }
1576 { TryAllocation t = AllocateMap(STRING_TYPE, kVariableSizeSentinel);
1577 if (!t->ToObject(&obj)) return false;
1578 }
1558 1579
1559 obj = AllocateMap(STRING_TYPE, kVariableSizeSentinel);
1560 if (obj->IsFailure()) return false;
1561 set_undetectable_string_map(Map::cast(obj)); 1580 set_undetectable_string_map(Map::cast(obj));
1562 Map::cast(obj)->set_is_undetectable(); 1581 Map::cast(obj)->set_is_undetectable();
1582 { TryAllocation t = AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel);
1583 if (!t->ToObject(&obj)) return false;
1584 }
1563 1585
1564 obj = AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel);
1565 if (obj->IsFailure()) return false;
1566 set_undetectable_ascii_string_map(Map::cast(obj)); 1586 set_undetectable_ascii_string_map(Map::cast(obj));
1567 Map::cast(obj)->set_is_undetectable(); 1587 Map::cast(obj)->set_is_undetectable();
1588 { TryAllocation t = AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel);
1589 if (!t->ToObject(&obj)) return false;
1590 }
1568 1591
1569 obj = AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel);
1570 if (obj->IsFailure()) return false;
1571 set_byte_array_map(Map::cast(obj)); 1592 set_byte_array_map(Map::cast(obj));
1593 { TryAllocation t = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize);
1594 if (!t->ToObject(&obj)) return false;
1595 }
1572 1596
1573 obj = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize);
1574 if (obj->IsFailure()) return false;
1575 set_pixel_array_map(Map::cast(obj)); 1597 set_pixel_array_map(Map::cast(obj));
1576 1598
1577 obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE, 1599 { TryAllocation t = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE,
1578 ExternalArray::kAlignedSize); 1600 ExternalArray::kAlignedSize);
1579 if (obj->IsFailure()) return false; 1601 if (!t->ToObject(&obj)) return false;
1602 }
1580 set_external_byte_array_map(Map::cast(obj)); 1603 set_external_byte_array_map(Map::cast(obj));
1581 1604
1582 obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, 1605 { TryAllocation t = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
1583 ExternalArray::kAlignedSize); 1606 ExternalArray::kAlignedSize);
1584 if (obj->IsFailure()) return false; 1607 if (!t->ToObject(&obj)) return false;
1608 }
1585 set_external_unsigned_byte_array_map(Map::cast(obj)); 1609 set_external_unsigned_byte_array_map(Map::cast(obj));
1586 1610
1587 obj = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE, 1611 { TryAllocation t = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE,
1588 ExternalArray::kAlignedSize); 1612 ExternalArray::kAlignedSize);
1589 if (obj->IsFailure()) return false; 1613 if (!t->ToObject(&obj)) return false;
1614 }
1590 set_external_short_array_map(Map::cast(obj)); 1615 set_external_short_array_map(Map::cast(obj));
1591 1616
1592 obj = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, 1617 { TryAllocation t = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
1593 ExternalArray::kAlignedSize); 1618 ExternalArray::kAlignedSize);
1594 if (obj->IsFailure()) return false; 1619 if (!t->ToObject(&obj)) return false;
1620 }
1595 set_external_unsigned_short_array_map(Map::cast(obj)); 1621 set_external_unsigned_short_array_map(Map::cast(obj));
1596 1622
1597 obj = AllocateMap(EXTERNAL_INT_ARRAY_TYPE, 1623 { TryAllocation t = AllocateMap(EXTERNAL_INT_ARRAY_TYPE,
1598 ExternalArray::kAlignedSize); 1624 ExternalArray::kAlignedSize);
1599 if (obj->IsFailure()) return false; 1625 if (!t->ToObject(&obj)) return false;
1626 }
1600 set_external_int_array_map(Map::cast(obj)); 1627 set_external_int_array_map(Map::cast(obj));
1601 1628
1602 obj = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, 1629 { TryAllocation t = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
1603 ExternalArray::kAlignedSize); 1630 ExternalArray::kAlignedSize);
1604 if (obj->IsFailure()) return false; 1631 if (!t->ToObject(&obj)) return false;
1632 }
1605 set_external_unsigned_int_array_map(Map::cast(obj)); 1633 set_external_unsigned_int_array_map(Map::cast(obj));
1606 1634
1607 obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE, 1635 { TryAllocation t = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE,
1608 ExternalArray::kAlignedSize); 1636 ExternalArray::kAlignedSize);
1609 if (obj->IsFailure()) return false; 1637 if (!t->ToObject(&obj)) return false;
1638 }
1610 set_external_float_array_map(Map::cast(obj)); 1639 set_external_float_array_map(Map::cast(obj));
1640 { TryAllocation t = AllocateMap(CODE_TYPE, kVariableSizeSentinel);
1641 if (!t->ToObject(&obj)) return false;
1642 }
1611 1643
1612 obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel);
1613 if (obj->IsFailure()) return false;
1614 set_code_map(Map::cast(obj)); 1644 set_code_map(Map::cast(obj));
1615 1645
1616 obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE, 1646 { TryAllocation t = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE,
1617 JSGlobalPropertyCell::kSize); 1647 JSGlobalPropertyCell::kSize);
1618 if (obj->IsFailure()) return false; 1648 if (!t->ToObject(&obj)) return false;
1649 }
1619 set_global_property_cell_map(Map::cast(obj)); 1650 set_global_property_cell_map(Map::cast(obj));
1651 { TryAllocation t = AllocateMap(FILLER_TYPE, kPointerSize);
1652 if (!t->ToObject(&obj)) return false;
1653 }
1620 1654
1621 obj = AllocateMap(FILLER_TYPE, kPointerSize);
1622 if (obj->IsFailure()) return false;
1623 set_one_pointer_filler_map(Map::cast(obj)); 1655 set_one_pointer_filler_map(Map::cast(obj));
1656 { TryAllocation t = AllocateMap(FILLER_TYPE, 2 * kPointerSize);
1657 if (!t->ToObject(&obj)) return false;
1658 }
1624 1659
1625 obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize);
1626 if (obj->IsFailure()) return false;
1627 set_two_pointer_filler_map(Map::cast(obj)); 1660 set_two_pointer_filler_map(Map::cast(obj));
1628 1661
1629 for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) { 1662 for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) {
1663 { TryAllocation t = AllocateMap(entry.type, entry.size);
1664 if (!t->ToObject(&obj)) return false;
1665 }
1630 const StructTable& entry = struct_table[i]; 1666 const StructTable& entry = struct_table[i];
1631 obj = AllocateMap(entry.type, entry.size);
1632 if (obj->IsFailure()) return false;
1633 roots_[entry.index] = Map::cast(obj); 1667 roots_[entry.index] = Map::cast(obj);
1634 } 1668 }
1669 { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1670 if (!t->ToObject(&obj)) return false;
1671 }
1635 1672
1636 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1637 if (obj->IsFailure()) return false;
1638 set_hash_table_map(Map::cast(obj)); 1673 set_hash_table_map(Map::cast(obj));
1674 { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1675 if (!t->ToObject(&obj)) return false;
1676 }
1639 1677
1640 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1641 if (obj->IsFailure()) return false;
1642 set_context_map(Map::cast(obj)); 1678 set_context_map(Map::cast(obj));
1679 { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1680 if (!t->ToObject(&obj)) return false;
1681 }
1643 1682
1644 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1645 if (obj->IsFailure()) return false;
1646 set_catch_context_map(Map::cast(obj)); 1683 set_catch_context_map(Map::cast(obj));
1684 { TryAllocation t = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1685 if (!t->ToObject(&obj)) return false;
1686 }
1647 1687
1648 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1649 if (obj->IsFailure()) return false;
1650 set_global_context_map(Map::cast(obj)); 1688 set_global_context_map(Map::cast(obj));
1651 1689
1652 obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE, 1690 { TryAllocation t = AllocateMap(SHARED_FUNCTION_INFO_TYPE,
1653 SharedFunctionInfo::kAlignedSize); 1691 SharedFunctionInfo::kAlignedSize);
1654 if (obj->IsFailure()) return false; 1692 if (!t->ToObject(&obj)) return false;
1693 }
1655 set_shared_function_info_map(Map::cast(obj)); 1694 set_shared_function_info_map(Map::cast(obj));
1656 1695
1657 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); 1696 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array()));
1658 return true; 1697 return true;
1659 } 1698 }
1660 1699
1661 1700
1662 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 1701 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
1663 // Statically ensure that it is safe to allocate heap numbers in paged 1702 // Statically ensure that it is safe to allocate heap numbers in paged
1664 // spaces. 1703 // spaces.
1665 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1704 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1666 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1705 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
1706 Object* result;
1707 { TryAllocation t = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
1708 if (!t->ToObject(&result)) return t;
1709 }
1667 1710
1668 Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
1669 if (result->IsFailure()) return result;
1670 1711
1671 HeapObject::cast(result)->set_map(heap_number_map()); 1712 HeapObject::cast(result)->set_map(heap_number_map());
1672 HeapNumber::cast(result)->set_value(value); 1713 HeapNumber::cast(result)->set_value(value);
1673 return result; 1714 return result;
1674 } 1715 }
1675 1716
1676 1717
1677 Object* Heap::AllocateHeapNumber(double value) { 1718 Object* Heap::AllocateHeapNumber(double value) {
1678 // Use general version, if we're forced to always allocate. 1719 // Use general version, if we're forced to always allocate.
1679 if (always_allocate()) return AllocateHeapNumber(value, TENURED); 1720 if (always_allocate()) return AllocateHeapNumber(value, TENURED);
1680 1721
1681 // This version of AllocateHeapNumber is optimized for 1722 // This version of AllocateHeapNumber is optimized for
1682 // allocation in new space. 1723 // allocation in new space.
1683 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1724 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1725 Object* result;
1726 { TryAllocation t = new_space_.AllocateRaw(HeapNumber::kSize);
1727 if (!t->ToObject(&result)) return t;
1728 }
1684 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 1729 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
1685 Object* result = new_space_.AllocateRaw(HeapNumber::kSize);
1686 if (result->IsFailure()) return result;
1687 HeapObject::cast(result)->set_map(heap_number_map()); 1730 HeapObject::cast(result)->set_map(heap_number_map());
1688 HeapNumber::cast(result)->set_value(value); 1731 HeapNumber::cast(result)->set_value(value);
1689 return result; 1732 return result;
1690 } 1733 }
1691 1734
1692 1735
1736 Object* result;
1737 { TryAllocation t = AllocateRawCell();
1738 if (!t->ToObject(&result)) return t;
1739 }
1693 Object* Heap::AllocateJSGlobalPropertyCell(Object* value) { 1740 Object* Heap::AllocateJSGlobalPropertyCell(Object* value) {
1694 Object* result = AllocateRawCell();
1695 if (result->IsFailure()) return result;
1696 HeapObject::cast(result)->set_map(global_property_cell_map()); 1741 HeapObject::cast(result)->set_map(global_property_cell_map());
1697 JSGlobalPropertyCell::cast(result)->set_value(value); 1742 JSGlobalPropertyCell::cast(result)->set_value(value);
1698 return result; 1743 return result;
1699 } 1744 }
1700 1745
1701 1746
1702 Object* Heap::CreateOddball(const char* to_string, 1747 Object* Heap::CreateOddball(const char* to_string,
1748 Object* result;
1749 { TryAllocation t = Allocate(oddball_map(), OLD_DATA_SPACE);
1750 if (!t->ToObject(&result)) return t;
1751 }
1703 Object* to_number) { 1752 Object* to_number) {
1704 Object* result = Allocate(oddball_map(), OLD_DATA_SPACE);
1705 if (result->IsFailure()) return result;
1706 return Oddball::cast(result)->Initialize(to_string, to_number); 1753 return Oddball::cast(result)->Initialize(to_string, to_number);
1707 } 1754 }
1708 1755
1709 1756
1710 bool Heap::CreateApiObjects() { 1757 bool Heap::CreateApiObjects() {
1711 Object* obj; 1758 Object* obj;
1759 { TryAllocation t = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
1760 if (!t->ToObject(&obj)) return false;
1761 }
1712 1762
1713 obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
1714 if (obj->IsFailure()) return false;
1715 set_neander_map(Map::cast(obj)); 1763 set_neander_map(Map::cast(obj));
1764 { TryAllocation t = Heap::AllocateJSObjectFromMap(neander_map());
1765 if (!t->ToObject(&obj)) return false;
1766 }
1716 1767
1717 obj = Heap::AllocateJSObjectFromMap(neander_map()); 1768 Object* elements;
1718 if (obj->IsFailure()) return false; 1769 { TryAllocation t = AllocateFixedArray(2);
1719 Object* elements = AllocateFixedArray(2); 1770 if (!t->ToObject(&elements)) return false;
1720 if (elements->IsFailure()) return false; 1771 }
1721 FixedArray::cast(elements)->set(0, Smi::FromInt(0)); 1772 FixedArray::cast(elements)->set(0, Smi::FromInt(0));
1722 JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); 1773 JSObject::cast(obj)->set_elements(FixedArray::cast(elements));
1723 set_message_listeners(JSObject::cast(obj)); 1774 set_message_listeners(JSObject::cast(obj));
1724 1775
1725 return true; 1776 return true;
1726 } 1777 }
1727 1778
1728 1779
1729 void Heap::CreateCEntryStub() { 1780 void Heap::CreateCEntryStub() {
1730 CEntryStub stub(1); 1781 CEntryStub stub(1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 Heap::CreateJSConstructEntryStub(); 1822 Heap::CreateJSConstructEntryStub();
1772 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP 1823 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP
1773 Heap::CreateRegExpCEntryStub(); 1824 Heap::CreateRegExpCEntryStub();
1774 #endif 1825 #endif
1775 } 1826 }
1776 1827
1777 1828
1778 bool Heap::CreateInitialObjects() { 1829 bool Heap::CreateInitialObjects() {
1779 Object* obj; 1830 Object* obj;
1780 1831
1832 { TryAllocation t = AllocateHeapNumber(-0.0, TENURED);
1833 if (!t->ToObject(&obj)) return false;
1834 }
1781 // The -0 value must be set before NumberFromDouble works. 1835 // The -0 value must be set before NumberFromDouble works.
1782 obj = AllocateHeapNumber(-0.0, TENURED);
1783 if (obj->IsFailure()) return false;
1784 set_minus_zero_value(obj); 1836 set_minus_zero_value(obj);
1785 ASSERT(signbit(minus_zero_value()->Number()) != 0); 1837 ASSERT(signbit(minus_zero_value()->Number()) != 0);
1838 { TryAllocation t = AllocateHeapNumber(OS::nan_value(), TENURED);
1839 if (!t->ToObject(&obj)) return false;
1840 }
1786 1841
1787 obj = AllocateHeapNumber(OS::nan_value(), TENURED);
1788 if (obj->IsFailure()) return false;
1789 set_nan_value(obj); 1842 set_nan_value(obj);
1843 { TryAllocation t = Allocate(oddball_map(), OLD_DATA_SPACE);
1844 if (!t->ToObject(&obj)) return false;
1845 }
1790 1846
1791 obj = Allocate(oddball_map(), OLD_DATA_SPACE);
1792 if (obj->IsFailure()) return false;
1793 set_undefined_value(obj); 1847 set_undefined_value(obj);
1794 ASSERT(!InNewSpace(undefined_value())); 1848 ASSERT(!InNewSpace(undefined_value()));
1795 1849
1850 { TryAllocation t = SymbolTable::Allocate(kInitialSymbolTableSize);
1851 if (!t->ToObject(&obj)) return false;
1852 }
1796 // Allocate initial symbol table. 1853 // Allocate initial symbol table.
1797 obj = SymbolTable::Allocate(kInitialSymbolTableSize);
1798 if (obj->IsFailure()) return false;
1799 // Don't use set_symbol_table() due to asserts. 1854 // Don't use set_symbol_table() due to asserts.
1800 roots_[kSymbolTableRootIndex] = obj; 1855 roots_[kSymbolTableRootIndex] = obj;
1801 1856
1857 Object* symbol;
1858 { TryAllocation t = LookupAsciiSymbol("undefined");
1859 if (!t->ToObject(&symbol)) return false;
1860 }
1802 // Assign the print strings for oddballs after creating symboltable. 1861 // Assign the print strings for oddballs after creating symboltable.
1803 Object* symbol = LookupAsciiSymbol("undefined");
1804 if (symbol->IsFailure()) return false;
1805 Oddball::cast(undefined_value())->set_to_string(String::cast(symbol)); 1862 Oddball::cast(undefined_value())->set_to_string(String::cast(symbol));
1806 Oddball::cast(undefined_value())->set_to_number(nan_value()); 1863 Oddball::cast(undefined_value())->set_to_number(nan_value());
1807 1864
1865 { TryAllocation t =
1866 Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0));
1867 if (!t->ToObject(&obj)) return false;
1868 }
1808 // Allocate the null_value 1869 // Allocate the null_value
1809 obj = Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0)); 1870 { TryAllocation t = CreateOddball("true", Smi::FromInt(1));
1810 if (obj->IsFailure()) return false; 1871 if (!t->ToObject(&obj)) return false;
1872 }
1811 1873
1812 obj = CreateOddball("true", Smi::FromInt(1));
1813 if (obj->IsFailure()) return false;
1814 set_true_value(obj); 1874 set_true_value(obj);
1875 { TryAllocation t = CreateOddball("false", Smi::FromInt(0));
1876 if (!t->ToObject(&obj)) return false;
1877 }
1815 1878
1816 obj = CreateOddball("false", Smi::FromInt(0));
1817 if (obj->IsFailure()) return false;
1818 set_false_value(obj); 1879 set_false_value(obj);
1880 { TryAllocation t = CreateOddball("hole", Smi::FromInt(-1));
1881 if (!t->ToObject(&obj)) return false;
1882 }
1819 1883
1820 obj = CreateOddball("hole", Smi::FromInt(-1));
1821 if (obj->IsFailure()) return false;
1822 set_the_hole_value(obj); 1884 set_the_hole_value(obj);
1885 { TryAllocation t =
1886 CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2));
1887 if (!t->ToObject(&obj)) return false;
1888 }
1823 1889
1824 obj = CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2));
1825 if (obj->IsFailure()) return false;
1826 set_no_interceptor_result_sentinel(obj); 1890 set_no_interceptor_result_sentinel(obj);
1891 { TryAllocation t = CreateOddball("termination_exception", Smi::FromInt(-3));
1892 if (!t->ToObject(&obj)) return false;
1893 }
1827 1894
1828 obj = CreateOddball("termination_exception", Smi::FromInt(-3));
1829 if (obj->IsFailure()) return false;
1830 set_termination_exception(obj); 1895 set_termination_exception(obj);
1831 1896
1897 { TryAllocation t = AllocateRawAsciiString(0, TENURED);
1898 if (!t->ToObject(&obj)) return false;
1899 }
1832 // Allocate the empty string. 1900 // Allocate the empty string.
1833 obj = AllocateRawAsciiString(0, TENURED);
1834 if (obj->IsFailure()) return false;
1835 set_empty_string(String::cast(obj)); 1901 set_empty_string(String::cast(obj));
1836 1902
1903 { TryAllocation t = LookupAsciiSymbol(constant_symbol_table[i].contents);
1904 if (!t->ToObject(&obj)) return false;
1905 }
1837 for (unsigned i = 0; i < ARRAY_SIZE(constant_symbol_table); i++) { 1906 for (unsigned i = 0; i < ARRAY_SIZE(constant_symbol_table); i++) {
1838 obj = LookupAsciiSymbol(constant_symbol_table[i].contents);
1839 if (obj->IsFailure()) return false;
1840 roots_[constant_symbol_table[i].index] = String::cast(obj); 1907 roots_[constant_symbol_table[i].index] = String::cast(obj);
1841 } 1908 }
1842 1909
1843 // Allocate the hidden symbol which is used to identify the hidden properties 1910 // Allocate the hidden symbol which is used to identify the hidden properties
1844 // in JSObjects. The hash code has a special value so that it will not match 1911 // in JSObjects. The hash code has a special value so that it will not match
1845 // the empty string when searching for the property. It cannot be part of the 1912 // the empty string when searching for the property. It cannot be part of the
1846 // loop above because it needs to be allocated manually with the special 1913 // loop above because it needs to be allocated manually with the special
1847 // hash code in place. The hash code for the hidden_symbol is zero to ensure 1914 // hash code in place. The hash code for the hidden_symbol is zero to ensure
1915 { TryAllocation t = AllocateSymbol(CStrVector(""), 0, String::kZeroHash);
1916 if (!t->ToObject(&obj)) return false;
1917 }
1848 // that it will always be at the first entry in property descriptors. 1918 // that it will always be at the first entry in property descriptors.
1849 obj = AllocateSymbol(CStrVector(""), 0, String::kZeroHash);
1850 if (obj->IsFailure()) return false;
1851 hidden_symbol_ = String::cast(obj); 1919 hidden_symbol_ = String::cast(obj);
1852 1920
1921 { TryAllocation t = AllocateProxy((Address) &Accessors::ObjectPrototype);
1922 if (!t->ToObject(&obj)) return false;
1923 }
1853 // Allocate the proxy for __proto__. 1924 // Allocate the proxy for __proto__.
1854 obj = AllocateProxy((Address) &Accessors::ObjectPrototype);
1855 if (obj->IsFailure()) return false;
1856 set_prototype_accessors(Proxy::cast(obj)); 1925 set_prototype_accessors(Proxy::cast(obj));
1857 1926
1858 // Allocate the code_stubs dictionary. The initial size is set to avoid 1927 // Allocate the code_stubs dictionary. The initial size is set to avoid
1928 { TryAllocation t = NumberDictionary::Allocate(128);
1929 if (!t->ToObject(&obj)) return false;
1930 }
1859 // expanding the dictionary during bootstrapping. 1931 // expanding the dictionary during bootstrapping.
1860 obj = NumberDictionary::Allocate(128);
1861 if (obj->IsFailure()) return false;
1862 set_code_stubs(NumberDictionary::cast(obj)); 1932 set_code_stubs(NumberDictionary::cast(obj));
1863 1933
1864 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size 1934 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size
1935 { TryAllocation t = NumberDictionary::Allocate(64);
1936 if (!t->ToObject(&obj)) return false;
1937 }
1865 // is set to avoid expanding the dictionary during bootstrapping. 1938 // is set to avoid expanding the dictionary during bootstrapping.
1866 obj = NumberDictionary::Allocate(64);
1867 if (obj->IsFailure()) return false;
1868 set_non_monomorphic_cache(NumberDictionary::cast(obj)); 1939 set_non_monomorphic_cache(NumberDictionary::cast(obj));
1869 1940
1870 set_instanceof_cache_function(Smi::FromInt(0)); 1941 set_instanceof_cache_function(Smi::FromInt(0));
1871 set_instanceof_cache_map(Smi::FromInt(0)); 1942 set_instanceof_cache_map(Smi::FromInt(0));
1872 set_instanceof_cache_answer(Smi::FromInt(0)); 1943 set_instanceof_cache_answer(Smi::FromInt(0));
1873 1944
1874 CreateFixedStubs(); 1945 CreateFixedStubs();
1875 1946
1947 { TryAllocation t = StringDictionary::Allocate(Runtime::kNumFunctions);
1948 if (!t->ToObject(&obj)) return false;
1949 }
1876 // Allocate the dictionary of intrinsic function names. 1950 // Allocate the dictionary of intrinsic function names.
1877 obj = StringDictionary::Allocate(Runtime::kNumFunctions); 1951 { TryAllocation t = Runtime::InitializeIntrinsicFunctionNames(obj);
1878 if (obj->IsFailure()) return false; 1952 if (!t->ToObject(&obj)) return false;
1879 obj = Runtime::InitializeIntrinsicFunctionNames(obj); 1953 }
1880 if (obj->IsFailure()) return false;
1881 set_intrinsic_function_names(StringDictionary::cast(obj)); 1954 set_intrinsic_function_names(StringDictionary::cast(obj));
1882 1955
1883 if (InitializeNumberStringCache()->IsFailure()) return false; 1956 if (InitializeNumberStringCache()->IsFailure()) return false;
1884 1957
1958 { TryAllocation t =
1959 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
1960 if (!t->ToObject(&obj)) return false;
1961 }
1885 // Allocate cache for single character ASCII strings. 1962 // Allocate cache for single character ASCII strings.
1886 obj = AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
1887 if (obj->IsFailure()) return false;
1888 set_single_character_string_cache(FixedArray::cast(obj)); 1963 set_single_character_string_cache(FixedArray::cast(obj));
1889 1964
1965 { TryAllocation t = AllocateFixedArray(Natives::GetBuiltinsCount());
1966 if (!t->ToObject(&obj)) return false;
1967 }
1890 // Allocate cache for external strings pointing to native source code. 1968 // Allocate cache for external strings pointing to native source code.
1891 obj = AllocateFixedArray(Natives::GetBuiltinsCount());
1892 if (obj->IsFailure()) return false;
1893 set_natives_source_cache(FixedArray::cast(obj)); 1969 set_natives_source_cache(FixedArray::cast(obj));
1894 1970
1895 // Handling of script id generation is in Factory::NewScript. 1971 // Handling of script id generation is in Factory::NewScript.
1896 set_last_script_id(undefined_value()); 1972 set_last_script_id(undefined_value());
1897 1973
1898 // Initialize keyed lookup cache. 1974 // Initialize keyed lookup cache.
1899 KeyedLookupCache::Clear(); 1975 KeyedLookupCache::Clear();
1900 1976
1901 // Initialize context slot cache. 1977 // Initialize context slot cache.
1902 ContextSlotCache::Clear(); 1978 ContextSlotCache::Clear();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 } 2127 }
2052 2128
2053 // Materialize the value in the heap. 2129 // Materialize the value in the heap.
2054 return AllocateHeapNumber(value, pretenure); 2130 return AllocateHeapNumber(value, pretenure);
2055 } 2131 }
2056 2132
2057 2133
2058 Object* Heap::AllocateProxy(Address proxy, PretenureFlag pretenure) { 2134 Object* Heap::AllocateProxy(Address proxy, PretenureFlag pretenure) {
2059 // Statically ensure that it is safe to allocate proxies in paged spaces. 2135 // Statically ensure that it is safe to allocate proxies in paged spaces.
2060 STATIC_ASSERT(Proxy::kSize <= Page::kMaxHeapObjectSize); 2136 STATIC_ASSERT(Proxy::kSize <= Page::kMaxHeapObjectSize);
2137 Object* result;
2138 { TryAllocation t = Allocate(proxy_map(), space);
2139 if (!t->ToObject(&result)) return t;
2140 }
2061 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2141 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2062 Object* result = Allocate(proxy_map(), space);
2063 if (result->IsFailure()) return result;
2064 2142
2065 Proxy::cast(result)->set_proxy(proxy); 2143 Proxy::cast(result)->set_proxy(proxy);
2066 return result; 2144 return result;
2067 } 2145 }
2068 2146
2069 2147
2148 Object* result;
2149 { TryAllocation t = Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
2150 if (!t->ToObject(&result)) return t;
2151 }
2070 Object* Heap::AllocateSharedFunctionInfo(Object* name) { 2152 Object* Heap::AllocateSharedFunctionInfo(Object* name) {
2071 Object* result = Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
2072 if (result->IsFailure()) return result;
2073 2153
2074 SharedFunctionInfo* share = SharedFunctionInfo::cast(result); 2154 SharedFunctionInfo* share = SharedFunctionInfo::cast(result);
2075 share->set_name(name); 2155 share->set_name(name);
2076 Code* illegal = Builtins::builtin(Builtins::Illegal); 2156 Code* illegal = Builtins::builtin(Builtins::Illegal);
2077 share->set_code(illegal); 2157 share->set_code(illegal);
2078 share->set_scope_info(SerializedScopeInfo::Empty()); 2158 share->set_scope_info(SerializedScopeInfo::Empty());
2079 Code* construct_stub = Builtins::builtin(Builtins::JSConstructStubGeneric); 2159 Code* construct_stub = Builtins::builtin(Builtins::JSConstructStubGeneric);
2080 share->set_construct_stub(construct_stub); 2160 share->set_construct_stub(construct_stub);
2081 share->set_expected_nof_properties(0); 2161 share->set_expected_nof_properties(0);
2082 share->set_length(0); 2162 share->set_length(0);
(...skipping 25 matching lines...) Expand all
2108 static inline Object* MakeOrFindTwoCharacterString(uint32_t c1, uint32_t c2) { 2188 static inline Object* MakeOrFindTwoCharacterString(uint32_t c1, uint32_t c2) {
2109 String* symbol; 2189 String* symbol;
2110 // Numeric strings have a different hash algorithm not known by 2190 // Numeric strings have a different hash algorithm not known by
2111 // LookupTwoCharsSymbolIfExists, so we skip this step for such strings. 2191 // LookupTwoCharsSymbolIfExists, so we skip this step for such strings.
2112 if ((!Between(c1, '0', '9') || !Between(c2, '0', '9')) && 2192 if ((!Between(c1, '0', '9') || !Between(c2, '0', '9')) &&
2113 Heap::symbol_table()->LookupTwoCharsSymbolIfExists(c1, c2, &symbol)) { 2193 Heap::symbol_table()->LookupTwoCharsSymbolIfExists(c1, c2, &symbol)) {
2114 return symbol; 2194 return symbol;
2115 // Now we know the length is 2, we might as well make use of that fact 2195 // Now we know the length is 2, we might as well make use of that fact
2116 // when building the new string. 2196 // when building the new string.
2117 } else if ((c1 | c2) <= String::kMaxAsciiCharCodeU) { // We can do this 2197 } else if ((c1 | c2) <= String::kMaxAsciiCharCodeU) { // We can do this
2198 Object* result;
2199 { TryAllocation t = Heap::AllocateRawAsciiString(2);
2200 if (!t->ToObject(&result)) return t;
2201 }
2118 ASSERT(IsPowerOf2(String::kMaxAsciiCharCodeU + 1)); // because of this. 2202 ASSERT(IsPowerOf2(String::kMaxAsciiCharCodeU + 1)); // because of this.
2119 Object* result = Heap::AllocateRawAsciiString(2);
2120 if (result->IsFailure()) return result;
2121 char* dest = SeqAsciiString::cast(result)->GetChars(); 2203 char* dest = SeqAsciiString::cast(result)->GetChars();
2122 dest[0] = c1; 2204 dest[0] = c1;
2123 dest[1] = c2; 2205 dest[1] = c2;
2124 return result; 2206 return result;
2207 Object* result;
2208 { TryAllocation t = Heap::AllocateRawTwoByteString(2);
2209 if (!t->ToObject(&result)) return t;
2210 }
2125 } else { 2211 } else {
2126 Object* result = Heap::AllocateRawTwoByteString(2);
2127 if (result->IsFailure()) return result;
2128 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); 2212 uc16* dest = SeqTwoByteString::cast(result)->GetChars();
2129 dest[0] = c1; 2213 dest[0] = c1;
2130 dest[1] = c2; 2214 dest[1] = c2;
2131 return result; 2215 return result;
2132 } 2216 }
2133 } 2217 }
2134 2218
2135 2219
2136 Object* Heap::AllocateConsString(String* first, String* second) { 2220 Object* Heap::AllocateConsString(String* first, String* second) {
2137 int first_length = first->length(); 2221 int first_length = first->length();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars(); 2259 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars();
2176 if (is_ascii_data_in_two_byte_string) { 2260 if (is_ascii_data_in_two_byte_string) {
2177 Counters::string_add_runtime_ext_to_ascii.Increment(); 2261 Counters::string_add_runtime_ext_to_ascii.Increment();
2178 } 2262 }
2179 } 2263 }
2180 2264
2181 // If the resulting string is small make a flat string. 2265 // If the resulting string is small make a flat string.
2182 if (length < String::kMinNonFlatLength) { 2266 if (length < String::kMinNonFlatLength) {
2183 ASSERT(first->IsFlat()); 2267 ASSERT(first->IsFlat());
2184 ASSERT(second->IsFlat()); 2268 ASSERT(second->IsFlat());
2269 Object* result;
2270 { TryAllocation t = AllocateRawAsciiString(length);
2271 if (!t->ToObject(&result)) return t;
2272 }
2185 if (is_ascii) { 2273 if (is_ascii) {
2186 Object* result = AllocateRawAsciiString(length);
2187 if (result->IsFailure()) return result;
2188 // Copy the characters into the new object. 2274 // Copy the characters into the new object.
2189 char* dest = SeqAsciiString::cast(result)->GetChars(); 2275 char* dest = SeqAsciiString::cast(result)->GetChars();
2190 // Copy first part. 2276 // Copy first part.
2191 const char* src; 2277 const char* src;
2192 if (first->IsExternalString()) { 2278 if (first->IsExternalString()) {
2193 src = ExternalAsciiString::cast(first)->resource()->data(); 2279 src = ExternalAsciiString::cast(first)->resource()->data();
2194 } else { 2280 } else {
2195 src = SeqAsciiString::cast(first)->GetChars(); 2281 src = SeqAsciiString::cast(first)->GetChars();
2196 } 2282 }
2197 for (int i = 0; i < first_length; i++) *dest++ = src[i]; 2283 for (int i = 0; i < first_length; i++) *dest++ = src[i];
2198 // Copy second part. 2284 // Copy second part.
2199 if (second->IsExternalString()) { 2285 if (second->IsExternalString()) {
2200 src = ExternalAsciiString::cast(second)->resource()->data(); 2286 src = ExternalAsciiString::cast(second)->resource()->data();
2201 } else { 2287 } else {
2202 src = SeqAsciiString::cast(second)->GetChars(); 2288 src = SeqAsciiString::cast(second)->GetChars();
2203 } 2289 }
2204 for (int i = 0; i < second_length; i++) *dest++ = src[i]; 2290 for (int i = 0; i < second_length; i++) *dest++ = src[i];
2205 return result; 2291 return result;
2206 } else { 2292 } else {
2293 Object* result;
2294 { TryAllocation t = AllocateRawAsciiString(length);
2295 if (!t->ToObject(&result)) return t;
2296 }
2207 if (is_ascii_data_in_two_byte_string) { 2297 if (is_ascii_data_in_two_byte_string) {
2208 Object* result = AllocateRawAsciiString(length);
2209 if (result->IsFailure()) return result;
2210 // Copy the characters into the new object. 2298 // Copy the characters into the new object.
2211 char* dest = SeqAsciiString::cast(result)->GetChars(); 2299 char* dest = SeqAsciiString::cast(result)->GetChars();
2212 String::WriteToFlat(first, dest, 0, first_length); 2300 String::WriteToFlat(first, dest, 0, first_length);
2213 String::WriteToFlat(second, dest + first_length, 0, second_length); 2301 String::WriteToFlat(second, dest + first_length, 0, second_length);
2214 return result; 2302 return result;
2215 } 2303 }
2304 Object* result;
2305 { TryAllocation t = AllocateRawTwoByteString(length);
2306 if (!t->ToObject(&result)) return t;
2307 }
2216 2308
2217 Object* result = AllocateRawTwoByteString(length);
2218 if (result->IsFailure()) return result;
2219 // Copy the characters into the new object. 2309 // Copy the characters into the new object.
2220 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); 2310 uc16* dest = SeqTwoByteString::cast(result)->GetChars();
2221 String::WriteToFlat(first, dest, 0, first_length); 2311 String::WriteToFlat(first, dest, 0, first_length);
2222 String::WriteToFlat(second, dest + first_length, 0, second_length); 2312 String::WriteToFlat(second, dest + first_length, 0, second_length);
2223 return result; 2313 return result;
2224 } 2314 }
2225 } 2315 }
2226 2316
2227 Map* map = (is_ascii || is_ascii_data_in_two_byte_string) ? 2317 Map* map = (is_ascii || is_ascii_data_in_two_byte_string) ?
2228 cons_ascii_string_map() : cons_string_map(); 2318 cons_ascii_string_map() : cons_string_map();
2319 Object* result;
2320 { TryAllocation t = Allocate(map, NEW_SPACE);
2321 if (!t->ToObject(&result)) return t;
2322 }
2229 2323
2230 Object* result = Allocate(map, NEW_SPACE);
2231 if (result->IsFailure()) return result;
2232 2324
2233 AssertNoAllocation no_gc; 2325 AssertNoAllocation no_gc;
2234 ConsString* cons_string = ConsString::cast(result); 2326 ConsString* cons_string = ConsString::cast(result);
2235 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(no_gc); 2327 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(no_gc);
2236 cons_string->set_length(length); 2328 cons_string->set_length(length);
2237 cons_string->set_hash_field(String::kEmptyHashField); 2329 cons_string->set_hash_field(String::kEmptyHashField);
2238 cons_string->set_first(first, mode); 2330 cons_string->set_first(first, mode);
2239 cons_string->set_second(second, mode); 2331 cons_string->set_second(second, mode);
2240 return result; 2332 return result;
2241 } 2333 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 2375
2284 2376
2285 Object* Heap::AllocateExternalStringFromAscii( 2377 Object* Heap::AllocateExternalStringFromAscii(
2286 ExternalAsciiString::Resource* resource) { 2378 ExternalAsciiString::Resource* resource) {
2287 size_t length = resource->length(); 2379 size_t length = resource->length();
2288 if (length > static_cast<size_t>(String::kMaxLength)) { 2380 if (length > static_cast<size_t>(String::kMaxLength)) {
2289 Top::context()->mark_out_of_memory(); 2381 Top::context()->mark_out_of_memory();
2290 return Failure::OutOfMemoryException(); 2382 return Failure::OutOfMemoryException();
2291 } 2383 }
2292 2384
2385 Object* result;
2386 { TryAllocation t = Allocate(map, NEW_SPACE);
2387 if (!t->ToObject(&result)) return t;
2388 }
2293 Map* map = external_ascii_string_map(); 2389 Map* map = external_ascii_string_map();
2294 Object* result = Allocate(map, NEW_SPACE);
2295 if (result->IsFailure()) return result;
2296 2390
2297 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 2391 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
2298 external_string->set_length(static_cast<int>(length)); 2392 external_string->set_length(static_cast<int>(length));
2299 external_string->set_hash_field(String::kEmptyHashField); 2393 external_string->set_hash_field(String::kEmptyHashField);
2300 external_string->set_resource(resource); 2394 external_string->set_resource(resource);
2301 2395
2302 return result; 2396 return result;
2303 } 2397 }
2304 2398
2305 2399
(...skipping 14 matching lines...) Expand all
2320 const uc16* data = resource->data(); 2414 const uc16* data = resource->data();
2321 for (size_t i = 0; i < length; i++) { 2415 for (size_t i = 0; i < length; i++) {
2322 if (data[i] > String::kMaxAsciiCharCode) { 2416 if (data[i] > String::kMaxAsciiCharCode) {
2323 is_ascii = false; 2417 is_ascii = false;
2324 break; 2418 break;
2325 } 2419 }
2326 } 2420 }
2327 } 2421 }
2328 2422
2329 Map* map = is_ascii ? 2423 Map* map = is_ascii ?
2424 Object* result;
2425 { TryAllocation t = Allocate(map, NEW_SPACE);
2426 if (!t->ToObject(&result)) return t;
2427 }
2330 Heap::external_string_with_ascii_data_map() : Heap::external_string_map(); 2428 Heap::external_string_with_ascii_data_map() : Heap::external_string_map();
2331 Object* result = Allocate(map, NEW_SPACE);
2332 if (result->IsFailure()) return result;
2333 2429
2334 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); 2430 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result);
2335 external_string->set_length(static_cast<int>(length)); 2431 external_string->set_length(static_cast<int>(length));
2336 external_string->set_hash_field(String::kEmptyHashField); 2432 external_string->set_hash_field(String::kEmptyHashField);
2337 external_string->set_resource(resource); 2433 external_string->set_resource(resource);
2338 2434
2339 return result; 2435 return result;
2340 } 2436 }
2341 2437
2342 2438
2343 Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { 2439 Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) {
2344 if (code <= String::kMaxAsciiCharCode) { 2440 if (code <= String::kMaxAsciiCharCode) {
2345 Object* value = Heap::single_character_string_cache()->get(code); 2441 Object* value = Heap::single_character_string_cache()->get(code);
2346 if (value != Heap::undefined_value()) return value; 2442 if (value != Heap::undefined_value()) return value;
2347 2443
2348 char buffer[1]; 2444 char buffer[1];
2349 buffer[0] = static_cast<char>(code); 2445 buffer[0] = static_cast<char>(code);
2350 Object* result = LookupSymbol(Vector<const char>(buffer, 1)); 2446 Object* result = LookupSymbol(Vector<const char>(buffer, 1));
2351 2447
2352 if (result->IsFailure()) return result; 2448 if (result->IsFailure()) return result;
2353 Heap::single_character_string_cache()->set(code, result); 2449 Heap::single_character_string_cache()->set(code, result);
2354 return result; 2450 return result;
2355 } 2451 }
2452 Object* result;
2453 { TryAllocation t = Heap::AllocateRawTwoByteString(1);
2454 if (!t->ToObject(&result)) return t;
2455 }
2356 2456
2357 Object* result = Heap::AllocateRawTwoByteString(1);
2358 if (result->IsFailure()) return result;
2359 String* answer = String::cast(result); 2457 String* answer = String::cast(result);
2360 answer->Set(0, code); 2458 answer->Set(0, code);
2361 return answer; 2459 return answer;
2362 } 2460 }
2363 2461
2364 2462
2365 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 2463 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
2366 if (length < 0 || length > ByteArray::kMaxLength) { 2464 if (length < 0 || length > ByteArray::kMaxLength) {
2367 return Failure::OutOfMemoryException(); 2465 return Failure::OutOfMemoryException();
2368 } 2466 }
(...skipping 11 matching lines...) Expand all
2380 return result; 2478 return result;
2381 } 2479 }
2382 2480
2383 2481
2384 Object* Heap::AllocateByteArray(int length) { 2482 Object* Heap::AllocateByteArray(int length) {
2385 if (length < 0 || length > ByteArray::kMaxLength) { 2483 if (length < 0 || length > ByteArray::kMaxLength) {
2386 return Failure::OutOfMemoryException(); 2484 return Failure::OutOfMemoryException();
2387 } 2485 }
2388 int size = ByteArray::SizeFor(length); 2486 int size = ByteArray::SizeFor(length);
2389 AllocationSpace space = 2487 AllocationSpace space =
2488 Object* result;
2489 { TryAllocation t = AllocateRaw(size, space, OLD_DATA_SPACE);
2490 if (!t->ToObject(&result)) return t;
2491 }
2390 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE; 2492 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE;
2391 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE);
2392 if (result->IsFailure()) return result;
2393 2493
2394 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map()); 2494 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map());
2395 reinterpret_cast<ByteArray*>(result)->set_length(length); 2495 reinterpret_cast<ByteArray*>(result)->set_length(length);
2396 return result; 2496 return result;
2397 } 2497 }
2398 2498
2399 2499
2400 void Heap::CreateFillerObjectAt(Address addr, int size) { 2500 void Heap::CreateFillerObjectAt(Address addr, int size) {
2401 if (size == 0) return; 2501 if (size == 0) return;
2402 HeapObject* filler = HeapObject::FromAddress(addr); 2502 HeapObject* filler = HeapObject::FromAddress(addr);
2403 if (size == kPointerSize) { 2503 if (size == kPointerSize) {
2404 filler->set_map(one_pointer_filler_map()); 2504 filler->set_map(one_pointer_filler_map());
2405 } else if (size == 2 * kPointerSize) { 2505 } else if (size == 2 * kPointerSize) {
2406 filler->set_map(two_pointer_filler_map()); 2506 filler->set_map(two_pointer_filler_map());
2407 } else { 2507 } else {
2408 filler->set_map(byte_array_map()); 2508 filler->set_map(byte_array_map());
2409 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size)); 2509 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size));
2410 } 2510 }
2411 } 2511 }
2412 2512
2413 2513
2414 Object* Heap::AllocatePixelArray(int length, 2514 Object* Heap::AllocatePixelArray(int length,
2415 uint8_t* external_pointer, 2515 uint8_t* external_pointer,
2416 PretenureFlag pretenure) { 2516 PretenureFlag pretenure) {
2517 Object* result;
2518 { TryAllocation t =
2519 AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE);
2520 if (!t->ToObject(&result)) return t;
2521 }
2417 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2522 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2418 Object* result = AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE);
2419 if (result->IsFailure()) return result;
2420 2523
2421 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map()); 2524 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map());
2422 reinterpret_cast<PixelArray*>(result)->set_length(length); 2525 reinterpret_cast<PixelArray*>(result)->set_length(length);
2423 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer); 2526 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer);
2424 2527
2425 return result; 2528 return result;
2426 } 2529 }
2427 2530
2428 2531
2429 Object* Heap::AllocateExternalArray(int length, 2532 Object* Heap::AllocateExternalArray(int length,
(...skipping 13 matching lines...) Expand all
2443 external_pointer); 2546 external_pointer);
2444 2547
2445 return result; 2548 return result;
2446 } 2549 }
2447 2550
2448 2551
2449 Object* Heap::CreateCode(const CodeDesc& desc, 2552 Object* Heap::CreateCode(const CodeDesc& desc,
2450 Code::Flags flags, 2553 Code::Flags flags,
2451 Handle<Object> self_reference) { 2554 Handle<Object> self_reference) {
2452 // Allocate ByteArray before the Code object, so that we do not risk 2555 // Allocate ByteArray before the Code object, so that we do not risk
2556 Object* reloc_info;
2557 { TryAllocation t = AllocateByteArray(desc.reloc_size, TENURED);
2558 if (!t->ToObject(&reloc_info)) return t;
2559 }
2453 // leaving uninitialized Code object (and breaking the heap). 2560 // leaving uninitialized Code object (and breaking the heap).
2454 Object* reloc_info = AllocateByteArray(desc.reloc_size, TENURED);
2455 if (reloc_info->IsFailure()) return reloc_info;
2456 2561
2457 // Compute size 2562 // Compute size
2458 int body_size = RoundUp(desc.instr_size, kObjectAlignment); 2563 int body_size = RoundUp(desc.instr_size, kObjectAlignment);
2459 int obj_size = Code::SizeFor(body_size); 2564 int obj_size = Code::SizeFor(body_size);
2460 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); 2565 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment));
2461 Object* result; 2566 Object* result;
2462 if (obj_size > MaxObjectSizeInPagedSpace()) { 2567 if (obj_size > MaxObjectSizeInPagedSpace()) {
2463 result = lo_space_->AllocateRawCode(obj_size); 2568 result = lo_space_->AllocateRawCode(obj_size);
2464 } else { 2569 } else {
2465 result = code_space_->AllocateRaw(obj_size); 2570 result = code_space_->AllocateRaw(obj_size);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 // Relocate the copy. 2617 // Relocate the copy.
2513 Code* new_code = Code::cast(result); 2618 Code* new_code = Code::cast(result);
2514 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2619 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2515 new_code->Relocate(new_addr - old_addr); 2620 new_code->Relocate(new_addr - old_addr);
2516 return new_code; 2621 return new_code;
2517 } 2622 }
2518 2623
2519 2624
2520 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { 2625 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
2521 // Allocate ByteArray before the Code object, so that we do not risk 2626 // Allocate ByteArray before the Code object, so that we do not risk
2627 Object* reloc_info_array;
2628 { TryAllocation t = AllocateByteArray(reloc_info.length(), TENURED);
2629 if (!t->ToObject(&reloc_info_array)) return t;
2630 }
2522 // leaving uninitialized Code object (and breaking the heap). 2631 // leaving uninitialized Code object (and breaking the heap).
2523 Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED);
2524 if (reloc_info_array->IsFailure()) return reloc_info_array;
2525 2632
2526 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); 2633 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment);
2527 2634
2528 int new_obj_size = Code::SizeFor(new_body_size); 2635 int new_obj_size = Code::SizeFor(new_body_size);
2529 2636
2530 Address old_addr = code->address(); 2637 Address old_addr = code->address();
2531 2638
2532 size_t relocation_offset = 2639 size_t relocation_offset =
2533 static_cast<size_t>(code->instruction_end() - old_addr); 2640 static_cast<size_t>(code->instruction_end() - old_addr);
2534 2641
(...skipping 29 matching lines...) Expand all
2564 } 2671 }
2565 2672
2566 2673
2567 Object* Heap::Allocate(Map* map, AllocationSpace space) { 2674 Object* Heap::Allocate(Map* map, AllocationSpace space) {
2568 ASSERT(gc_state_ == NOT_IN_GC); 2675 ASSERT(gc_state_ == NOT_IN_GC);
2569 ASSERT(map->instance_type() != MAP_TYPE); 2676 ASSERT(map->instance_type() != MAP_TYPE);
2570 // If allocation failures are disallowed, we may allocate in a different 2677 // If allocation failures are disallowed, we may allocate in a different
2571 // space when new space is full and the object is not a large object. 2678 // space when new space is full and the object is not a large object.
2572 AllocationSpace retry_space = 2679 AllocationSpace retry_space =
2573 (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type()); 2680 (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type());
2574 Object* result = 2681 Object* result;
2575 AllocateRaw(map->instance_size(), space, retry_space); 2682 { TryAllocation t =
2576 if (result->IsFailure()) return result; 2683 AllocateRaw(map->instance_size(), space, retry_space);
2684 if (!t->ToObject(&result)) return t;
2685 }
2577 HeapObject::cast(result)->set_map(map); 2686 HeapObject::cast(result)->set_map(map);
2578 #ifdef ENABLE_LOGGING_AND_PROFILING 2687 #ifdef ENABLE_LOGGING_AND_PROFILING
2579 ProducerHeapProfile::RecordJSObjectAllocation(result); 2688 ProducerHeapProfile::RecordJSObjectAllocation(result);
2580 #endif 2689 #endif
2581 return result; 2690 return result;
2582 } 2691 }
2583 2692
2584 2693
2585 Object* Heap::InitializeFunction(JSFunction* function, 2694 Object* Heap::InitializeFunction(JSFunction* function,
2586 SharedFunctionInfo* shared, 2695 SharedFunctionInfo* shared,
2587 Object* prototype) { 2696 Object* prototype) {
2588 ASSERT(!prototype->IsMap()); 2697 ASSERT(!prototype->IsMap());
2589 function->initialize_properties(); 2698 function->initialize_properties();
2590 function->initialize_elements(); 2699 function->initialize_elements();
2591 function->set_shared(shared); 2700 function->set_shared(shared);
2592 function->set_code(shared->code()); 2701 function->set_code(shared->code());
2593 function->set_prototype_or_initial_map(prototype); 2702 function->set_prototype_or_initial_map(prototype);
2594 function->set_context(undefined_value()); 2703 function->set_context(undefined_value());
2595 function->set_literals(empty_fixed_array()); 2704 function->set_literals(empty_fixed_array());
2596 return function; 2705 return function;
2597 } 2706 }
2598 2707
2599 2708
2600 Object* Heap::AllocateFunctionPrototype(JSFunction* function) { 2709 Object* Heap::AllocateFunctionPrototype(JSFunction* function) {
2601 // Allocate the prototype. Make sure to use the object function 2710 // Allocate the prototype. Make sure to use the object function
2602 // from the function's context, since the function can be from a 2711 // from the function's context, since the function can be from a
2603 // different context. 2712 // different context.
2604 JSFunction* object_function = 2713 JSFunction* object_function =
2714 Object* prototype;
2715 { TryAllocation t = AllocateJSObject(object_function);
2716 if (!t->ToObject(&prototype)) return t;
2717 }
2605 function->context()->global_context()->object_function(); 2718 function->context()->global_context()->object_function();
2606 Object* prototype = AllocateJSObject(object_function);
2607 if (prototype->IsFailure()) return prototype;
2608 // When creating the prototype for the function we must set its 2719 // When creating the prototype for the function we must set its
2609 // constructor to the function. 2720 // constructor to the function.
2610 Object* result = 2721 Object* result =
2611 JSObject::cast(prototype)->SetProperty(constructor_symbol(), 2722 JSObject::cast(prototype)->SetProperty(constructor_symbol(),
2612 function, 2723 function,
2613 DONT_ENUM); 2724 DONT_ENUM);
2614 if (result->IsFailure()) return result; 2725 if (result->IsFailure()) return result;
2615 return prototype; 2726 return prototype;
2616 } 2727 }
2617 2728
2618 2729
2619 Object* Heap::AllocateFunction(Map* function_map, 2730 Object* Heap::AllocateFunction(Map* function_map,
2620 SharedFunctionInfo* shared, 2731 SharedFunctionInfo* shared,
2621 Object* prototype, 2732 Object* prototype,
2622 PretenureFlag pretenure) { 2733 PretenureFlag pretenure) {
2623 AllocationSpace space = 2734 AllocationSpace space =
2735 Object* result;
2736 { TryAllocation t = Allocate(function_map, space);
2737 if (!t->ToObject(&result)) return t;
2738 }
2624 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2739 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2625 Object* result = Allocate(function_map, space);
2626 if (result->IsFailure()) return result;
2627 return InitializeFunction(JSFunction::cast(result), shared, prototype); 2740 return InitializeFunction(JSFunction::cast(result), shared, prototype);
2628 } 2741 }
2629 2742
2630 2743
2631 Object* Heap::AllocateArgumentsObject(Object* callee, int length) { 2744 Object* Heap::AllocateArgumentsObject(Object* callee, int length) {
2632 // To get fast allocation and map sharing for arguments objects we 2745 // To get fast allocation and map sharing for arguments objects we
2633 // allocate them based on an arguments boilerplate. 2746 // allocate them based on an arguments boilerplate.
2634 2747
2635 // This calls Copy directly rather than using Heap::AllocateRaw so we 2748 // This calls Copy directly rather than using Heap::AllocateRaw so we
2636 // duplicate the check here. 2749 // duplicate the check here.
2637 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 2750 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
2638 2751
2639 JSObject* boilerplate = 2752 JSObject* boilerplate =
2640 Top::context()->global_context()->arguments_boilerplate(); 2753 Top::context()->global_context()->arguments_boilerplate();
2641 2754
2642 // Check that the size of the boilerplate matches our 2755 // Check that the size of the boilerplate matches our
2643 // expectations. The ArgumentsAccessStub::GenerateNewObject relies 2756 // expectations. The ArgumentsAccessStub::GenerateNewObject relies
2644 // on the size being a known constant. 2757 // on the size being a known constant.
2645 ASSERT(kArgumentsObjectSize == boilerplate->map()->instance_size()); 2758 ASSERT(kArgumentsObjectSize == boilerplate->map()->instance_size());
2646 2759
2647 // Do the allocation. 2760 // Do the allocation.
2648 Object* result = 2761 Object* result;
2649 AllocateRaw(kArgumentsObjectSize, NEW_SPACE, OLD_POINTER_SPACE); 2762 { TryAllocation t =
2650 if (result->IsFailure()) return result; 2763 AllocateRaw(kArgumentsObjectSize, NEW_SPACE, OLD_POINTER_SPACE);
2764 if (!t->ToObject(&result)) return t;
2765 }
2651 2766
2652 // Copy the content. The arguments boilerplate doesn't have any 2767 // Copy the content. The arguments boilerplate doesn't have any
2653 // fields that point to new space so it's safe to skip the write 2768 // fields that point to new space so it's safe to skip the write
2654 // barrier here. 2769 // barrier here.
2655 CopyBlock(HeapObject::cast(result)->address(), 2770 CopyBlock(HeapObject::cast(result)->address(),
2656 boilerplate->address(), 2771 boilerplate->address(),
2657 kArgumentsObjectSize); 2772 kArgumentsObjectSize);
2658 2773
2659 // Set the two properties. 2774 // Set the two properties.
2660 JSObject::cast(result)->InObjectPropertyAtPut(arguments_callee_index, 2775 JSObject::cast(result)->InObjectPropertyAtPut(arguments_callee_index,
(...skipping 23 matching lines...) Expand all
2684 return false; 2799 return false;
2685 } 2800 }
2686 2801
2687 2802
2688 Object* Heap::AllocateInitialMap(JSFunction* fun) { 2803 Object* Heap::AllocateInitialMap(JSFunction* fun) {
2689 ASSERT(!fun->has_initial_map()); 2804 ASSERT(!fun->has_initial_map());
2690 2805
2691 // First create a new map with the size and number of in-object properties 2806 // First create a new map with the size and number of in-object properties
2692 // suggested by the function. 2807 // suggested by the function.
2693 int instance_size = fun->shared()->CalculateInstanceSize(); 2808 int instance_size = fun->shared()->CalculateInstanceSize();
2809 Object* map_obj;
2810 { TryAllocation t = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size);
2811 if (!t->ToObject(&map_obj)) return t;
2812 }
2694 int in_object_properties = fun->shared()->CalculateInObjectProperties(); 2813 int in_object_properties = fun->shared()->CalculateInObjectProperties();
2695 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size);
2696 if (map_obj->IsFailure()) return map_obj;
2697 2814
2698 // Fetch or allocate prototype. 2815 // Fetch or allocate prototype.
2699 Object* prototype; 2816 Object* prototype;
2700 if (fun->has_instance_prototype()) { 2817 if (fun->has_instance_prototype()) {
2701 prototype = fun->instance_prototype(); 2818 prototype = fun->instance_prototype();
2819 { TryAllocation t = AllocateFunctionPrototype(fun);
2820 if (!t->ToObject(&prototype)) return t;
2821 }
2702 } else { 2822 } else {
2703 prototype = AllocateFunctionPrototype(fun);
2704 if (prototype->IsFailure()) return prototype;
2705 } 2823 }
2706 Map* map = Map::cast(map_obj); 2824 Map* map = Map::cast(map_obj);
2707 map->set_inobject_properties(in_object_properties); 2825 map->set_inobject_properties(in_object_properties);
2708 map->set_unused_property_fields(in_object_properties); 2826 map->set_unused_property_fields(in_object_properties);
2709 map->set_prototype(prototype); 2827 map->set_prototype(prototype);
2710 ASSERT(map->has_fast_elements()); 2828 ASSERT(map->has_fast_elements());
2711 2829
2712 // If the function has only simple this property assignments add 2830 // If the function has only simple this property assignments add
2713 // field descriptors for these to the initial map as the object 2831 // field descriptors for these to the initial map as the object
2714 // cannot be constructed without having these properties. Guard by 2832 // cannot be constructed without having these properties. Guard by
2715 // the inline_new flag so we only change the map if we generate a 2833 // the inline_new flag so we only change the map if we generate a
2716 // specialized construct stub. 2834 // specialized construct stub.
2717 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); 2835 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields);
2718 if (fun->shared()->CanGenerateInlineConstructor(prototype)) { 2836 if (fun->shared()->CanGenerateInlineConstructor(prototype)) {
2719 int count = fun->shared()->this_property_assignments_count(); 2837 int count = fun->shared()->this_property_assignments_count();
2720 if (count > in_object_properties) { 2838 if (count > in_object_properties) {
2721 // Inline constructor can only handle inobject properties. 2839 // Inline constructor can only handle inobject properties.
2722 fun->shared()->ForbidInlineConstructor(); 2840 fun->shared()->ForbidInlineConstructor();
2841 Object* descriptors_obj;
2842 { TryAllocation t = DescriptorArray::Allocate(count);
2843 if (!t->ToObject(&descriptors_obj)) return t;
2844 }
2723 } else { 2845 } else {
2724 Object* descriptors_obj = DescriptorArray::Allocate(count);
2725 if (descriptors_obj->IsFailure()) return descriptors_obj;
2726 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj); 2846 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj);
2727 for (int i = 0; i < count; i++) { 2847 for (int i = 0; i < count; i++) {
2728 String* name = fun->shared()->GetThisPropertyAssignmentName(i); 2848 String* name = fun->shared()->GetThisPropertyAssignmentName(i);
2729 ASSERT(name->IsSymbol()); 2849 ASSERT(name->IsSymbol());
2730 FieldDescriptor field(name, i, NONE); 2850 FieldDescriptor field(name, i, NONE);
2731 field.SetEnumerationIndex(i); 2851 field.SetEnumerationIndex(i);
2732 descriptors->Set(i, &field); 2852 descriptors->Set(i, &field);
2733 } 2853 }
2734 descriptors->SetNextEnumerationIndex(count); 2854 descriptors->SetNextEnumerationIndex(count);
2735 descriptors->SortUnchecked(); 2855 descriptors->SortUnchecked();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2791 // Both types of global objects should be allocated using 2911 // Both types of global objects should be allocated using
2792 // AllocateGlobalObject to be properly initialized. 2912 // AllocateGlobalObject to be properly initialized.
2793 ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); 2913 ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE);
2794 ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); 2914 ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE);
2795 2915
2796 // Allocate the backing storage for the properties. 2916 // Allocate the backing storage for the properties.
2797 int prop_size = 2917 int prop_size =
2798 map->pre_allocated_property_fields() + 2918 map->pre_allocated_property_fields() +
2799 map->unused_property_fields() - 2919 map->unused_property_fields() -
2800 map->inobject_properties(); 2920 map->inobject_properties();
2921 Object* properties;
2922 { TryAllocation t = AllocateFixedArray(prop_size, pretenure);
2923 if (!t->ToObject(&properties)) return t;
2924 }
2801 ASSERT(prop_size >= 0); 2925 ASSERT(prop_size >= 0);
2802 Object* properties = AllocateFixedArray(prop_size, pretenure);
2803 if (properties->IsFailure()) return properties;
2804 2926
2805 // Allocate the JSObject. 2927 // Allocate the JSObject.
2806 AllocationSpace space = 2928 AllocationSpace space =
2807 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2929 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2930 Object* obj;
2931 { TryAllocation t = Allocate(map, space);
2932 if (!t->ToObject(&obj)) return t;
2933 }
2808 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2934 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
2809 Object* obj = Allocate(map, space);
2810 if (obj->IsFailure()) return obj;
2811 2935
2812 // Initialize the JSObject. 2936 // Initialize the JSObject.
2813 InitializeJSObjectFromMap(JSObject::cast(obj), 2937 InitializeJSObjectFromMap(JSObject::cast(obj),
2814 FixedArray::cast(properties), 2938 FixedArray::cast(properties),
2815 map); 2939 map);
2816 ASSERT(JSObject::cast(obj)->HasFastElements()); 2940 ASSERT(JSObject::cast(obj)->HasFastElements());
2817 return obj; 2941 return obj;
2818 } 2942 }
2819 2943
2820 2944
2821 Object* Heap::AllocateJSObject(JSFunction* constructor, 2945 Object* Heap::AllocateJSObject(JSFunction* constructor,
2822 PretenureFlag pretenure) { 2946 PretenureFlag pretenure) {
2823 // Allocate the initial map if absent. 2947 // Allocate the initial map if absent.
2948 Object* initial_map;
2949 { TryAllocation t = AllocateInitialMap(constructor);
2950 if (!t->ToObject(&initial_map)) return t;
2951 }
2824 if (!constructor->has_initial_map()) { 2952 if (!constructor->has_initial_map()) {
2825 Object* initial_map = AllocateInitialMap(constructor);
2826 if (initial_map->IsFailure()) return initial_map;
2827 constructor->set_initial_map(Map::cast(initial_map)); 2953 constructor->set_initial_map(Map::cast(initial_map));
2828 Map::cast(initial_map)->set_constructor(constructor); 2954 Map::cast(initial_map)->set_constructor(constructor);
2829 } 2955 }
2830 // Allocate the object based on the constructors initial map. 2956 // Allocate the object based on the constructors initial map.
2831 Object* result = 2957 Object* result =
2832 AllocateJSObjectFromMap(constructor->initial_map(), pretenure); 2958 AllocateJSObjectFromMap(constructor->initial_map(), pretenure);
2833 // Make sure result is NOT a global object if valid. 2959 // Make sure result is NOT a global object if valid.
2834 ASSERT(result->IsFailure() || !result->IsGlobalObject()); 2960 ASSERT(result->IsFailure() || !result->IsGlobalObject());
2835 return result; 2961 return result;
2836 } 2962 }
(...skipping 26 matching lines...) Expand all
2863 StringDictionary* dictionary = StringDictionary::cast(obj); 2989 StringDictionary* dictionary = StringDictionary::cast(obj);
2864 2990
2865 // The global object might be created from an object template with accessors. 2991 // The global object might be created from an object template with accessors.
2866 // Fill these accessors into the dictionary. 2992 // Fill these accessors into the dictionary.
2867 DescriptorArray* descs = map->instance_descriptors(); 2993 DescriptorArray* descs = map->instance_descriptors();
2868 for (int i = 0; i < descs->number_of_descriptors(); i++) { 2994 for (int i = 0; i < descs->number_of_descriptors(); i++) {
2869 PropertyDetails details = descs->GetDetails(i); 2995 PropertyDetails details = descs->GetDetails(i);
2870 ASSERT(details.type() == CALLBACKS); // Only accessors are expected. 2996 ASSERT(details.type() == CALLBACKS); // Only accessors are expected.
2871 PropertyDetails d = 2997 PropertyDetails d =
2872 PropertyDetails(details.attributes(), CALLBACKS, details.index()); 2998 PropertyDetails(details.attributes(), CALLBACKS, details.index());
2999 { TryAllocation t = Heap::AllocateJSGlobalPropertyCell(value);
3000 if (!t->ToObject(&value)) return t;
3001 }
2873 Object* value = descs->GetCallbacksObject(i); 3002 Object* value = descs->GetCallbacksObject(i);
2874 value = Heap::AllocateJSGlobalPropertyCell(value); 3003 Object* result;
2875 if (value->IsFailure()) return value; 3004 { TryAllocation t = dictionary->Add(descs->GetKey(i), value, d);
3005 if (!t->ToObject(&result)) return t;
3006 }
2876 3007
2877 Object* result = dictionary->Add(descs->GetKey(i), value, d);
2878 if (result->IsFailure()) return result;
2879 dictionary = StringDictionary::cast(result); 3008 dictionary = StringDictionary::cast(result);
2880 } 3009 }
2881 3010
3011 { TryAllocation t = Allocate(map, OLD_POINTER_SPACE);
3012 if (!t->ToObject(&obj)) return t;
3013 }
2882 // Allocate the global object and initialize it with the backing store. 3014 // Allocate the global object and initialize it with the backing store.
2883 obj = Allocate(map, OLD_POINTER_SPACE);
2884 if (obj->IsFailure()) return obj;
2885 JSObject* global = JSObject::cast(obj); 3015 JSObject* global = JSObject::cast(obj);
2886 InitializeJSObjectFromMap(global, dictionary, map); 3016 InitializeJSObjectFromMap(global, dictionary, map);
2887 3017
3018 { TryAllocation t = map->CopyDropDescriptors();
3019 if (!t->ToObject(&obj)) return t;
3020 }
2888 // Create a new map for the global object. 3021 // Create a new map for the global object.
2889 obj = map->CopyDropDescriptors();
2890 if (obj->IsFailure()) return obj;
2891 Map* new_map = Map::cast(obj); 3022 Map* new_map = Map::cast(obj);
2892 3023
2893 // Setup the global object as a normalized object. 3024 // Setup the global object as a normalized object.
2894 global->set_map(new_map); 3025 global->set_map(new_map);
2895 global->map()->set_instance_descriptors(Heap::empty_descriptor_array()); 3026 global->map()->set_instance_descriptors(Heap::empty_descriptor_array());
2896 global->set_properties(dictionary); 3027 global->set_properties(dictionary);
2897 3028
2898 // Make sure result is a global object with properties in dictionary. 3029 // Make sure result is a global object with properties in dictionary.
2899 ASSERT(global->IsGlobalObject()); 3030 ASSERT(global->IsGlobalObject());
2900 ASSERT(!global->HasFastProperties()); 3031 ASSERT(!global->HasFastProperties());
2901 return global; 3032 return global;
2902 } 3033 }
2903 3034
2904 3035
2905 Object* Heap::CopyJSObject(JSObject* source) { 3036 Object* Heap::CopyJSObject(JSObject* source) {
2906 // Never used to copy functions. If functions need to be copied we 3037 // Never used to copy functions. If functions need to be copied we
2907 // have to be careful to clear the literals array. 3038 // have to be careful to clear the literals array.
2908 ASSERT(!source->IsJSFunction()); 3039 ASSERT(!source->IsJSFunction());
2909 3040
2910 // Make the clone. 3041 // Make the clone.
2911 Map* map = source->map(); 3042 Map* map = source->map();
2912 int object_size = map->instance_size(); 3043 int object_size = map->instance_size();
2913 Object* clone; 3044 Object* clone;
2914 3045
2915 // If we're forced to always allocate, we use the general allocation 3046 // If we're forced to always allocate, we use the general allocation
2916 // functions which may leave us with an object in old space. 3047 // functions which may leave us with an object in old space.
3048 { TryAllocation t = AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE);
3049 if (!t->ToObject(&clone)) return t;
3050 }
2917 if (always_allocate()) { 3051 if (always_allocate()) {
2918 clone = AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE);
2919 if (clone->IsFailure()) return clone;
2920 Address clone_address = HeapObject::cast(clone)->address(); 3052 Address clone_address = HeapObject::cast(clone)->address();
2921 CopyBlock(clone_address, 3053 CopyBlock(clone_address,
2922 source->address(), 3054 source->address(),
2923 object_size); 3055 object_size);
2924 // Update write barrier for all fields that lie beyond the header. 3056 // Update write barrier for all fields that lie beyond the header.
2925 RecordWrites(clone_address, 3057 RecordWrites(clone_address,
2926 JSObject::kHeaderSize, 3058 JSObject::kHeaderSize,
2927 (object_size - JSObject::kHeaderSize) / kPointerSize); 3059 (object_size - JSObject::kHeaderSize) / kPointerSize);
3060 { TryAllocation t = new_space_.AllocateRaw(object_size);
3061 if (!t->ToObject(&clone)) return t;
3062 }
2928 } else { 3063 } else {
2929 clone = new_space_.AllocateRaw(object_size);
2930 if (clone->IsFailure()) return clone;
2931 ASSERT(Heap::InNewSpace(clone)); 3064 ASSERT(Heap::InNewSpace(clone));
2932 // Since we know the clone is allocated in new space, we can copy 3065 // Since we know the clone is allocated in new space, we can copy
2933 // the contents without worrying about updating the write barrier. 3066 // the contents without worrying about updating the write barrier.
2934 CopyBlock(HeapObject::cast(clone)->address(), 3067 CopyBlock(HeapObject::cast(clone)->address(),
2935 source->address(), 3068 source->address(),
2936 object_size); 3069 object_size);
2937 } 3070 }
2938 3071
2939 FixedArray* elements = FixedArray::cast(source->elements()); 3072 FixedArray* elements = FixedArray::cast(source->elements());
2940 FixedArray* properties = FixedArray::cast(source->properties()); 3073 FixedArray* properties = FixedArray::cast(source->properties());
2941 // Update elements if necessary. 3074 // Update elements if necessary.
2942 if (elements->length() > 0) { 3075 if (elements->length() > 0) {
2943 Object* elem = 3076 Object* elem =
2944 (elements->map() == fixed_cow_array_map()) ? 3077 (elements->map() == fixed_cow_array_map()) ?
2945 elements : CopyFixedArray(elements); 3078 elements : CopyFixedArray(elements);
2946 if (elem->IsFailure()) return elem; 3079 if (elem->IsFailure()) return elem;
2947 JSObject::cast(clone)->set_elements(FixedArray::cast(elem)); 3080 JSObject::cast(clone)->set_elements(FixedArray::cast(elem));
2948 } 3081 }
2949 // Update properties if necessary. 3082 // Update properties if necessary.
3083 Object* prop;
3084 { TryAllocation t = CopyFixedArray(properties);
3085 if (!t->ToObject(&prop)) return t;
3086 }
2950 if (properties->length() > 0) { 3087 if (properties->length() > 0) {
2951 Object* prop = CopyFixedArray(properties);
2952 if (prop->IsFailure()) return prop;
2953 JSObject::cast(clone)->set_properties(FixedArray::cast(prop)); 3088 JSObject::cast(clone)->set_properties(FixedArray::cast(prop));
2954 } 3089 }
2955 // Return the new clone. 3090 // Return the new clone.
2956 #ifdef ENABLE_LOGGING_AND_PROFILING 3091 #ifdef ENABLE_LOGGING_AND_PROFILING
2957 ProducerHeapProfile::RecordJSObjectAllocation(clone); 3092 ProducerHeapProfile::RecordJSObjectAllocation(clone);
2958 #endif 3093 #endif
2959 return clone; 3094 return clone;
2960 } 3095 }
2961 3096
2962 3097
2963 Object* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, 3098 Object* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor,
2964 JSGlobalProxy* object) { 3099 JSGlobalProxy* object) {
2965 ASSERT(constructor->has_initial_map()); 3100 ASSERT(constructor->has_initial_map());
2966 Map* map = constructor->initial_map(); 3101 Map* map = constructor->initial_map();
2967 3102
2968 // Check that the already allocated object has the same size and type as 3103 // Check that the already allocated object has the same size and type as
2969 // objects allocated using the constructor. 3104 // objects allocated using the constructor.
2970 ASSERT(map->instance_size() == object->map()->instance_size()); 3105 ASSERT(map->instance_size() == object->map()->instance_size());
2971 ASSERT(map->instance_type() == object->map()->instance_type()); 3106 ASSERT(map->instance_type() == object->map()->instance_type());
2972 3107
2973 // Allocate the backing storage for the properties. 3108 // Allocate the backing storage for the properties.
3109 Object* properties;
3110 { TryAllocation t = AllocateFixedArray(prop_size, TENURED);
3111 if (!t->ToObject(&properties)) return t;
3112 }
2974 int prop_size = map->unused_property_fields() - map->inobject_properties(); 3113 int prop_size = map->unused_property_fields() - map->inobject_properties();
2975 Object* properties = AllocateFixedArray(prop_size, TENURED);
2976 if (properties->IsFailure()) return properties;
2977 3114
2978 // Reset the map for the object. 3115 // Reset the map for the object.
2979 object->set_map(constructor->initial_map()); 3116 object->set_map(constructor->initial_map());
2980 3117
2981 // Reinitialize the object from the constructor map. 3118 // Reinitialize the object from the constructor map.
2982 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); 3119 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map);
2983 return object; 3120 return object;
2984 } 3121 }
2985 3122
2986 3123
2987 Object* Heap::AllocateStringFromAscii(Vector<const char> string, 3124 Object* Heap::AllocateStringFromAscii(Vector<const char> string,
3125 Object* result;
3126 { TryAllocation t = AllocateRawAsciiString(string.length(), pretenure);
3127 if (!t->ToObject(&result)) return t;
3128 }
2988 PretenureFlag pretenure) { 3129 PretenureFlag pretenure) {
2989 Object* result = AllocateRawAsciiString(string.length(), pretenure);
2990 if (result->IsFailure()) return result;
2991 3130
2992 // Copy the characters into the new object. 3131 // Copy the characters into the new object.
2993 SeqAsciiString* string_result = SeqAsciiString::cast(result); 3132 SeqAsciiString* string_result = SeqAsciiString::cast(result);
2994 for (int i = 0; i < string.length(); i++) { 3133 for (int i = 0; i < string.length(); i++) {
2995 string_result->SeqAsciiStringSet(i, string[i]); 3134 string_result->SeqAsciiStringSet(i, string[i]);
2996 } 3135 }
2997 return result; 3136 return result;
2998 } 3137 }
2999 3138
3000 3139
3001 Object* Heap::AllocateStringFromUtf8(Vector<const char> string, 3140 Object* Heap::AllocateStringFromUtf8(Vector<const char> string,
3002 PretenureFlag pretenure) { 3141 PretenureFlag pretenure) {
3003 // V8 only supports characters in the Basic Multilingual Plane. 3142 // V8 only supports characters in the Basic Multilingual Plane.
3004 const uc32 kMaxSupportedChar = 0xFFFF; 3143 const uc32 kMaxSupportedChar = 0xFFFF;
3005 // Count the number of characters in the UTF-8 string and check if 3144 // Count the number of characters in the UTF-8 string and check if
3006 // it is an ASCII string. 3145 // it is an ASCII string.
3007 Access<Scanner::Utf8Decoder> decoder(Scanner::utf8_decoder()); 3146 Access<Scanner::Utf8Decoder> decoder(Scanner::utf8_decoder());
3008 decoder->Reset(string.start(), string.length()); 3147 decoder->Reset(string.start(), string.length());
3009 int chars = 0; 3148 int chars = 0;
3010 bool is_ascii = true; 3149 bool is_ascii = true;
3011 while (decoder->has_more()) { 3150 while (decoder->has_more()) {
3012 uc32 r = decoder->GetNext(); 3151 uc32 r = decoder->GetNext();
3013 if (r > String::kMaxAsciiCharCode) is_ascii = false; 3152 if (r > String::kMaxAsciiCharCode) is_ascii = false;
3014 chars++; 3153 chars++;
3015 } 3154 }
3016 3155
3017 // If the string is ascii, we do not need to convert the characters 3156 // If the string is ascii, we do not need to convert the characters
3018 // since UTF8 is backwards compatible with ascii. 3157 // since UTF8 is backwards compatible with ascii.
3019 if (is_ascii) return AllocateStringFromAscii(string, pretenure); 3158 if (is_ascii) return AllocateStringFromAscii(string, pretenure);
3159 Object* result;
3160 { TryAllocation t = AllocateRawTwoByteString(chars, pretenure);
3161 if (!t->ToObject(&result)) return t;
3162 }
3020 3163
3021 Object* result = AllocateRawTwoByteString(chars, pretenure);
3022 if (result->IsFailure()) return result;
3023 3164
3024 // Convert and copy the characters into the new object. 3165 // Convert and copy the characters into the new object.
3025 String* string_result = String::cast(result); 3166 String* string_result = String::cast(result);
3026 decoder->Reset(string.start(), string.length()); 3167 decoder->Reset(string.start(), string.length());
3027 for (int i = 0; i < chars; i++) { 3168 for (int i = 0; i < chars; i++) {
3028 uc32 r = decoder->GetNext(); 3169 uc32 r = decoder->GetNext();
3029 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; } 3170 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; }
3030 string_result->Set(i, r); 3171 string_result->Set(i, r);
3031 } 3172 }
3032 return result; 3173 return result;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
3148 if (space == NEW_SPACE) { 3289 if (space == NEW_SPACE) {
3149 if (size > kMaxObjectSizeInNewSpace) { 3290 if (size > kMaxObjectSizeInNewSpace) {
3150 // Allocate in large object space, retry space will be ignored. 3291 // Allocate in large object space, retry space will be ignored.
3151 space = LO_SPACE; 3292 space = LO_SPACE;
3152 } else if (size > MaxObjectSizeInPagedSpace()) { 3293 } else if (size > MaxObjectSizeInPagedSpace()) {
3153 // Allocate in new space, retry in large object space. 3294 // Allocate in new space, retry in large object space.
3154 retry_space = LO_SPACE; 3295 retry_space = LO_SPACE;
3155 } 3296 }
3156 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { 3297 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
3157 space = LO_SPACE; 3298 space = LO_SPACE;
3299 Object* result;
3300 { TryAllocation t = AllocateRaw(size, space, retry_space);
3301 if (!t->ToObject(&result)) return t;
3158 } 3302 }
3159 Object* result = AllocateRaw(size, space, retry_space); 3303 }
3160 if (result->IsFailure()) return result;
3161 3304
3162 // Partially initialize the object. 3305 // Partially initialize the object.
3163 HeapObject::cast(result)->set_map(ascii_string_map()); 3306 HeapObject::cast(result)->set_map(ascii_string_map());
3164 String::cast(result)->set_length(length); 3307 String::cast(result)->set_length(length);
3165 String::cast(result)->set_hash_field(String::kEmptyHashField); 3308 String::cast(result)->set_hash_field(String::kEmptyHashField);
3166 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 3309 ASSERT_EQ(size, HeapObject::cast(result)->Size());
3167 return result; 3310 return result;
3168 } 3311 }
3169 3312
3170 3313
3171 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { 3314 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) {
3172 if (length < 0 || length > SeqTwoByteString::kMaxLength) { 3315 if (length < 0 || length > SeqTwoByteString::kMaxLength) {
3173 return Failure::OutOfMemoryException(); 3316 return Failure::OutOfMemoryException();
3174 } 3317 }
3175 int size = SeqTwoByteString::SizeFor(length); 3318 int size = SeqTwoByteString::SizeFor(length);
3176 ASSERT(size <= SeqTwoByteString::kMaxSize); 3319 ASSERT(size <= SeqTwoByteString::kMaxSize);
3177 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 3320 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
3178 AllocationSpace retry_space = OLD_DATA_SPACE; 3321 AllocationSpace retry_space = OLD_DATA_SPACE;
3179 3322
3180 if (space == NEW_SPACE) { 3323 if (space == NEW_SPACE) {
3181 if (size > kMaxObjectSizeInNewSpace) { 3324 if (size > kMaxObjectSizeInNewSpace) {
3182 // Allocate in large object space, retry space will be ignored. 3325 // Allocate in large object space, retry space will be ignored.
3183 space = LO_SPACE; 3326 space = LO_SPACE;
3184 } else if (size > MaxObjectSizeInPagedSpace()) { 3327 } else if (size > MaxObjectSizeInPagedSpace()) {
3185 // Allocate in new space, retry in large object space. 3328 // Allocate in new space, retry in large object space.
3186 retry_space = LO_SPACE; 3329 retry_space = LO_SPACE;
3187 } 3330 }
3188 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { 3331 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
3189 space = LO_SPACE; 3332 space = LO_SPACE;
3333 Object* result;
3334 { TryAllocation t = AllocateRaw(size, space, retry_space);
3335 if (!t->ToObject(&result)) return t;
3190 } 3336 }
3191 Object* result = AllocateRaw(size, space, retry_space); 3337 }
3192 if (result->IsFailure()) return result;
3193 3338
3194 // Partially initialize the object. 3339 // Partially initialize the object.
3195 HeapObject::cast(result)->set_map(string_map()); 3340 HeapObject::cast(result)->set_map(string_map());
3196 String::cast(result)->set_length(length); 3341 String::cast(result)->set_length(length);
3197 String::cast(result)->set_hash_field(String::kEmptyHashField); 3342 String::cast(result)->set_hash_field(String::kEmptyHashField);
3198 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 3343 ASSERT_EQ(size, HeapObject::cast(result)->Size());
3199 return result; 3344 return result;
3200 } 3345 }
3201 3346
3202 3347
3203 Object* Heap::AllocateEmptyFixedArray() { 3348 Object* Heap::AllocateEmptyFixedArray() {
3349 Object* result;
3350 { TryAllocation t = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
3351 if (!t->ToObject(&result)) return t;
3352 }
3204 int size = FixedArray::SizeFor(0); 3353 int size = FixedArray::SizeFor(0);
3205 Object* result = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
3206 if (result->IsFailure()) return result;
3207 // Initialize the object. 3354 // Initialize the object.
3208 reinterpret_cast<FixedArray*>(result)->set_map(fixed_array_map()); 3355 reinterpret_cast<FixedArray*>(result)->set_map(fixed_array_map());
3209 reinterpret_cast<FixedArray*>(result)->set_length(0); 3356 reinterpret_cast<FixedArray*>(result)->set_length(0);
3210 return result; 3357 return result;
3211 } 3358 }
3212 3359
3213 3360
3214 Object* Heap::AllocateRawFixedArray(int length) { 3361 Object* Heap::AllocateRawFixedArray(int length) {
3215 if (length < 0 || length > FixedArray::kMaxLength) { 3362 if (length < 0 || length > FixedArray::kMaxLength) {
3216 return Failure::OutOfMemoryException(); 3363 return Failure::OutOfMemoryException();
3217 } 3364 }
3218 ASSERT(length > 0); 3365 ASSERT(length > 0);
3219 // Use the general function if we're forced to always allocate. 3366 // Use the general function if we're forced to always allocate.
3220 if (always_allocate()) return AllocateFixedArray(length, TENURED); 3367 if (always_allocate()) return AllocateFixedArray(length, TENURED);
3221 // Allocate the raw data for a fixed array. 3368 // Allocate the raw data for a fixed array.
3222 int size = FixedArray::SizeFor(length); 3369 int size = FixedArray::SizeFor(length);
3223 return size <= kMaxObjectSizeInNewSpace 3370 return size <= kMaxObjectSizeInNewSpace
3224 ? new_space_.AllocateRaw(size) 3371 ? new_space_.AllocateRaw(size)
3225 : lo_space_->AllocateRawFixedArray(size); 3372 : lo_space_->AllocateRawFixedArray(size);
3226 } 3373 }
3227 3374
3228 3375
3229 Object* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { 3376 Object* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
3377 Object* obj;
3378 { TryAllocation t = AllocateRawFixedArray(len);
3379 if (!t->ToObject(&obj)) return t;
3380 }
3230 int len = src->length(); 3381 int len = src->length();
3231 Object* obj = AllocateRawFixedArray(len);
3232 if (obj->IsFailure()) return obj;
3233 if (Heap::InNewSpace(obj)) { 3382 if (Heap::InNewSpace(obj)) {
3234 HeapObject* dst = HeapObject::cast(obj); 3383 HeapObject* dst = HeapObject::cast(obj);
3235 dst->set_map(map); 3384 dst->set_map(map);
3236 CopyBlock(dst->address() + kPointerSize, 3385 CopyBlock(dst->address() + kPointerSize,
3237 src->address() + kPointerSize, 3386 src->address() + kPointerSize,
3238 FixedArray::SizeFor(len) - kPointerSize); 3387 FixedArray::SizeFor(len) - kPointerSize);
3239 return obj; 3388 return obj;
3240 } 3389 }
3241 HeapObject::cast(obj)->set_map(map); 3390 HeapObject::cast(obj)->set_map(map);
3242 FixedArray* result = FixedArray::cast(obj); 3391 FixedArray* result = FixedArray::cast(obj);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3291 } 3440 }
3292 3441
3293 3442
3294 static Object* AllocateFixedArrayWithFiller(int length, 3443 static Object* AllocateFixedArrayWithFiller(int length,
3295 PretenureFlag pretenure, 3444 PretenureFlag pretenure,
3296 Object* filler) { 3445 Object* filler) {
3297 ASSERT(length >= 0); 3446 ASSERT(length >= 0);
3298 ASSERT(Heap::empty_fixed_array()->IsFixedArray()); 3447 ASSERT(Heap::empty_fixed_array()->IsFixedArray());
3299 if (length == 0) return Heap::empty_fixed_array(); 3448 if (length == 0) return Heap::empty_fixed_array();
3300 3449
3450 Object* result;
3451 { TryAllocation t = Heap::AllocateRawFixedArray(length, pretenure);
3452 if (!t->ToObject(&result)) return t;
3453 }
3301 ASSERT(!Heap::InNewSpace(filler)); 3454 ASSERT(!Heap::InNewSpace(filler));
3302 Object* result = Heap::AllocateRawFixedArray(length, pretenure);
3303 if (result->IsFailure()) return result;
3304 3455
3305 HeapObject::cast(result)->set_map(Heap::fixed_array_map()); 3456 HeapObject::cast(result)->set_map(Heap::fixed_array_map());
3306 FixedArray* array = FixedArray::cast(result); 3457 FixedArray* array = FixedArray::cast(result);
3307 array->set_length(length); 3458 array->set_length(length);
3308 MemsetPointer(array->data_start(), filler, length); 3459 MemsetPointer(array->data_start(), filler, length);
3309 return array; 3460 return array;
3310 } 3461 }
3311 3462
3312 3463
3313 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 3464 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
3314 return AllocateFixedArrayWithFiller(length, pretenure, undefined_value()); 3465 return AllocateFixedArrayWithFiller(length, pretenure, undefined_value());
3315 } 3466 }
3316 3467
3317 3468
3318 Object* Heap::AllocateFixedArrayWithHoles(int length, PretenureFlag pretenure) { 3469 Object* Heap::AllocateFixedArrayWithHoles(int length, PretenureFlag pretenure) {
3319 return AllocateFixedArrayWithFiller(length, pretenure, the_hole_value()); 3470 return AllocateFixedArrayWithFiller(length, pretenure, the_hole_value());
3320 } 3471 }
3321 3472
3322 3473
3323 Object* Heap::AllocateUninitializedFixedArray(int length) { 3474 Object* Heap::AllocateUninitializedFixedArray(int length) {
3324 if (length == 0) return empty_fixed_array(); 3475 if (length == 0) return empty_fixed_array();
3476 Object* obj;
3477 { TryAllocation t = AllocateRawFixedArray(length);
3478 if (!t->ToObject(&obj)) return t;
3479 }
3325 3480
3326 Object* obj = AllocateRawFixedArray(length);
3327 if (obj->IsFailure()) return obj;
3328 3481
3329 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map()); 3482 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map());
3330 FixedArray::cast(obj)->set_length(length); 3483 FixedArray::cast(obj)->set_length(length);
3331 return obj; 3484 return obj;
3332 } 3485 }
3333 3486
3334 3487
3488 Object* result;
3489 { TryAllocation t = Heap::AllocateFixedArray(length, pretenure);
3490 if (!t->ToObject(&result)) return t;
3491 }
3335 Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { 3492 Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
3336 Object* result = Heap::AllocateFixedArray(length, pretenure);
3337 if (result->IsFailure()) return result;
3338 reinterpret_cast<HeapObject*>(result)->set_map(hash_table_map()); 3493 reinterpret_cast<HeapObject*>(result)->set_map(hash_table_map());
3339 ASSERT(result->IsHashTable()); 3494 ASSERT(result->IsHashTable());
3340 return result; 3495 return result;
3341 } 3496 }
3342 3497
3343 3498
3499 Object* result;
3500 { TryAllocation t = Heap::AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS);
3501 if (!t->ToObject(&result)) return t;
3502 }
3344 Object* Heap::AllocateGlobalContext() { 3503 Object* Heap::AllocateGlobalContext() {
3345 Object* result = Heap::AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS);
3346 if (result->IsFailure()) return result;
3347 Context* context = reinterpret_cast<Context*>(result); 3504 Context* context = reinterpret_cast<Context*>(result);
3348 context->set_map(global_context_map()); 3505 context->set_map(global_context_map());
3349 ASSERT(context->IsGlobalContext()); 3506 ASSERT(context->IsGlobalContext());
3350 ASSERT(result->IsContext()); 3507 ASSERT(result->IsContext());
3351 return result; 3508 return result;
3352 } 3509 }
3353 3510
3354 3511
3355 Object* Heap::AllocateFunctionContext(int length, JSFunction* function) { 3512 Object* Heap::AllocateFunctionContext(int length, JSFunction* function) {
3513 Object* result;
3514 { TryAllocation t = Heap::AllocateFixedArray(length);
3515 if (!t->ToObject(&result)) return t;
3516 }
3356 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); 3517 ASSERT(length >= Context::MIN_CONTEXT_SLOTS);
3357 Object* result = Heap::AllocateFixedArray(length);
3358 if (result->IsFailure()) return result;
3359 Context* context = reinterpret_cast<Context*>(result); 3518 Context* context = reinterpret_cast<Context*>(result);
3360 context->set_map(context_map()); 3519 context->set_map(context_map());
3361 context->set_closure(function); 3520 context->set_closure(function);
3362 context->set_fcontext(context); 3521 context->set_fcontext(context);
3363 context->set_previous(NULL); 3522 context->set_previous(NULL);
3364 context->set_extension(NULL); 3523 context->set_extension(NULL);
3365 context->set_global(function->context()->global()); 3524 context->set_global(function->context()->global());
3366 ASSERT(!context->IsGlobalContext()); 3525 ASSERT(!context->IsGlobalContext());
3367 ASSERT(context->is_function_context()); 3526 ASSERT(context->is_function_context());
3368 ASSERT(result->IsContext()); 3527 ASSERT(result->IsContext());
3369 return result; 3528 return result;
3370 } 3529 }
3371 3530
3372 3531
3373 Object* Heap::AllocateWithContext(Context* previous, 3532 Object* Heap::AllocateWithContext(Context* previous,
3374 JSObject* extension, 3533 JSObject* extension,
3534 Object* result;
3535 { TryAllocation t = Heap::AllocateFixedArray(Context::MIN_CONTEXT_SLOTS);
3536 if (!t->ToObject(&result)) return t;
3537 }
3375 bool is_catch_context) { 3538 bool is_catch_context) {
3376 Object* result = Heap::AllocateFixedArray(Context::MIN_CONTEXT_SLOTS);
3377 if (result->IsFailure()) return result;
3378 Context* context = reinterpret_cast<Context*>(result); 3539 Context* context = reinterpret_cast<Context*>(result);
3379 context->set_map(is_catch_context ? catch_context_map() : context_map()); 3540 context->set_map(is_catch_context ? catch_context_map() : context_map());
3380 context->set_closure(previous->closure()); 3541 context->set_closure(previous->closure());
3381 context->set_fcontext(previous->fcontext()); 3542 context->set_fcontext(previous->fcontext());
3382 context->set_previous(previous); 3543 context->set_previous(previous);
3383 context->set_extension(extension); 3544 context->set_extension(extension);
3384 context->set_global(previous->global()); 3545 context->set_global(previous->global());
3385 ASSERT(!context->IsGlobalContext()); 3546 ASSERT(!context->IsGlobalContext());
3386 ASSERT(!context->is_function_context()); 3547 ASSERT(!context->is_function_context());
3387 ASSERT(result->IsContext()); 3548 ASSERT(result->IsContext());
3388 return result; 3549 return result;
3389 } 3550 }
3390 3551
3391 3552
3392 Object* Heap::AllocateStruct(InstanceType type) { 3553 Object* Heap::AllocateStruct(InstanceType type) {
3393 Map* map; 3554 Map* map;
3394 switch (type) { 3555 switch (type) {
3395 #define MAKE_CASE(NAME, Name, name) case NAME##_TYPE: map = name##_map(); break; 3556 #define MAKE_CASE(NAME, Name, name) case NAME##_TYPE: map = name##_map(); break;
3396 STRUCT_LIST(MAKE_CASE) 3557 STRUCT_LIST(MAKE_CASE)
3397 #undef MAKE_CASE 3558 #undef MAKE_CASE
3398 default: 3559 default:
3399 UNREACHABLE(); 3560 UNREACHABLE();
3400 return Failure::InternalError(); 3561 return Failure::InternalError();
3401 } 3562 }
3402 int size = map->instance_size(); 3563 int size = map->instance_size();
3403 AllocationSpace space = 3564 AllocationSpace space =
3565 Object* result;
3566 { TryAllocation t = Heap::Allocate(map, space);
3567 if (!t->ToObject(&result)) return t;
3568 }
3404 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_POINTER_SPACE; 3569 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_POINTER_SPACE;
3405 Object* result = Heap::Allocate(map, space);
3406 if (result->IsFailure()) return result;
3407 Struct::cast(result)->InitializeBody(size); 3570 Struct::cast(result)->InitializeBody(size);
3408 return result; 3571 return result;
3409 } 3572 }
3410 3573
3411 3574
3412 bool Heap::IdleNotification() { 3575 bool Heap::IdleNotification() {
3413 static const int kIdlesBeforeScavenge = 4; 3576 static const int kIdlesBeforeScavenge = 4;
3414 static const int kIdlesBeforeMarkSweep = 7; 3577 static const int kIdlesBeforeMarkSweep = 7;
3415 static const int kIdlesBeforeMarkCompact = 8; 3578 static const int kIdlesBeforeMarkCompact = 8;
3416 static int number_idle_notifications = 0; 3579 static int number_idle_notifications = 0;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
3657 old_data_space_->Verify(&no_dirty_regions_visitor); 3820 old_data_space_->Verify(&no_dirty_regions_visitor);
3658 code_space_->Verify(&no_dirty_regions_visitor); 3821 code_space_->Verify(&no_dirty_regions_visitor);
3659 cell_space_->Verify(&no_dirty_regions_visitor); 3822 cell_space_->Verify(&no_dirty_regions_visitor);
3660 3823
3661 lo_space_->Verify(); 3824 lo_space_->Verify();
3662 } 3825 }
3663 #endif // DEBUG 3826 #endif // DEBUG
3664 3827
3665 3828
3666 Object* Heap::LookupSymbol(Vector<const char> string) { 3829 Object* Heap::LookupSymbol(Vector<const char> string) {
3830 Object* new_table;
3831 { TryAllocation t = symbol_table()->LookupSymbol(string, &symbol);
3832 if (!t->ToObject(&new_table)) return t;
3833 }
3667 Object* symbol = NULL; 3834 Object* symbol = NULL;
3668 Object* new_table = symbol_table()->LookupSymbol(string, &symbol);
3669 if (new_table->IsFailure()) return new_table;
3670 // Can't use set_symbol_table because SymbolTable::cast knows that 3835 // Can't use set_symbol_table because SymbolTable::cast knows that
3671 // SymbolTable is a singleton and checks for identity. 3836 // SymbolTable is a singleton and checks for identity.
3672 roots_[kSymbolTableRootIndex] = new_table; 3837 roots_[kSymbolTableRootIndex] = new_table;
3673 ASSERT(symbol != NULL); 3838 ASSERT(symbol != NULL);
3674 return symbol; 3839 return symbol;
3675 } 3840 }
3676 3841
3677 3842
3678 Object* Heap::LookupSymbol(String* string) { 3843 Object* Heap::LookupSymbol(String* string) {
3679 if (string->IsSymbol()) return string; 3844 if (string->IsSymbol()) return string;
3845 Object* new_table;
3846 { TryAllocation t = symbol_table()->LookupString(string, &symbol);
3847 if (!t->ToObject(&new_table)) return t;
3848 }
3680 Object* symbol = NULL; 3849 Object* symbol = NULL;
3681 Object* new_table = symbol_table()->LookupString(string, &symbol);
3682 if (new_table->IsFailure()) return new_table;
3683 // Can't use set_symbol_table because SymbolTable::cast knows that 3850 // Can't use set_symbol_table because SymbolTable::cast knows that
3684 // SymbolTable is a singleton and checks for identity. 3851 // SymbolTable is a singleton and checks for identity.
3685 roots_[kSymbolTableRootIndex] = new_table; 3852 roots_[kSymbolTableRootIndex] = new_table;
3686 ASSERT(symbol != NULL); 3853 ASSERT(symbol != NULL);
3687 return symbol; 3854 return symbol;
3688 } 3855 }
3689 3856
3690 3857
3691 bool Heap::LookupSymbolIfExists(String* string, String** symbol) { 3858 bool Heap::LookupSymbolIfExists(String* string, String** symbol) {
3692 if (string->IsSymbol()) { 3859 if (string->IsSymbol()) {
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
4996 void ExternalStringTable::TearDown() { 5163 void ExternalStringTable::TearDown() {
4997 new_space_strings_.Free(); 5164 new_space_strings_.Free();
4998 old_space_strings_.Free(); 5165 old_space_strings_.Free();
4999 } 5166 }
5000 5167
5001 5168
5002 List<Object*> ExternalStringTable::new_space_strings_; 5169 List<Object*> ExternalStringTable::new_space_strings_;
5003 List<Object*> ExternalStringTable::old_space_strings_; 5170 List<Object*> ExternalStringTable::old_space_strings_;
5004 5171
5005 } } // namespace v8::internal 5172 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/code-stubs.cc ('k') | src/ia32/macro-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698