Introduce Heap::SelectSpace helper for allocations.

R=hpayer@chromium.org

Review URL: https://codereview.chromium.org/22925004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16894 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fc21795a
...@@ -140,12 +140,11 @@ MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str, ...@@ -140,12 +140,11 @@ MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str,
// Compute map and object size. // Compute map and object size.
Map* map = ascii_internalized_string_map(); Map* map = ascii_internalized_string_map();
int size = SeqOneByteString::SizeFor(str.length()); int size = SeqOneByteString::SizeFor(str.length());
AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED);
// Allocate string. // Allocate string.
Object* result; Object* result;
{ MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
? lo_space_->AllocateRaw(size, NOT_EXECUTABLE)
: old_data_space_->AllocateRaw(size);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
} }
...@@ -174,12 +173,11 @@ MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, ...@@ -174,12 +173,11 @@ MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str,
// Compute map and object size. // Compute map and object size.
Map* map = internalized_string_map(); Map* map = internalized_string_map();
int size = SeqTwoByteString::SizeFor(str.length()); int size = SeqTwoByteString::SizeFor(str.length());
AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED);
// Allocate string. // Allocate string.
Object* result; Object* result;
{ MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
? lo_space_->AllocateRaw(size, NOT_EXECUTABLE)
: old_data_space_->AllocateRaw(size);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
} }
......
...@@ -2896,12 +2896,12 @@ bool Heap::CreateInitialMaps() { ...@@ -2896,12 +2896,12 @@ bool Heap::CreateInitialMaps() {
MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
// Statically ensure that it is safe to allocate heap numbers in paged // Statically ensure that it is safe to allocate heap numbers in paged
// spaces. // spaces.
int size = HeapNumber::kSize;
STATIC_ASSERT(HeapNumber::kSize <= Page::kNonCodeObjectAreaSize); STATIC_ASSERT(HeapNumber::kSize <= Page::kNonCodeObjectAreaSize);
AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
Object* result; Object* result;
{ MaybeObject* maybe_result = { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
} }
...@@ -4065,31 +4065,8 @@ MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { ...@@ -4065,31 +4065,8 @@ MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
if (length < 0 || length > ByteArray::kMaxLength) { if (length < 0 || length > ByteArray::kMaxLength) {
return Failure::OutOfMemoryException(0x7); return Failure::OutOfMemoryException(0x7);
} }
if (pretenure == NOT_TENURED) {
return AllocateByteArray(length);
}
int size = ByteArray::SizeFor(length);
AllocationSpace space =
(size > Page::kMaxNonCodeHeapObjectSize) ? LO_SPACE : OLD_DATA_SPACE;
Object* result;
{ MaybeObject* maybe_result = AllocateRaw(size, space, space);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier(
byte_array_map());
reinterpret_cast<ByteArray*>(result)->set_length(length);
return result;
}
MaybeObject* Heap::AllocateByteArray(int length) {
if (length < 0 || length > ByteArray::kMaxLength) {
return Failure::OutOfMemoryException(0x8);
}
int size = ByteArray::SizeFor(length); int size = ByteArray::SizeFor(length);
AllocationSpace space = AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
(size > Page::kMaxNonCodeHeapObjectSize) ? LO_SPACE : NEW_SPACE;
Object* result; Object* result;
{ MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
...@@ -4120,11 +4097,10 @@ MaybeObject* Heap::AllocateExternalArray(int length, ...@@ -4120,11 +4097,10 @@ MaybeObject* Heap::AllocateExternalArray(int length,
ExternalArrayType array_type, ExternalArrayType array_type,
void* external_pointer, void* external_pointer,
PretenureFlag pretenure) { PretenureFlag pretenure) {
AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; int size = ExternalArray::kAlignedSize;
AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
Object* result; Object* result;
{ MaybeObject* maybe_result = AllocateRaw(ExternalArray::kAlignedSize, { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
space,
OLD_DATA_SPACE);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
} }
...@@ -4562,9 +4538,8 @@ MaybeObject* Heap::AllocateJSObjectFromMap( ...@@ -4562,9 +4538,8 @@ MaybeObject* Heap::AllocateJSObjectFromMap(
} }
// Allocate the JSObject. // Allocate the JSObject.
AllocationSpace space = int size = map->instance_size();
(pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure);
if (map->instance_size() > Page::kMaxNonCodeHeapObjectSize) space = LO_SPACE;
Object* obj; Object* obj;
MaybeObject* maybe_obj = Allocate(map, space); MaybeObject* maybe_obj = Allocate(map, space);
if (!maybe_obj->To(&obj)) return maybe_obj; if (!maybe_obj->To(&obj)) return maybe_obj;
...@@ -4597,8 +4572,8 @@ MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite( ...@@ -4597,8 +4572,8 @@ MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite(
} }
// Allocate the JSObject. // Allocate the JSObject.
AllocationSpace space = NEW_SPACE; int size = map->instance_size();
if (map->instance_size() > Page::kMaxNonCodeHeapObjectSize) space = LO_SPACE; AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, NOT_TENURED);
Object* obj; Object* obj;
MaybeObject* maybe_obj = MaybeObject* maybe_obj =
AllocateWithAllocationSite(map, space, allocation_site); AllocateWithAllocationSite(map, space, allocation_site);
...@@ -5266,12 +5241,11 @@ MaybeObject* Heap::AllocateInternalizedStringImpl( ...@@ -5266,12 +5241,11 @@ MaybeObject* Heap::AllocateInternalizedStringImpl(
map = internalized_string_map(); map = internalized_string_map();
size = SeqTwoByteString::SizeFor(chars); size = SeqTwoByteString::SizeFor(chars);
} }
AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED);
// Allocate string. // Allocate string.
Object* result; Object* result;
{ MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
? lo_space_->AllocateRaw(size, NOT_EXECUTABLE)
: old_data_space_->AllocateRaw(size);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
} }
...@@ -5310,16 +5284,10 @@ MaybeObject* Heap::AllocateRawOneByteString(int length, ...@@ -5310,16 +5284,10 @@ MaybeObject* Heap::AllocateRawOneByteString(int length,
} }
int size = SeqOneByteString::SizeFor(length); int size = SeqOneByteString::SizeFor(length);
ASSERT(size <= SeqOneByteString::kMaxSize); ASSERT(size <= SeqOneByteString::kMaxSize);
AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
AllocationSpace retry_space = OLD_DATA_SPACE;
if (size > Page::kMaxNonCodeHeapObjectSize) {
// Allocate in large object space, retry space will be ignored.
space = LO_SPACE;
}
Object* result; Object* result;
{ MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
} }
...@@ -5340,16 +5308,10 @@ MaybeObject* Heap::AllocateRawTwoByteString(int length, ...@@ -5340,16 +5308,10 @@ MaybeObject* Heap::AllocateRawTwoByteString(int length,
} }
int size = SeqTwoByteString::SizeFor(length); int size = SeqTwoByteString::SizeFor(length);
ASSERT(size <= SeqTwoByteString::kMaxSize); ASSERT(size <= SeqTwoByteString::kMaxSize);
AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
AllocationSpace retry_space = OLD_DATA_SPACE;
if (size > Page::kMaxNonCodeHeapObjectSize) {
// Allocate in large object space, retry space will be ignored.
space = LO_SPACE;
}
Object* result; Object* result;
{ MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
} }
...@@ -5475,16 +5437,9 @@ MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { ...@@ -5475,16 +5437,9 @@ MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) {
return Failure::OutOfMemoryException(0xe); return Failure::OutOfMemoryException(0xe);
} }
int size = FixedArray::SizeFor(length); int size = FixedArray::SizeFor(length);
AllocationSpace space = AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure);
(pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
AllocationSpace retry_space = OLD_POINTER_SPACE;
if (size > Page::kMaxNonCodeHeapObjectSize) {
// Allocate in large object space, retry space will be ignored.
space = LO_SPACE;
}
return AllocateRaw(size, space, retry_space); return AllocateRaw(size, space, OLD_POINTER_SPACE);
} }
...@@ -5602,20 +5557,13 @@ MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, ...@@ -5602,20 +5557,13 @@ MaybeObject* Heap::AllocateRawFixedDoubleArray(int length,
return Failure::OutOfMemoryException(0xf); return Failure::OutOfMemoryException(0xf);
} }
int size = FixedDoubleArray::SizeFor(length); int size = FixedDoubleArray::SizeFor(length);
AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
AllocationSpace retry_space = OLD_DATA_SPACE;
#ifndef V8_HOST_ARCH_64_BIT #ifndef V8_HOST_ARCH_64_BIT
size += kPointerSize; size += kPointerSize;
#endif #endif
AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
if (size > Page::kMaxNonCodeHeapObjectSize) {
// Allocate in large object space, retry space will be ignored.
space = LO_SPACE;
}
HeapObject* object; HeapObject* object;
{ MaybeObject* maybe_object = AllocateRaw(size, space, retry_space); { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_DATA_SPACE);
if (!maybe_object->To<HeapObject>(&object)) return maybe_object; if (!maybe_object->To<HeapObject>(&object)) return maybe_object;
} }
...@@ -5819,8 +5767,7 @@ STRUCT_LIST(MAKE_CASE) ...@@ -5819,8 +5767,7 @@ STRUCT_LIST(MAKE_CASE)
return Failure::InternalError(); return Failure::InternalError();
} }
int size = map->instance_size(); int size = map->instance_size();
AllocationSpace space = AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED);
(size > Page::kMaxNonCodeHeapObjectSize) ? LO_SPACE : OLD_POINTER_SPACE;
Object* result; Object* result;
{ MaybeObject* maybe_result = Allocate(map, space); { MaybeObject* maybe_result = Allocate(map, space);
if (!maybe_result->ToObject(&result)) return maybe_result; if (!maybe_result->ToObject(&result)) return maybe_result;
......
...@@ -864,14 +864,9 @@ class Heap { ...@@ -864,14 +864,9 @@ class Heap {
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
// failed. // failed.
// Please note this does not perform a garbage collection. // Please note this does not perform a garbage collection.
MUST_USE_RESULT MaybeObject* AllocateByteArray(int length, MUST_USE_RESULT MaybeObject* AllocateByteArray(
PretenureFlag pretenure); int length,
PretenureFlag pretenure = NOT_TENURED);
// Allocate a non-tenured byte array of the specified length
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
// failed.
// Please note this does not perform a garbage collection.
MUST_USE_RESULT MaybeObject* AllocateByteArray(int length);
// Allocates an external array of the specified length and type. // Allocates an external array of the specified length and type.
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
...@@ -2066,6 +2061,17 @@ class Heap { ...@@ -2066,6 +2061,17 @@ class Heap {
inline void UpdateOldSpaceLimits(); inline void UpdateOldSpaceLimits();
// Selects the proper allocation space depending on the given object
// size, pretenuring decision, and preferred old-space.
static AllocationSpace SelectSpace(int object_size,
AllocationSpace preferred_old_space,
PretenureFlag pretenure) {
ASSERT(preferred_old_space == OLD_POINTER_SPACE ||
preferred_old_space == OLD_DATA_SPACE);
if (object_size > Page::kMaxNonCodeHeapObjectSize) return LO_SPACE;
return (pretenure == TENURED) ? preferred_old_space : NEW_SPACE;
}
// Allocate an uninitialized object in map space. The behavior is identical // Allocate an uninitialized object in map space. The behavior is identical
// to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't // to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't
// have to test the allocation space argument and (b) can reduce code size // have to test the allocation space argument and (b) can reduce code size
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment