2014-10-20 11:42:56 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
|
|
|
#include "src/api.h"
|
2015-07-31 11:07:50 +00:00
|
|
|
#include "src/debug/debug.h"
|
2014-10-20 11:42:56 +00:00
|
|
|
#include "src/execution.h"
|
|
|
|
#include "src/factory.h"
|
|
|
|
#include "src/global-handles.h"
|
|
|
|
#include "src/macro-assembler.h"
|
|
|
|
#include "src/objects.h"
|
2015-10-01 13:48:05 +00:00
|
|
|
#include "test/cctest/test-feedback-vector.h"
|
2014-10-20 11:42:56 +00:00
|
|
|
|
|
|
|
using namespace v8::internal;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
#define CHECK_SLOT_KIND(helper, index, expected_kind) \
|
|
|
|
CHECK_EQ(expected_kind, helper.vector()->GetKind(helper.slot(index)));
|
2015-09-28 08:23:35 +00:00
|
|
|
|
|
|
|
|
2015-10-26 13:10:08 +00:00
|
|
|
static Handle<JSFunction> GetFunction(const char* name) {
|
|
|
|
v8::MaybeLocal<v8::Value> v8_f = CcTest::global()->Get(
|
|
|
|
v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str(name));
|
|
|
|
Handle<JSFunction> f =
|
|
|
|
Handle<JSFunction>::cast(v8::Utils::OpenHandle(*v8_f.ToLocalChecked()));
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
TEST(VectorStructure) {
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone zone(isolate->allocator(), ZONE_NAME);
|
2014-10-20 11:42:56 +00:00
|
|
|
|
|
|
|
// Empty vectors are the empty fixed array.
|
2015-09-28 11:41:40 +00:00
|
|
|
StaticFeedbackVectorSpec empty;
|
2015-10-07 10:33:22 +00:00
|
|
|
Handle<TypeFeedbackVector> vector = NewTypeFeedbackVector(isolate, &empty);
|
2016-09-14 10:20:08 +00:00
|
|
|
CHECK(Handle<FixedArray>::cast(vector).is_identical_to(
|
|
|
|
factory->empty_type_feedback_vector()));
|
2014-10-20 11:42:56 +00:00
|
|
|
// Which can nonetheless be queried.
|
2015-10-01 13:48:05 +00:00
|
|
|
CHECK(vector->is_empty());
|
|
|
|
|
|
|
|
{
|
2016-07-28 08:04:10 +00:00
|
|
|
FeedbackVectorSpec one_slot(&zone);
|
2015-10-01 13:48:05 +00:00
|
|
|
one_slot.AddGeneralSlot();
|
2015-10-07 10:33:22 +00:00
|
|
|
vector = NewTypeFeedbackVector(isolate, &one_slot);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(vector);
|
|
|
|
CHECK_EQ(1, helper.slot_count());
|
|
|
|
}
|
2014-10-20 11:42:56 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
{
|
2016-07-28 08:04:10 +00:00
|
|
|
FeedbackVectorSpec one_icslot(&zone);
|
2015-10-01 13:48:05 +00:00
|
|
|
one_icslot.AddCallICSlot();
|
2015-10-07 10:33:22 +00:00
|
|
|
vector = NewTypeFeedbackVector(isolate, &one_icslot);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(vector);
|
|
|
|
CHECK_EQ(1, helper.slot_count());
|
|
|
|
}
|
2014-10-20 11:42:56 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
{
|
2016-07-28 08:04:10 +00:00
|
|
|
FeedbackVectorSpec spec(&zone);
|
2015-10-01 13:48:05 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
spec.AddGeneralSlot();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
spec.AddCallICSlot();
|
|
|
|
}
|
2015-10-07 10:33:22 +00:00
|
|
|
vector = NewTypeFeedbackVector(isolate, &spec);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(vector);
|
|
|
|
CHECK_EQ(8, helper.slot_count());
|
|
|
|
|
|
|
|
int index = vector->GetIndex(helper.slot(0));
|
|
|
|
|
2015-10-07 10:33:22 +00:00
|
|
|
CHECK_EQ(TypeFeedbackVector::kReservedIndexCount, index);
|
|
|
|
CHECK_EQ(helper.slot(0), vector->ToSlot(index));
|
2015-10-01 13:48:05 +00:00
|
|
|
|
|
|
|
index = vector->GetIndex(helper.slot(3));
|
2015-10-07 10:33:22 +00:00
|
|
|
CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + 3, index);
|
|
|
|
CHECK_EQ(helper.slot(3), vector->ToSlot(index));
|
2015-10-01 13:48:05 +00:00
|
|
|
|
|
|
|
index = vector->GetIndex(helper.slot(7));
|
2015-10-07 10:33:22 +00:00
|
|
|
CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + 3 +
|
|
|
|
4 * TypeFeedbackMetadata::GetSlotSize(
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlotKind::CALL_IC),
|
|
|
|
index);
|
2015-10-07 10:33:22 +00:00
|
|
|
CHECK_EQ(helper.slot(7), vector->ToSlot(index));
|
2015-10-01 13:48:05 +00:00
|
|
|
|
2015-10-07 10:33:22 +00:00
|
|
|
CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + 3 +
|
|
|
|
5 * TypeFeedbackMetadata::GetSlotSize(
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlotKind::CALL_IC),
|
|
|
|
vector->length());
|
|
|
|
}
|
2017-01-09 15:31:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
FeedbackVectorSpec spec(&zone);
|
|
|
|
spec.AddGeneralSlot();
|
|
|
|
spec.AddCreateClosureSlot(5);
|
|
|
|
spec.AddGeneralSlot();
|
|
|
|
vector = NewTypeFeedbackVector(isolate, &spec);
|
|
|
|
FeedbackVectorHelper helper(vector);
|
|
|
|
CHECK_EQ(1, TypeFeedbackMetadata::GetSlotSize(
|
|
|
|
FeedbackVectorSlotKind::CREATE_CLOSURE));
|
|
|
|
FeedbackVectorSlot slot = helper.slot(1);
|
|
|
|
FixedArray* array = FixedArray::cast(vector->Get(slot));
|
2017-01-19 17:12:28 +00:00
|
|
|
CHECK_EQ(array, *factory->empty_literals_array());
|
2017-01-09 15:31:00 +00:00
|
|
|
}
|
2014-10-27 16:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// IC slots need an encoding to recognize what is in there.
|
|
|
|
TEST(VectorICMetadata) {
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone zone(isolate->allocator(), ZONE_NAME);
|
2014-10-27 16:34:28 +00:00
|
|
|
|
2016-07-28 08:04:10 +00:00
|
|
|
FeedbackVectorSpec spec(&zone);
|
2014-10-27 16:34:28 +00:00
|
|
|
// Set metadata.
|
2015-10-01 13:48:05 +00:00
|
|
|
for (int i = 0; i < 40; i++) {
|
|
|
|
switch (i % 4) {
|
2015-09-28 11:41:40 +00:00
|
|
|
case 0:
|
2015-10-01 13:48:05 +00:00
|
|
|
spec.AddGeneralSlot();
|
2015-09-28 11:41:40 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-10-01 13:48:05 +00:00
|
|
|
spec.AddCallICSlot();
|
2015-09-28 11:41:40 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-10-01 13:48:05 +00:00
|
|
|
spec.AddLoadICSlot();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
spec.AddKeyedLoadICSlot();
|
2015-09-28 11:41:40 +00:00
|
|
|
break;
|
2014-10-28 16:05:08 +00:00
|
|
|
}
|
2014-10-27 16:34:28 +00:00
|
|
|
}
|
|
|
|
|
2015-10-07 10:33:22 +00:00
|
|
|
Handle<TypeFeedbackVector> vector = NewTypeFeedbackVector(isolate, &spec);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(vector);
|
|
|
|
CHECK_EQ(40, helper.slot_count());
|
2014-11-27 16:36:18 +00:00
|
|
|
|
2014-10-27 16:34:28 +00:00
|
|
|
// Meanwhile set some feedback values and type feedback values to
|
|
|
|
// verify the data structure remains intact.
|
|
|
|
vector->Set(FeedbackVectorSlot(0), *vector);
|
|
|
|
|
2014-11-27 16:36:18 +00:00
|
|
|
// Verify the metadata is correctly set up from the spec.
|
2015-10-01 13:48:05 +00:00
|
|
|
for (int i = 0; i < 40; i++) {
|
|
|
|
FeedbackVectorSlotKind kind = vector->GetKind(helper.slot(i));
|
|
|
|
switch (i % 4) {
|
|
|
|
case 0:
|
|
|
|
CHECK_EQ(FeedbackVectorSlotKind::GENERAL, kind);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
CHECK_EQ(FeedbackVectorSlotKind::CALL_IC, kind);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
CHECK_EQ(FeedbackVectorSlotKind::LOAD_IC, kind);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
CHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, kind);
|
|
|
|
break;
|
2014-10-27 16:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-20 11:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(VectorSlotClearing) {
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone zone(isolate->allocator(), ZONE_NAME);
|
2014-10-20 11:42:56 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
// We only test clearing FeedbackVectorSlots, not FeedbackVectorSlots.
|
|
|
|
// The reason is that FeedbackVectorSlots need a full code environment
|
2014-10-20 11:42:56 +00:00
|
|
|
// to fully test (See VectorICProfilerStatistics test below).
|
2016-07-28 08:04:10 +00:00
|
|
|
FeedbackVectorSpec spec(&zone);
|
2015-10-01 13:48:05 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
spec.AddGeneralSlot();
|
|
|
|
}
|
2015-10-07 10:33:22 +00:00
|
|
|
Handle<TypeFeedbackVector> vector = NewTypeFeedbackVector(isolate, &spec);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(vector);
|
2014-10-20 11:42:56 +00:00
|
|
|
|
|
|
|
// Fill with information
|
2015-10-01 13:48:05 +00:00
|
|
|
vector->Set(helper.slot(0), Smi::FromInt(1));
|
2015-04-02 09:39:32 +00:00
|
|
|
Handle<WeakCell> cell = factory->NewWeakCell(factory->fixed_array_map());
|
2015-10-01 13:48:05 +00:00
|
|
|
vector->Set(helper.slot(1), *cell);
|
2014-10-20 17:32:06 +00:00
|
|
|
Handle<AllocationSite> site = factory->NewAllocationSite();
|
2015-10-01 13:48:05 +00:00
|
|
|
vector->Set(helper.slot(2), *site);
|
2014-10-20 11:42:56 +00:00
|
|
|
|
2015-04-02 09:39:32 +00:00
|
|
|
// GC time clearing leaves slots alone.
|
|
|
|
vector->ClearSlotsAtGCTime(NULL);
|
2015-10-01 13:48:05 +00:00
|
|
|
Object* obj = vector->Get(helper.slot(1));
|
2015-04-02 09:39:32 +00:00
|
|
|
CHECK(obj->IsWeakCell() && !WeakCell::cast(obj)->cleared());
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
vector->ClearSlots(NULL);
|
|
|
|
|
2015-04-02 09:39:32 +00:00
|
|
|
// The feedback vector slots are cleared. AllocationSites are still granted
|
2014-10-20 11:42:56 +00:00
|
|
|
// an exemption from clearing, as are smis.
|
2015-10-01 13:48:05 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(1), vector->Get(helper.slot(0)));
|
2014-10-20 11:42:56 +00:00
|
|
|
CHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(isolate),
|
2015-10-01 13:48:05 +00:00
|
|
|
vector->Get(helper.slot(1)));
|
|
|
|
CHECK(vector->Get(helper.slot(2))->IsAllocationSite());
|
2014-10-20 11:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-28 16:05:08 +00:00
|
|
|
TEST(VectorCallICStates) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
// Make sure function f has a call that uses a type feedback slot.
|
|
|
|
CompileRun(
|
|
|
|
"function foo() { return 17; }"
|
|
|
|
"function f(a) { a(); } f(foo);");
|
2015-10-26 13:10:08 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
2014-10-28 16:05:08 +00:00
|
|
|
// There should be one IC.
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot(0);
|
2014-10-28 16:05:08 +00:00
|
|
|
CallICNexus nexus(feedback_vector, slot);
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
// CallIC doesn't return map feedback.
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!nexus.FindFirstMap());
|
2014-10-28 16:05:08 +00:00
|
|
|
|
|
|
|
CompileRun("f(function() { return 16; })");
|
|
|
|
CHECK_EQ(GENERIC, nexus.StateFromFeedback());
|
|
|
|
|
2015-02-04 09:46:05 +00:00
|
|
|
// After a collection, state should remain GENERIC.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
|
2015-02-04 09:46:05 +00:00
|
|
|
CHECK_EQ(GENERIC, nexus.StateFromFeedback());
|
2016-07-13 07:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(VectorCallFeedbackForArray) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
// Make sure function f has a call that uses a type feedback slot.
|
|
|
|
CompileRun(
|
|
|
|
"function foo() { return 17; }"
|
|
|
|
"function f(a) { a(); } f(Array);");
|
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
// There should be one IC.
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
|
|
|
Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
|
|
|
|
FeedbackVectorSlot slot(0);
|
|
|
|
CallICNexus nexus(feedback_vector, slot);
|
2014-10-28 16:05:08 +00:00
|
|
|
|
2015-02-04 09:46:05 +00:00
|
|
|
// A call to Array is special, it contains an AllocationSite as feedback.
|
2014-10-28 16:05:08 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
2015-02-04 09:46:05 +00:00
|
|
|
CHECK(nexus.GetFeedback()->IsAllocationSite());
|
2014-10-28 16:05:08 +00:00
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
|
2016-07-13 07:58:40 +00:00
|
|
|
// It should stay monomorphic even after a GC.
|
2014-10-28 16:05:08 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
}
|
2014-11-27 16:36:18 +00:00
|
|
|
|
2016-05-24 11:53:13 +00:00
|
|
|
TEST(VectorCallCounts) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
|
|
|
|
// Make sure function f has a call that uses a type feedback slot.
|
|
|
|
CompileRun(
|
|
|
|
"function foo() { return 17; }"
|
|
|
|
"function f(a) { a(); } f(foo);");
|
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
// There should be one IC.
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
|
2016-05-24 11:53:13 +00:00
|
|
|
FeedbackVectorSlot slot(0);
|
|
|
|
CallICNexus nexus(feedback_vector, slot);
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
CompileRun("f(foo); f(foo);");
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
CHECK_EQ(3, nexus.ExtractCallCount());
|
2016-09-13 11:03:43 +00:00
|
|
|
|
|
|
|
// Send the IC megamorphic, but we should still have incrementing counts.
|
|
|
|
CompileRun("f(function() { return 12; });");
|
|
|
|
CHECK_EQ(GENERIC, nexus.StateFromFeedback());
|
|
|
|
CHECK_EQ(4, nexus.ExtractCallCount());
|
2016-07-13 07:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(VectorConstructCounts) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2016-05-24 11:53:13 +00:00
|
|
|
|
2016-07-13 07:58:40 +00:00
|
|
|
// Make sure function f has a call that uses a type feedback slot.
|
2016-05-24 11:53:13 +00:00
|
|
|
CompileRun(
|
|
|
|
"function Foo() {}"
|
|
|
|
"function f(a) { new a(); } f(Foo);");
|
2016-07-13 07:58:40 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
|
|
|
Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
|
2016-09-14 03:22:56 +00:00
|
|
|
|
2016-07-13 07:58:40 +00:00
|
|
|
FeedbackVectorSlot slot(0);
|
2016-09-14 03:22:56 +00:00
|
|
|
CallICNexus nexus(feedback_vector, slot);
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
2016-07-13 07:58:40 +00:00
|
|
|
CHECK(feedback_vector->Get(slot)->IsWeakCell());
|
2016-05-24 11:53:13 +00:00
|
|
|
|
|
|
|
CompileRun("f(Foo); f(Foo);");
|
2016-09-14 03:22:56 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
CHECK_EQ(3, nexus.ExtractCallCount());
|
|
|
|
|
|
|
|
// Send the IC megamorphic, but we should still have incrementing counts.
|
|
|
|
CompileRun("f(function() {});");
|
|
|
|
CHECK_EQ(GENERIC, nexus.StateFromFeedback());
|
|
|
|
CHECK_EQ(4, nexus.ExtractCallCount());
|
2016-05-24 11:53:13 +00:00
|
|
|
}
|
2014-11-27 16:36:18 +00:00
|
|
|
|
|
|
|
TEST(VectorLoadICStates) {
|
2015-05-15 13:25:25 +00:00
|
|
|
if (i::FLAG_always_opt) return;
|
2014-11-27 16:36:18 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
|
|
|
|
// Make sure function f has a call that uses a type feedback slot.
|
|
|
|
CompileRun(
|
|
|
|
"var o = { foo: 3 };"
|
|
|
|
"function f(a) { return a.foo; } f(o);");
|
2015-10-26 13:10:08 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
2014-11-27 16:36:18 +00:00
|
|
|
// There should be one IC.
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot(0);
|
2014-11-27 16:36:18 +00:00
|
|
|
LoadICNexus nexus(feedback_vector, slot);
|
|
|
|
CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
CompileRun("f(o)");
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
// Verify that the monomorphic map is the one we expect.
|
2015-10-26 13:10:08 +00:00
|
|
|
v8::MaybeLocal<v8::Value> v8_o =
|
|
|
|
CcTest::global()->Get(context.local(), v8_str("o"));
|
|
|
|
Handle<JSObject> o =
|
|
|
|
Handle<JSObject>::cast(v8::Utils::OpenHandle(*v8_o.ToLocalChecked()));
|
2014-11-27 16:36:18 +00:00
|
|
|
CHECK_EQ(o->map(), nexus.FindFirstMap());
|
|
|
|
|
|
|
|
// Now go polymorphic.
|
|
|
|
CompileRun("f({ blarg: 3, foo: 2 })");
|
|
|
|
CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"delete o.foo;"
|
|
|
|
"f(o)");
|
|
|
|
CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
CompileRun("f({ blarg: 3, torino: 10, foo: 2 })");
|
|
|
|
CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback());
|
|
|
|
MapHandleList maps;
|
|
|
|
nexus.FindAllMaps(&maps);
|
|
|
|
CHECK_EQ(4, maps.length());
|
|
|
|
|
|
|
|
// Finally driven megamorphic.
|
|
|
|
CompileRun("f({ blarg: 3, gran: 3, torino: 10, foo: 2 })");
|
|
|
|
CHECK_EQ(MEGAMORPHIC, nexus.StateFromFeedback());
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!nexus.FindFirstMap());
|
2014-11-27 16:36:18 +00:00
|
|
|
|
2014-12-12 13:56:11 +00:00
|
|
|
// After a collection, state should not be reset to PREMONOMORPHIC.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
|
2014-12-12 13:56:11 +00:00
|
|
|
CHECK_EQ(MEGAMORPHIC, nexus.StateFromFeedback());
|
2014-11-27 16:36:18 +00:00
|
|
|
}
|
2015-01-15 12:52:33 +00:00
|
|
|
|
|
|
|
|
2015-03-12 09:22:47 +00:00
|
|
|
TEST(VectorLoadICSlotSharing) {
|
2015-05-15 13:25:25 +00:00
|
|
|
if (i::FLAG_always_opt) return;
|
2015-03-12 09:22:47 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
|
|
|
|
// Function f has 3 LoadICs, one for each o, but the ICs share the same
|
|
|
|
// feedback vector IC slot.
|
|
|
|
CompileRun(
|
2015-07-06 16:36:28 +00:00
|
|
|
"o = 10;"
|
2015-03-12 09:22:47 +00:00
|
|
|
"function f() {"
|
2016-08-08 01:15:22 +00:00
|
|
|
" var x = o || 10;"
|
|
|
|
" return o , x , o;"
|
2015-03-12 09:22:47 +00:00
|
|
|
"}"
|
|
|
|
"f();");
|
2015-10-26 13:10:08 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
2015-03-12 09:22:47 +00:00
|
|
|
// There should be one IC slot.
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
|
|
|
CHECK_EQ(1, helper.slot_count());
|
|
|
|
FeedbackVectorSlot slot(0);
|
2016-06-14 13:20:42 +00:00
|
|
|
LoadGlobalICNexus nexus(feedback_vector, slot);
|
2015-03-12 09:22:47 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-15 12:52:33 +00:00
|
|
|
TEST(VectorLoadICOnSmi) {
|
2015-05-15 13:25:25 +00:00
|
|
|
if (i::FLAG_always_opt) return;
|
2015-01-15 12:52:33 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
|
|
|
|
// Make sure function f has a call that uses a type feedback slot.
|
|
|
|
CompileRun(
|
|
|
|
"var o = { foo: 3 };"
|
|
|
|
"function f(a) { return a.foo; } f(o);");
|
2015-10-26 13:10:08 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
2015-01-15 12:52:33 +00:00
|
|
|
// There should be one IC.
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot(0);
|
2015-01-15 12:52:33 +00:00
|
|
|
LoadICNexus nexus(feedback_vector, slot);
|
|
|
|
CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
CompileRun("f(34)");
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
// Verify that the monomorphic map is the one we expect.
|
|
|
|
Map* number_map = heap->heap_number_map();
|
|
|
|
CHECK_EQ(number_map, nexus.FindFirstMap());
|
|
|
|
|
|
|
|
// Now go polymorphic on o.
|
|
|
|
CompileRun("f(o)");
|
|
|
|
CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
MapHandleList maps;
|
|
|
|
nexus.FindAllMaps(&maps);
|
|
|
|
CHECK_EQ(2, maps.length());
|
|
|
|
|
|
|
|
// One of the maps should be the o map.
|
2015-10-26 13:10:08 +00:00
|
|
|
v8::MaybeLocal<v8::Value> v8_o =
|
|
|
|
CcTest::global()->Get(context.local(), v8_str("o"));
|
|
|
|
Handle<JSObject> o =
|
|
|
|
Handle<JSObject>::cast(v8::Utils::OpenHandle(*v8_o.ToLocalChecked()));
|
2015-01-15 12:52:33 +00:00
|
|
|
bool number_map_found = false;
|
|
|
|
bool o_map_found = false;
|
|
|
|
for (int i = 0; i < maps.length(); i++) {
|
|
|
|
Handle<Map> current = maps[i];
|
|
|
|
if (*current == number_map)
|
|
|
|
number_map_found = true;
|
|
|
|
else if (*current == o->map())
|
|
|
|
o_map_found = true;
|
|
|
|
}
|
|
|
|
CHECK(number_map_found && o_map_found);
|
|
|
|
|
|
|
|
// The degree of polymorphism doesn't change.
|
|
|
|
CompileRun("f(100)");
|
|
|
|
CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback());
|
|
|
|
MapHandleList maps2;
|
|
|
|
nexus.FindAllMaps(&maps2);
|
|
|
|
CHECK_EQ(2, maps2.length());
|
|
|
|
}
|
2015-07-30 10:37:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(ReferenceContextAllocatesNoSlots) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
{
|
|
|
|
CompileRun(
|
|
|
|
"function testvar(x) {"
|
|
|
|
" y = x;"
|
|
|
|
" y = a;"
|
|
|
|
" return y;"
|
|
|
|
"}"
|
|
|
|
"a = 3;"
|
|
|
|
"testvar({});");
|
|
|
|
|
|
|
|
Handle<JSFunction> f = GetFunction("testvar");
|
|
|
|
|
|
|
|
// There should be two LOAD_ICs, one for a and one for y at the end.
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
2016-05-27 08:09:12 +00:00
|
|
|
handle(f->feedback_vector(), isolate);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_EQ(4, helper.slot_count());
|
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::STORE_IC);
|
2016-06-14 13:20:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC);
|
2016-06-14 13:20:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
|
2015-09-04 08:36:29 +00:00
|
|
|
}
|
2015-07-30 10:37:58 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
{
|
|
|
|
CompileRun(
|
|
|
|
"function testprop(x) {"
|
|
|
|
" x.blue = a;"
|
|
|
|
"}"
|
|
|
|
"testprop({ blue: 3 });");
|
2015-07-30 10:37:58 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("testprop");
|
2015-07-30 10:37:58 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
// There should be one LOAD_IC, for the load of a.
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_EQ(2, helper.slot_count());
|
2016-06-14 13:20:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::STORE_IC);
|
2015-09-04 08:36:29 +00:00
|
|
|
}
|
2015-07-30 10:37:58 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
{
|
|
|
|
CompileRun(
|
|
|
|
"function testpropfunc(x) {"
|
|
|
|
" x().blue = a;"
|
|
|
|
" return x().blue;"
|
|
|
|
"}"
|
|
|
|
"function makeresult() { return { blue: 3 }; }"
|
|
|
|
"testpropfunc(makeresult);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f = GetFunction("testpropfunc");
|
|
|
|
|
2016-06-14 13:20:42 +00:00
|
|
|
// There should be 1 LOAD_GLOBAL_IC to load x (in both cases), 2 CALL_ICs
|
|
|
|
// to call x and a LOAD_IC to load blue.
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_EQ(5, helper.slot_count());
|
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::CALL_IC);
|
2016-06-14 13:20:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::CALL_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC);
|
2015-09-04 08:36:29 +00:00
|
|
|
}
|
2015-07-30 10:37:58 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
{
|
|
|
|
CompileRun(
|
|
|
|
"function testkeyedprop(x) {"
|
|
|
|
" x[0] = a;"
|
|
|
|
" return x[0];"
|
|
|
|
"}"
|
|
|
|
"testkeyedprop([0, 1, 2]);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f = GetFunction("testkeyedprop");
|
|
|
|
|
2016-06-14 13:20:42 +00:00
|
|
|
// There should be 1 LOAD_GLOBAL_ICs for the load of a, and one
|
|
|
|
// KEYED_LOAD_IC for the load of x[0] in the return statement.
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_EQ(3, helper.slot_count());
|
2016-06-14 13:20:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::KEYED_STORE_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::KEYED_LOAD_IC);
|
2015-09-04 08:36:29 +00:00
|
|
|
}
|
2015-07-30 10:37:58 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
{
|
|
|
|
CompileRun(
|
|
|
|
"function testcompound(x) {"
|
|
|
|
" x.old = x.young = x.in_between = a;"
|
|
|
|
" return x.old + x.young;"
|
|
|
|
"}"
|
|
|
|
"testcompound({ old: 3, young: 3, in_between: 3 });");
|
|
|
|
|
|
|
|
Handle<JSFunction> f = GetFunction("testcompound");
|
|
|
|
|
2016-06-14 13:20:42 +00:00
|
|
|
// There should be 1 LOAD_GLOBAL_IC for load of a and 2 LOAD_ICs, for load
|
|
|
|
// of x.old and x.young.
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
2016-08-08 01:15:22 +00:00
|
|
|
CHECK_EQ(7, helper.slot_count());
|
2016-06-14 13:20:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
|
2015-11-17 13:15:29 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::STORE_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::STORE_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC);
|
|
|
|
CHECK_SLOT_KIND(helper, 5, FeedbackVectorSlotKind::LOAD_IC);
|
2016-09-20 13:53:32 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 6, FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC);
|
2015-09-04 08:36:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(VectorStoreICBasic) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"function f(a) {"
|
|
|
|
" a.foo = 5;"
|
|
|
|
"}"
|
|
|
|
"var a = { foo: 3 };"
|
|
|
|
"f(a);"
|
|
|
|
"f(a);"
|
|
|
|
"f(a);");
|
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
// There should be one IC slot.
|
2016-05-27 08:09:12 +00:00
|
|
|
Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
|
|
|
CHECK_EQ(1, helper.slot_count());
|
|
|
|
FeedbackVectorSlot slot(0);
|
2015-09-04 08:36:29 +00:00
|
|
|
StoreICNexus nexus(feedback_vector, slot);
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
2015-07-30 10:37:58 +00:00
|
|
|
}
|
2015-09-30 13:46:56 +00:00
|
|
|
|
|
|
|
} // namespace
|