OLD | NEW |
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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 #define WRITE_SHORT_FIELD(p, offset, value) \ | 854 #define WRITE_SHORT_FIELD(p, offset, value) \ |
855 (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value) | 855 (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value) |
856 | 856 |
857 #define READ_BYTE_FIELD(p, offset) \ | 857 #define READ_BYTE_FIELD(p, offset) \ |
858 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset))) | 858 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset))) |
859 | 859 |
860 #define WRITE_BYTE_FIELD(p, offset, value) \ | 860 #define WRITE_BYTE_FIELD(p, offset, value) \ |
861 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value) | 861 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value) |
862 | 862 |
863 | 863 |
| 864 Address HeapObject::GetFieldAddress(int offset) { |
| 865 return reinterpret_cast<Address>(RawField(this, offset)); |
| 866 } |
| 867 |
| 868 |
864 Object** HeapObject::RawField(HeapObject* obj, int byte_offset) { | 869 Object** HeapObject::RawField(HeapObject* obj, int byte_offset) { |
865 return &READ_FIELD(obj, byte_offset); | 870 return &READ_FIELD(obj, byte_offset); |
866 } | 871 } |
867 | 872 |
868 | 873 |
869 int Smi::value() { | 874 int Smi::value() { |
870 return Internals::SmiValue(this); | 875 return Internals::SmiValue(this); |
871 } | 876 } |
872 | 877 |
873 | 878 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 | 1311 |
1307 int JSObject::GetInternalFieldCount() { | 1312 int JSObject::GetInternalFieldCount() { |
1308 ASSERT(1 << kPointerSizeLog2 == kPointerSize); | 1313 ASSERT(1 << kPointerSizeLog2 == kPointerSize); |
1309 // Make sure to adjust for the number of in-object properties. These | 1314 // Make sure to adjust for the number of in-object properties. These |
1310 // properties do contribute to the size, but are not internal fields. | 1315 // properties do contribute to the size, but are not internal fields. |
1311 return ((Size() - GetHeaderSize()) >> kPointerSizeLog2) - | 1316 return ((Size() - GetHeaderSize()) >> kPointerSizeLog2) - |
1312 map()->inobject_properties(); | 1317 map()->inobject_properties(); |
1313 } | 1318 } |
1314 | 1319 |
1315 | 1320 |
| 1321 Address JSObject::GetInternalFieldOffset(int index) { |
| 1322 ASSERT(index < GetInternalFieldCount() && index >= 0); |
| 1323 return reinterpret_cast<Address>( |
| 1324 &READ_FIELD(this, GetHeaderSize() + (kPointerSize * index))); |
| 1325 } |
| 1326 |
| 1327 |
1316 Object* JSObject::GetInternalField(int index) { | 1328 Object* JSObject::GetInternalField(int index) { |
1317 ASSERT(index < GetInternalFieldCount() && index >= 0); | 1329 ASSERT(index < GetInternalFieldCount() && index >= 0); |
1318 // Internal objects do follow immediately after the header, whereas in-object | 1330 // Internal objects do follow immediately after the header, whereas in-object |
1319 // properties are at the end of the object. Therefore there is no need | 1331 // properties are at the end of the object. Therefore there is no need |
1320 // to adjust the index here. | 1332 // to adjust the index here. |
1321 return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index)); | 1333 return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index)); |
1322 } | 1334 } |
1323 | 1335 |
1324 | 1336 |
1325 void JSObject::SetInternalField(int index, Object* value) { | 1337 void JSObject::SetInternalField(int index, Object* value) { |
1326 ASSERT(index < GetInternalFieldCount() && index >= 0); | 1338 ASSERT(index < GetInternalFieldCount() && index >= 0); |
1327 // Internal objects do follow immediately after the header, whereas in-object | 1339 // Internal objects do follow immediately after the header, whereas in-object |
1328 // properties are at the end of the object. Therefore there is no need | 1340 // properties are at the end of the object. Therefore there is no need |
1329 // to adjust the index here. | 1341 // to adjust the index here. |
1330 int offset = GetHeaderSize() + (kPointerSize * index); | 1342 int offset = GetHeaderSize() + (kPointerSize * index); |
1331 WRITE_FIELD(this, offset, value); | 1343 WRITE_FIELD(this, offset, value); |
1332 WRITE_BARRIER(this, offset); | 1344 WRITE_BARRIER(this, offset); |
1333 } | 1345 } |
1334 | 1346 |
1335 | 1347 |
1336 // Access fast-case object properties at index. The use of these routines | 1348 // Access fast-case object properties at index. The use of these routines |
1337 // is needed to correctly distinguish between properties stored in-object and | 1349 // is needed to correctly distinguish between properties stored in-object and |
1338 // properties stored in the properties array. | 1350 // properties stored in the properties array. |
| 1351 Address JSObject::GetFastPropertyAddress(int index) { |
| 1352 // Adjust for the number of properties stored in the object. |
| 1353 index -= map()->inobject_properties(); |
| 1354 if (index < 0) { |
| 1355 int offset = map()->instance_size() + (index * kPointerSize); |
| 1356 return reinterpret_cast<Address>(&READ_FIELD(this, offset)); |
| 1357 } else { |
| 1358 return NULL; |
| 1359 } |
| 1360 } |
| 1361 |
| 1362 |
1339 Object* JSObject::FastPropertyAt(int index) { | 1363 Object* JSObject::FastPropertyAt(int index) { |
1340 // Adjust for the number of properties stored in the object. | 1364 // Adjust for the number of properties stored in the object. |
1341 index -= map()->inobject_properties(); | 1365 index -= map()->inobject_properties(); |
1342 if (index < 0) { | 1366 if (index < 0) { |
1343 int offset = map()->instance_size() + (index * kPointerSize); | 1367 int offset = map()->instance_size() + (index * kPointerSize); |
1344 return READ_FIELD(this, offset); | 1368 return READ_FIELD(this, offset); |
1345 } else { | 1369 } else { |
1346 ASSERT(index < properties()->length()); | 1370 ASSERT(index < properties()->length()); |
1347 return properties()->get(index); | 1371 return properties()->get(index); |
1348 } | 1372 } |
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3936 #undef WRITE_INT_FIELD | 3960 #undef WRITE_INT_FIELD |
3937 #undef READ_SHORT_FIELD | 3961 #undef READ_SHORT_FIELD |
3938 #undef WRITE_SHORT_FIELD | 3962 #undef WRITE_SHORT_FIELD |
3939 #undef READ_BYTE_FIELD | 3963 #undef READ_BYTE_FIELD |
3940 #undef WRITE_BYTE_FIELD | 3964 #undef WRITE_BYTE_FIELD |
3941 | 3965 |
3942 | 3966 |
3943 } } // namespace v8::internal | 3967 } } // namespace v8::internal |
3944 | 3968 |
3945 #endif // V8_OBJECTS_INL_H_ | 3969 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |