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

Side by Side Diff: src/objects-inl.h

Issue 7341: Allocate room for expected number of properties based on the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 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/objects-debug.cc ('k') | src/runtime.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 return JSObject::kHeaderSize; 891 return JSObject::kHeaderSize;
892 default: 892 default:
893 UNREACHABLE(); 893 UNREACHABLE();
894 return 0; 894 return 0;
895 } 895 }
896 } 896 }
897 897
898 898
899 int JSObject::GetInternalFieldCount() { 899 int JSObject::GetInternalFieldCount() {
900 ASSERT(1 << kPointerSizeLog2 == kPointerSize); 900 ASSERT(1 << kPointerSizeLog2 == kPointerSize);
901 return (Size() - GetHeaderSize()) >> kPointerSizeLog2; 901 // Make sure to adjust for the number of in-object properties. These
902 // properties do contribute to the size, but are not internal fields.
903 return ((Size() - GetHeaderSize()) >> kPointerSizeLog2) -
904 map()->inobject_properties();
902 } 905 }
903 906
904 907
905 Object* JSObject::GetInternalField(int index) { 908 Object* JSObject::GetInternalField(int index) {
906 ASSERT(index < GetInternalFieldCount() && index >= 0); 909 ASSERT(index < GetInternalFieldCount() && index >= 0);
910 // Internal objects do follow immediately after the header, whereas in-object
911 // properties are at the end of the object. Therefore there is no need
912 // to adjust the index here.
907 return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index)); 913 return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index));
908 } 914 }
909 915
910 916
911 void JSObject::SetInternalField(int index, Object* value) { 917 void JSObject::SetInternalField(int index, Object* value) {
912 ASSERT(index < GetInternalFieldCount() && index >= 0); 918 ASSERT(index < GetInternalFieldCount() && index >= 0);
919 // Internal objects do follow immediately after the header, whereas in-object
920 // properties are at the end of the object. Therefore there is no need
921 // to adjust the index here.
913 int offset = GetHeaderSize() + (kPointerSize * index); 922 int offset = GetHeaderSize() + (kPointerSize * index);
914 WRITE_FIELD(this, offset, value); 923 WRITE_FIELD(this, offset, value);
915 WRITE_BARRIER(this, offset); 924 WRITE_BARRIER(this, offset);
916 } 925 }
917 926
918 927
928 // Access fast-case object properties at index. The use of these routines
929 // is needed to correctly distinguish between properties stored in-object and
930 // properties stored in the properties array.
931 inline Object* JSObject::FastPropertyAt(int index) {
932 // Adjust for the number of properties stored in the object.
933 index -= map()->inobject_properties();
934 if (index < 0) {
935 int offset = map()->instance_size() + (index * kPointerSize);
936 return READ_FIELD(this, offset);
937 } else {
938 ASSERT(index < properties()->length());
939 return properties()->get(index);
940 }
941 }
942
943
944 inline Object* JSObject::FastPropertyAtPut(int index, Object* value) {
945 // Adjust for the number of properties stored in the object.
946 index -= map()->inobject_properties();
947 if (index < 0) {
948 int offset = map()->instance_size() + (index * kPointerSize);
949 WRITE_FIELD(this, offset, value);
950 WRITE_BARRIER(this, offset);
951 } else {
952 ASSERT(index < properties()->length());
953 properties()->set(index, value);
954 }
955 return value;
956 }
957
958
919 void JSObject::InitializeBody(int object_size) { 959 void JSObject::InitializeBody(int object_size) {
920 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { 960 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) {
921 WRITE_FIELD(this, offset, Heap::undefined_value()); 961 WRITE_FIELD(this, offset, Heap::undefined_value());
922 } 962 }
923 } 963 }
924 964
925 965
926 void Struct::InitializeBody(int object_size) { 966 void Struct::InitializeBody(int object_size) {
927 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { 967 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) {
928 WRITE_FIELD(this, offset, Heap::undefined_value()); 968 WRITE_FIELD(this, offset, Heap::undefined_value());
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag); 1562 return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag);
1523 } 1563 }
1524 1564
1525 1565
1526 Address ByteArray::GetDataStartAddress() { 1566 Address ByteArray::GetDataStartAddress() {
1527 return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize; 1567 return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize;
1528 } 1568 }
1529 1569
1530 1570
1531 int Map::instance_size() { 1571 int Map::instance_size() {
1532 return READ_BYTE_FIELD(this, kInstanceSizeOffset); 1572 return READ_BYTE_FIELD(this, kInstanceSizeOffset) << kPointerSizeLog2;
1573 }
1574
1575
1576 int Map::inobject_properties() {
1577 return READ_BYTE_FIELD(this, kInObjectPropertiesOffset);
1533 } 1578 }
1534 1579
1535 1580
1536 int HeapObject::SizeFromMap(Map* map) { 1581 int HeapObject::SizeFromMap(Map* map) {
1537 InstanceType instance_type = map->instance_type(); 1582 InstanceType instance_type = map->instance_type();
1538 // Only inline the two most frequent cases. 1583 // Only inline the two most frequent cases.
1539 if (instance_type == JS_OBJECT_TYPE) return map->instance_size(); 1584 if (instance_type == JS_OBJECT_TYPE) return map->instance_size();
1540 if (instance_type == FIXED_ARRAY_TYPE) { 1585 if (instance_type == FIXED_ARRAY_TYPE) {
1541 return reinterpret_cast<FixedArray*>(this)->FixedArraySize(); 1586 return reinterpret_cast<FixedArray*>(this)->FixedArraySize();
1542 } 1587 }
1543 // Otherwise do the general size computation. 1588 // Otherwise do the general size computation.
1544 return SlowSizeFromMap(map); 1589 return SlowSizeFromMap(map);
1545 } 1590 }
1546 1591
1547 1592
1548 void Map::set_instance_size(int value) { 1593 void Map::set_instance_size(int value) {
1594 ASSERT((value & ~(kPointerSize - 1)) == value);
1595 value >>= kPointerSizeLog2;
1549 ASSERT(0 <= value && value < 256); 1596 ASSERT(0 <= value && value < 256);
1550 WRITE_BYTE_FIELD(this, kInstanceSizeOffset, static_cast<byte>(value)); 1597 WRITE_BYTE_FIELD(this, kInstanceSizeOffset, static_cast<byte>(value));
1551 } 1598 }
1552 1599
1553 1600
1601 void Map::set_inobject_properties(int value) {
1602 ASSERT(0 <= value && value < 256);
1603 WRITE_BYTE_FIELD(this, kInObjectPropertiesOffset, static_cast<byte>(value));
1604 }
1605
1606
1554 InstanceType Map::instance_type() { 1607 InstanceType Map::instance_type() {
1555 return static_cast<InstanceType>(READ_BYTE_FIELD(this, kInstanceTypeOffset)); 1608 return static_cast<InstanceType>(READ_BYTE_FIELD(this, kInstanceTypeOffset));
1556 } 1609 }
1557 1610
1558 1611
1559 void Map::set_instance_type(InstanceType value) { 1612 void Map::set_instance_type(InstanceType value) {
1560 ASSERT(0 <= value && value < 256); 1613 ASSERT(0 <= value && value < 256);
1561 WRITE_BYTE_FIELD(this, kInstanceTypeOffset, value); 1614 WRITE_BYTE_FIELD(this, kInstanceTypeOffset, value);
1562 } 1615 }
1563 1616
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
2262 #undef WRITE_INT_FIELD 2315 #undef WRITE_INT_FIELD
2263 #undef READ_SHORT_FIELD 2316 #undef READ_SHORT_FIELD
2264 #undef WRITE_SHORT_FIELD 2317 #undef WRITE_SHORT_FIELD
2265 #undef READ_BYTE_FIELD 2318 #undef READ_BYTE_FIELD
2266 #undef WRITE_BYTE_FIELD 2319 #undef WRITE_BYTE_FIELD
2267 2320
2268 2321
2269 } } // namespace v8::internal 2322 } } // namespace v8::internal
2270 2323
2271 #endif // V8_OBJECTS_INL_H_ 2324 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects-debug.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698