}
-bool Heap::InNewSpace(Address addr) {
- return new_space_.Contains(addr);
+bool Heap::InNewSpace(Address address) {
+ return new_space_.Contains(address);
}
}
+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;
// 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);
}
+// 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();
}