2012-01-26 21:47:57 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2013-03-07 11:12:26 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2012-09-20 10:45:38 +00:00
|
|
|
#include "compilation-cache.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
#include "execution.h"
|
|
|
|
#include "factory.h"
|
|
|
|
#include "macro-assembler.h"
|
|
|
|
#include "global-handles.h"
|
2012-09-20 10:45:38 +00:00
|
|
|
#include "stub-cache.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
#include "cctest.h"
|
|
|
|
|
|
|
|
using namespace v8::internal;
|
|
|
|
|
|
|
|
|
2012-10-23 08:25:04 +00:00
|
|
|
// Go through all incremental marking steps in one swoop.
|
|
|
|
static void SimulateIncrementalMarking() {
|
2013-09-19 09:46:15 +00:00
|
|
|
MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector();
|
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2013-03-11 10:23:24 +00:00
|
|
|
if (collector->IsConcurrentSweepingInProgress()) {
|
|
|
|
collector->WaitUntilSweepingCompleted();
|
|
|
|
}
|
2012-12-10 15:14:20 +00:00
|
|
|
CHECK(marking->IsMarking() || marking->IsStopped());
|
|
|
|
if (marking->IsStopped()) {
|
|
|
|
marking->Start();
|
|
|
|
}
|
2012-10-23 08:25:04 +00:00
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
while (!marking->IsComplete()) {
|
|
|
|
marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
|
|
|
|
}
|
|
|
|
CHECK(marking->IsComplete());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
static void CheckMap(Map* map, int type, int instance_size) {
|
|
|
|
CHECK(map->IsHeapObject());
|
|
|
|
#ifdef DEBUG
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->Contains(map));
|
2008-08-22 13:33:59 +00:00
|
|
|
#endif
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK_EQ(CcTest::heap()->meta_map(), map->map());
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(type, map->instance_type());
|
|
|
|
CHECK_EQ(instance_size, map->instance_size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(HeapMaps) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
CheckMap(heap->meta_map(), MAP_TYPE, Map::kSize);
|
|
|
|
CheckMap(heap->heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize);
|
|
|
|
CheckMap(heap->fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
|
|
|
CheckMap(heap->string_map(), STRING_TYPE, kVariableSizeSentinel);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static void CheckOddball(Isolate* isolate, Object* obj, const char* string) {
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(obj->IsOddball());
|
|
|
|
bool exc;
|
2013-09-03 06:59:01 +00:00
|
|
|
Handle<Object> handle(obj, isolate);
|
2013-02-25 14:46:09 +00:00
|
|
|
Object* print_string =
|
2013-09-03 06:59:01 +00:00
|
|
|
*Execution::ToString(isolate, handle, &exc);
|
2013-01-09 10:30:54 +00:00
|
|
|
CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static void CheckSmi(Isolate* isolate, int value, const char* string) {
|
2008-08-22 13:33:59 +00:00
|
|
|
bool exc;
|
2013-09-03 06:59:01 +00:00
|
|
|
Handle<Object> handle(Smi::FromInt(value), isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
Object* print_string =
|
2013-09-03 06:59:01 +00:00
|
|
|
*Execution::ToString(isolate, handle, &exc);
|
2013-01-09 10:30:54 +00:00
|
|
|
CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static void CheckNumber(Isolate* isolate, double value, const char* string) {
|
2013-09-19 09:46:15 +00:00
|
|
|
Object* obj = CcTest::heap()->NumberFromDouble(value)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(obj->IsNumber());
|
|
|
|
bool exc;
|
2013-09-03 06:59:01 +00:00
|
|
|
Handle<Object> handle(obj, isolate);
|
2013-02-25 14:46:09 +00:00
|
|
|
Object* print_string =
|
2013-09-03 06:59:01 +00:00
|
|
|
*Execution::ToString(isolate, handle, &exc);
|
2013-01-09 10:30:54 +00:00
|
|
|
CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static void CheckFindCodeObject(Isolate* isolate) {
|
2008-08-22 13:33:59 +00:00
|
|
|
// Test FindCodeObject
|
|
|
|
#define __ assm.
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, NULL, 0);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
__ nop(); // supported on all architectures
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2013-02-25 14:46:09 +00:00
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Object* code = heap->CreateCode(
|
2010-10-25 15:22:03 +00:00
|
|
|
desc,
|
|
|
|
Code::ComputeFlags(Code::STUB),
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Code>())->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(code->IsCode());
|
|
|
|
|
|
|
|
HeapObject* obj = HeapObject::cast(code);
|
|
|
|
Address obj_addr = obj->address();
|
|
|
|
|
|
|
|
for (int i = 0; i < obj->Size(); i += kPointerSize) {
|
2013-07-19 09:39:01 +00:00
|
|
|
Object* found = isolate->FindCodeObject(obj_addr + i);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(code, found);
|
|
|
|
}
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Object* copy = heap->CreateCode(
|
2010-10-25 15:22:03 +00:00
|
|
|
desc,
|
|
|
|
Code::ComputeFlags(Code::STUB),
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Code>())->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(copy->IsCode());
|
|
|
|
HeapObject* obj_copy = HeapObject::cast(copy);
|
2013-07-19 09:39:01 +00:00
|
|
|
Object* not_right = isolate->FindCodeObject(obj_copy->address() +
|
|
|
|
obj_copy->Size() / 2);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(not_right != code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(HeapObjects) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-02-25 14:46:09 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope sc(isolate);
|
2013-02-25 14:46:09 +00:00
|
|
|
Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(1.000123, value->Number());
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
value = heap->NumberFromDouble(1.0)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(1.0, value->Number());
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
value = heap->NumberFromInt32(1024)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(1024.0, value->Number());
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
value = heap->NumberFromInt32(Smi::kMinValue)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value());
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
value = heap->NumberFromInt32(Smi::kMaxValue)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value());
|
|
|
|
|
2009-10-12 11:19:20 +00:00
|
|
|
#ifndef V8_TARGET_ARCH_X64
|
2009-10-08 12:36:12 +00:00
|
|
|
// TODO(lrn): We need a NumberFromIntptr function in order to test this.
|
2013-02-25 14:46:09 +00:00
|
|
|
value = heap->NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number());
|
2009-10-08 12:36:12 +00:00
|
|
|
#endif
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* maybe_value =
|
2013-02-25 14:46:09 +00:00
|
|
|
heap->NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1);
|
2010-10-25 15:22:03 +00:00
|
|
|
value = maybe_value->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
2009-10-08 12:36:12 +00:00
|
|
|
CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1),
|
|
|
|
value->Number());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
maybe_value = heap->NumberFromUint32(static_cast<uint32_t>(1) << 31);
|
2013-01-07 15:02:56 +00:00
|
|
|
value = maybe_value->ToObjectChecked();
|
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31),
|
|
|
|
value->Number());
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// nan oddball checks
|
2013-02-25 14:46:09 +00:00
|
|
|
CHECK(heap->nan_value()->IsNumber());
|
2013-04-19 14:20:36 +00:00
|
|
|
CHECK(std::isnan(heap->nan_value()->Number()));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s = factory->NewStringFromAscii(CStrVector("fisk hest "));
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK(s->IsString());
|
|
|
|
CHECK_EQ(10, s->length());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-17 11:34:20 +00:00
|
|
|
Handle<String> object_string = Handle<String>::cast(factory->Object_string());
|
2013-09-19 09:17:13 +00:00
|
|
|
Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(global, object_string));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check ToString for oddballs
|
2013-02-25 14:46:09 +00:00
|
|
|
CheckOddball(isolate, heap->true_value(), "true");
|
|
|
|
CheckOddball(isolate, heap->false_value(), "false");
|
|
|
|
CheckOddball(isolate, heap->null_value(), "null");
|
|
|
|
CheckOddball(isolate, heap->undefined_value(), "undefined");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check ToString for Smis
|
2013-02-25 14:46:09 +00:00
|
|
|
CheckSmi(isolate, 0, "0");
|
|
|
|
CheckSmi(isolate, 42, "42");
|
|
|
|
CheckSmi(isolate, -42, "-42");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check ToString for Numbers
|
2013-02-25 14:46:09 +00:00
|
|
|
CheckNumber(isolate, 1.1, "1.1");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
CheckFindCodeObject(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Tagging) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2009-05-22 14:01:06 +00:00
|
|
|
int request = 24;
|
2010-05-27 12:30:45 +00:00
|
|
|
CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request)));
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(Smi::FromInt(42)->IsSmi());
|
2010-10-18 12:58:56 +00:00
|
|
|
CHECK(Failure::RetryAfterGC(NEW_SPACE)->IsFailure());
|
2009-05-22 14:01:06 +00:00
|
|
|
CHECK_EQ(NEW_SPACE,
|
2010-10-18 12:58:56 +00:00
|
|
|
Failure::RetryAfterGC(NEW_SPACE)->allocation_space());
|
2008-09-05 12:34:09 +00:00
|
|
|
CHECK_EQ(OLD_POINTER_SPACE,
|
2010-10-18 12:58:56 +00:00
|
|
|
Failure::RetryAfterGC(OLD_POINTER_SPACE)->allocation_space());
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(Failure::Exception()->IsFailure());
|
|
|
|
CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi());
|
|
|
|
CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GarbageCollection) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope sc(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
// Check GC.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-19 09:17:13 +00:00
|
|
|
Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("theFunction");
|
|
|
|
Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
|
|
|
|
Handle<String> prop_namex = factory->InternalizeUtf8String("theSlotx");
|
|
|
|
Handle<String> obj_name = factory->InternalizeUtf8String("theObject");
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
|
|
|
Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
// Allocate a function and keep it in global object's property.
|
|
|
|
Handle<JSFunction> function =
|
2013-02-15 09:27:10 +00:00
|
|
|
factory->NewFunction(name, factory->undefined_value());
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Map> initial_map =
|
2013-02-15 09:27:10 +00:00
|
|
|
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
2010-03-05 09:51:10 +00:00
|
|
|
function->set_initial_map(*initial_map);
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(global, name, function, NONE, kNonStrictMode);
|
2010-03-05 09:51:10 +00:00
|
|
|
// Allocate an object. Unrooted after leaving the scope.
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetProperty(obj, prop_namex, twenty_four, NONE, kNonStrictMode);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
|
|
|
CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
|
|
|
|
CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
// Function should be alive.
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(global, name));
|
2010-03-05 09:51:10 +00:00
|
|
|
// Check function is retained.
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* func_value = CcTest::i_isolate()->context()->global_object()->
|
2011-03-18 20:35:07 +00:00
|
|
|
GetProperty(*name)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(func_value->IsJSFunction());
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSFunction> function(JSFunction::cast(func_value));
|
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
// Allocate another object, make it reachable from global.
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(global, obj_name, obj, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
// After gc, it should survive.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(global, obj_name));
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK(CcTest::i_isolate()->context()->global_object()->
|
2011-03-18 20:35:07 +00:00
|
|
|
GetProperty(*obj_name)->ToObjectChecked()->IsJSObject());
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* obj = CcTest::i_isolate()->context()->global_object()->
|
2011-03-18 20:35:07 +00:00
|
|
|
GetProperty(*obj_name)->ToObjectChecked();
|
2010-10-25 15:22:03 +00:00
|
|
|
JSObject* js_obj = JSObject::cast(obj);
|
|
|
|
CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
static void VerifyStringAllocation(Isolate* isolate, const char* string) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string));
|
2009-11-11 09:50:06 +00:00
|
|
|
CHECK_EQ(StrLength(string), s->length());
|
2009-03-17 09:33:06 +00:00
|
|
|
for (int index = 0; index < s->length(); index++) {
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index));
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(String) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
VerifyStringAllocation(isolate, "a");
|
|
|
|
VerifyStringAllocation(isolate, "ab");
|
|
|
|
VerifyStringAllocation(isolate, "abc");
|
|
|
|
VerifyStringAllocation(isolate, "abcd");
|
|
|
|
VerifyStringAllocation(isolate, "fiskerdrengen er paa havet");
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LocalHandles) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
const char* name = "Kasper the spunky";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> string = factory->NewStringFromAscii(CStrVector(name));
|
2009-11-11 09:50:06 +00:00
|
|
|
CHECK_EQ(StrLength(name), string->length());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GlobalHandles) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Object> h1;
|
|
|
|
Handle<Object> h2;
|
|
|
|
Handle<Object> h3;
|
|
|
|
Handle<Object> h4;
|
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
|
|
|
|
Handle<Object> u = factory->NewNumber(1.12344);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
h1 = global_handles->Create(*i);
|
|
|
|
h2 = global_handles->Create(*u);
|
|
|
|
h3 = global_handles->Create(*i);
|
|
|
|
h4 = global_handles->Create(*u);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// after gc, it should survive
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK((*h1)->IsString());
|
|
|
|
CHECK((*h2)->IsHeapNumber());
|
|
|
|
CHECK((*h3)->IsString());
|
|
|
|
CHECK((*h4)->IsHeapNumber());
|
|
|
|
|
|
|
|
CHECK_EQ(*h3, *h1);
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles->Destroy(h1.location());
|
|
|
|
global_handles->Destroy(h3.location());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK_EQ(*h4, *h2);
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles->Destroy(h2.location());
|
|
|
|
global_handles->Destroy(h4.location());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool WeakPointerCleared = false;
|
|
|
|
|
2013-01-25 08:31:46 +00:00
|
|
|
static void TestWeakGlobalHandleCallback(v8::Isolate* isolate,
|
2013-05-07 10:44:30 +00:00
|
|
|
v8::Persistent<v8::Value>* handle,
|
2008-08-22 13:33:59 +00:00
|
|
|
void* id) {
|
2009-05-19 08:59:23 +00:00
|
|
|
if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true;
|
2013-11-22 12:43:17 +00:00
|
|
|
handle->Reset();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(WeakGlobalHandlesScavenge) {
|
2013-06-19 08:58:09 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
WeakPointerCleared = false;
|
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Object> h1;
|
|
|
|
Handle<Object> h2;
|
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
|
|
|
|
Handle<Object> u = factory->NewNumber(1.12344);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
h1 = global_handles->Create(*i);
|
|
|
|
h2 = global_handles->Create(*u);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles->MakeWeak(h2.location(),
|
|
|
|
reinterpret_cast<void*>(1234),
|
2013-06-03 08:17:04 +00:00
|
|
|
&TestWeakGlobalHandleCallback);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Scavenge treats weak pointers as normal roots.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->PerformScavenge();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK((*h1)->IsString());
|
|
|
|
CHECK((*h2)->IsHeapNumber());
|
|
|
|
|
|
|
|
CHECK(!WeakPointerCleared);
|
2011-03-18 20:35:07 +00:00
|
|
|
CHECK(!global_handles->IsNearDeath(h2.location()));
|
|
|
|
CHECK(!global_handles->IsNearDeath(h1.location()));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles->Destroy(h1.location());
|
|
|
|
global_handles->Destroy(h2.location());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(WeakGlobalHandlesMark) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
WeakPointerCleared = false;
|
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Object> h1;
|
|
|
|
Handle<Object> h2;
|
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
|
|
|
|
Handle<Object> u = factory->NewNumber(1.12344);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
h1 = global_handles->Create(*i);
|
|
|
|
h2 = global_handles->Create(*u);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2012-12-10 15:14:20 +00:00
|
|
|
// Make sure the objects are promoted.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
|
|
heap->CollectGarbage(NEW_SPACE);
|
|
|
|
CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles->MakeWeak(h2.location(),
|
|
|
|
reinterpret_cast<void*>(1234),
|
2013-06-03 08:17:04 +00:00
|
|
|
&TestWeakGlobalHandleCallback);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
|
|
|
|
CHECK(!GlobalHandles::IsNearDeath(h2.location()));
|
|
|
|
|
2012-12-10 15:14:20 +00:00
|
|
|
// Incremental marking potentially marked handles before they turned weak.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK((*h1)->IsString());
|
|
|
|
|
|
|
|
CHECK(WeakPointerCleared);
|
|
|
|
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles->Destroy(h1.location());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:20:38 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
TEST(DeleteWeakGlobalHandle) {
|
2013-06-19 08:58:09 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
WeakPointerCleared = false;
|
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Object> h;
|
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
|
2011-03-18 20:35:07 +00:00
|
|
|
h = global_handles->Create(*i);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles->MakeWeak(h.location(),
|
|
|
|
reinterpret_cast<void*>(1234),
|
2013-06-03 08:17:04 +00:00
|
|
|
&TestWeakGlobalHandleCallback);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Scanvenge does not recognize weak reference.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->PerformScavenge();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK(!WeakPointerCleared);
|
|
|
|
|
|
|
|
// Mark-compact treats weak reference properly.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectGarbage(OLD_POINTER_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK(WeakPointerCleared);
|
|
|
|
}
|
|
|
|
|
2012-08-02 14:20:38 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
static const char* not_so_random_string_table[] = {
|
|
|
|
"abstract",
|
|
|
|
"boolean",
|
|
|
|
"break",
|
|
|
|
"byte",
|
|
|
|
"case",
|
|
|
|
"catch",
|
|
|
|
"char",
|
|
|
|
"class",
|
|
|
|
"const",
|
|
|
|
"continue",
|
|
|
|
"debugger",
|
|
|
|
"default",
|
|
|
|
"delete",
|
|
|
|
"do",
|
|
|
|
"double",
|
|
|
|
"else",
|
|
|
|
"enum",
|
|
|
|
"export",
|
|
|
|
"extends",
|
|
|
|
"false",
|
|
|
|
"final",
|
|
|
|
"finally",
|
|
|
|
"float",
|
|
|
|
"for",
|
|
|
|
"function",
|
|
|
|
"goto",
|
|
|
|
"if",
|
|
|
|
"implements",
|
|
|
|
"import",
|
|
|
|
"in",
|
|
|
|
"instanceof",
|
|
|
|
"int",
|
|
|
|
"interface",
|
|
|
|
"long",
|
|
|
|
"native",
|
|
|
|
"new",
|
|
|
|
"null",
|
|
|
|
"package",
|
|
|
|
"private",
|
|
|
|
"protected",
|
|
|
|
"public",
|
|
|
|
"return",
|
|
|
|
"short",
|
|
|
|
"static",
|
|
|
|
"super",
|
|
|
|
"switch",
|
|
|
|
"synchronized",
|
|
|
|
"this",
|
|
|
|
"throw",
|
|
|
|
"throws",
|
|
|
|
"transient",
|
|
|
|
"true",
|
|
|
|
"try",
|
|
|
|
"typeof",
|
|
|
|
"var",
|
|
|
|
"void",
|
|
|
|
"volatile",
|
|
|
|
"while",
|
|
|
|
"with",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
static void CheckInternalizedStrings(const char** strings) {
|
2008-08-22 13:33:59 +00:00
|
|
|
for (const char* string = *strings; *strings != 0; string = *strings++) {
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* a;
|
2013-09-19 09:46:15 +00:00
|
|
|
MaybeObject* maybe_a = CcTest::heap()->InternalizeUtf8String(string);
|
2013-02-28 17:03:34 +00:00
|
|
|
// InternalizeUtf8String may return a failure if a GC is needed.
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_a->ToObject(&a)) continue;
|
2013-02-28 17:03:34 +00:00
|
|
|
CHECK(a->IsInternalizedString());
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* b;
|
2013-09-19 09:46:15 +00:00
|
|
|
MaybeObject* maybe_b = CcTest::heap()->InternalizeUtf8String(string);
|
2010-10-25 15:29:06 +00:00
|
|
|
if (!maybe_b->ToObject(&b)) continue;
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(b, a);
|
2013-01-09 10:30:54 +00:00
|
|
|
CHECK(String::cast(b)->IsUtf8EqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
TEST(StringTable) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
CheckInternalizedStrings(not_so_random_string_table);
|
|
|
|
CheckInternalizedStrings(not_so_random_string_table);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FunctionAllocation) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("theFunction");
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSFunction> function =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewFunction(name, factory->undefined_value());
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Map> initial_map =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
2010-03-05 09:51:10 +00:00
|
|
|
function->set_initial_map(*initial_map);
|
|
|
|
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
|
|
|
Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
|
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
|
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode);
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
|
2008-08-22 13:33:59 +00:00
|
|
|
// Check that we can add properties to function objects.
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(function, prop_name, twenty_four, NONE,
|
|
|
|
kNonStrictMode);
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ObjectProperties) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
String* object_string = String::cast(CcTest::heap()->Object_string());
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* raw_object = CcTest::i_isolate()->context()->global_object()->
|
2013-02-28 17:03:34 +00:00
|
|
|
GetProperty(object_string)->ToObjectChecked();
|
2010-10-25 15:22:03 +00:00
|
|
|
JSFunction* object_function = JSFunction::cast(raw_object);
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSFunction> constructor(object_function);
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(constructor);
|
|
|
|
Handle<String> first = factory->InternalizeUtf8String("first");
|
|
|
|
Handle<String> second = factory->InternalizeUtf8String("second");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> one(Smi::FromInt(1), isolate);
|
|
|
|
Handle<Smi> two(Smi::FromInt(2), isolate);
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// check for empty
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(!JSReceiver::HasLocalProperty(obj, first));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// add first
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, first));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// delete first
|
2013-07-17 16:38:49 +00:00
|
|
|
JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(!JSReceiver::HasLocalProperty(obj, first));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// add first and then second
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, first));
|
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// delete first and then second
|
2013-07-17 16:38:49 +00:00
|
|
|
JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, second));
|
2013-07-17 16:38:49 +00:00
|
|
|
JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(!JSReceiver::HasLocalProperty(obj, first));
|
|
|
|
CHECK(!JSReceiver::HasLocalProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// add first and then second
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, first));
|
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// delete second and then first
|
2013-07-17 16:38:49 +00:00
|
|
|
JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, first));
|
2013-07-17 16:38:49 +00:00
|
|
|
JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(!JSReceiver::HasLocalProperty(obj, first));
|
|
|
|
CHECK(!JSReceiver::HasLocalProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// check string and internalized string match
|
2012-01-30 14:57:36 +00:00
|
|
|
const char* string1 = "fisk";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1));
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(obj, s1, one, NONE, kNonStrictMode);
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s1_string = factory->InternalizeUtf8String(string1);
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, s1_string));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// check internalized string and string match
|
2012-01-30 14:57:36 +00:00
|
|
|
const char* string2 = "fugl";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s2_string = factory->InternalizeUtf8String(string2);
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(obj, s2_string, one, NONE, kNonStrictMode);
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2));
|
2013-09-17 11:34:20 +00:00
|
|
|
CHECK(JSReceiver::HasLocalProperty(obj, s2));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(JSObjectMaps) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("theFunction");
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSFunction> function =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewFunction(name, factory->undefined_value());
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Map> initial_map =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
2010-03-05 09:51:10 +00:00
|
|
|
function->set_initial_map(*initial_map);
|
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
|
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Set a propery
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
|
|
|
JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode);
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check the map has changed
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK(*initial_map != obj->map());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(JSArray) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("Array");
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* raw_object = CcTest::i_isolate()->context()->global_object()->
|
2011-03-18 20:35:07 +00:00
|
|
|
GetProperty(*name)->ToObjectChecked();
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSFunction> function = Handle<JSFunction>(
|
2010-10-25 15:22:03 +00:00
|
|
|
JSFunction::cast(raw_object));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Allocate the object.
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<JSObject> object = factory->NewJSObject(function);
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSArray> array = Handle<JSArray>::cast(object);
|
2010-08-31 08:05:42 +00:00
|
|
|
// We just initialized the VM, no heap allocation failure yet.
|
2011-11-03 08:59:01 +00:00
|
|
|
array->Initialize(0)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Set array length to 0.
|
2011-11-03 08:59:01 +00:00
|
|
|
array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(0), array->length());
|
2011-09-22 11:30:04 +00:00
|
|
|
// Must be in fast mode.
|
2012-05-23 14:24:29 +00:00
|
|
|
CHECK(array->HasFastSmiOrObjectElements());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// array[length] = name.
|
2013-11-14 17:30:48 +00:00
|
|
|
JSReceiver::SetElement(array, 0, name, NONE, kNonStrictMode);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(1), array->length());
|
2013-09-04 07:05:11 +00:00
|
|
|
CHECK_EQ(array->GetElement(isolate, 0), *name);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
// Set array length with larger than smi value.
|
|
|
|
Handle<Object> length =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
|
2011-11-03 08:59:01 +00:00
|
|
|
array->SetElementsLength(*length)->ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
uint32_t int_length = 0;
|
2010-05-27 12:30:45 +00:00
|
|
|
CHECK(length->ToArrayIndex(&int_length));
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(*length, array->length());
|
2009-07-28 08:43:51 +00:00
|
|
|
CHECK(array->HasDictionaryElements()); // Must be in slow mode.
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// array[length] = name.
|
2013-11-14 17:30:48 +00:00
|
|
|
JSReceiver::SetElement(array, int_length, name, NONE, kNonStrictMode);
|
2008-08-22 13:33:59 +00:00
|
|
|
uint32_t new_int_length = 0;
|
2010-05-27 12:30:45 +00:00
|
|
|
CHECK(array->length()->ToArrayIndex(&new_int_length));
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
|
2013-09-04 07:05:11 +00:00
|
|
|
CHECK_EQ(array->GetElement(isolate, int_length), *name);
|
|
|
|
CHECK_EQ(array->GetElement(isolate, 0), *name);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(JSObjectCopy) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
String* object_string = String::cast(CcTest::heap()->Object_string());
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* raw_object = CcTest::i_isolate()->context()->global_object()->
|
2013-02-28 17:03:34 +00:00
|
|
|
GetProperty(object_string)->ToObjectChecked();
|
2010-10-25 15:22:03 +00:00
|
|
|
JSFunction* object_function = JSFunction::cast(raw_object);
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSFunction> constructor(object_function);
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(constructor);
|
|
|
|
Handle<String> first = factory->InternalizeUtf8String("first");
|
|
|
|
Handle<String> second = factory->InternalizeUtf8String("second");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> one(Smi::FromInt(1), isolate);
|
|
|
|
Handle<Smi> two(Smi::FromInt(2), isolate);
|
|
|
|
|
|
|
|
JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-11-14 17:30:48 +00:00
|
|
|
JSReceiver::SetElement(obj, 0, first, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetElement(obj, 1, second, NONE, kNonStrictMode);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Make the clone.
|
2013-09-13 09:51:11 +00:00
|
|
|
Handle<JSObject> clone = JSObject::Copy(obj);
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK(!clone.is_identical_to(obj));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-04 07:05:11 +00:00
|
|
|
CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0));
|
|
|
|
CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first));
|
|
|
|
CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Flip the values.
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(clone, first, two, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetProperty(clone, second, one, NONE, kNonStrictMode);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-11-14 17:30:48 +00:00
|
|
|
JSReceiver::SetElement(clone, 0, second, NONE, kNonStrictMode);
|
|
|
|
JSReceiver::SetElement(clone, 1, first, NONE, kNonStrictMode);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-04 07:05:11 +00:00
|
|
|
CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0));
|
|
|
|
CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
|
|
|
|
CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(StringAllocation) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 };
|
|
|
|
for (int length = 0; length < 100; length++) {
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
char* non_ascii = NewArray<char>(3 * length + 1);
|
|
|
|
char* ascii = NewArray<char>(length + 1);
|
|
|
|
non_ascii[3 * length] = 0;
|
|
|
|
ascii[length] = 0;
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
ascii[i] = 'a';
|
|
|
|
non_ascii[3 * i] = chars[0];
|
|
|
|
non_ascii[3 * i + 1] = chars[1];
|
|
|
|
non_ascii[3 * i + 2] = chars[2];
|
|
|
|
}
|
|
|
|
Handle<String> non_ascii_sym =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->InternalizeUtf8String(
|
2013-02-28 17:03:34 +00:00
|
|
|
Vector<const char>(non_ascii, 3 * length));
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(length, non_ascii_sym->length());
|
|
|
|
Handle<String> ascii_sym =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->InternalizeOneByteString(OneByteVector(ascii, length));
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(length, ascii_sym->length());
|
|
|
|
Handle<String> non_ascii_str =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length));
|
2008-08-22 13:33:59 +00:00
|
|
|
non_ascii_str->Hash();
|
|
|
|
CHECK_EQ(length, non_ascii_str->length());
|
|
|
|
Handle<String> ascii_str =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewStringFromUtf8(Vector<const char>(ascii, length));
|
2008-08-22 13:33:59 +00:00
|
|
|
ascii_str->Hash();
|
|
|
|
CHECK_EQ(length, ascii_str->length());
|
|
|
|
DeleteArray(non_ascii);
|
|
|
|
DeleteArray(ascii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-11 13:02:20 +00:00
|
|
|
static int ObjectsFoundInHeap(Heap* heap, Handle<Object> objs[], int size) {
|
2008-08-22 13:33:59 +00:00
|
|
|
// Count the number of objects found in the heap.
|
|
|
|
int found_count = 0;
|
2013-06-17 06:52:01 +00:00
|
|
|
heap->EnsureHeapIsIterable();
|
2013-02-11 13:02:20 +00:00
|
|
|
HeapIterator iterator(heap);
|
2010-01-25 22:53:18 +00:00
|
|
|
for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
|
2008-08-22 13:33:59 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
if (*objs[i] == obj) {
|
|
|
|
found_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Iteration) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Array of objects to scan haep for.
|
|
|
|
const int objs_count = 6;
|
|
|
|
Handle<Object> objs[objs_count];
|
|
|
|
int next_objs_index = 0;
|
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
// Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE
|
2013-06-04 10:30:05 +00:00
|
|
|
objs[next_objs_index++] = factory->NewJSArray(10);
|
|
|
|
objs[next_objs_index++] = factory->NewJSArray(10,
|
2012-05-23 14:24:29 +00:00
|
|
|
FAST_HOLEY_ELEMENTS,
|
|
|
|
TENURED);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
// Allocate a small string to OLD_DATA_SPACE and NEW_SPACE
|
2008-08-22 13:33:59 +00:00
|
|
|
objs[next_objs_index++] =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewStringFromAscii(CStrVector("abcdefghij"));
|
2008-08-22 13:33:59 +00:00
|
|
|
objs[next_objs_index++] =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewStringFromAscii(CStrVector("abcdefghij"), TENURED);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Allocate a large string (for large object space).
|
2012-02-23 12:11:24 +00:00
|
|
|
int large_size = Page::kMaxNonCodeHeapObjectSize + 1;
|
2008-08-22 13:33:59 +00:00
|
|
|
char* str = new char[large_size];
|
|
|
|
for (int i = 0; i < large_size - 1; ++i) str[i] = 'a';
|
|
|
|
str[large_size - 1] = '\0';
|
|
|
|
objs[next_objs_index++] =
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewStringFromAscii(CStrVector(str), TENURED);
|
2008-08-22 13:33:59 +00:00
|
|
|
delete[] str;
|
|
|
|
|
|
|
|
// Add a Map object to look for.
|
|
|
|
objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map());
|
|
|
|
|
|
|
|
CHECK_EQ(objs_count, next_objs_index);
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK_EQ(objs_count, ObjectsFoundInHeap(CcTest::heap(), objs, objs_count));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2010-03-25 13:10:50 +00:00
|
|
|
|
|
|
|
|
2010-03-25 14:07:17 +00:00
|
|
|
TEST(EmptyHandleEscapeFrom) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2010-03-25 14:07:17 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2010-03-25 14:07:17 +00:00
|
|
|
Handle<JSObject> runaway;
|
|
|
|
|
|
|
|
{
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope nested(CcTest::isolate());
|
2010-03-25 14:07:17 +00:00
|
|
|
Handle<JSObject> empty;
|
|
|
|
runaway = empty.EscapeFrom(&nested);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(runaway.is_null());
|
|
|
|
}
|
2010-03-25 15:32:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int LenFromSize(int size) {
|
|
|
|
return (size - FixedArray::kHeaderSize) / kPointerSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Regression39128) {
|
|
|
|
// Test case for crbug.com/39128.
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2010-03-25 15:32:58 +00:00
|
|
|
|
|
|
|
// Increase the chance of 'bump-the-pointer' allocation in old space.
|
2013-09-19 09:46:15 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2010-03-25 15:32:58 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2010-03-25 15:32:58 +00:00
|
|
|
|
|
|
|
// The plan: create JSObject which references objects in new space.
|
|
|
|
// Then clone this object (forcing it to go into old space) and check
|
2010-05-27 12:30:45 +00:00
|
|
|
// that region dirty marks are updated correctly.
|
2010-03-25 15:32:58 +00:00
|
|
|
|
|
|
|
// Step 1: prepare a map for the object. We add 1 inobject property to it.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> object_ctor(
|
2013-09-19 09:17:13 +00:00
|
|
|
CcTest::i_isolate()->native_context()->object_function());
|
2010-03-25 15:32:58 +00:00
|
|
|
CHECK(object_ctor->has_initial_map());
|
|
|
|
Handle<Map> object_map(object_ctor->initial_map());
|
|
|
|
// Create a map with single inobject property.
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<Map> my_map = factory->CopyMap(object_map, 1);
|
2010-03-25 15:32:58 +00:00
|
|
|
int n_properties = my_map->inobject_properties();
|
|
|
|
CHECK_GT(n_properties, 0);
|
|
|
|
|
|
|
|
int object_size = my_map->instance_size();
|
|
|
|
|
|
|
|
// Step 2: allocate a lot of objects so to almost fill new space: we need
|
|
|
|
// just enough room to allocate JSObject and thus fill the newspace.
|
|
|
|
|
|
|
|
int allocation_amount = Min(FixedArray::kMaxSize,
|
2013-08-05 12:52:53 +00:00
|
|
|
Page::kMaxNonCodeHeapObjectSize + kPointerSize);
|
2010-03-25 15:32:58 +00:00
|
|
|
int allocation_len = LenFromSize(allocation_amount);
|
2013-09-19 09:46:15 +00:00
|
|
|
NewSpace* new_space = heap->new_space();
|
2010-03-25 15:32:58 +00:00
|
|
|
Address* top_addr = new_space->allocation_top_address();
|
|
|
|
Address* limit_addr = new_space->allocation_limit_address();
|
|
|
|
while ((*limit_addr - *top_addr) > allocation_amount) {
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(!heap->always_allocate());
|
|
|
|
Object* array = heap->AllocateFixedArray(allocation_len)->ToObjectChecked();
|
2011-03-18 20:35:07 +00:00
|
|
|
CHECK(!array->IsFailure());
|
2010-03-25 15:32:58 +00:00
|
|
|
CHECK(new_space->Contains(array));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 3: now allocate fixed array and JSObject to fill the whole new space.
|
2010-04-13 11:59:37 +00:00
|
|
|
int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size);
|
2010-03-25 15:32:58 +00:00
|
|
|
int fixed_array_len = LenFromSize(to_fill);
|
|
|
|
CHECK(fixed_array_len < FixedArray::kMaxLength);
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(!heap->always_allocate());
|
|
|
|
Object* array = heap->AllocateFixedArray(fixed_array_len)->ToObjectChecked();
|
2011-03-18 20:35:07 +00:00
|
|
|
CHECK(!array->IsFailure());
|
2010-03-25 15:32:58 +00:00
|
|
|
CHECK(new_space->Contains(array));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
Object* object = heap->AllocateJSObjectFromMap(*my_map)->ToObjectChecked();
|
2010-03-25 15:32:58 +00:00
|
|
|
CHECK(new_space->Contains(object));
|
|
|
|
JSObject* jsobject = JSObject::cast(object);
|
2010-05-27 12:30:45 +00:00
|
|
|
CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length());
|
2010-03-25 15:32:58 +00:00
|
|
|
CHECK_EQ(0, jsobject->properties()->length());
|
|
|
|
// Create a reference to object in new space in jsobject.
|
|
|
|
jsobject->FastPropertyAtPut(-1, array);
|
|
|
|
|
2010-04-13 11:59:37 +00:00
|
|
|
CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr));
|
2010-03-25 15:32:58 +00:00
|
|
|
|
|
|
|
// Step 4: clone jsobject, but force always allocate first to create a clone
|
|
|
|
// in old pointer space.
|
2013-09-19 09:46:15 +00:00
|
|
|
Address old_pointer_space_top = heap->old_pointer_space()->top();
|
2010-03-25 15:32:58 +00:00
|
|
|
AlwaysAllocateScope aa_scope;
|
2013-09-19 09:46:15 +00:00
|
|
|
Object* clone_obj = heap->CopyJSObject(jsobject)->ToObjectChecked();
|
2010-03-25 15:32:58 +00:00
|
|
|
JSObject* clone = JSObject::cast(clone_obj);
|
|
|
|
if (clone->address() != old_pointer_space_top) {
|
|
|
|
// Alas, got allocated from free list, we cannot do checks.
|
|
|
|
return;
|
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(heap->old_pointer_space()->Contains(clone->address()));
|
2010-03-25 15:32:58 +00:00
|
|
|
}
|
2010-06-07 15:39:10 +00:00
|
|
|
|
2010-10-18 14:59:03 +00:00
|
|
|
|
2010-06-07 15:39:10 +00:00
|
|
|
TEST(TestCodeFlushing) {
|
2010-06-11 08:52:36 +00:00
|
|
|
// If we do not flush code this test is invalid.
|
|
|
|
if (!FLAG_flush_code) return;
|
2012-10-23 08:25:04 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-10-23 13:48:04 +00:00
|
|
|
i::FLAG_optimize_for_size = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2010-06-07 15:39:10 +00:00
|
|
|
const char* source = "function foo() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
|
|
|
"foo()";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> foo_name = factory->InternalizeUtf8String("foo");
|
2010-06-07 15:39:10 +00:00
|
|
|
|
|
|
|
// This compile will add the code to the compilation cache.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
CompileRun(source);
|
|
|
|
}
|
2010-06-07 15:39:10 +00:00
|
|
|
|
|
|
|
// Check function is compiled.
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* func_value = CcTest::i_isolate()->context()->global_object()->
|
2011-03-18 20:35:07 +00:00
|
|
|
GetProperty(*foo_name)->ToObjectChecked();
|
2010-06-07 15:39:10 +00:00
|
|
|
CHECK(func_value->IsJSFunction());
|
|
|
|
Handle<JSFunction> function(JSFunction::cast(func_value));
|
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
2012-10-23 08:25:04 +00:00
|
|
|
// The code will survive at least two GCs.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2010-06-07 15:39:10 +00:00
|
|
|
CHECK(function->shared()->is_compiled());
|
2010-08-17 11:44:01 +00:00
|
|
|
|
2012-10-23 08:25:04 +00:00
|
|
|
// Simulate several GCs that use full marking.
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2012-10-23 08:25:04 +00:00
|
|
|
}
|
2010-06-07 15:39:10 +00:00
|
|
|
|
|
|
|
// foo should no longer be in the compilation cache
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK(!function->shared()->is_compiled() || function->IsOptimized());
|
|
|
|
CHECK(!function->is_compiled() || function->IsOptimized());
|
2010-06-07 15:39:10 +00:00
|
|
|
// Call foo to get it recompiled.
|
|
|
|
CompileRun("foo()");
|
|
|
|
CHECK(function->shared()->is_compiled());
|
2010-08-17 11:44:01 +00:00
|
|
|
CHECK(function->is_compiled());
|
2010-06-07 15:39:10 +00:00
|
|
|
}
|
2010-10-18 14:59:03 +00:00
|
|
|
|
|
|
|
|
2013-10-23 13:48:04 +00:00
|
|
|
TEST(TestCodeFlushingPreAged) {
|
|
|
|
// If we do not flush code this test is invalid.
|
|
|
|
if (!FLAG_flush_code) return;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_optimize_for_size = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
const char* source = "function foo() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
|
|
|
"foo()";
|
|
|
|
Handle<String> foo_name = factory->InternalizeUtf8String("foo");
|
|
|
|
|
|
|
|
// Compile foo, but don't run it.
|
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check function is compiled.
|
|
|
|
Object* func_value = Isolate::Current()->context()->global_object()->
|
|
|
|
GetProperty(*foo_name)->ToObjectChecked();
|
|
|
|
CHECK(func_value->IsJSFunction());
|
|
|
|
Handle<JSFunction> function(JSFunction::cast(func_value));
|
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
|
|
|
// The code has been run so will survive at least one GC.
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
|
|
|
// The code was only run once, so it should be pre-aged and collected on the
|
|
|
|
// next GC.
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
CHECK(!function->shared()->is_compiled() || function->IsOptimized());
|
|
|
|
|
|
|
|
// Execute the function again twice, and ensure it is reset to the young age.
|
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("foo();"
|
|
|
|
"foo();");
|
|
|
|
}
|
|
|
|
|
|
|
|
// The code will survive at least two GC now that it is young again.
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
|
|
|
// Simulate several GCs that use full marking.
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
// foo should no longer be in the compilation cache
|
|
|
|
CHECK(!function->shared()->is_compiled() || function->IsOptimized());
|
|
|
|
CHECK(!function->is_compiled() || function->IsOptimized());
|
|
|
|
// Call foo to get it recompiled.
|
|
|
|
CompileRun("foo()");
|
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
CHECK(function->is_compiled());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-23 08:25:04 +00:00
|
|
|
TEST(TestCodeFlushingIncremental) {
|
|
|
|
// If we do not flush code this test is invalid.
|
2012-11-06 11:54:05 +00:00
|
|
|
if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
|
2012-10-23 08:25:04 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-10-23 13:48:04 +00:00
|
|
|
i::FLAG_optimize_for_size = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-10-23 08:25:04 +00:00
|
|
|
const char* source = "function foo() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
|
|
|
"foo()";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> foo_name = factory->InternalizeUtf8String("foo");
|
2012-10-23 08:25:04 +00:00
|
|
|
|
|
|
|
// This compile will add the code to the compilation cache.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2012-10-23 08:25:04 +00:00
|
|
|
CompileRun(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check function is compiled.
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* func_value = CcTest::i_isolate()->context()->global_object()->
|
2012-10-23 08:25:04 +00:00
|
|
|
GetProperty(*foo_name)->ToObjectChecked();
|
|
|
|
CHECK(func_value->IsJSFunction());
|
|
|
|
Handle<JSFunction> function(JSFunction::cast(func_value));
|
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
|
|
|
// The code will survive at least two GCs.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2012-10-23 08:25:04 +00:00
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
|
|
|
// Simulate several GCs that use incremental marking.
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
SimulateIncrementalMarking();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-10-23 08:25:04 +00:00
|
|
|
}
|
|
|
|
CHECK(!function->shared()->is_compiled() || function->IsOptimized());
|
|
|
|
CHECK(!function->is_compiled() || function->IsOptimized());
|
|
|
|
|
|
|
|
// This compile will compile the function again.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2012-10-23 08:25:04 +00:00
|
|
|
CompileRun("foo();");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate several GCs that use incremental marking but make sure
|
|
|
|
// the loop breaks once the function is enqueued as a candidate.
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
SimulateIncrementalMarking();
|
|
|
|
if (!function->next_function_link()->IsUndefined()) break;
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-10-23 08:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Force optimization while incremental marking is active and while
|
|
|
|
// the function is enqueued as a candidate.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2012-10-23 08:25:04 +00:00
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(foo); foo();");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate one final GC to make sure the candidate queue is sane.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-10-23 08:25:04 +00:00
|
|
|
CHECK(function->shared()->is_compiled() || !function->IsOptimized());
|
|
|
|
CHECK(function->is_compiled() || !function->IsOptimized());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-26 09:44:34 +00:00
|
|
|
TEST(TestCodeFlushingIncrementalScavenge) {
|
|
|
|
// If we do not flush code this test is invalid.
|
2012-11-06 11:54:05 +00:00
|
|
|
if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
|
2012-10-26 09:44:34 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-10-23 13:48:04 +00:00
|
|
|
i::FLAG_optimize_for_size = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-10-26 09:44:34 +00:00
|
|
|
const char* source = "var foo = function() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
|
|
|
"foo();"
|
|
|
|
"var bar = function() {"
|
|
|
|
" var x = 23;"
|
|
|
|
"};"
|
|
|
|
"bar();";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> foo_name = factory->InternalizeUtf8String("foo");
|
|
|
|
Handle<String> bar_name = factory->InternalizeUtf8String("bar");
|
2012-10-26 09:44:34 +00:00
|
|
|
|
|
|
|
// Perfrom one initial GC to enable code flushing.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2012-10-26 09:44:34 +00:00
|
|
|
|
|
|
|
// This compile will add the code to the compilation cache.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2012-10-26 09:44:34 +00:00
|
|
|
CompileRun(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check functions are compiled.
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* func_value = CcTest::i_isolate()->context()->global_object()->
|
2012-10-26 09:44:34 +00:00
|
|
|
GetProperty(*foo_name)->ToObjectChecked();
|
|
|
|
CHECK(func_value->IsJSFunction());
|
|
|
|
Handle<JSFunction> function(JSFunction::cast(func_value));
|
|
|
|
CHECK(function->shared()->is_compiled());
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* func_value2 = CcTest::i_isolate()->context()->global_object()->
|
2012-10-26 09:44:34 +00:00
|
|
|
GetProperty(*bar_name)->ToObjectChecked();
|
|
|
|
CHECK(func_value2->IsJSFunction());
|
|
|
|
Handle<JSFunction> function2(JSFunction::cast(func_value2));
|
|
|
|
CHECK(function2->shared()->is_compiled());
|
|
|
|
|
|
|
|
// Clear references to functions so that one of them can die.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2012-10-26 09:44:34 +00:00
|
|
|
CompileRun("foo = 0; bar = 0;");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bump the code age so that flushing is triggered while the function
|
|
|
|
// object is still located in new-space.
|
|
|
|
const int kAgingThreshold = 6;
|
2012-12-03 13:38:39 +00:00
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
function->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
function2->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
2012-10-26 09:44:34 +00:00
|
|
|
|
|
|
|
// Simulate incremental marking so that the functions are enqueued as
|
|
|
|
// code flushing candidates. Then kill one of the functions. Finally
|
|
|
|
// perform a scavenge while incremental marking is still running.
|
|
|
|
SimulateIncrementalMarking();
|
|
|
|
*function2.location() = NULL;
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectGarbage(NEW_SPACE, "test scavenge while marking");
|
2012-10-26 09:44:34 +00:00
|
|
|
|
|
|
|
// Simulate one final GC to make sure the candidate queue is sane.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-10-26 09:44:34 +00:00
|
|
|
CHECK(!function->shared()->is_compiled() || function->IsOptimized());
|
|
|
|
CHECK(!function->is_compiled() || function->IsOptimized());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-08 10:26:50 +00:00
|
|
|
TEST(TestCodeFlushingIncrementalAbort) {
|
|
|
|
// If we do not flush code this test is invalid.
|
|
|
|
if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-10-23 13:48:04 +00:00
|
|
|
i::FLAG_optimize_for_size = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-11-08 10:26:50 +00:00
|
|
|
const char* source = "function foo() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
|
|
|
"foo()";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> foo_name = factory->InternalizeUtf8String("foo");
|
2012-11-08 10:26:50 +00:00
|
|
|
|
|
|
|
// This compile will add the code to the compilation cache.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2012-11-08 10:26:50 +00:00
|
|
|
CompileRun(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check function is compiled.
|
2013-09-19 09:17:13 +00:00
|
|
|
Object* func_value = CcTest::i_isolate()->context()->global_object()->
|
2012-11-08 10:26:50 +00:00
|
|
|
GetProperty(*foo_name)->ToObjectChecked();
|
|
|
|
CHECK(func_value->IsJSFunction());
|
|
|
|
Handle<JSFunction> function(JSFunction::cast(func_value));
|
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
|
|
|
// The code will survive at least two GCs.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2012-11-08 10:26:50 +00:00
|
|
|
CHECK(function->shared()->is_compiled());
|
|
|
|
|
|
|
|
// Bump the code age so that flushing is triggered.
|
|
|
|
const int kAgingThreshold = 6;
|
2012-12-03 13:38:39 +00:00
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
function->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
2012-11-08 10:26:50 +00:00
|
|
|
|
|
|
|
// Simulate incremental marking so that the function is enqueued as
|
|
|
|
// code flushing candidate.
|
|
|
|
SimulateIncrementalMarking();
|
|
|
|
|
2013-03-21 08:50:29 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2012-11-08 10:26:50 +00:00
|
|
|
// Enable the debugger and add a breakpoint while incremental marking
|
|
|
|
// is running so that incremental marking aborts and code flushing is
|
|
|
|
// disabled.
|
|
|
|
int position = 0;
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> breakpoint_object(Smi::FromInt(0), isolate);
|
2013-02-15 09:27:10 +00:00
|
|
|
isolate->debug()->SetBreakPoint(function, breakpoint_object, &position);
|
|
|
|
isolate->debug()->ClearAllBreakPoints();
|
2013-03-21 08:50:29 +00:00
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
2012-11-08 10:26:50 +00:00
|
|
|
|
|
|
|
// Force optimization now that code flushing is disabled.
|
2013-04-10 08:29:39 +00:00
|
|
|
{ v8::HandleScope scope(CcTest::isolate());
|
2012-11-08 10:26:50 +00:00
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(foo); foo();");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate one final GC to make sure the candidate queue is sane.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-11-08 10:26:50 +00:00
|
|
|
CHECK(function->shared()->is_compiled() || !function->IsOptimized());
|
|
|
|
CHECK(function->is_compiled() || !function->IsOptimized());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Count the number of native contexts in the weak list of native contexts.
|
|
|
|
int CountNativeContexts() {
|
2010-10-18 14:59:03 +00:00
|
|
|
int count = 0;
|
2013-09-19 09:46:15 +00:00
|
|
|
Object* object = CcTest::heap()->native_contexts_list();
|
2010-10-18 14:59:03 +00:00
|
|
|
while (!object->IsUndefined()) {
|
|
|
|
count++;
|
|
|
|
object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK);
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Count the number of user functions in the weak list of optimized
|
2012-08-17 09:03:08 +00:00
|
|
|
// functions attached to a native context.
|
2010-12-07 11:31:57 +00:00
|
|
|
static int CountOptimizedUserFunctions(v8::Handle<v8::Context> context) {
|
|
|
|
int count = 0;
|
|
|
|
Handle<Context> icontext = v8::Utils::OpenHandle(*context);
|
|
|
|
Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST);
|
|
|
|
while (object->IsJSFunction() && !JSFunction::cast(object)->IsBuiltin()) {
|
|
|
|
count++;
|
|
|
|
object = JSFunction::cast(object)->next_function_link();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-18 14:59:03 +00:00
|
|
|
TEST(TestInternalWeakLists) {
|
2011-03-18 20:35:07 +00:00
|
|
|
v8::V8::Initialize();
|
|
|
|
|
2012-12-10 15:14:20 +00:00
|
|
|
// Some flags turn Scavenge collections into Mark-sweep collections
|
|
|
|
// and hence are incompatible with this test case.
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction) return;
|
|
|
|
|
2010-10-18 14:59:03 +00:00
|
|
|
static const int kNumTestContexts = 10;
|
|
|
|
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::Handle<v8::Context> ctx[kNumTestContexts];
|
2010-10-18 14:59:03 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(0, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
|
|
|
|
// Create a number of global contests which gets linked together.
|
|
|
|
for (int i = 0; i < kNumTestContexts; i++) {
|
2013-09-19 08:54:58 +00:00
|
|
|
ctx[i] = v8::Context::New(CcTest::isolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-07-08 09:07:57 +00:00
|
|
|
// Collect garbage that might have been created by one of the
|
|
|
|
// installed extensions.
|
|
|
|
isolate->compilation_cache()->Clear();
|
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
|
2013-09-03 08:49:44 +00:00
|
|
|
bool opt = (FLAG_always_opt && isolate->use_crankshaft());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(i + 1, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
|
|
|
|
ctx[i]->Enter();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Create a handle scope so no function objects get stuch in the outer
|
|
|
|
// handle scope
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
const char* source = "function f1() { };"
|
|
|
|
"function f2() { };"
|
|
|
|
"function f3() { };"
|
|
|
|
"function f4() { };"
|
|
|
|
"function f5() { };";
|
|
|
|
CompileRun(source);
|
|
|
|
CHECK_EQ(0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
CompileRun("f1()");
|
|
|
|
CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
CompileRun("f2()");
|
|
|
|
CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
CompileRun("f3()");
|
|
|
|
CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
CompileRun("f4()");
|
|
|
|
CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
CompileRun("f5()");
|
|
|
|
CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
|
|
|
|
// Remove function f1, and
|
|
|
|
CompileRun("f1=null");
|
|
|
|
|
|
|
|
// Scavenge treats these references as strong.
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->PerformScavenge();
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark compact handles the weak references.
|
2013-02-15 09:27:10 +00:00
|
|
|
isolate->compilation_cache()->Clear();
|
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
|
|
|
|
// Get rid of f3 and f5 in the same way.
|
|
|
|
CompileRun("f3=null");
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->PerformScavenge();
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
CompileRun("f5=null");
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->PerformScavenge();
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i]));
|
|
|
|
|
2010-10-18 14:59:03 +00:00
|
|
|
ctx[i]->Exit();
|
|
|
|
}
|
|
|
|
|
2010-10-18 17:01:30 +00:00
|
|
|
// Force compilation cache cleanup.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->NotifyContextDisposed();
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2010-10-18 17:01:30 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Dispose the native contexts one by one.
|
2010-10-18 14:59:03 +00:00
|
|
|
for (int i = 0; i < kNumTestContexts; i++) {
|
2013-05-02 20:18:42 +00:00
|
|
|
// TODO(dcarney): is there a better way to do this?
|
|
|
|
i::Object** unsafe = reinterpret_cast<i::Object**>(*ctx[i]);
|
2013-09-19 09:46:15 +00:00
|
|
|
*unsafe = CcTest::heap()->undefined_value();
|
2010-10-18 14:59:03 +00:00
|
|
|
ctx[i].Clear();
|
|
|
|
|
|
|
|
// Scavenge treats these references as strong.
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->PerformScavenge();
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(kNumTestContexts - i, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark compact handles the weak references.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(kNumTestContexts - i - 1, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(0, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Count the number of native contexts in the weak list of native contexts
|
2010-10-18 14:59:03 +00:00
|
|
|
// causing a GC after the specified number of elements.
|
2013-02-25 14:46:09 +00:00
|
|
|
static int CountNativeContextsWithGC(Isolate* isolate, int n) {
|
|
|
|
Heap* heap = isolate->heap();
|
2010-10-18 14:59:03 +00:00
|
|
|
int count = 0;
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> object(heap->native_contexts_list(), isolate);
|
2010-10-18 14:59:03 +00:00
|
|
|
while (!object->IsUndefined()) {
|
|
|
|
count++;
|
2013-02-25 14:46:09 +00:00
|
|
|
if (count == n) heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2010-10-18 14:59:03 +00:00
|
|
|
object =
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK),
|
|
|
|
isolate);
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Count the number of user functions in the weak list of optimized
|
2012-08-17 09:03:08 +00:00
|
|
|
// functions attached to a native context causing a GC after the
|
2010-12-07 11:31:57 +00:00
|
|
|
// specified number of elements.
|
|
|
|
static int CountOptimizedUserFunctionsWithGC(v8::Handle<v8::Context> context,
|
|
|
|
int n) {
|
|
|
|
int count = 0;
|
|
|
|
Handle<Context> icontext = v8::Utils::OpenHandle(*context);
|
2013-02-25 14:46:09 +00:00
|
|
|
Isolate* isolate = icontext->GetIsolate();
|
|
|
|
Handle<Object> object(icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST),
|
|
|
|
isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
while (object->IsJSFunction() &&
|
|
|
|
!Handle<JSFunction>::cast(object)->IsBuiltin()) {
|
|
|
|
count++;
|
2013-02-25 14:46:09 +00:00
|
|
|
if (count == n) isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2010-12-07 11:31:57 +00:00
|
|
|
object = Handle<Object>(
|
2013-02-25 14:46:09 +00:00
|
|
|
Object::cast(JSFunction::cast(*object)->next_function_link()),
|
|
|
|
isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-18 14:59:03 +00:00
|
|
|
TEST(TestInternalWeakListsTraverseWithGC) {
|
2011-03-18 20:35:07 +00:00
|
|
|
v8::V8::Initialize();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2010-10-18 14:59:03 +00:00
|
|
|
static const int kNumTestContexts = 10;
|
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::Handle<v8::Context> ctx[kNumTestContexts];
|
2010-10-18 14:59:03 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(0, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
|
|
|
|
// Create an number of contexts and check the length of the weak list both
|
|
|
|
// with and without GCs while iterating the list.
|
|
|
|
for (int i = 0; i < kNumTestContexts; i++) {
|
2013-09-19 08:54:58 +00:00
|
|
|
ctx[i] = v8::Context::New(CcTest::isolate());
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(i + 1, CountNativeContexts());
|
2013-02-25 14:46:09 +00:00
|
|
|
CHECK_EQ(i + 1, CountNativeContextsWithGC(isolate, i / 2 + 1));
|
2010-12-07 11:01:02 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-09-03 08:49:44 +00:00
|
|
|
bool opt = (FLAG_always_opt && isolate->use_crankshaft());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Compile a number of functions the length of the weak list of optimized
|
|
|
|
// functions both with and without GCs while iterating the list.
|
|
|
|
ctx[0]->Enter();
|
|
|
|
const char* source = "function f1() { };"
|
|
|
|
"function f2() { };"
|
|
|
|
"function f3() { };"
|
|
|
|
"function f4() { };"
|
|
|
|
"function f5() { };";
|
|
|
|
CompileRun(source);
|
|
|
|
CHECK_EQ(0, CountOptimizedUserFunctions(ctx[0]));
|
|
|
|
CompileRun("f1()");
|
|
|
|
CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctions(ctx[0]));
|
|
|
|
CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 1));
|
|
|
|
CompileRun("f2()");
|
|
|
|
CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[0]));
|
|
|
|
CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 1));
|
|
|
|
CompileRun("f3()");
|
|
|
|
CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[0]));
|
|
|
|
CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 1));
|
|
|
|
CompileRun("f4()");
|
|
|
|
CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0]));
|
|
|
|
CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2));
|
|
|
|
CompileRun("f5()");
|
|
|
|
CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0]));
|
|
|
|
CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4));
|
|
|
|
|
|
|
|
ctx[0]->Exit();
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
2010-11-15 10:38:24 +00:00
|
|
|
|
|
|
|
|
2012-01-11 10:33:34 +00:00
|
|
|
TEST(TestSizeOfObjects) {
|
|
|
|
v8::V8::Initialize();
|
|
|
|
|
|
|
|
// Get initial heap size after several full GCs, which will stabilize
|
|
|
|
// the heap size and return with sweeping finished completely.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
CHECK(CcTest::heap()->old_pointer_space()->IsLazySweepingComplete());
|
|
|
|
int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects());
|
2012-01-11 10:33:34 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Allocate objects on several different old-space pages so that
|
|
|
|
// lazy sweeping kicks in for subsequent GC runs.
|
|
|
|
AlwaysAllocateScope always_allocate;
|
2012-01-11 10:59:21 +00:00
|
|
|
int filler_size = static_cast<int>(FixedArray::SizeFor(8192));
|
2012-01-11 10:33:34 +00:00
|
|
|
for (int i = 1; i <= 100; i++) {
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->AllocateFixedArray(8192, TENURED)->ToObjectChecked();
|
2012-01-11 10:59:21 +00:00
|
|
|
CHECK_EQ(initial_size + i * filler_size,
|
2013-09-19 09:46:15 +00:00
|
|
|
static_cast<int>(CcTest::heap()->SizeOfObjects()));
|
2012-01-11 10:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The heap size should go back to initial size after a full GC, even
|
|
|
|
// though sweeping didn't finish yet.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-05-02 12:58:40 +00:00
|
|
|
|
|
|
|
// Normally sweeping would not be complete here, but no guarantees.
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects()));
|
2012-01-11 10:33:34 +00:00
|
|
|
|
|
|
|
// Advancing the sweeper step-wise should not change the heap size.
|
2013-09-19 09:46:15 +00:00
|
|
|
while (!CcTest::heap()->old_pointer_space()->IsLazySweepingComplete()) {
|
|
|
|
CcTest::heap()->old_pointer_space()->AdvanceSweeper(KB);
|
|
|
|
CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects()));
|
2012-01-11 10:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-15 10:38:24 +00:00
|
|
|
TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->EnsureHeapIsIterable();
|
|
|
|
intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects();
|
|
|
|
HeapIterator iterator(CcTest::heap());
|
2010-11-15 10:38:24 +00:00
|
|
|
intptr_t size_of_objects_2 = 0;
|
|
|
|
for (HeapObject* obj = iterator.next();
|
|
|
|
obj != NULL;
|
|
|
|
obj = iterator.next()) {
|
2012-09-14 11:16:56 +00:00
|
|
|
if (!obj->IsFreeSpace()) {
|
|
|
|
size_of_objects_2 += obj->Size();
|
|
|
|
}
|
2010-11-15 10:38:24 +00:00
|
|
|
}
|
2012-01-31 13:33:44 +00:00
|
|
|
// Delta must be within 5% of the larger result.
|
|
|
|
// TODO(gc): Tighten this up by distinguishing between byte
|
|
|
|
// arrays that are real and those that merely mark free space
|
|
|
|
// on the heap.
|
2010-11-15 10:38:24 +00:00
|
|
|
if (size_of_objects_1 > size_of_objects_2) {
|
|
|
|
intptr_t delta = size_of_objects_1 - size_of_objects_2;
|
|
|
|
PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, "
|
|
|
|
"Iterator: %" V8_PTR_PREFIX "d, "
|
|
|
|
"delta: %" V8_PTR_PREFIX "d\n",
|
|
|
|
size_of_objects_1, size_of_objects_2, delta);
|
2012-01-31 13:33:44 +00:00
|
|
|
CHECK_GT(size_of_objects_1 / 20, delta);
|
2010-11-15 10:38:24 +00:00
|
|
|
} else {
|
|
|
|
intptr_t delta = size_of_objects_2 - size_of_objects_1;
|
|
|
|
PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, "
|
|
|
|
"Iterator: %" V8_PTR_PREFIX "d, "
|
|
|
|
"delta: %" V8_PTR_PREFIX "d\n",
|
|
|
|
size_of_objects_1, size_of_objects_2, delta);
|
2011-09-19 18:36:47 +00:00
|
|
|
CHECK_GT(size_of_objects_2 / 20, delta);
|
2010-11-15 10:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-21 10:49:40 +00:00
|
|
|
|
|
|
|
|
2011-11-08 12:42:02 +00:00
|
|
|
static void FillUpNewSpace(NewSpace* new_space) {
|
|
|
|
// Fill up new space to the point that it is completely full. Make sure
|
|
|
|
// that the scavenger does not undo the filling.
|
2013-03-15 12:06:53 +00:00
|
|
|
Heap* heap = new_space->heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
2011-11-08 12:42:02 +00:00
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
intptr_t available = new_space->EffectiveCapacity() - new_space->Size();
|
2012-04-05 15:36:31 +00:00
|
|
|
intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1;
|
2011-11-08 12:42:02 +00:00
|
|
|
for (intptr_t i = 0; i < number_of_fillers; i++) {
|
2013-03-15 12:06:53 +00:00
|
|
|
CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED)));
|
2011-11-08 12:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-20 13:37:40 +00:00
|
|
|
TEST(GrowAndShrinkNewSpace) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
NewSpace* new_space = heap->new_space();
|
2011-09-20 13:37:40 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
if (heap->ReservedSemiSpaceSize() == heap->InitialSemiSpaceSize() ||
|
|
|
|
heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) {
|
2012-04-26 14:45:58 +00:00
|
|
|
// The max size cannot exceed the reserved size, since semispaces must be
|
|
|
|
// always within the reserved space. We can't test new space growing and
|
|
|
|
// shrinking if the reserved size is the same as the minimum (initial) size.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-20 13:37:40 +00:00
|
|
|
// Explicitly growing should double the space capacity.
|
2011-09-22 14:50:20 +00:00
|
|
|
intptr_t old_capacity, new_capacity;
|
2011-09-20 13:37:40 +00:00
|
|
|
old_capacity = new_space->Capacity();
|
|
|
|
new_space->Grow();
|
|
|
|
new_capacity = new_space->Capacity();
|
2011-09-22 16:40:07 +00:00
|
|
|
CHECK(2 * old_capacity == new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
2011-09-22 14:50:20 +00:00
|
|
|
old_capacity = new_space->Capacity();
|
2011-11-08 12:42:02 +00:00
|
|
|
FillUpNewSpace(new_space);
|
2011-09-22 14:50:20 +00:00
|
|
|
new_capacity = new_space->Capacity();
|
2011-09-22 16:40:07 +00:00
|
|
|
CHECK(old_capacity == new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
|
|
|
// Explicitly shrinking should not affect space capacity.
|
|
|
|
old_capacity = new_space->Capacity();
|
|
|
|
new_space->Shrink();
|
|
|
|
new_capacity = new_space->Capacity();
|
2011-09-22 16:40:07 +00:00
|
|
|
CHECK(old_capacity == new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
2011-09-22 14:50:20 +00:00
|
|
|
// Let the scavenger empty the new space.
|
2013-09-19 09:46:15 +00:00
|
|
|
heap->CollectGarbage(NEW_SPACE);
|
2011-09-22 14:50:20 +00:00
|
|
|
CHECK_LE(new_space->Size(), old_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
|
|
|
// Explicitly shrinking should halve the space capacity.
|
|
|
|
old_capacity = new_space->Capacity();
|
|
|
|
new_space->Shrink();
|
|
|
|
new_capacity = new_space->Capacity();
|
2011-09-22 16:40:07 +00:00
|
|
|
CHECK(old_capacity == 2 * new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
|
|
|
// Consecutive shrinking should not affect space capacity.
|
|
|
|
old_capacity = new_space->Capacity();
|
|
|
|
new_space->Shrink();
|
|
|
|
new_space->Shrink();
|
|
|
|
new_space->Shrink();
|
|
|
|
new_capacity = new_space->Capacity();
|
2011-09-22 16:40:07 +00:00
|
|
|
CHECK(old_capacity == new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
}
|
2011-11-08 12:42:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(CollectingAllAvailableGarbageShrinksNewSpace) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
if (heap->ReservedSemiSpaceSize() == heap->InitialSemiSpaceSize() ||
|
|
|
|
heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) {
|
2012-04-26 14:45:58 +00:00
|
|
|
// The max size cannot exceed the reserved size, since semispaces must be
|
|
|
|
// always within the reserved space. We can't test new space growing and
|
|
|
|
// shrinking if the reserved size is the same as the minimum (initial) size.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
NewSpace* new_space = heap->new_space();
|
2011-11-08 12:42:02 +00:00
|
|
|
intptr_t old_capacity, new_capacity;
|
|
|
|
old_capacity = new_space->Capacity();
|
|
|
|
new_space->Grow();
|
|
|
|
new_capacity = new_space->Capacity();
|
|
|
|
CHECK(2 * old_capacity == new_capacity);
|
|
|
|
FillUpNewSpace(new_space);
|
2013-09-19 09:46:15 +00:00
|
|
|
heap->CollectAllAvailableGarbage();
|
2011-11-08 12:42:02 +00:00
|
|
|
new_capacity = new_space->Capacity();
|
|
|
|
CHECK(old_capacity == new_capacity);
|
|
|
|
}
|
2011-11-30 11:13:36 +00:00
|
|
|
|
2011-12-14 14:01:54 +00:00
|
|
|
|
|
|
|
static int NumberOfGlobalObjects() {
|
|
|
|
int count = 0;
|
2013-09-19 09:46:15 +00:00
|
|
|
HeapIterator iterator(CcTest::heap());
|
2011-12-14 14:01:54 +00:00
|
|
|
for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
|
|
|
|
if (obj->IsGlobalObject()) count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that we don't embed maps from foreign contexts into
|
|
|
|
// optimized code.
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaMap) {
|
2011-12-19 12:39:52 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-14 14:01:54 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(4, NumberOfGlobalObjects());
|
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-14 14:01:54 +00:00
|
|
|
CompileRun("var v = {x: 42}");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2011-12-14 14:01:54 +00:00
|
|
|
v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
|
|
|
|
ctx2->Enter();
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v);
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() { return o.x; }"
|
2011-12-19 12:39:52 +00:00
|
|
|
"for (var i = 0; i < 10; ++i) f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
2011-12-14 14:01:54 +00:00
|
|
|
"f();");
|
|
|
|
CHECK_EQ(42, res->Int32Value());
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
|
|
|
|
ctx2->Exit();
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1)->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2012-10-12 13:49:12 +00:00
|
|
|
v8::V8::ContextDisposedNotification();
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that we don't embed functions from foreign contexts into
|
|
|
|
// optimized code.
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaFunction) {
|
2011-12-19 12:39:52 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-14 14:01:54 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(4, NumberOfGlobalObjects());
|
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-14 14:01:54 +00:00
|
|
|
CompileRun("var v = function() { return 42; }");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2011-12-14 14:01:54 +00:00
|
|
|
v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
|
|
|
|
ctx2->Enter();
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v);
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f(x) { return x(); }"
|
2011-12-19 12:39:52 +00:00
|
|
|
"for (var i = 0; i < 10; ++i) f(o);"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
2011-12-14 14:01:54 +00:00
|
|
|
"f(o);");
|
|
|
|
CHECK_EQ(42, res->Int32Value());
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
|
|
|
|
ctx2->Exit();
|
|
|
|
ctx1->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2012-10-12 13:49:12 +00:00
|
|
|
v8::V8::ContextDisposedNotification();
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
2011-12-19 12:39:52 +00:00
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaMapKeyed) {
|
2011-12-19 12:39:52 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-19 12:39:52 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(4, NumberOfGlobalObjects());
|
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-19 12:39:52 +00:00
|
|
|
CompileRun("var v = [42, 43]");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2011-12-19 12:39:52 +00:00
|
|
|
v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
|
|
|
|
ctx2->Enter();
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v);
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() { return o[0]; }"
|
|
|
|
"for (var i = 0; i < 10; ++i) f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
CHECK_EQ(42, res->Int32Value());
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
|
|
|
|
ctx2->Exit();
|
|
|
|
ctx1->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2012-10-12 13:49:12 +00:00
|
|
|
v8::V8::ContextDisposedNotification();
|
2011-12-19 12:39:52 +00:00
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaMapProto) {
|
2011-12-19 12:39:52 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-19 12:39:52 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(4, NumberOfGlobalObjects());
|
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-19 12:39:52 +00:00
|
|
|
CompileRun("var v = { y: 42}");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2011-12-19 12:39:52 +00:00
|
|
|
v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
|
|
|
|
ctx2->Enter();
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v);
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var p = {x: 42};"
|
|
|
|
" p.__proto__ = o;"
|
|
|
|
" return p.x;"
|
|
|
|
"}"
|
|
|
|
"for (var i = 0; i < 10; ++i) f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
CHECK_EQ(42, res->Int32Value());
|
|
|
|
ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
|
|
|
|
ctx2->Exit();
|
|
|
|
ctx1->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2012-10-12 13:49:12 +00:00
|
|
|
v8::V8::ContextDisposedNotification();
|
2011-12-19 12:39:52 +00:00
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
2012-01-11 09:39:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(InstanceOfStubWriteBarrier) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2012-01-11 09:39:37 +00:00
|
|
|
i::FLAG_verify_heap = true;
|
2012-01-11 09:49:47 +00:00
|
|
|
#endif
|
2012-10-12 11:41:14 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft()) return;
|
2012-11-16 10:33:57 +00:00
|
|
|
if (i::FLAG_force_marking_deque_overflows) return;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope outer_scope(CcTest::isolate());
|
2012-01-11 09:39:37 +00:00
|
|
|
|
|
|
|
{
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-01-11 09:39:37 +00:00
|
|
|
CompileRun(
|
|
|
|
"function foo () { }"
|
|
|
|
"function mkbar () { return new (new Function(\"\")) (); }"
|
|
|
|
"function f (x) { return (x instanceof foo); }"
|
|
|
|
"function g () { f(mkbar()); }"
|
|
|
|
"f(new foo()); f(new foo());"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f(new foo()); g();");
|
|
|
|
}
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2012-01-11 09:39:37 +00:00
|
|
|
marking->Abort();
|
|
|
|
marking->Start();
|
|
|
|
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-01-11 09:39:37 +00:00
|
|
|
|
|
|
|
CHECK(f->IsOptimized());
|
|
|
|
|
|
|
|
while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) &&
|
|
|
|
!marking->IsStopped()) {
|
2012-04-03 07:32:19 +00:00
|
|
|
// Discard any pending GC requests otherwise we will get GC when we enter
|
|
|
|
// code below.
|
|
|
|
marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
|
2012-01-11 09:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
|
|
|
|
{
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-23 11:25:52 +00:00
|
|
|
v8::Handle<v8::Object> global = CcTest::global();
|
2012-01-11 09:39:37 +00:00
|
|
|
v8::Handle<v8::Function> g =
|
|
|
|
v8::Handle<v8::Function>::Cast(global->Get(v8_str("g")));
|
|
|
|
g->Call(global, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->incremental_marking()->set_should_hurry(true);
|
|
|
|
CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE);
|
2012-01-11 09:39:37 +00:00
|
|
|
}
|
2012-01-19 13:38:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(PrototypeTransitionClearing) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-01-19 13:38:37 +00:00
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"var base = {};"
|
|
|
|
"var live = [];"
|
|
|
|
"for (var i = 0; i < 10; i++) {"
|
|
|
|
" var object = {};"
|
|
|
|
" var prototype = {};"
|
|
|
|
" object.__proto__ = prototype;"
|
|
|
|
" if (i >= 3) live.push(object, prototype);"
|
|
|
|
"}");
|
|
|
|
|
|
|
|
Handle<JSObject> baseObject =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Object>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("base"))));
|
2012-01-19 13:38:37 +00:00
|
|
|
|
2012-06-15 11:53:09 +00:00
|
|
|
// Verify that only dead prototype transitions are cleared.
|
|
|
|
CHECK_EQ(10, baseObject->map()->NumberOfProtoTransitions());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2012-06-15 11:53:09 +00:00
|
|
|
const int transitions = 10 - 3;
|
2012-06-06 10:17:26 +00:00
|
|
|
CHECK_EQ(transitions, baseObject->map()->NumberOfProtoTransitions());
|
2012-01-19 13:38:37 +00:00
|
|
|
|
|
|
|
// Verify that prototype transitions array was compacted.
|
2012-07-10 07:53:00 +00:00
|
|
|
FixedArray* trans = baseObject->map()->GetPrototypeTransitions();
|
2012-06-06 10:17:26 +00:00
|
|
|
for (int i = 0; i < transitions; i++) {
|
2012-01-19 13:38:37 +00:00
|
|
|
int j = Map::kProtoTransitionHeaderSize +
|
|
|
|
i * Map::kProtoTransitionElementsPerEntry;
|
|
|
|
CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap());
|
2012-06-06 10:17:26 +00:00
|
|
|
Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset);
|
|
|
|
CHECK(proto->IsTheHole() || proto->IsJSObject());
|
2012-01-19 13:38:37 +00:00
|
|
|
}
|
2012-01-20 12:44:04 +00:00
|
|
|
|
|
|
|
// Make sure next prototype is placed on an old-space evacuation candidate.
|
|
|
|
Handle<JSObject> prototype;
|
2013-09-19 09:46:15 +00:00
|
|
|
PagedSpace* space = CcTest::heap()->old_pointer_space();
|
2012-11-16 11:39:32 +00:00
|
|
|
{
|
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
SimulateFullSpace(space);
|
2013-06-04 10:30:05 +00:00
|
|
|
prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED);
|
2012-11-16 11:39:32 +00:00
|
|
|
}
|
2012-01-20 12:44:04 +00:00
|
|
|
|
|
|
|
// Add a prototype on an evacuation candidate and verify that transition
|
|
|
|
// clearing correctly records slots in prototype transition array.
|
|
|
|
i::FLAG_always_compact = true;
|
|
|
|
Handle<Map> map(baseObject->map());
|
2012-07-10 07:53:00 +00:00
|
|
|
CHECK(!space->LastPage()->Contains(
|
|
|
|
map->GetPrototypeTransitions()->address()));
|
2012-01-20 12:44:04 +00:00
|
|
|
CHECK(space->LastPage()->Contains(prototype->address()));
|
2013-07-02 15:32:46 +00:00
|
|
|
JSObject::SetPrototype(baseObject, prototype, false);
|
|
|
|
CHECK(Map::GetPrototypeTransition(map, prototype)->IsMap());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2013-07-02 15:32:46 +00:00
|
|
|
CHECK(Map::GetPrototypeTransition(map, prototype)->IsMap());
|
2012-01-19 13:38:37 +00:00
|
|
|
}
|
2012-04-03 17:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) {
|
2013-06-19 08:58:09 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2012-04-03 17:22:05 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2012-04-03 17:22:05 +00:00
|
|
|
i::FLAG_verify_heap = true;
|
|
|
|
#endif
|
2012-10-12 11:41:14 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft()) return;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope outer_scope(CcTest::isolate());
|
2012-04-03 17:22:05 +00:00
|
|
|
|
|
|
|
{
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-04-03 17:22:05 +00:00
|
|
|
CompileRun(
|
|
|
|
"function f () {"
|
|
|
|
" var s = 0;"
|
|
|
|
" for (var i = 0; i < 100; i++) s += i;"
|
|
|
|
" return s;"
|
|
|
|
"}"
|
|
|
|
"f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
}
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-04-03 17:22:05 +00:00
|
|
|
CHECK(f->IsOptimized());
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2012-04-03 17:22:05 +00:00
|
|
|
marking->Abort();
|
|
|
|
marking->Start();
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
// The following two calls will increment CcTest::heap()->global_ic_age().
|
2012-04-03 17:22:05 +00:00
|
|
|
const int kLongIdlePauseInMs = 1000;
|
|
|
|
v8::V8::ContextDisposedNotification();
|
|
|
|
v8::V8::IdleNotification(kLongIdlePauseInMs);
|
|
|
|
|
|
|
|
while (!marking->IsStopped() && !marking->IsComplete()) {
|
|
|
|
marking->Step(1 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
|
|
|
|
}
|
2012-05-02 12:58:40 +00:00
|
|
|
if (!marking->IsStopped() || marking->should_hurry()) {
|
|
|
|
// We don't normally finish a GC via Step(), we normally finish by
|
|
|
|
// setting the stack guard and then do the final steps in the stack
|
|
|
|
// guard interrupt. But here we didn't ask for that, and there is no
|
|
|
|
// JS code running to trigger the interrupt, so we explicitly finalize
|
|
|
|
// here.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags,
|
2012-05-02 12:58:40 +00:00
|
|
|
"Test finalizing incremental mark-sweep");
|
|
|
|
}
|
2012-04-03 17:22:05 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK_EQ(CcTest::heap()->global_ic_age(), f->shared()->ic_age());
|
2012-04-03 17:22:05 +00:00
|
|
|
CHECK_EQ(0, f->shared()->opt_count());
|
|
|
|
CHECK_EQ(0, f->shared()->code()->profiler_ticks());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) {
|
2013-06-19 08:58:09 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2012-04-03 17:22:05 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2012-04-03 17:22:05 +00:00
|
|
|
i::FLAG_verify_heap = true;
|
|
|
|
#endif
|
2012-10-12 11:41:14 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft()) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope outer_scope(CcTest::isolate());
|
2012-04-03 17:22:05 +00:00
|
|
|
|
|
|
|
{
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-04-03 17:22:05 +00:00
|
|
|
CompileRun(
|
|
|
|
"function f () {"
|
|
|
|
" var s = 0;"
|
|
|
|
" for (var i = 0; i < 100; i++) s += i;"
|
|
|
|
" return s;"
|
|
|
|
"}"
|
|
|
|
"f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
}
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-04-03 17:22:05 +00:00
|
|
|
CHECK(f->IsOptimized());
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->incremental_marking()->Abort();
|
2012-04-03 17:22:05 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
// The following two calls will increment CcTest::heap()->global_ic_age().
|
2012-04-03 17:22:05 +00:00
|
|
|
// Since incremental marking is off, IdleNotification will do full GC.
|
|
|
|
const int kLongIdlePauseInMs = 1000;
|
|
|
|
v8::V8::ContextDisposedNotification();
|
|
|
|
v8::V8::IdleNotification(kLongIdlePauseInMs);
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK_EQ(CcTest::heap()->global_ic_age(), f->shared()->ic_age());
|
2012-04-03 17:22:05 +00:00
|
|
|
CHECK_EQ(0, f->shared()->opt_count());
|
|
|
|
CHECK_EQ(0, f->shared()->code()->profiler_ticks());
|
|
|
|
}
|
2012-04-05 15:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Test that HAllocateObject will always return an object in new-space.
|
|
|
|
TEST(OptimizedAllocationAlwaysInNewSpace) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2012-12-10 15:14:20 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-04-05 15:36:31 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
SimulateFullSpace(CcTest::heap()->new_space());
|
2012-04-05 15:36:31 +00:00
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function c(x) {"
|
|
|
|
" this.x = x;"
|
|
|
|
" for (var i = 0; i < 32; i++) {"
|
|
|
|
" this['x' + i] = x;"
|
|
|
|
" }"
|
|
|
|
"}"
|
|
|
|
"function f(x) { return new c(x); };"
|
|
|
|
"f(1); f(2); f(3);"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f(4);");
|
2012-04-05 16:40:13 +00:00
|
|
|
CHECK_EQ(4, res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value());
|
2012-04-05 15:36:31 +00:00
|
|
|
|
2013-03-07 14:00:53 +00:00
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InNewSpace(*o));
|
2013-03-07 14:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 07:42:23 +00:00
|
|
|
TEST(OptimizedPretenuringAllocationFolding) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-08-27 07:42:23 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-08-27 07:42:23 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-08-27 07:42:23 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function DataObject() {"
|
|
|
|
" this.a = 1.1;"
|
|
|
|
" this.b = [{}];"
|
|
|
|
" this.c = 1.2;"
|
|
|
|
" this.d = [{}];"
|
|
|
|
" this.e = 1.3;"
|
|
|
|
" this.f = [{}];"
|
|
|
|
"}"
|
|
|
|
"function f() {"
|
|
|
|
" return new DataObject();"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(0)));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1)));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(2)));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(3)));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(4)));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(5)));
|
2013-08-27 07:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringAllocationFoldingBlocks) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-08-27 07:42:23 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-08-27 07:42:23 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-08-27 07:42:23 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function DataObject() {"
|
|
|
|
" this.a = [{}];"
|
|
|
|
" this.b = [{}];"
|
|
|
|
" this.c = 1.1;"
|
|
|
|
" this.d = 1.2;"
|
|
|
|
" this.e = [{}];"
|
|
|
|
" this.f = 1.3;"
|
|
|
|
"}"
|
|
|
|
"function f() {"
|
|
|
|
" return new DataObject();"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(0)));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1)));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(2)));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(3)));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(4)));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(5)));
|
2013-08-27 07:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-25 07:47:53 +00:00
|
|
|
TEST(OptimizedPretenuringObjectArrayLiterals) {
|
2013-03-07 14:00:53 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-03-07 14:00:53 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-03-07 14:00:53 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
2013-06-25 07:47:53 +00:00
|
|
|
" var numbers = [{}, {}, {}];"
|
2013-03-07 14:00:53 +00:00
|
|
|
" return numbers;"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
2013-03-07 14:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-25 07:47:53 +00:00
|
|
|
TEST(OptimizedPretenuringMixedInObjectProperties) {
|
2013-04-10 13:52:08 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-04-10 13:52:08 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-04-10 13:52:08 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-04-10 13:52:08 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
2013-06-25 07:47:53 +00:00
|
|
|
" var numbers = {a: {c: 2.2, d: {}}, b: 1.1};"
|
|
|
|
" return numbers;"
|
2013-04-10 13:52:08 +00:00
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(0)));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(1)));
|
2013-06-25 07:47:53 +00:00
|
|
|
|
|
|
|
JSObject* inner_object = reinterpret_cast<JSObject*>(o->RawFastPropertyAt(0));
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(inner_object));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(inner_object->RawFastPropertyAt(0)));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(inner_object->RawFastPropertyAt(1)));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringDoubleArrayProperties) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-06-25 07:47:53 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-06-25 07:47:53 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var numbers = {a: 1.1, b: 2.2};"
|
|
|
|
" return numbers;"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->properties()));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringdoubleArrayLiterals) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-06-25 07:47:53 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-06-25 07:47:53 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var numbers = [1.1, 2.2, 3.3];"
|
|
|
|
" return numbers;"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(o->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringNestedMixedArrayLiterals) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-06-25 07:47:53 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-06-25 07:47:53 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var numbers = [[{}, {}, {}],[1.1, 2.2, 3.3]];"
|
|
|
|
" return numbers;"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0"));
|
|
|
|
Handle<JSObject> int_array_handle =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array));
|
|
|
|
v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1"));
|
|
|
|
Handle<JSObject> double_array_handle =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array));
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(double_array_handle->elements()));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringNestedObjectLiterals) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-06-25 07:47:53 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-06-25 07:47:53 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var numbers = [[{}, {}, {}],[{}, {}, {}]];"
|
|
|
|
" return numbers;"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0"));
|
|
|
|
Handle<JSObject> int_array_handle_1 =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_1));
|
|
|
|
v8::Local<v8::Value> int_array_2 = v8::Object::Cast(*res)->Get(v8_str("1"));
|
|
|
|
Handle<JSObject> int_array_handle_2 =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_2));
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle_1));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle_1->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle_2));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle_2->elements()));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringNestedDoubleLiterals) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-06-25 07:47:53 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-06-25 07:47:53 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var numbers = [[1.1, 1.2, 1.3],[2.1, 2.2, 2.3]];"
|
|
|
|
" return numbers;"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
v8::Local<v8::Value> double_array_1 =
|
|
|
|
v8::Object::Cast(*res)->Get(v8_str("0"));
|
|
|
|
Handle<JSObject> double_array_handle_1 =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_1));
|
|
|
|
v8::Local<v8::Value> double_array_2 =
|
|
|
|
v8::Object::Cast(*res)->Get(v8_str("1"));
|
|
|
|
Handle<JSObject> double_array_handle_2 =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_2));
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_1));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_1->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_2));
|
|
|
|
CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_2->elements()));
|
2013-04-10 13:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-07 14:00:53 +00:00
|
|
|
// Test regular array literals allocation.
|
|
|
|
TEST(OptimizedAllocationArrayLiterals) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-03-07 14:00:53 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-03-07 14:00:53 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
|
2012-04-05 15:36:31 +00:00
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InNewSpace(o->elements()));
|
2012-04-05 15:36:31 +00:00
|
|
|
}
|
2012-05-16 10:07:50 +00:00
|
|
|
|
|
|
|
|
2013-07-15 15:12:16 +00:00
|
|
|
TEST(OptimizedPretenuringCallNew) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-11-27 14:03:40 +00:00
|
|
|
i::FLAG_allocation_site_pretenuring = false;
|
2013-07-15 15:12:16 +00:00
|
|
|
i::FLAG_pretenuring_call_new = true;
|
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
2013-07-15 15:12:16 +00:00
|
|
|
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
2013-07-15 15:12:16 +00:00
|
|
|
|
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function g() { this.a = 0; }"
|
|
|
|
"function f() {"
|
|
|
|
" return new g();"
|
|
|
|
"};"
|
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
|
|
|
|
|
|
|
Handle<JSObject> o =
|
|
|
|
v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InOldPointerSpace(*o));
|
2013-07-15 15:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 10:07:50 +00:00
|
|
|
static int CountMapTransitions(Map* map) {
|
2012-07-05 13:54:20 +00:00
|
|
|
return map->transitions()->number_of_transitions();
|
2012-05-16 10:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that map transitions are cleared and maps are collected with
|
|
|
|
// incremental marking as well.
|
|
|
|
TEST(Regress1465) {
|
2013-06-17 06:44:44 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2012-05-16 10:07:50 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_trace_incremental_marking = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-08-02 14:20:38 +00:00
|
|
|
static const int transitions_count = 256;
|
2012-05-16 10:07:50 +00:00
|
|
|
|
2012-08-02 14:20:38 +00:00
|
|
|
{
|
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
for (int i = 0; i < transitions_count; i++) {
|
|
|
|
EmbeddedVector<char, 64> buffer;
|
|
|
|
OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i);
|
|
|
|
CompileRun(buffer.start());
|
|
|
|
}
|
|
|
|
CompileRun("var root = new Object;");
|
2012-05-16 10:07:50 +00:00
|
|
|
}
|
2012-08-02 14:20:38 +00:00
|
|
|
|
2012-05-16 10:07:50 +00:00
|
|
|
Handle<JSObject> root =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Object>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("root"))));
|
2012-05-16 10:07:50 +00:00
|
|
|
|
|
|
|
// Count number of live transitions before marking.
|
|
|
|
int transitions_before = CountMapTransitions(root->map());
|
|
|
|
CompileRun("%DebugPrint(root);");
|
2012-08-02 14:20:38 +00:00
|
|
|
CHECK_EQ(transitions_count, transitions_before);
|
2012-05-16 10:07:50 +00:00
|
|
|
|
2012-08-06 11:04:40 +00:00
|
|
|
SimulateIncrementalMarking();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-05-16 10:07:50 +00:00
|
|
|
|
|
|
|
// Count number of live transitions after marking. Note that one transition
|
|
|
|
// is left, because 'o' still holds an instance of one transition target.
|
|
|
|
int transitions_after = CountMapTransitions(root->map());
|
|
|
|
CompileRun("%DebugPrint(root);");
|
|
|
|
CHECK_EQ(1, transitions_after);
|
|
|
|
}
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress2143a) {
|
|
|
|
i::FLAG_collect_maps = true;
|
|
|
|
i::FLAG_incremental_marking = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// Prepare a map transition from the root object together with a yet
|
|
|
|
// untransitioned root object.
|
|
|
|
CompileRun("var root = new Object;"
|
|
|
|
"root.foo = 0;"
|
|
|
|
"root = new Object;");
|
|
|
|
|
2012-08-06 11:04:40 +00:00
|
|
|
SimulateIncrementalMarking();
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// Compile a StoreIC that performs the prepared map transition. This
|
|
|
|
// will restart incremental marking and should make sure the root is
|
|
|
|
// marked grey again.
|
|
|
|
CompileRun("function f(o) {"
|
|
|
|
" o.foo = 0;"
|
|
|
|
"}"
|
|
|
|
"f(new Object);"
|
|
|
|
"f(root);");
|
|
|
|
|
|
|
|
// This bug only triggers with aggressive IC clearing.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->AgeInlineCaches();
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// Explicitly request GC to perform final marking step and sweeping.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
Handle<JSObject> root =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Object>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("root"))));
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// The root object should be in a sane state.
|
|
|
|
CHECK(root->IsJSObject());
|
|
|
|
CHECK(root->map()->IsMap());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress2143b) {
|
|
|
|
i::FLAG_collect_maps = true;
|
|
|
|
i::FLAG_incremental_marking = true;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// Prepare a map transition from the root object together with a yet
|
|
|
|
// untransitioned root object.
|
|
|
|
CompileRun("var root = new Object;"
|
|
|
|
"root.foo = 0;"
|
|
|
|
"root = new Object;");
|
|
|
|
|
2012-08-06 11:04:40 +00:00
|
|
|
SimulateIncrementalMarking();
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// Compile an optimized LStoreNamedField that performs the prepared
|
|
|
|
// map transition. This will restart incremental marking and should
|
|
|
|
// make sure the root is marked grey again.
|
|
|
|
CompileRun("function f(o) {"
|
|
|
|
" o.foo = 0;"
|
|
|
|
"}"
|
|
|
|
"f(new Object);"
|
|
|
|
"f(new Object);"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f(root);"
|
|
|
|
"%DeoptimizeFunction(f);");
|
|
|
|
|
|
|
|
// This bug only triggers with aggressive IC clearing.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->AgeInlineCaches();
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// Explicitly request GC to perform final marking step and sweeping.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
Handle<JSObject> root =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Object>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("root"))));
|
2012-05-29 16:39:26 +00:00
|
|
|
|
|
|
|
// The root object should be in a sane state.
|
|
|
|
CHECK(root->IsJSObject());
|
|
|
|
CHECK(root->map()->IsMap());
|
|
|
|
}
|
2012-06-22 09:29:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(ReleaseOverReservedPages) {
|
|
|
|
i::FLAG_trace_gc = true;
|
2012-07-31 14:59:32 +00:00
|
|
|
// The optimizer can allocate stuff, messing up the test.
|
|
|
|
i::FLAG_crankshaft = false;
|
|
|
|
i::FLAG_always_opt = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-06-22 09:29:49 +00:00
|
|
|
static const int number_of_test_pages = 20;
|
|
|
|
|
|
|
|
// Prepare many pages with low live-bytes count.
|
2013-09-19 09:46:15 +00:00
|
|
|
PagedSpace* old_pointer_space = heap->old_pointer_space();
|
2012-06-22 09:29:49 +00:00
|
|
|
CHECK_EQ(1, old_pointer_space->CountTotalPages());
|
|
|
|
for (int i = 0; i < number_of_test_pages; i++) {
|
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
SimulateFullSpace(old_pointer_space);
|
2013-06-04 10:30:05 +00:00
|
|
|
factory->NewFixedArray(1, TENURED);
|
2012-06-22 09:29:49 +00:00
|
|
|
}
|
|
|
|
CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
|
|
|
|
|
|
|
|
// Triggering one GC will cause a lot of garbage to be discovered but
|
|
|
|
// even spread across all allocated pages.
|
2013-09-19 09:46:15 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation");
|
2012-12-10 15:14:20 +00:00
|
|
|
CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
|
2012-06-22 09:29:49 +00:00
|
|
|
|
|
|
|
// Triggering subsequent GCs should cause at least half of the pages
|
|
|
|
// to be released to the OS after at most two cycles.
|
2013-09-19 09:46:15 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 1");
|
2012-06-22 09:29:49 +00:00
|
|
|
CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
|
2013-09-19 09:46:15 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 2");
|
2012-06-22 09:29:49 +00:00
|
|
|
CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages() * 2);
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
// Triggering a last-resort GC should cause all pages to be released to the
|
|
|
|
// OS so that other processes can seize the memory. If we get a failure here
|
|
|
|
// where there are 2 pages left instead of 1, then we should increase the
|
|
|
|
// size of the first page a little in SizeOfFirstPage in spaces.cc. The
|
|
|
|
// first page should be small in order to reduce memory used when the VM
|
|
|
|
// boots, but if the 20 small arrays don't fit on the first page then that's
|
|
|
|
// an indication that it is too small.
|
2013-09-19 09:46:15 +00:00
|
|
|
heap->CollectAllAvailableGarbage("triggered really hard");
|
2012-06-22 09:29:49 +00:00
|
|
|
CHECK_EQ(1, old_pointer_space->CountTotalPages());
|
|
|
|
}
|
2012-07-18 13:39:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress2237) {
|
2013-06-17 06:36:46 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
Handle<String> slice(CcTest::heap()->empty_string());
|
2012-07-18 13:39:53 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Generate a parent that lives in new-space.
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope inner_scope(CcTest::isolate());
|
2012-07-18 13:39:53 +00:00
|
|
|
const char* c = "This text is long enough to trigger sliced strings.";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s = factory->NewStringFromAscii(CStrVector(c));
|
2012-11-15 13:31:27 +00:00
|
|
|
CHECK(s->IsSeqOneByteString());
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(CcTest::heap()->InNewSpace(*s));
|
2012-07-18 13:39:53 +00:00
|
|
|
|
|
|
|
// Generate a sliced string that is based on the above parent and
|
|
|
|
// lives in old-space.
|
2013-09-19 09:46:15 +00:00
|
|
|
SimulateFullSpace(CcTest::heap()->new_space());
|
2012-07-18 13:39:53 +00:00
|
|
|
AlwaysAllocateScope always_allocate;
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> t = factory->NewProperSubString(s, 5, 35);
|
2012-07-18 13:39:53 +00:00
|
|
|
CHECK(t->IsSlicedString());
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(!CcTest::heap()->InNewSpace(*t));
|
2012-07-18 13:39:53 +00:00
|
|
|
*slice.location() = *t.location();
|
|
|
|
}
|
|
|
|
|
2012-11-15 13:31:27 +00:00
|
|
|
CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-11-15 13:31:27 +00:00
|
|
|
CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
|
2012-07-18 13:39:53 +00:00
|
|
|
}
|
2012-07-27 09:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef OBJECT_PRINT
|
|
|
|
TEST(PrintSharedFunctionInfo) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-07-27 09:54:56 +00:00
|
|
|
const char* source = "f = function() { return 987654321; }\n"
|
|
|
|
"g = function() { return 123456789; }\n";
|
|
|
|
CompileRun(source);
|
|
|
|
Handle<JSFunction> g =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("g"))));
|
2012-07-27 09:54:56 +00:00
|
|
|
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-07-27 09:54:56 +00:00
|
|
|
g->shared()->PrintLn();
|
|
|
|
}
|
|
|
|
#endif // OBJECT_PRINT
|
2012-07-30 13:09:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress2211) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-07-30 13:09:09 +00:00
|
|
|
|
|
|
|
v8::Handle<v8::String> value = v8_str("val string");
|
|
|
|
Smi* hash = Smi::FromInt(321);
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
2012-07-30 13:09:09 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
// Store identity hash first and common hidden property second.
|
|
|
|
v8::Handle<v8::Object> obj = v8::Object::New();
|
|
|
|
Handle<JSObject> internal_obj = v8::Utils::OpenHandle(*obj);
|
|
|
|
CHECK(internal_obj->HasFastProperties());
|
|
|
|
|
|
|
|
// In the first iteration, set hidden value first and identity hash second.
|
|
|
|
// In the second iteration, reverse the order.
|
|
|
|
if (i == 0) obj->SetHiddenValue(v8_str("key string"), value);
|
2013-11-05 11:47:11 +00:00
|
|
|
JSObject::SetIdentityHash(internal_obj, handle(hash, CcTest::i_isolate()));
|
2012-07-30 13:09:09 +00:00
|
|
|
if (i == 1) obj->SetHiddenValue(v8_str("key string"), value);
|
|
|
|
|
|
|
|
// Check values.
|
|
|
|
CHECK_EQ(hash,
|
2013-02-28 17:03:34 +00:00
|
|
|
internal_obj->GetHiddenProperty(heap->identity_hash_string()));
|
2012-07-30 13:09:09 +00:00
|
|
|
CHECK(value->Equals(obj->GetHiddenValue(v8_str("key string"))));
|
|
|
|
|
|
|
|
// Check size.
|
|
|
|
DescriptorArray* descriptors = internal_obj->map()->instance_descriptors();
|
|
|
|
ObjectHashTable* hashtable = ObjectHashTable::cast(
|
2013-05-08 15:02:08 +00:00
|
|
|
internal_obj->RawFastPropertyAt(descriptors->GetFieldIndex(0)));
|
2012-07-30 13:48:52 +00:00
|
|
|
// HashTable header (5) and 4 initial entries (8).
|
|
|
|
CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize);
|
2012-07-30 13:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-01 11:24:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(IncrementalMarkingClearsTypeFeedbackCells) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-08-01 11:24:14 +00:00
|
|
|
v8::Local<v8::Value> fun1, fun2;
|
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() {};");
|
|
|
|
fun1 = env->Global()->Get(v8_str("fun"));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() {};");
|
|
|
|
fun2 = env->Global()->Get(v8_str("fun"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare function f that contains type feedback for closures
|
2012-08-17 09:03:08 +00:00
|
|
|
// originating from two different native contexts.
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Set(v8_str("fun1"), fun1);
|
|
|
|
CcTest::global()->Set(v8_str("fun2"), fun2);
|
2012-08-01 11:24:14 +00:00
|
|
|
CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);");
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-08-01 11:24:14 +00:00
|
|
|
Handle<TypeFeedbackCells> cells(TypeFeedbackInfo::cast(
|
|
|
|
f->shared()->code()->type_feedback_info())->type_feedback_cells());
|
|
|
|
|
|
|
|
CHECK_EQ(2, cells->CellCount());
|
2013-06-12 15:03:44 +00:00
|
|
|
CHECK(cells->GetCell(0)->value()->IsJSFunction());
|
|
|
|
CHECK(cells->GetCell(1)->value()->IsJSFunction());
|
2012-08-01 11:24:14 +00:00
|
|
|
|
2012-08-06 11:04:40 +00:00
|
|
|
SimulateIncrementalMarking();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-08-01 11:24:14 +00:00
|
|
|
|
|
|
|
CHECK_EQ(2, cells->CellCount());
|
2013-06-12 15:03:44 +00:00
|
|
|
CHECK(cells->GetCell(0)->value()->IsTheHole());
|
|
|
|
CHECK(cells->GetCell(1)->value()->IsTheHole());
|
2012-08-01 11:24:14 +00:00
|
|
|
}
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
static Code* FindFirstIC(Code* code, Code::Kind kind) {
|
|
|
|
int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
|
|
|
|
RelocInfo::ModeMask(RelocInfo::CONSTRUCT_CALL) |
|
|
|
|
RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID) |
|
|
|
|
RelocInfo::ModeMask(RelocInfo::CODE_TARGET_CONTEXT);
|
|
|
|
for (RelocIterator it(code, mask); !it.done(); it.next()) {
|
|
|
|
RelocInfo* info = it.rinfo();
|
|
|
|
Code* target = Code::GetCodeFromTargetAddress(info->target_address());
|
|
|
|
if (target->is_inline_cache_stub() && target->kind() == kind) {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(IncrementalMarkingPreservesMonomorhpicIC) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
// Prepare function f that contains a monomorphic IC for object
|
2012-08-17 09:03:08 +00:00
|
|
|
// originating from the same native context.
|
2012-08-06 10:35:48 +00:00
|
|
|
CompileRun("function fun() { this.x = 1; }; var obj = new fun();"
|
|
|
|
"function f(o) { return o.x; } f(obj); f(obj);");
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
|
|
|
|
CHECK(ic_before->ic_state() == MONOMORPHIC);
|
|
|
|
|
2012-08-06 11:04:40 +00:00
|
|
|
SimulateIncrementalMarking();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
|
|
|
|
CHECK(ic_after->ic_state() == MONOMORPHIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(IncrementalMarkingClearsMonomorhpicIC) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-08-06 10:35:48 +00:00
|
|
|
v8::Local<v8::Value> obj1;
|
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
|
|
|
|
obj1 = env->Global()->Get(v8_str("obj"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare function f that contains a monomorphic IC for object
|
2012-08-17 09:03:08 +00:00
|
|
|
// originating from a different native context.
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Set(v8_str("obj1"), obj1);
|
2012-08-06 10:35:48 +00:00
|
|
|
CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);");
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
|
|
|
|
CHECK(ic_before->ic_state() == MONOMORPHIC);
|
|
|
|
|
|
|
|
// Fire context dispose notification.
|
|
|
|
v8::V8::ContextDisposedNotification();
|
2012-08-06 11:04:40 +00:00
|
|
|
SimulateIncrementalMarking();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
|
2013-09-25 09:25:39 +00:00
|
|
|
CHECK(IC::IsCleared(ic_after));
|
2012-08-06 10:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(IncrementalMarkingClearsPolymorhpicIC) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-08-06 10:35:48 +00:00
|
|
|
v8::Local<v8::Value> obj1, obj2;
|
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
|
|
|
|
obj1 = env->Global()->Get(v8_str("obj"));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() { this.x = 2; }; var obj = new fun();");
|
|
|
|
obj2 = env->Global()->Get(v8_str("obj"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare function f that contains a polymorphic IC for objects
|
2012-08-17 09:03:08 +00:00
|
|
|
// originating from two different native contexts.
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Set(v8_str("obj1"), obj1);
|
|
|
|
CcTest::global()->Set(v8_str("obj2"), obj2);
|
2012-08-06 10:35:48 +00:00
|
|
|
CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);");
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
|
2013-03-04 14:03:27 +00:00
|
|
|
CHECK(ic_before->ic_state() == POLYMORPHIC);
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
// Fire context dispose notification.
|
|
|
|
v8::V8::ContextDisposedNotification();
|
2012-08-06 11:04:40 +00:00
|
|
|
SimulateIncrementalMarking();
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
|
2013-09-25 09:25:39 +00:00
|
|
|
CHECK(IC::IsCleared(ic_after));
|
2012-08-06 10:35:48 +00:00
|
|
|
}
|
2012-08-29 07:51:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SourceResource: public v8::String::ExternalAsciiStringResource {
|
|
|
|
public:
|
|
|
|
explicit SourceResource(const char* data)
|
|
|
|
: data_(data), length_(strlen(data)) { }
|
|
|
|
|
|
|
|
virtual void Dispose() {
|
|
|
|
i::DeleteArray(data_);
|
|
|
|
data_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* data() const { return data_; }
|
|
|
|
|
|
|
|
size_t length() const { return length_; }
|
|
|
|
|
|
|
|
bool IsDisposed() { return data_ == NULL; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* data_;
|
|
|
|
size_t length_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-24 12:16:02 +00:00
|
|
|
void ReleaseStackTraceDataTest(const char* source, const char* accessor) {
|
2012-08-29 07:51:48 +00:00
|
|
|
// Test that the data retained by the Error.stack accessor is released
|
|
|
|
// after the first time the accessor is fired. We use external string
|
|
|
|
// to check whether the data is being released since the external string
|
|
|
|
// resource's callback is fired when the external string is GC'ed.
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-08-29 07:51:48 +00:00
|
|
|
SourceResource* resource = new SourceResource(i::StrDup(source));
|
|
|
|
{
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-11-28 08:21:26 +00:00
|
|
|
v8::Handle<v8::String> source_string =
|
|
|
|
v8::String::NewExternal(CcTest::isolate(), resource);
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2012-08-29 07:51:48 +00:00
|
|
|
v8::Script::Compile(source_string)->Run();
|
|
|
|
CHECK(!resource->IsDisposed());
|
|
|
|
}
|
2013-09-19 09:46:15 +00:00
|
|
|
// CcTest::heap()->CollectAllAvailableGarbage();
|
2013-07-24 12:16:02 +00:00
|
|
|
CHECK(!resource->IsDisposed());
|
|
|
|
|
|
|
|
CompileRun(accessor);
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllAvailableGarbage();
|
2012-08-29 07:51:48 +00:00
|
|
|
|
|
|
|
// External source has been released.
|
|
|
|
CHECK(resource->IsDisposed());
|
|
|
|
delete resource;
|
|
|
|
}
|
2012-09-20 10:45:38 +00:00
|
|
|
|
|
|
|
|
2012-11-12 14:54:29 +00:00
|
|
|
TEST(ReleaseStackTraceData) {
|
2013-11-19 11:52:47 +00:00
|
|
|
FLAG_use_ic = false; // ICs retain objects.
|
|
|
|
FLAG_concurrent_recompilation = false;
|
2013-09-19 13:30:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2012-11-12 14:54:29 +00:00
|
|
|
static const char* source1 = "var error = null; "
|
|
|
|
/* Normal Error */ "try { "
|
|
|
|
" throw new Error(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = e; "
|
|
|
|
"} ";
|
|
|
|
static const char* source2 = "var error = null; "
|
|
|
|
/* Stack overflow */ "try { "
|
|
|
|
" (function f() { f(); })(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = e; "
|
|
|
|
"} ";
|
2013-07-24 12:16:02 +00:00
|
|
|
static const char* source3 = "var error = null; "
|
|
|
|
/* Normal Error */ "try { "
|
|
|
|
/* as prototype */ " throw new Error(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = {}; "
|
|
|
|
" error.__proto__ = e; "
|
|
|
|
"} ";
|
|
|
|
static const char* source4 = "var error = null; "
|
|
|
|
/* Stack overflow */ "try { "
|
|
|
|
/* as prototype */ " (function f() { f(); })(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = {}; "
|
|
|
|
" error.__proto__ = e; "
|
|
|
|
"} ";
|
|
|
|
static const char* getter = "error.stack";
|
|
|
|
static const char* setter = "error.stack = 0";
|
|
|
|
|
|
|
|
ReleaseStackTraceDataTest(source1, setter);
|
|
|
|
ReleaseStackTraceDataTest(source2, setter);
|
|
|
|
// We do not test source3 and source4 with setter, since the setter is
|
|
|
|
// supposed to (untypically) write to the receiver, not the holder. This is
|
|
|
|
// to emulate the behavior of a data property.
|
|
|
|
|
|
|
|
ReleaseStackTraceDataTest(source1, getter);
|
|
|
|
ReleaseStackTraceDataTest(source2, getter);
|
|
|
|
ReleaseStackTraceDataTest(source3, getter);
|
|
|
|
ReleaseStackTraceDataTest(source4, getter);
|
2012-11-12 14:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-20 10:45:38 +00:00
|
|
|
TEST(Regression144230) {
|
2013-06-13 12:49:38 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-25 14:46:09 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2012-09-20 10:45:38 +00:00
|
|
|
|
|
|
|
// First make sure that the uninitialized CallIC stub is on a single page
|
|
|
|
// that will later be selected as an evacuation candidate.
|
|
|
|
{
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2012-09-20 10:45:38 +00:00
|
|
|
AlwaysAllocateScope always_allocate;
|
2013-02-25 14:46:09 +00:00
|
|
|
SimulateFullSpace(heap->code_space());
|
2013-02-15 09:27:10 +00:00
|
|
|
isolate->stub_cache()->ComputeCallInitialize(9, RelocInfo::CODE_TARGET);
|
2012-09-20 10:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Second compile a CallIC and execute it once so that it gets patched to
|
|
|
|
// the pre-monomorphic stub. These code objects are on yet another page.
|
|
|
|
{
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2012-09-20 10:45:38 +00:00
|
|
|
AlwaysAllocateScope always_allocate;
|
2013-02-25 14:46:09 +00:00
|
|
|
SimulateFullSpace(heap->code_space());
|
2012-09-20 10:45:38 +00:00
|
|
|
CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};"
|
|
|
|
"function call() { o.f(1,2,3,4,5,6,7,8,9); };"
|
|
|
|
"call();");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Third we fill up the last page of the code space so that it does not get
|
|
|
|
// chosen as an evacuation candidate.
|
|
|
|
{
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2012-09-20 10:45:38 +00:00
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
CompileRun("for (var i = 0; i < 2000; i++) {"
|
|
|
|
" eval('function f' + i + '() { return ' + i +'; };' +"
|
|
|
|
" 'f' + i + '();');"
|
|
|
|
"}");
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-09-20 10:45:38 +00:00
|
|
|
|
|
|
|
// Fourth is the tricky part. Make sure the code containing the CallIC is
|
|
|
|
// visited first without clearing the IC. The shared function info is then
|
|
|
|
// visited later, causing the CallIC to be cleared.
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> name = isolate->factory()->InternalizeUtf8String("call");
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<GlobalObject> global(isolate->context()->global_object());
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> zero(Smi::FromInt(0), isolate);
|
2012-09-20 10:45:38 +00:00
|
|
|
MaybeObject* maybe_call = global->GetProperty(*name);
|
|
|
|
JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked());
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(global, name, zero, NONE, kNonStrictMode);
|
2013-02-15 09:27:10 +00:00
|
|
|
isolate->compilation_cache()->Clear();
|
2013-02-25 14:46:09 +00:00
|
|
|
call->shared()->set_ic_age(heap->global_ic_age() + 1);
|
|
|
|
Handle<Object> call_code(call->code(), isolate);
|
|
|
|
Handle<Object> call_function(call, isolate);
|
2012-09-20 10:45:38 +00:00
|
|
|
|
|
|
|
// Now we are ready to mess up the heap.
|
2013-02-25 14:46:09 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kReduceMemoryFootprintMask);
|
2012-09-20 10:45:38 +00:00
|
|
|
|
|
|
|
// Either heap verification caught the problem already or we go kaboom once
|
|
|
|
// the CallIC is executed the next time.
|
2013-09-17 11:01:43 +00:00
|
|
|
JSReceiver::SetProperty(global, name, call_function, NONE, kNonStrictMode);
|
2012-09-20 10:45:38 +00:00
|
|
|
CompileRun("call();");
|
|
|
|
}
|
2012-12-06 16:27:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress159140) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_flush_code_incrementally = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2012-12-06 16:27:32 +00:00
|
|
|
|
|
|
|
// Perform one initial GC to enable code flushing.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2012-12-06 16:27:32 +00:00
|
|
|
|
|
|
|
// Prepare several closures that are all eligible for code flushing
|
|
|
|
// because all reachable ones are not optimized. Make sure that the
|
|
|
|
// optimized code object is directly reachable through a handle so
|
|
|
|
// that it is marked black during incremental marking.
|
|
|
|
Handle<Code> code;
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2012-12-06 16:27:32 +00:00
|
|
|
CompileRun("function h(x) {}"
|
|
|
|
"function mkClosure() {"
|
|
|
|
" return function(x) { return x + 1; };"
|
|
|
|
"}"
|
|
|
|
"var f = mkClosure();"
|
|
|
|
"var g = mkClosure();"
|
|
|
|
"f(1); f(2);"
|
|
|
|
"g(1); g(2);"
|
|
|
|
"h(1); h(2);"
|
|
|
|
"%OptimizeFunctionOnNextCall(f); f(3);"
|
|
|
|
"%OptimizeFunctionOnNextCall(h); h(3);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-12-06 16:27:32 +00:00
|
|
|
CHECK(f->is_compiled());
|
|
|
|
CompileRun("f = null;");
|
|
|
|
|
|
|
|
Handle<JSFunction> g =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("g"))));
|
2012-12-06 16:27:32 +00:00
|
|
|
CHECK(g->is_compiled());
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
g->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
code = inner_scope.CloseAndEscape(Handle<Code>(f->code()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate incremental marking so that the functions are enqueued as
|
|
|
|
// code flushing candidates. Then optimize one function. Finally
|
|
|
|
// finish the GC to complete code flushing.
|
|
|
|
SimulateIncrementalMarking();
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(g); g(3);");
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-12-06 16:27:32 +00:00
|
|
|
|
|
|
|
// Unoptimized code is missing and the deoptimizer will go ballistic.
|
|
|
|
CompileRun("g('bozo');");
|
|
|
|
}
|
2012-12-12 10:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress165495) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_flush_code_incrementally = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2012-12-12 10:46:01 +00:00
|
|
|
|
|
|
|
// Perform one initial GC to enable code flushing.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2012-12-12 10:46:01 +00:00
|
|
|
|
|
|
|
// Prepare an optimized closure that the optimized code map will get
|
|
|
|
// populated. Then age the unoptimized code to trigger code flushing
|
|
|
|
// but make sure the optimized code is unreachable.
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2012-12-12 10:46:01 +00:00
|
|
|
CompileRun("function mkClosure() {"
|
|
|
|
" return function(x) { return x + 1; };"
|
|
|
|
"}"
|
|
|
|
"var f = mkClosure();"
|
|
|
|
"f(1); f(2);"
|
|
|
|
"%OptimizeFunctionOnNextCall(f); f(3);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2012-12-12 10:46:01 +00:00
|
|
|
CHECK(f->is_compiled());
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
CompileRun("f = null;");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate incremental marking so that unoptimized code is flushed
|
|
|
|
// even though it still is cached in the optimized code map.
|
|
|
|
SimulateIncrementalMarking();
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2012-12-12 10:46:01 +00:00
|
|
|
|
|
|
|
// Make a new closure that will get code installed from the code map.
|
|
|
|
// Unoptimized code is missing and the deoptimizer will go ballistic.
|
|
|
|
CompileRun("var g = mkClosure(); g('bozo');");
|
|
|
|
}
|
2013-01-11 13:13:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress169209) {
|
2013-02-06 13:21:28 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2013-01-11 13:13:11 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_flush_code_incrementally = true;
|
2013-05-13 14:18:43 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-01-11 13:13:11 +00:00
|
|
|
|
|
|
|
// Perform one initial GC to enable code flushing.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2013-01-11 13:13:11 +00:00
|
|
|
|
|
|
|
// Prepare a shared function info eligible for code flushing for which
|
|
|
|
// the unoptimized code will be replaced during optimization.
|
|
|
|
Handle<SharedFunctionInfo> shared1;
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2013-01-11 13:13:11 +00:00
|
|
|
CompileRun("function f() { return 'foobar'; }"
|
|
|
|
"function g(x) { if (x) f(); }"
|
|
|
|
"f();"
|
|
|
|
"g(false);"
|
|
|
|
"g(false);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2013-01-11 13:13:11 +00:00
|
|
|
CHECK(f->is_compiled());
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
shared1 = inner_scope.CloseAndEscape(handle(f->shared(), isolate));
|
2013-01-11 13:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare a shared function info eligible for code flushing that will
|
|
|
|
// represent the dangling tail of the candidate list.
|
|
|
|
Handle<SharedFunctionInfo> shared2;
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2013-01-11 13:13:11 +00:00
|
|
|
CompileRun("function flushMe() { return 0; }"
|
|
|
|
"flushMe(1);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("flushMe"))));
|
2013-01-11 13:13:11 +00:00
|
|
|
CHECK(f->is_compiled());
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
shared2 = inner_scope.CloseAndEscape(handle(f->shared(), isolate));
|
2013-01-11 13:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate incremental marking and collect code flushing candidates.
|
|
|
|
SimulateIncrementalMarking();
|
|
|
|
CHECK(shared1->code()->gc_metadata() != NULL);
|
|
|
|
|
|
|
|
// Optimize function and make sure the unoptimized code is replaced.
|
|
|
|
#ifdef DEBUG
|
|
|
|
FLAG_stop_at = "f";
|
|
|
|
#endif
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(g);"
|
|
|
|
"g(false);");
|
|
|
|
|
|
|
|
// Finish garbage collection cycle.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2013-01-11 13:13:11 +00:00
|
|
|
CHECK(shared1->code()->gc_metadata() == NULL);
|
|
|
|
}
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Helper function that simulates a fill new-space in the heap.
|
|
|
|
static inline void AllocateAllButNBytes(v8::internal::NewSpace* space,
|
|
|
|
int extra_bytes) {
|
|
|
|
int space_remaining = static_cast<int>(
|
|
|
|
*space->allocation_limit_address() - *space->allocation_top_address());
|
|
|
|
CHECK(space_remaining >= extra_bytes);
|
|
|
|
int new_linear_size = space_remaining - extra_bytes;
|
|
|
|
v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size);
|
|
|
|
v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe);
|
|
|
|
node->set_size(space->heap(), new_linear_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress169928) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_crankshaft = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// Some flags turn Scavenge collections into Mark-sweep collections
|
|
|
|
// and hence are incompatible with this test case.
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction) return;
|
|
|
|
|
|
|
|
// Prepare the environment
|
|
|
|
CompileRun("function fastliteralcase(literal, value) {"
|
|
|
|
" literal[0] = value;"
|
|
|
|
" return literal;"
|
|
|
|
"}"
|
|
|
|
"function get_standard_literal() {"
|
|
|
|
" var literal = [1, 2, 3];"
|
|
|
|
" return literal;"
|
|
|
|
"}"
|
|
|
|
"obj = fastliteralcase(get_standard_literal(), 1);"
|
|
|
|
"obj = fastliteralcase(get_standard_literal(), 1.5);"
|
|
|
|
"obj = fastliteralcase(get_standard_literal(), 2);");
|
|
|
|
|
|
|
|
// prepare the heap
|
|
|
|
v8::Local<v8::String> mote_code_string =
|
|
|
|
v8_str("fastliteralcase(mote, 2.5);");
|
|
|
|
|
|
|
|
v8::Local<v8::String> array_name = v8_str("mote");
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Set(array_name, v8::Int32::New(0));
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// First make sure we flip spaces
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectGarbage(NEW_SPACE);
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// Allocate the object.
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<FixedArray> array_data = factory->NewFixedArray(2, NOT_TENURED);
|
2013-01-21 12:26:29 +00:00
|
|
|
array_data->set(0, Smi::FromInt(1));
|
|
|
|
array_data->set(1, Smi::FromInt(2));
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
AllocateAllButNBytes(CcTest::heap()->new_space(),
|
2013-07-19 13:30:49 +00:00
|
|
|
JSArray::kSize + AllocationMemento::kSize +
|
2013-01-21 12:26:29 +00:00
|
|
|
kPointerSize);
|
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<JSArray> array = factory->NewJSArrayWithElements(array_data,
|
2013-01-21 12:26:29 +00:00
|
|
|
FAST_SMI_ELEMENTS,
|
|
|
|
NOT_TENURED);
|
|
|
|
|
|
|
|
CHECK_EQ(Smi::FromInt(2), array->length());
|
|
|
|
CHECK(array->HasFastSmiOrObjectElements());
|
|
|
|
|
2013-07-19 13:30:49 +00:00
|
|
|
// We need filler the size of AllocationMemento object, plus an extra
|
2013-01-21 12:26:29 +00:00
|
|
|
// fill pointer value.
|
2013-09-19 09:46:15 +00:00
|
|
|
MaybeObject* maybe_object = CcTest::heap()->AllocateRaw(
|
2013-07-19 13:30:49 +00:00
|
|
|
AllocationMemento::kSize + kPointerSize, NEW_SPACE, OLD_POINTER_SPACE);
|
2013-01-21 12:26:29 +00:00
|
|
|
Object* obj = NULL;
|
|
|
|
CHECK(maybe_object->ToObject(&obj));
|
|
|
|
Address addr_obj = reinterpret_cast<Address>(
|
|
|
|
reinterpret_cast<byte*>(obj - kHeapObjectTag));
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CreateFillerObjectAt(addr_obj,
|
2013-07-19 13:30:49 +00:00
|
|
|
AllocationMemento::kSize + kPointerSize);
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// Give the array a name, making sure not to allocate strings.
|
|
|
|
v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array);
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Set(array_name, array_obj);
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// This should crash with a protection violation if we are running a build
|
|
|
|
// with the bug.
|
|
|
|
AlwaysAllocateScope aa_scope;
|
|
|
|
v8::Script::Compile(mote_code_string)->Run();
|
|
|
|
}
|
2013-01-23 16:15:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress168801) {
|
|
|
|
i::FLAG_always_compact = true;
|
|
|
|
i::FLAG_cache_optimized_code = false;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_flush_code_incrementally = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-01-23 16:15:15 +00:00
|
|
|
|
|
|
|
// Perform one initial GC to enable code flushing.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2013-01-23 16:15:15 +00:00
|
|
|
|
|
|
|
// Ensure the code ends up on an evacuation candidate.
|
2013-02-15 09:27:10 +00:00
|
|
|
SimulateFullSpace(heap->code_space());
|
2013-01-23 16:15:15 +00:00
|
|
|
|
|
|
|
// Prepare an unoptimized function that is eligible for code flushing.
|
|
|
|
Handle<JSFunction> function;
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2013-01-23 16:15:15 +00:00
|
|
|
CompileRun("function mkClosure() {"
|
|
|
|
" return function(x) { return x + 1; };"
|
|
|
|
"}"
|
|
|
|
"var f = mkClosure();"
|
|
|
|
"f(1); f(2);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2013-01-23 16:15:15 +00:00
|
|
|
CHECK(f->is_compiled());
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
function = inner_scope.CloseAndEscape(handle(*f, isolate));
|
2013-01-23 16:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate incremental marking so that unoptimized function is enqueued as a
|
|
|
|
// candidate for code flushing. The shared function info however will not be
|
|
|
|
// explicitly enqueued.
|
|
|
|
SimulateIncrementalMarking();
|
|
|
|
|
|
|
|
// Now optimize the function so that it is taken off the candidate list.
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2013-01-23 16:15:15 +00:00
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(f); f(3);");
|
|
|
|
}
|
|
|
|
|
|
|
|
// This cycle will bust the heap and subsequent cycles will go ballistic.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2013-01-23 16:15:15 +00:00
|
|
|
}
|
2013-02-11 15:11:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress173458) {
|
|
|
|
i::FLAG_always_compact = true;
|
|
|
|
i::FLAG_cache_optimized_code = false;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_flush_code_incrementally = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-02-11 15:11:00 +00:00
|
|
|
|
|
|
|
// Perform one initial GC to enable code flushing.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
|
2013-02-11 15:11:00 +00:00
|
|
|
|
|
|
|
// Ensure the code ends up on an evacuation candidate.
|
2013-02-15 09:27:10 +00:00
|
|
|
SimulateFullSpace(heap->code_space());
|
2013-02-11 15:11:00 +00:00
|
|
|
|
|
|
|
// Prepare an unoptimized function that is eligible for code flushing.
|
|
|
|
Handle<JSFunction> function;
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2013-02-11 15:11:00 +00:00
|
|
|
CompileRun("function mkClosure() {"
|
|
|
|
" return function(x) { return x + 1; };"
|
|
|
|
"}"
|
|
|
|
"var f = mkClosure();"
|
|
|
|
"f(1); f(2);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
2013-09-23 11:25:52 +00:00
|
|
|
CcTest::global()->Get(v8_str("f"))));
|
2013-02-11 15:11:00 +00:00
|
|
|
CHECK(f->is_compiled());
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
|
|
|
|
}
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
function = inner_scope.CloseAndEscape(handle(*f, isolate));
|
2013-02-11 15:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate incremental marking so that unoptimized function is enqueued as a
|
|
|
|
// candidate for code flushing. The shared function info however will not be
|
|
|
|
// explicitly enqueued.
|
|
|
|
SimulateIncrementalMarking();
|
|
|
|
|
2013-03-21 08:50:29 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2013-02-11 15:11:00 +00:00
|
|
|
// Now enable the debugger which in turn will disable code flushing.
|
2013-02-15 09:27:10 +00:00
|
|
|
CHECK(isolate->debug()->Load());
|
2013-03-21 08:50:29 +00:00
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
2013-02-11 15:11:00 +00:00
|
|
|
|
|
|
|
// This cycle will bust the heap and subsequent cycles will go ballistic.
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags);
|
2013-02-11 15:11:00 +00:00
|
|
|
}
|
2013-03-18 11:26:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DummyVisitor : public ObjectVisitor {
|
|
|
|
public:
|
|
|
|
void VisitPointers(Object** start, Object** end) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeferredHandles) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-03-18 11:26:09 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-09-10 06:43:23 +00:00
|
|
|
v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate));
|
2013-03-18 11:26:09 +00:00
|
|
|
v8::ImplementationUtilities::HandleScopeData* data =
|
|
|
|
isolate->handle_scope_data();
|
|
|
|
Handle<Object> init(heap->empty_string(), isolate);
|
|
|
|
while (data->next < data->limit) {
|
|
|
|
Handle<Object> obj(heap->empty_string(), isolate);
|
|
|
|
}
|
|
|
|
// An entire block of handles has been filled.
|
|
|
|
// Next handle would require a new block.
|
|
|
|
ASSERT(data->next == data->limit);
|
|
|
|
|
|
|
|
DeferredHandleScope deferred(isolate);
|
|
|
|
DummyVisitor visitor;
|
|
|
|
isolate->handle_scope_implementer()->Iterate(&visitor);
|
|
|
|
deferred.Detach();
|
|
|
|
}
|
2013-05-29 11:13:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(IncrementalMarkingStepMakesBigProgressWithLargeObjects) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("function f(n) {"
|
|
|
|
" var a = new Array(n);"
|
|
|
|
" for (var i = 0; i < n; i += 100) a[i] = i;"
|
|
|
|
"};"
|
|
|
|
"f(10 * 1024 * 1024);");
|
2013-09-19 09:46:15 +00:00
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2013-05-29 11:13:59 +00:00
|
|
|
if (marking->IsStopped()) marking->Start();
|
|
|
|
// This big step should be sufficient to mark the whole array.
|
|
|
|
marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
|
|
|
|
ASSERT(marking->IsComplete());
|
|
|
|
}
|
2013-11-14 15:14:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(DisableInlineAllocation) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("function test() {"
|
|
|
|
" var x = [];"
|
|
|
|
" for (var i = 0; i < 10; i++) {"
|
|
|
|
" x[i] = [ {}, [1,2,3], [1,x,3] ];"
|
|
|
|
" }"
|
|
|
|
"}"
|
|
|
|
"function run() {"
|
|
|
|
" %OptimizeFunctionOnNextCall(test);"
|
|
|
|
" test();"
|
|
|
|
" %DeoptimizeFunction(test);"
|
|
|
|
"}");
|
|
|
|
|
|
|
|
// Warm-up with inline allocation enabled.
|
|
|
|
CompileRun("test(); test(); run();");
|
|
|
|
|
|
|
|
// Run test with inline allocation disabled.
|
|
|
|
CcTest::heap()->DisableInlineAllocation();
|
|
|
|
CompileRun("run()");
|
|
|
|
|
|
|
|
// Run test with inline allocation disabled and pretenuring.
|
|
|
|
CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
|
|
|
|
CompileRun("run()");
|
|
|
|
|
|
|
|
// Run test with inline allocation re-enabled.
|
|
|
|
CcTest::heap()->EnableInlineAllocation();
|
|
|
|
CompileRun("run()");
|
|
|
|
}
|
2013-11-19 16:57:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int AllocationSitesCount(Heap* heap) {
|
|
|
|
int count = 0;
|
|
|
|
for (Object* site = heap->allocation_sites_list();
|
|
|
|
!(site->IsUndefined());
|
|
|
|
site = AllocationSite::cast(site)->weak_next()) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(EnsureAllocationSiteDependentCodesProcessed) {
|
|
|
|
if (i::FLAG_always_opt || !i::FLAG_crankshaft) return;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
|
|
|
|
2013-11-20 14:20:07 +00:00
|
|
|
if (!isolate->use_crankshaft()) return;
|
|
|
|
|
2013-11-19 16:57:49 +00:00
|
|
|
// The allocation site at the head of the list is ours.
|
|
|
|
Handle<AllocationSite> site;
|
|
|
|
{
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
|
|
|
|
int count = AllocationSitesCount(heap);
|
|
|
|
CompileRun("var bar = function() { return (new Array()); };"
|
|
|
|
"var a = bar();"
|
|
|
|
"bar();"
|
|
|
|
"bar();");
|
|
|
|
|
|
|
|
// One allocation site should have been created.
|
|
|
|
int new_count = AllocationSitesCount(heap);
|
2013-11-19 17:29:43 +00:00
|
|
|
CHECK_EQ(new_count, (count + 1));
|
2013-11-19 16:57:49 +00:00
|
|
|
site = Handle<AllocationSite>::cast(
|
|
|
|
global_handles->Create(
|
|
|
|
AllocationSite::cast(heap->allocation_sites_list())));
|
|
|
|
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(bar); bar();");
|
|
|
|
|
|
|
|
DependentCode::GroupStartIndexes starts(site->dependent_code());
|
2013-11-19 17:29:43 +00:00
|
|
|
CHECK_GE(starts.number_of_entries(), 1);
|
2013-11-19 16:57:49 +00:00
|
|
|
int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
|
2013-11-19 17:29:43 +00:00
|
|
|
CHECK(site->dependent_code()->is_code_at(index));
|
2013-11-19 16:57:49 +00:00
|
|
|
Code* function_bar = site->dependent_code()->code_at(index);
|
|
|
|
Handle<JSFunction> bar_handle =
|
|
|
|
v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(v8_str("bar"))));
|
2013-11-19 17:29:43 +00:00
|
|
|
CHECK_EQ(bar_handle->code(), function_bar);
|
2013-11-19 16:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure that a gc should get rid of the function, even though we
|
|
|
|
// still have the allocation site alive.
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
heap->CollectAllGarbage(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The site still exists because of our global handle, but the code is no
|
|
|
|
// longer referred to by dependent_code().
|
|
|
|
DependentCode::GroupStartIndexes starts(site->dependent_code());
|
|
|
|
int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
|
2013-11-19 17:29:43 +00:00
|
|
|
CHECK(!(site->dependent_code()->is_code_at(index)));
|
2013-11-19 16:57:49 +00:00
|
|
|
}
|