OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 | 858 |
859 #define FIELD_ADDR(p, offset) \ | 859 #define FIELD_ADDR(p, offset) \ |
860 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) | 860 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) |
861 | 861 |
862 #define READ_FIELD(p, offset) \ | 862 #define READ_FIELD(p, offset) \ |
863 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset))) | 863 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset))) |
864 | 864 |
865 #define WRITE_FIELD(p, offset, value) \ | 865 #define WRITE_FIELD(p, offset, value) \ |
866 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) | 866 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) |
867 | 867 |
868 #define WRITE_BARRIER(heap, object, offset, value) \ | 868 #define WRITE_BARRIER(heap, object, offset, value) \ |
869 heap->incremental_marking()->RecordWrite(object, value); \ | 869 heap->incremental_marking()->RecordWrite( \ |
870 if (HEAP->InNewSpace(value)) { \ | 870 object, HeapObject::RawField(object, offset), value); \ |
871 heap->RecordWrite(object->address(), offset); \ | 871 if (heap->InNewSpace(value)) { \ |
| 872 heap->RecordWrite(object->address(), offset); \ |
872 } | 873 } |
873 // TODO(gc) !!! | |
874 | 874 |
875 #ifndef V8_TARGET_ARCH_MIPS | 875 #ifndef V8_TARGET_ARCH_MIPS |
876 #define READ_DOUBLE_FIELD(p, offset) \ | 876 #define READ_DOUBLE_FIELD(p, offset) \ |
877 (*reinterpret_cast<double*>(FIELD_ADDR(p, offset))) | 877 (*reinterpret_cast<double*>(FIELD_ADDR(p, offset))) |
878 #else // V8_TARGET_ARCH_MIPS | 878 #else // V8_TARGET_ARCH_MIPS |
879 // Prevent gcc from using load-double (mips ldc1) on (possibly) | 879 // Prevent gcc from using load-double (mips ldc1) on (possibly) |
880 // non-64-bit aligned HeapNumber::value. | 880 // non-64-bit aligned HeapNumber::value. |
881 static inline double read_double_field(HeapNumber* p, int offset) { | 881 static inline double read_double_field(HeapNumber* p, int offset) { |
882 union conversion { | 882 union conversion { |
883 double d; | 883 double d; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 | 1111 |
1112 | 1112 |
1113 Map* HeapObject::map() { | 1113 Map* HeapObject::map() { |
1114 return map_word().ToMap(); | 1114 return map_word().ToMap(); |
1115 } | 1115 } |
1116 | 1116 |
1117 | 1117 |
1118 void HeapObject::set_map(Map* value) { | 1118 void HeapObject::set_map(Map* value) { |
1119 set_map_word(MapWord::FromMap(value)); | 1119 set_map_word(MapWord::FromMap(value)); |
1120 if (value != NULL) { | 1120 if (value != NULL) { |
1121 value->GetHeap()->incremental_marking()->RecordWrite(this, value); | 1121 // We are passing NULL as a slot because maps can never be on evacuation |
| 1122 // candidate. |
| 1123 // TODO(gc) Maps are compacted by a separate (non-evacuation) algorithm. |
| 1124 value->GetHeap()->incremental_marking()->RecordWrite(this, NULL, value); |
1122 } | 1125 } |
1123 } | 1126 } |
1124 | 1127 |
1125 | 1128 |
1126 MapWord HeapObject::map_word() { | 1129 MapWord HeapObject::map_word() { |
1127 return MapWord(reinterpret_cast<uintptr_t>(READ_FIELD(this, kMapOffset))); | 1130 return MapWord(reinterpret_cast<uintptr_t>(READ_FIELD(this, kMapOffset))); |
1128 } | 1131 } |
1129 | 1132 |
1130 | 1133 |
1131 void HeapObject::set_map_word(MapWord map_word) { | 1134 void HeapObject::set_map_word(MapWord map_word) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 | 1248 |
1246 Object* JSGlobalPropertyCell::value() { | 1249 Object* JSGlobalPropertyCell::value() { |
1247 return READ_FIELD(this, kValueOffset); | 1250 return READ_FIELD(this, kValueOffset); |
1248 } | 1251 } |
1249 | 1252 |
1250 | 1253 |
1251 void JSGlobalPropertyCell::set_value(Object* val, WriteBarrierMode ignored) { | 1254 void JSGlobalPropertyCell::set_value(Object* val, WriteBarrierMode ignored) { |
1252 // The write barrier is not used for global property cells. | 1255 // The write barrier is not used for global property cells. |
1253 ASSERT(!val->IsJSGlobalPropertyCell()); | 1256 ASSERT(!val->IsJSGlobalPropertyCell()); |
1254 WRITE_FIELD(this, kValueOffset, val); | 1257 WRITE_FIELD(this, kValueOffset, val); |
1255 // TODO(gc) ISOLATES MERGE cell should heap accessor. | 1258 GetHeap()->incremental_marking()->RecordWrite( |
1256 GetHeap()->incremental_marking()->RecordWrite(this, val); | 1259 this, HeapObject::RawField(this, kValueOffset), val); |
1257 } | 1260 } |
1258 | 1261 |
1259 | 1262 |
1260 int JSObject::GetHeaderSize() { | 1263 int JSObject::GetHeaderSize() { |
1261 InstanceType type = map()->instance_type(); | 1264 InstanceType type = map()->instance_type(); |
1262 // Check for the most common kind of JavaScript object before | 1265 // Check for the most common kind of JavaScript object before |
1263 // falling into the generic switch. This speeds up the internal | 1266 // falling into the generic switch. This speeds up the internal |
1264 // field operations considerably on average. | 1267 // field operations considerably on average. |
1265 if (type == JS_OBJECT_TYPE) return JSObject::kHeaderSize; | 1268 if (type == JS_OBJECT_TYPE) return JSObject::kHeaderSize; |
1266 switch (type) { | 1269 switch (type) { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 WRITE_FIELD(this, offset, value); | 1490 WRITE_FIELD(this, offset, value); |
1488 WRITE_BARRIER(GetHeap(), this, offset, value); | 1491 WRITE_BARRIER(GetHeap(), this, offset, value); |
1489 } | 1492 } |
1490 | 1493 |
1491 | 1494 |
1492 void FixedArray::fast_set(FixedArray* array, int index, Object* value) { | 1495 void FixedArray::fast_set(FixedArray* array, int index, Object* value) { |
1493 ASSERT(array->map() != HEAP->raw_unchecked_fixed_cow_array_map()); | 1496 ASSERT(array->map() != HEAP->raw_unchecked_fixed_cow_array_map()); |
1494 ASSERT(index >= 0 && index < array->length()); | 1497 ASSERT(index >= 0 && index < array->length()); |
1495 ASSERT(!HEAP->InNewSpace(value)); | 1498 ASSERT(!HEAP->InNewSpace(value)); |
1496 WRITE_FIELD(array, kHeaderSize + index * kPointerSize, value); | 1499 WRITE_FIELD(array, kHeaderSize + index * kPointerSize, value); |
1497 array->GetHeap()->incremental_marking()->RecordWrite(array, value); | 1500 array->GetHeap()->incremental_marking()->RecordWrite( |
| 1501 array, |
| 1502 HeapObject::RawField(array, kHeaderSize + index * kPointerSize), |
| 1503 value); |
1498 } | 1504 } |
1499 | 1505 |
1500 | 1506 |
1501 void FixedArray::set_undefined(int index) { | 1507 void FixedArray::set_undefined(int index) { |
1502 ASSERT(map() != HEAP->fixed_cow_array_map()); | 1508 ASSERT(map() != HEAP->fixed_cow_array_map()); |
1503 set_undefined(GetHeap(), index); | 1509 set_undefined(GetHeap(), index); |
1504 } | 1510 } |
1505 | 1511 |
1506 | 1512 |
1507 void FixedArray::set_undefined(Heap* heap, int index) { | 1513 void FixedArray::set_undefined(Heap* heap, int index) { |
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2899 } | 2905 } |
2900 } | 2906 } |
2901 | 2907 |
2902 | 2908 |
2903 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) | 2909 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) |
2904 ACCESSORS(Map, prototype_transitions, FixedArray, kPrototypeTransitionsOffset) | 2910 ACCESSORS(Map, prototype_transitions, FixedArray, kPrototypeTransitionsOffset) |
2905 ACCESSORS(Map, constructor, Object, kConstructorOffset) | 2911 ACCESSORS(Map, constructor, Object, kConstructorOffset) |
2906 | 2912 |
2907 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) | 2913 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) |
2908 ACCESSORS(JSFunction, literals, FixedArray, kLiteralsOffset) | 2914 ACCESSORS(JSFunction, literals, FixedArray, kLiteralsOffset) |
2909 ACCESSORS_GCSAFE(JSFunction, | 2915 ACCESSORS(JSFunction, |
2910 next_function_link, | 2916 next_function_link, |
2911 Object, | 2917 Object, |
2912 kNextFunctionLinkOffset) | 2918 kNextFunctionLinkOffset) |
2913 | 2919 |
2914 ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) | 2920 ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) |
2915 ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) | 2921 ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) |
2916 ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) | 2922 ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) |
2917 | 2923 |
2918 ACCESSORS(JSGlobalProxy, context, Object, kContextOffset) | 2924 ACCESSORS(JSGlobalProxy, context, Object, kContextOffset) |
2919 | 2925 |
2920 ACCESSORS(AccessorInfo, getter, Object, kGetterOffset) | 2926 ACCESSORS(AccessorInfo, getter, Object, kGetterOffset) |
2921 ACCESSORS(AccessorInfo, setter, Object, kSetterOffset) | 2927 ACCESSORS(AccessorInfo, setter, Object, kSetterOffset) |
2922 ACCESSORS(AccessorInfo, data, Object, kDataOffset) | 2928 ACCESSORS(AccessorInfo, data, Object, kDataOffset) |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3325 return reinterpret_cast<Code*>( | 3331 return reinterpret_cast<Code*>( |
3326 Code::GetObjectFromEntryAddress(FIELD_ADDR(this, kCodeEntryOffset))); | 3332 Code::GetObjectFromEntryAddress(FIELD_ADDR(this, kCodeEntryOffset))); |
3327 } | 3333 } |
3328 | 3334 |
3329 | 3335 |
3330 void JSFunction::set_code(Code* value) { | 3336 void JSFunction::set_code(Code* value) { |
3331 // Skip the write barrier because code is never in new space. | 3337 // Skip the write barrier because code is never in new space. |
3332 ASSERT(!HEAP->InNewSpace(value)); | 3338 ASSERT(!HEAP->InNewSpace(value)); |
3333 Address entry = value->entry(); | 3339 Address entry = value->entry(); |
3334 WRITE_INTPTR_FIELD(this, kCodeEntryOffset, reinterpret_cast<intptr_t>(entry)); | 3340 WRITE_INTPTR_FIELD(this, kCodeEntryOffset, reinterpret_cast<intptr_t>(entry)); |
3335 GetHeap()->incremental_marking()->RecordWrite(this, value); | 3341 GetHeap()->incremental_marking()->RecordWrite( |
| 3342 this, |
| 3343 HeapObject::RawField(this, kCodeEntryOffset), |
| 3344 value); |
3336 } | 3345 } |
3337 | 3346 |
3338 | 3347 |
3339 void JSFunction::ReplaceCode(Code* code) { | 3348 void JSFunction::ReplaceCode(Code* code) { |
3340 bool was_optimized = IsOptimized(); | 3349 bool was_optimized = IsOptimized(); |
3341 bool is_optimized = code->kind() == Code::OPTIMIZED_FUNCTION; | 3350 bool is_optimized = code->kind() == Code::OPTIMIZED_FUNCTION; |
3342 | 3351 |
3343 set_code(code); | 3352 set_code(code); |
3344 | 3353 |
3345 // Add/remove the function from the list of optimized functions for this | 3354 // Add/remove the function from the list of optimized functions for this |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4165 #undef WRITE_INT_FIELD | 4174 #undef WRITE_INT_FIELD |
4166 #undef READ_SHORT_FIELD | 4175 #undef READ_SHORT_FIELD |
4167 #undef WRITE_SHORT_FIELD | 4176 #undef WRITE_SHORT_FIELD |
4168 #undef READ_BYTE_FIELD | 4177 #undef READ_BYTE_FIELD |
4169 #undef WRITE_BYTE_FIELD | 4178 #undef WRITE_BYTE_FIELD |
4170 | 4179 |
4171 | 4180 |
4172 } } // namespace v8::internal | 4181 } } // namespace v8::internal |
4173 | 4182 |
4174 #endif // V8_OBJECTS_INL_H_ | 4183 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |