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

Side by Side Diff: src/heap.cc

Issue 203583007: Support weak heap references in the ConstantPool to support IsWeakObjectInOptimizedCode objects. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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
OLDNEW
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 4037 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 bool crankshafted, 4048 bool crankshafted,
4049 int prologue_offset) { 4049 int prologue_offset) {
4050 // Allocate ByteArray and ConstantPoolArray before the Code object, so that we 4050 // Allocate ByteArray and ConstantPoolArray before the Code object, so that we
4051 // do not risk leaving uninitialized Code object (and breaking the heap). 4051 // do not risk leaving uninitialized Code object (and breaking the heap).
4052 ByteArray* reloc_info; 4052 ByteArray* reloc_info;
4053 MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED); 4053 MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED);
4054 if (!maybe_reloc_info->To(&reloc_info)) return maybe_reloc_info; 4054 if (!maybe_reloc_info->To(&reloc_info)) return maybe_reloc_info;
4055 4055
4056 ConstantPoolArray* constant_pool; 4056 ConstantPoolArray* constant_pool;
4057 if (FLAG_enable_ool_constant_pool) { 4057 if (FLAG_enable_ool_constant_pool) {
4058 MaybeObject* maybe_constant_pool = desc.origin->AllocateConstantPool(this); 4058 MaybeObject* maybe_constant_pool =
4059 desc.origin->AllocateConstantPool(this, crankshafted);
4059 if (!maybe_constant_pool->To(&constant_pool)) return maybe_constant_pool; 4060 if (!maybe_constant_pool->To(&constant_pool)) return maybe_constant_pool;
4060 } else { 4061 } else {
4061 constant_pool = empty_constant_pool_array(); 4062 constant_pool = empty_constant_pool_array();
4062 } 4063 }
4063 4064
4064 // Compute size. 4065 // Compute size.
4065 int body_size = RoundUp(desc.instr_size, kObjectAlignment); 4066 int body_size = RoundUp(desc.instr_size, kObjectAlignment);
4066 int obj_size = Code::SizeFor(body_size); 4067 int obj_size = Code::SizeFor(body_size);
4067 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); 4068 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment));
4068 MaybeObject* maybe_result; 4069 MaybeObject* maybe_result;
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
5157 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); 5158 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset);
5158 return obj; 5159 return obj;
5159 } 5160 }
5160 5161
5161 5162
5162 MaybeObject* Heap::CopyConstantPoolArrayWithMap(ConstantPoolArray* src, 5163 MaybeObject* Heap::CopyConstantPoolArrayWithMap(ConstantPoolArray* src,
5163 Map* map) { 5164 Map* map) {
5164 int int64_entries = src->count_of_int64_entries(); 5165 int int64_entries = src->count_of_int64_entries();
5165 int code_ptr_entries = src->count_of_code_ptr_entries(); 5166 int code_ptr_entries = src->count_of_code_ptr_entries();
5166 int heap_ptr_entries = src->count_of_heap_ptr_entries(); 5167 int heap_ptr_entries = src->count_of_heap_ptr_entries();
5168 int weak_ptr_entries = src->count_of_weak_ptr_entries();
5167 int int32_entries = src->count_of_int32_entries(); 5169 int int32_entries = src->count_of_int32_entries();
5168 Object* obj; 5170 Object* obj;
5169 { MaybeObject* maybe_obj = 5171 { MaybeObject* maybe_obj = AllocateConstantPoolArray(int64_entries,
5170 AllocateConstantPoolArray(int64_entries, code_ptr_entries, 5172 code_ptr_entries, heap_ptr_entries, weak_ptr_entries, int32_entries);
5171 heap_ptr_entries, int32_entries);
5172 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 5173 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
5173 } 5174 }
5174 HeapObject* dst = HeapObject::cast(obj); 5175 HeapObject* dst = HeapObject::cast(obj);
5175 dst->set_map_no_write_barrier(map); 5176 dst->set_map_no_write_barrier(map);
5176 int size = ConstantPoolArray::SizeFor( 5177 int size = ConstantPoolArray::SizeFor(int64_entries,
5177 int64_entries, code_ptr_entries, heap_ptr_entries, int32_entries); 5178 code_ptr_entries + heap_ptr_entries + weak_ptr_entries, int32_entries);
5178 CopyBlock( 5179 CopyBlock(
5179 dst->address() + ConstantPoolArray::kLengthOffset, 5180 dst->address() + ConstantPoolArray::kLengthOffset,
5180 src->address() + ConstantPoolArray::kLengthOffset, 5181 src->address() + ConstantPoolArray::kLengthOffset,
5181 size - ConstantPoolArray::kLengthOffset); 5182 size - ConstantPoolArray::kLengthOffset);
5182 return obj; 5183 return obj;
5183 } 5184 }
5184 5185
5185 5186
5186 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { 5187 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) {
5187 if (length < 0 || length > FixedArray::kMaxLength) { 5188 if (length < 0 || length > FixedArray::kMaxLength) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
5310 if (!maybe_object->To<HeapObject>(&object)) return maybe_object; 5311 if (!maybe_object->To<HeapObject>(&object)) return maybe_object;
5311 } 5312 }
5312 5313
5313 return EnsureDoubleAligned(this, object, size); 5314 return EnsureDoubleAligned(this, object, size);
5314 } 5315 }
5315 5316
5316 5317
5317 MaybeObject* Heap::AllocateConstantPoolArray(int number_of_int64_entries, 5318 MaybeObject* Heap::AllocateConstantPoolArray(int number_of_int64_entries,
5318 int number_of_code_ptr_entries, 5319 int number_of_code_ptr_entries,
5319 int number_of_heap_ptr_entries, 5320 int number_of_heap_ptr_entries,
5321 int number_of_weak_ptr_entries,
5320 int number_of_int32_entries) { 5322 int number_of_int32_entries) {
5321 ASSERT(number_of_int64_entries > 0 || number_of_code_ptr_entries > 0 || 5323 ASSERT(number_of_int64_entries > 0 || number_of_code_ptr_entries > 0 ||
5322 number_of_heap_ptr_entries > 0 || number_of_int32_entries > 0); 5324 number_of_heap_ptr_entries > 0 || number_of_weak_ptr_entries > 0 ||
5325 number_of_int32_entries > 0);
5326 int number_of_ptr_entries = number_of_code_ptr_entries +
5327 number_of_heap_ptr_entries + number_of_weak_ptr_entries;
5323 int size = ConstantPoolArray::SizeFor(number_of_int64_entries, 5328 int size = ConstantPoolArray::SizeFor(number_of_int64_entries,
5324 number_of_code_ptr_entries, 5329 number_of_ptr_entries,
5325 number_of_heap_ptr_entries,
5326 number_of_int32_entries); 5330 number_of_int32_entries);
5327 #ifndef V8_HOST_ARCH_64_BIT 5331 #ifndef V8_HOST_ARCH_64_BIT
5328 size += kPointerSize; 5332 size += kPointerSize;
5329 #endif 5333 #endif
5330 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED); 5334 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED);
5331 5335
5332 HeapObject* object; 5336 HeapObject* object;
5333 { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_POINTER_SPACE); 5337 { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_POINTER_SPACE);
5334 if (!maybe_object->To<HeapObject>(&object)) return maybe_object; 5338 if (!maybe_object->To<HeapObject>(&object)) return maybe_object;
5335 } 5339 }
5336 object = EnsureDoubleAligned(this, object, size); 5340 object = EnsureDoubleAligned(this, object, size);
5337 HeapObject::cast(object)->set_map_no_write_barrier(constant_pool_array_map()); 5341 HeapObject::cast(object)->set_map_no_write_barrier(constant_pool_array_map());
5338 5342
5339 ConstantPoolArray* constant_pool = 5343 ConstantPoolArray* constant_pool =
5340 reinterpret_cast<ConstantPoolArray*>(object); 5344 reinterpret_cast<ConstantPoolArray*>(object);
5341 constant_pool->SetEntryCounts(number_of_int64_entries, 5345 constant_pool->SetEntryCounts(number_of_int64_entries,
5342 number_of_code_ptr_entries, 5346 number_of_code_ptr_entries,
5343 number_of_heap_ptr_entries, 5347 number_of_heap_ptr_entries,
5348 number_of_weak_ptr_entries,
5344 number_of_int32_entries); 5349 number_of_int32_entries);
5345 if (number_of_code_ptr_entries > 0) { 5350 if (number_of_code_ptr_entries > 0) {
5346 int offset = 5351 int offset =
5347 constant_pool->OffsetOfElementAt(constant_pool->first_code_ptr_index()); 5352 constant_pool->OffsetOfElementAt(constant_pool->first_code_ptr_index());
5348 MemsetPointer( 5353 MemsetPointer(
5349 reinterpret_cast<Address*>(HeapObject::RawField(constant_pool, offset)), 5354 reinterpret_cast<Address*>(HeapObject::RawField(constant_pool, offset)),
5350 isolate()->builtins()->builtin(Builtins::kIllegal)->entry(), 5355 isolate()->builtins()->builtin(Builtins::kIllegal)->entry(),
5351 number_of_code_ptr_entries); 5356 number_of_code_ptr_entries);
5352 } 5357 }
5353 if (number_of_heap_ptr_entries > 0) { 5358 if (number_of_heap_ptr_entries > 0 || number_of_weak_ptr_entries > 0) {
5354 int offset = 5359 int offset =
5355 constant_pool->OffsetOfElementAt(constant_pool->first_heap_ptr_index()); 5360 constant_pool->OffsetOfElementAt(constant_pool->first_heap_ptr_index());
5356 MemsetPointer( 5361 MemsetPointer(
5357 HeapObject::RawField(constant_pool, offset), 5362 HeapObject::RawField(constant_pool, offset),
5358 undefined_value(), 5363 undefined_value(),
5359 number_of_heap_ptr_entries); 5364 number_of_heap_ptr_entries + number_of_weak_ptr_entries);
5360 } 5365 }
5361 return constant_pool; 5366 return constant_pool;
5362 } 5367 }
5363 5368
5364 5369
5365 MaybeObject* Heap::AllocateEmptyConstantPoolArray() { 5370 MaybeObject* Heap::AllocateEmptyConstantPoolArray() {
5366 int size = ConstantPoolArray::SizeFor(0, 0, 0, 0); 5371 int size = ConstantPoolArray::SizeFor(0, 0, 0);
5367 Object* result; 5372 Object* result;
5368 { MaybeObject* maybe_result = 5373 { MaybeObject* maybe_result =
5369 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); 5374 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
5370 if (!maybe_result->ToObject(&result)) return maybe_result; 5375 if (!maybe_result->ToObject(&result)) return maybe_result;
5371 } 5376 }
5372 HeapObject::cast(result)->set_map_no_write_barrier(constant_pool_array_map()); 5377 HeapObject::cast(result)->set_map_no_write_barrier(constant_pool_array_map());
5373 ConstantPoolArray::cast(result)->SetEntryCounts(0, 0, 0, 0); 5378 ConstantPoolArray::cast(result)->SetEntryCounts(0, 0, 0, 0, 0);
5374 return result; 5379 return result;
5375 } 5380 }
5376 5381
5377 5382
5378 MaybeObject* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { 5383 MaybeObject* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
5379 Object* result; 5384 Object* result;
5380 { MaybeObject* maybe_result = AllocateFixedArray(length, pretenure); 5385 { MaybeObject* maybe_result = AllocateFixedArray(length, pretenure);
5381 if (!maybe_result->ToObject(&result)) return maybe_result; 5386 if (!maybe_result->ToObject(&result)) return maybe_result;
5382 } 5387 }
5383 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier( 5388 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(
(...skipping 2406 matching lines...) Expand 10 before | Expand all | Expand 10 after
7790 static_cast<int>(object_sizes_last_time_[index])); 7795 static_cast<int>(object_sizes_last_time_[index]));
7791 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7796 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7792 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7797 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7793 7798
7794 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7799 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7795 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7800 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7796 ClearObjectStats(); 7801 ClearObjectStats();
7797 } 7802 }
7798 7803
7799 } } // namespace v8::internal 7804 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/objects.h » ('j') | src/objects-visiting-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698