Reviewers: Vyacheslav Egorov,
Message:
PTAL.
Description:
Limited the size of transition arrays so they never end up in the large
object
space.
Also renamed SizeOf on DescriptorArray to LengthOf for consistency.
Please review this at https://chromiumcodereview.appspot.com/10822011/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/objects-inl.h
M src/objects.h
M src/objects.cc
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
f4e0767198049a7cad3a63877ca376da7d42b973..8b22755c8230211278b9874ce97415cdb4fcf9f2
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -3582,6 +3582,14 @@ Map* Map::elements_transition_map() {
}
+bool Map::CanHaveMoreTransitions() {
+ if (!HasTransitionArray()) return true;
+ return FixedArray::SizeFor(transitions()->length() +
+ TransitionArray::kTransitionSize)
+ <= Page::kMaxNonCodeHeapObjectSize;
+}
+
+
MaybeObject* Map::AddTransition(String* key, Map* target) {
if (HasTransitionArray()) return transitions()->CopyInsert(key, target);
return TransitionArray::NewWith(key, target);
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
67ff486905d498889a93e64c14717fc0569604b5..e229017daad07afa0d31a203c6d68bcec2c616b4
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -2121,8 +2121,6 @@ template<RightTrimMode trim_mode>
static void RightTrimFixedArray(Heap* heap, FixedArray* elms, int to_trim)
{
ASSERT(elms->map() != HEAP->fixed_cow_array_map());
// For now this trick is only applied to fixed arrays in new and paged
space.
- // In large object space the object's start must coincide with chunk
- // and thus the trick is just not applicable.
ASSERT(!HEAP->lo_space()->Contains(elms));
const int len = elms->length();
@@ -2218,7 +2216,7 @@ void Map::CopyAppendCallbackDescriptors(Handle<Map>
map,
}
// If duplicates were detected, trim the descriptor array to the right
size.
- int new_array_size = DescriptorArray::SizeFor(new_number_of_descriptors);
+ int new_array_size =
DescriptorArray::LengthFor(new_number_of_descriptors);
if (new_array_size < result->length()) {
RightTrimFixedArray<FROM_MUTATOR>(
isolate->heap(), *result, result->length() - new_array_size);
@@ -4884,7 +4882,7 @@ MaybeObject*
Map::CopyReplaceDescriptors(DescriptorArray* descriptors,
result->SetLastAdded(last_added);
}
- if (flag == INSERT_TRANSITION) {
+ if (flag == INSERT_TRANSITION && CanHaveMoreTransitions()) {
TransitionArray* transitions;
MaybeObject* maybe_transitions = AddTransition(name, result);
if (!maybe_transitions->To(&transitions)) return maybe_transitions;
@@ -5844,7 +5842,7 @@ MaybeObject* DescriptorArray::Allocate(int
number_of_descriptors,
}
// Allocate the array of keys.
MaybeObject* maybe_array =
- heap->AllocateFixedArray(SizeFor(number_of_descriptors));
+ heap->AllocateFixedArray(LengthFor(number_of_descriptors));
if (!maybe_array->To(&result)) return maybe_array;
result->set(kEnumCacheIndex, Smi::FromInt(0));
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
3694955eaf786bc04c07cdf400a4cb06be15ba3d..18a7cf8f2133f344ee7609e91dac8515d8366abd
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -2635,7 +2635,9 @@ class DescriptorArray: public FixedArray {
// fit in a page).
static const int kMaxNumberOfDescriptors = 1024 + 512;
- static int SizeFor(int number_of_descriptors) {
+ // Returns the fixed array length required to hold number_of_descriptors
+ // descriptors.
+ static int LengthFor(int number_of_descriptors) {
return ToKeyIndex(number_of_descriptors);
}
@@ -4896,6 +4898,11 @@ class Map: public HeapObject {
String* name,
LookupResult* result);
+ // The size of transition arrays are limited so they do not end up in
large
+ // object space. Otherwise ClearNonLiveTransitions would leak memory
while
+ // applying in-place right trimming.
+ inline bool CanHaveMoreTransitions();
+
void SetLastAdded(int index) {
set_bit_field3(LastAddedBits::update(bit_field3(), index));
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev