OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Getter that returns a Smi as an int and writes an int as a Smi. | 118 // Getter that returns a Smi as an int and writes an int as a Smi. |
119 #define SMI_ACCESSORS(holder, name, offset) \ | 119 #define SMI_ACCESSORS(holder, name, offset) \ |
120 int holder::name() { \ | 120 int holder::name() { \ |
121 Object* value = READ_FIELD(this, offset); \ | 121 Object* value = READ_FIELD(this, offset); \ |
122 return Smi::cast(value)->value(); \ | 122 return Smi::cast(value)->value(); \ |
123 } \ | 123 } \ |
124 void holder::set_##name(int value) { \ | 124 void holder::set_##name(int value) { \ |
125 WRITE_FIELD(this, offset, Smi::FromInt(value)); \ | 125 WRITE_FIELD(this, offset, Smi::FromInt(value)); \ |
126 } | 126 } |
127 | 127 |
| 128 #define SYNCHRONIZED_SMI_ACCESSORS(holder, name, offset) \ |
| 129 int holder::synchronized_##name() { \ |
| 130 Object* value = ACQUIRE_READ_FIELD(this, offset); \ |
| 131 return Smi::cast(value)->value(); \ |
| 132 } \ |
| 133 void holder::synchronized_set_##name(int value) { \ |
| 134 RELEASE_WRITE_FIELD(this, offset, Smi::FromInt(value)); \ |
| 135 } |
| 136 |
128 | 137 |
129 #define BOOL_GETTER(holder, field, name, offset) \ | 138 #define BOOL_GETTER(holder, field, name, offset) \ |
130 bool holder::name() { \ | 139 bool holder::name() { \ |
131 return BooleanBit::get(field(), offset); \ | 140 return BooleanBit::get(field(), offset); \ |
132 } \ | 141 } \ |
133 | 142 |
134 | 143 |
135 #define BOOL_ACCESSORS(holder, field, name, offset) \ | 144 #define BOOL_ACCESSORS(holder, field, name, offset) \ |
136 bool holder::name() { \ | 145 bool holder::name() { \ |
137 return BooleanBit::get(field(), offset); \ | 146 return BooleanBit::get(field(), offset); \ |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 return GetPropertyWithReceiver(this, key, attributes); | 1097 return GetPropertyWithReceiver(this, key, attributes); |
1089 } | 1098 } |
1090 | 1099 |
1091 | 1100 |
1092 #define FIELD_ADDR(p, offset) \ | 1101 #define FIELD_ADDR(p, offset) \ |
1093 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) | 1102 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) |
1094 | 1103 |
1095 #define READ_FIELD(p, offset) \ | 1104 #define READ_FIELD(p, offset) \ |
1096 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset))) | 1105 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset))) |
1097 | 1106 |
| 1107 #define ACQUIRE_READ_FIELD(p, offset) \ |
| 1108 reinterpret_cast<Object*>( \ |
| 1109 Acquire_Load(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset)))) |
| 1110 |
| 1111 #define NO_BARRIER_READ_FIELD(p, offset) \ |
| 1112 reinterpret_cast<Object*>( \ |
| 1113 NoBarrier_Load(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset)))) |
| 1114 |
1098 #define WRITE_FIELD(p, offset, value) \ | 1115 #define WRITE_FIELD(p, offset, value) \ |
1099 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) | 1116 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) |
1100 | 1117 |
| 1118 #define RELEASE_WRITE_FIELD(p, offset, value) \ |
| 1119 Release_Store(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset)), \ |
| 1120 reinterpret_cast<AtomicWord>(value)); |
| 1121 |
| 1122 #define NO_BARRIER_WRITE_FIELD(p, offset, value) \ |
| 1123 NoBarrier_Store(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset)), \ |
| 1124 reinterpret_cast<AtomicWord>(value)); |
| 1125 |
1101 #define WRITE_BARRIER(heap, object, offset, value) \ | 1126 #define WRITE_BARRIER(heap, object, offset, value) \ |
1102 heap->incremental_marking()->RecordWrite( \ | 1127 heap->incremental_marking()->RecordWrite( \ |
1103 object, HeapObject::RawField(object, offset), value); \ | 1128 object, HeapObject::RawField(object, offset), value); \ |
1104 if (heap->InNewSpace(value)) { \ | 1129 if (heap->InNewSpace(value)) { \ |
1105 heap->RecordWrite(object->address(), offset); \ | 1130 heap->RecordWrite(object->address(), offset); \ |
1106 } | 1131 } |
1107 | 1132 |
1108 #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ | 1133 #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ |
1109 if (mode == UPDATE_WRITE_BARRIER) { \ | 1134 if (mode == UPDATE_WRITE_BARRIER) { \ |
1110 heap->incremental_marking()->RecordWrite( \ | 1135 heap->incremental_marking()->RecordWrite( \ |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 void HeapObject::set_map(Map* value) { | 1366 void HeapObject::set_map(Map* value) { |
1342 set_map_word(MapWord::FromMap(value)); | 1367 set_map_word(MapWord::FromMap(value)); |
1343 if (value != NULL) { | 1368 if (value != NULL) { |
1344 // TODO(1600) We are passing NULL as a slot because maps can never be on | 1369 // TODO(1600) We are passing NULL as a slot because maps can never be on |
1345 // evacuation candidate. | 1370 // evacuation candidate. |
1346 value->GetHeap()->incremental_marking()->RecordWrite(this, NULL, value); | 1371 value->GetHeap()->incremental_marking()->RecordWrite(this, NULL, value); |
1347 } | 1372 } |
1348 } | 1373 } |
1349 | 1374 |
1350 | 1375 |
| 1376 Map* HeapObject::synchronized_map() { |
| 1377 return synchronized_map_word().ToMap(); |
| 1378 } |
| 1379 |
| 1380 |
| 1381 void HeapObject::synchronized_set_map(Map* value) { |
| 1382 synchronized_set_map_word(MapWord::FromMap(value)); |
| 1383 if (value != NULL) { |
| 1384 // TODO(1600) We are passing NULL as a slot because maps can never be on |
| 1385 // evacuation candidate. |
| 1386 value->GetHeap()->incremental_marking()->RecordWrite(this, NULL, value); |
| 1387 } |
| 1388 } |
| 1389 |
| 1390 |
1351 // Unsafe accessor omitting write barrier. | 1391 // Unsafe accessor omitting write barrier. |
1352 void HeapObject::set_map_no_write_barrier(Map* value) { | 1392 void HeapObject::set_map_no_write_barrier(Map* value) { |
1353 set_map_word(MapWord::FromMap(value)); | 1393 set_map_word(MapWord::FromMap(value)); |
1354 } | 1394 } |
1355 | 1395 |
1356 | 1396 |
1357 MapWord HeapObject::map_word() { | 1397 MapWord HeapObject::map_word() { |
1358 return MapWord(reinterpret_cast<uintptr_t>(READ_FIELD(this, kMapOffset))); | 1398 return MapWord( |
| 1399 reinterpret_cast<uintptr_t>(NO_BARRIER_READ_FIELD(this, kMapOffset))); |
1359 } | 1400 } |
1360 | 1401 |
1361 | 1402 |
1362 void HeapObject::set_map_word(MapWord map_word) { | 1403 void HeapObject::set_map_word(MapWord map_word) { |
1363 // WRITE_FIELD does not invoke write barrier, but there is no need | 1404 NO_BARRIER_WRITE_FIELD( |
1364 // here. | 1405 this, kMapOffset, reinterpret_cast<Object*>(map_word.value_)); |
1365 WRITE_FIELD(this, kMapOffset, reinterpret_cast<Object*>(map_word.value_)); | |
1366 } | 1406 } |
1367 | 1407 |
1368 | 1408 |
| 1409 MapWord HeapObject::synchronized_map_word() { |
| 1410 return MapWord( |
| 1411 reinterpret_cast<uintptr_t>(ACQUIRE_READ_FIELD(this, kMapOffset))); |
| 1412 } |
| 1413 |
| 1414 |
| 1415 void HeapObject::synchronized_set_map_word(MapWord map_word) { |
| 1416 RELEASE_WRITE_FIELD( |
| 1417 this, kMapOffset, reinterpret_cast<Object*>(map_word.value_)); |
| 1418 } |
| 1419 |
| 1420 |
1369 HeapObject* HeapObject::FromAddress(Address address) { | 1421 HeapObject* HeapObject::FromAddress(Address address) { |
1370 ASSERT_TAG_ALIGNED(address); | 1422 ASSERT_TAG_ALIGNED(address); |
1371 return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); | 1423 return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); |
1372 } | 1424 } |
1373 | 1425 |
1374 | 1426 |
1375 Address HeapObject::address() { | 1427 Address HeapObject::address() { |
1376 return reinterpret_cast<Address>(this) - kHeapObjectTag; | 1428 return reinterpret_cast<Address>(this) - kHeapObjectTag; |
1377 } | 1429 } |
1378 | 1430 |
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2907 | 2959 |
2908 | 2960 |
2909 template <typename Shape, typename Key> | 2961 template <typename Shape, typename Key> |
2910 HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { | 2962 HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { |
2911 ASSERT(obj->IsHashTable()); | 2963 ASSERT(obj->IsHashTable()); |
2912 return reinterpret_cast<HashTable*>(obj); | 2964 return reinterpret_cast<HashTable*>(obj); |
2913 } | 2965 } |
2914 | 2966 |
2915 | 2967 |
2916 SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) | 2968 SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) |
| 2969 SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) |
| 2970 |
2917 SMI_ACCESSORS(FreeSpace, size, kSizeOffset) | 2971 SMI_ACCESSORS(FreeSpace, size, kSizeOffset) |
2918 | 2972 |
2919 SMI_ACCESSORS(String, length, kLengthOffset) | 2973 SMI_ACCESSORS(String, length, kLengthOffset) |
| 2974 SYNCHRONIZED_SMI_ACCESSORS(String, length, kLengthOffset) |
2920 | 2975 |
2921 | 2976 |
2922 uint32_t Name::hash_field() { | 2977 uint32_t Name::hash_field() { |
2923 return READ_UINT32_FIELD(this, kHashFieldOffset); | 2978 return READ_UINT32_FIELD(this, kHashFieldOffset); |
2924 } | 2979 } |
2925 | 2980 |
2926 | 2981 |
2927 void Name::set_hash_field(uint32_t value) { | 2982 void Name::set_hash_field(uint32_t value) { |
2928 WRITE_UINT32_FIELD(this, kHashFieldOffset, value); | 2983 WRITE_UINT32_FIELD(this, kHashFieldOffset, value); |
2929 #if V8_HOST_ARCH_64_BIT | 2984 #if V8_HOST_ARCH_64_BIT |
(...skipping 3859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6789 #undef READ_UINT32_FIELD | 6844 #undef READ_UINT32_FIELD |
6790 #undef WRITE_UINT32_FIELD | 6845 #undef WRITE_UINT32_FIELD |
6791 #undef READ_SHORT_FIELD | 6846 #undef READ_SHORT_FIELD |
6792 #undef WRITE_SHORT_FIELD | 6847 #undef WRITE_SHORT_FIELD |
6793 #undef READ_BYTE_FIELD | 6848 #undef READ_BYTE_FIELD |
6794 #undef WRITE_BYTE_FIELD | 6849 #undef WRITE_BYTE_FIELD |
6795 | 6850 |
6796 } } // namespace v8::internal | 6851 } } // namespace v8::internal |
6797 | 6852 |
6798 #endif // V8_OBJECTS_INL_H_ | 6853 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |