Added pretenuring of array literals test.

BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13860 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
hpayer@chromium.org 2013-03-07 14:00:53 +00:00
parent 9e0ffc02d1
commit b9989623a7
3 changed files with 77 additions and 4 deletions

View File

@ -320,8 +320,8 @@ bool Heap::InNewSpace(Object* object) {
}
bool Heap::InNewSpace(Address addr) {
return new_space_.Contains(addr);
bool Heap::InNewSpace(Address address) {
return new_space_.Contains(address);
}
@ -335,6 +335,16 @@ bool Heap::InToSpace(Object* object) {
}
bool Heap::InOldPointerSpace(Address address) {
return old_pointer_space_->Contains(address);
}
bool Heap::InOldPointerSpace(Object* object) {
return InOldPointerSpace(reinterpret_cast<Address>(object));
}
bool Heap::OldGenerationAllocationLimitReached() {
if (!incremental_marking()->IsStopped()) return false;
return OldGenerationSpaceAvailable() < 0;

View File

@ -1310,11 +1310,15 @@ class Heap {
// Returns whether the object resides in new space.
inline bool InNewSpace(Object* object);
inline bool InNewSpace(Address addr);
inline bool InNewSpacePage(Address addr);
inline bool InNewSpace(Address address);
inline bool InNewSpacePage(Address address);
inline bool InFromSpace(Object* object);
inline bool InToSpace(Object* object);
// Returns whether the object resides in old pointer space.
inline bool InOldPointerSpace(Address address);
inline bool InOldPointerSpace(Object* object);
// Checks whether an address/object in the heap (including auxiliary
// area and unused area).
bool Contains(Address addr);

View File

@ -2044,6 +2044,65 @@ TEST(OptimizedAllocationAlwaysInNewSpace) {
}
// Test pretenuring of array literals allocated with HAllocate.
TEST(OptimizedPretenuringArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
InitializeVM();
if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope;
AlwaysAllocateScope always_allocate;
v8::Local<v8::Value> res = CompileRun(
"function f() {"
" var numbers = new Array(1, 2, 3);"
" numbers[0] = 3.14;"
" return numbers;"
"};"
"f(); f(); f();"
"%OptimizeFunctionOnNextCall(f);"
"f();");
CHECK_EQ(static_cast<int>(3.14),
v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
// TODO(hpayer): remove InNewSpace check and test if object was allocated
// in old pointer space.
CHECK(!HEAP->InOldPointerSpace(*o));
CHECK(HEAP->InNewSpace(*o));
}
// Test regular array literals allocation.
TEST(OptimizedAllocationArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
InitializeVM();
if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
v8::HandleScope scope;
AlwaysAllocateScope always_allocate;
v8::Local<v8::Value> res = CompileRun(
"function f() {"
" var numbers = new Array(1, 2, 3);"
" numbers[0] = 3.14;"
" return numbers;"
"};"
"f(); f(); f();"
"%OptimizeFunctionOnNextCall(f);"
"f();");
CHECK_EQ(static_cast<int>(3.14),
v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value());
Handle<JSObject> o =
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
CHECK(HEAP->InNewSpace(*o));
}
static int CountMapTransitions(Map* map) {
return map->transitions()->number_of_transitions();
}