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

Side by Side Diff: src/heap.cc

Issue 24261012: Remove duplicated heap allocation functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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/heap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2893 matching lines...) Expand 10 before | Expand all | Expand 10 after
2904 AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE); 2904 AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
2905 if (!maybe_result->ToObject(&result)) return maybe_result; 2905 if (!maybe_result->ToObject(&result)) return maybe_result;
2906 } 2906 }
2907 2907
2908 HeapObject::cast(result)->set_map_no_write_barrier(heap_number_map()); 2908 HeapObject::cast(result)->set_map_no_write_barrier(heap_number_map());
2909 HeapNumber::cast(result)->set_value(value); 2909 HeapNumber::cast(result)->set_value(value);
2910 return result; 2910 return result;
2911 } 2911 }
2912 2912
2913 2913
2914 MaybeObject* Heap::AllocateHeapNumber(double value) {
2915 // Use general version, if we're forced to always allocate.
2916 if (always_allocate()) return AllocateHeapNumber(value, TENURED);
2917
2918 // This version of AllocateHeapNumber is optimized for
2919 // allocation in new space.
2920 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxNonCodeHeapObjectSize);
2921 Object* result;
2922 { MaybeObject* maybe_result = new_space_.AllocateRaw(HeapNumber::kSize);
2923 if (!maybe_result->ToObject(&result)) return maybe_result;
2924 }
2925 HeapObject::cast(result)->set_map_no_write_barrier(heap_number_map());
2926 HeapNumber::cast(result)->set_value(value);
2927 return result;
2928 }
2929
2930
2931 MaybeObject* Heap::AllocateCell(Object* value) { 2914 MaybeObject* Heap::AllocateCell(Object* value) {
2932 Object* result; 2915 Object* result;
2933 { MaybeObject* maybe_result = AllocateRawCell(); 2916 { MaybeObject* maybe_result = AllocateRawCell();
2934 if (!maybe_result->ToObject(&result)) return maybe_result; 2917 if (!maybe_result->ToObject(&result)) return maybe_result;
2935 } 2918 }
2936 HeapObject::cast(result)->set_map_no_write_barrier(cell_map()); 2919 HeapObject::cast(result)->set_map_no_write_barrier(cell_map());
2937 Cell::cast(result)->set_value(value); 2920 Cell::cast(result)->set_value(value);
2938 return result; 2921 return result;
2939 } 2922 }
2940 2923
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after
4058 String* answer = String::cast(result); 4041 String* answer = String::cast(result);
4059 answer->Set(0, code); 4042 answer->Set(0, code);
4060 return answer; 4043 return answer;
4061 } 4044 }
4062 4045
4063 4046
4064 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 4047 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
4065 if (length < 0 || length > ByteArray::kMaxLength) { 4048 if (length < 0 || length > ByteArray::kMaxLength) {
4066 return Failure::OutOfMemoryException(0x7); 4049 return Failure::OutOfMemoryException(0x7);
4067 } 4050 }
4068 if (pretenure == NOT_TENURED) {
4069 return AllocateByteArray(length);
4070 }
4071 int size = ByteArray::SizeFor(length); 4051 int size = ByteArray::SizeFor(length);
4072 AllocationSpace space = 4052 AllocationSpace space =
4073 (size > Page::kMaxNonCodeHeapObjectSize) ? LO_SPACE : OLD_DATA_SPACE; 4053 (size > Page::kMaxNonCodeHeapObjectSize) ? LO_SPACE : OLD_DATA_SPACE;
4074 Object* result; 4054 Object* result;
4075 { MaybeObject* maybe_result = AllocateRaw(size, space, space); 4055 { MaybeObject* maybe_result = AllocateRaw(size, space, space);
4076 if (!maybe_result->ToObject(&result)) return maybe_result; 4056 if (!maybe_result->ToObject(&result)) return maybe_result;
4077 } 4057 }
4078 4058
4079 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier( 4059 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier(
4080 byte_array_map()); 4060 byte_array_map());
4081 reinterpret_cast<ByteArray*>(result)->set_length(length); 4061 reinterpret_cast<ByteArray*>(result)->set_length(length);
4082 return result; 4062 return result;
4083 } 4063 }
4084 4064
4085 4065
4086 MaybeObject* Heap::AllocateByteArray(int length) {
4087 if (length < 0 || length > ByteArray::kMaxLength) {
4088 return Failure::OutOfMemoryException(0x8);
4089 }
4090 int size = ByteArray::SizeFor(length);
4091 AllocationSpace space =
4092 (size > Page::kMaxNonCodeHeapObjectSize) ? LO_SPACE : NEW_SPACE;
4093 Object* result;
4094 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
4095 if (!maybe_result->ToObject(&result)) return maybe_result;
4096 }
4097
4098 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier(
4099 byte_array_map());
4100 reinterpret_cast<ByteArray*>(result)->set_length(length);
4101 return result;
4102 }
4103
4104
4105 void Heap::CreateFillerObjectAt(Address addr, int size) { 4066 void Heap::CreateFillerObjectAt(Address addr, int size) {
4106 if (size == 0) return; 4067 if (size == 0) return;
4107 HeapObject* filler = HeapObject::FromAddress(addr); 4068 HeapObject* filler = HeapObject::FromAddress(addr);
4108 if (size == kPointerSize) { 4069 if (size == kPointerSize) {
4109 filler->set_map_no_write_barrier(one_pointer_filler_map()); 4070 filler->set_map_no_write_barrier(one_pointer_filler_map());
4110 } else if (size == 2 * kPointerSize) { 4071 } else if (size == 2 * kPointerSize) {
4111 filler->set_map_no_write_barrier(two_pointer_filler_map()); 4072 filler->set_map_no_write_barrier(two_pointer_filler_map());
4112 } else { 4073 } else {
4113 filler->set_map_no_write_barrier(free_space_map()); 4074 filler->set_map_no_write_barrier(free_space_map());
4114 FreeSpace::cast(filler)->set_size(size); 4075 FreeSpace::cast(filler)->set_size(size);
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after
5445 HeapObject* dst = HeapObject::cast(obj); 5406 HeapObject* dst = HeapObject::cast(obj);
5446 dst->set_map_no_write_barrier(map); 5407 dst->set_map_no_write_barrier(map);
5447 CopyBlock( 5408 CopyBlock(
5448 dst->address() + FixedDoubleArray::kLengthOffset, 5409 dst->address() + FixedDoubleArray::kLengthOffset,
5449 src->address() + FixedDoubleArray::kLengthOffset, 5410 src->address() + FixedDoubleArray::kLengthOffset,
5450 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); 5411 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset);
5451 return obj; 5412 return obj;
5452 } 5413 }
5453 5414
5454 5415
5455 MaybeObject* Heap::AllocateFixedArray(int length) {
5456 ASSERT(length >= 0);
5457 if (length == 0) return empty_fixed_array();
5458 Object* result;
5459 { MaybeObject* maybe_result = AllocateRawFixedArray(length);
5460 if (!maybe_result->ToObject(&result)) return maybe_result;
5461 }
5462 // Initialize header.
5463 FixedArray* array = reinterpret_cast<FixedArray*>(result);
5464 array->set_map_no_write_barrier(fixed_array_map());
5465 array->set_length(length);
5466 // Initialize body.
5467 ASSERT(!InNewSpace(undefined_value()));
5468 MemsetPointer(array->data_start(), undefined_value(), length);
5469 return result;
5470 }
5471
5472
5473 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { 5416 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) {
5474 if (length < 0 || length > FixedArray::kMaxLength) { 5417 if (length < 0 || length > FixedArray::kMaxLength) {
5475 return Failure::OutOfMemoryException(0xe); 5418 return Failure::OutOfMemoryException(0xe);
5476 } 5419 }
5477 int size = FixedArray::SizeFor(length); 5420 int size = FixedArray::SizeFor(length);
5478 AllocationSpace space = 5421 AllocationSpace space =
5479 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 5422 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
5480 AllocationSpace retry_space = OLD_POINTER_SPACE; 5423 AllocationSpace retry_space = OLD_POINTER_SPACE;
5481 5424
5482 if (size > Page::kMaxNonCodeHeapObjectSize) { 5425 if (size > Page::kMaxNonCodeHeapObjectSize) {
(...skipping 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after
7987 if (FLAG_concurrent_recompilation) { 7930 if (FLAG_concurrent_recompilation) {
7988 heap_->relocation_mutex_->Lock(); 7931 heap_->relocation_mutex_->Lock();
7989 #ifdef DEBUG 7932 #ifdef DEBUG
7990 heap_->relocation_mutex_locked_by_optimizer_thread_ = 7933 heap_->relocation_mutex_locked_by_optimizer_thread_ =
7991 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); 7934 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread();
7992 #endif // DEBUG 7935 #endif // DEBUG
7993 } 7936 }
7994 } 7937 }
7995 7938
7996 } } // namespace v8::internal 7939 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698