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"
|
|
|
|
|
2018-07-23 11:42:37 +00:00
|
|
|
#include "src/api-inl.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/global-handles.h"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2014-10-20 11:42:56 +00:00
|
|
|
#include "src/macro-assembler.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-10-01 13:48:05 +00:00
|
|
|
#include "test/cctest/test-feedback-vector.h"
|
2014-10-20 11:42:56 +00:00
|
|
|
|
2017-08-11 11:22:28 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2014-10-20 11:42:56 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-02-08 08:33:33 +00:00
|
|
|
Handle<FeedbackVector> vector;
|
2015-10-01 13:48:05 +00:00
|
|
|
|
|
|
|
{
|
2016-07-28 08:04:10 +00:00
|
|
|
FeedbackVectorSpec one_slot(&zone);
|
2017-09-01 10:49:06 +00:00
|
|
|
one_slot.AddForInSlot();
|
2017-02-07 14:05:02 +00:00
|
|
|
vector = NewFeedbackVector(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();
|
2017-02-07 14:05:02 +00:00
|
|
|
vector = NewFeedbackVector(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++) {
|
2017-09-01 10:49:06 +00:00
|
|
|
spec.AddForInSlot();
|
2015-10-01 13:48:05 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
spec.AddCallICSlot();
|
|
|
|
}
|
2017-02-07 14:05:02 +00:00
|
|
|
vector = NewFeedbackVector(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(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(helper.slot(3), vector->ToSlot(index));
|
2015-10-01 13:48:05 +00:00
|
|
|
|
|
|
|
index = vector->GetIndex(helper.slot(7));
|
2017-07-27 12:45:00 +00:00
|
|
|
CHECK_EQ(3 + 4 * FeedbackMetadata::GetSlotSize(FeedbackSlotKind::kCall),
|
2017-02-07 15:19:35 +00:00
|
|
|
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
|
|
|
|
2017-07-27 12:45:00 +00:00
|
|
|
CHECK_EQ(3 + 5 * FeedbackMetadata::GetSlotSize(FeedbackSlotKind::kCall),
|
2017-02-07 15:19:35 +00:00
|
|
|
vector->length());
|
2015-10-01 13:48:05 +00:00
|
|
|
}
|
2017-01-09 15:31:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
FeedbackVectorSpec spec(&zone);
|
2017-09-01 10:49:06 +00:00
|
|
|
spec.AddForInSlot();
|
2017-01-26 12:08:35 +00:00
|
|
|
spec.AddCreateClosureSlot();
|
2017-09-01 10:49:06 +00:00
|
|
|
spec.AddForInSlot();
|
2017-02-07 14:05:02 +00:00
|
|
|
vector = NewFeedbackVector(isolate, &spec);
|
2017-01-09 15:31:00 +00:00
|
|
|
FeedbackVectorHelper helper(vector);
|
2017-02-07 15:19:35 +00:00
|
|
|
CHECK_EQ(1,
|
2017-02-07 17:49:58 +00:00
|
|
|
FeedbackMetadata::GetSlotSize(FeedbackSlotKind::kCreateClosure));
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot = helper.slot(1);
|
2018-05-08 07:20:40 +00:00
|
|
|
FeedbackCell* cell =
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
FeedbackCell::cast(vector->Get(slot)->GetHeapObjectAssumeStrong());
|
2017-02-06 10:18:05 +00:00
|
|
|
CHECK_EQ(cell->value(), *factory->undefined_value());
|
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:
|
2017-09-01 10:49:06 +00:00
|
|
|
spec.AddForInSlot();
|
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
|
|
|
}
|
|
|
|
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> vector = NewFeedbackVector(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.
|
2018-05-08 07:20:40 +00:00
|
|
|
vector->Set(FeedbackSlot(0), MaybeObject::FromObject(*vector));
|
2014-10-27 16:34:28 +00:00
|
|
|
|
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++) {
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlotKind kind = vector->GetKind(helper.slot(i));
|
2015-10-01 13:48:05 +00:00
|
|
|
switch (i % 4) {
|
|
|
|
case 0:
|
2017-09-01 10:49:06 +00:00
|
|
|
CHECK_EQ(FeedbackSlotKind::kForIn, kind);
|
2015-10-01 13:48:05 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_EQ(FeedbackSlotKind::kCall, kind);
|
2015-10-01 13:48:05 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_EQ(FeedbackSlotKind::kLoadProperty, kind);
|
2015-10-01 13:48:05 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_EQ(FeedbackSlotKind::kLoadKeyed, kind);
|
2015-10-01 13:48:05 +00:00
|
|
|
break;
|
2014-10-27 16:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
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.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2014-10-28 16:05:08 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
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.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-02-04 09:46:05 +00:00
|
|
|
CHECK_EQ(GENERIC, nexus.StateFromFeedback());
|
2016-07-13 07:58:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 18:30:22 +00:00
|
|
|
TEST(VectorCallFeedback) {
|
2016-07-13 07:58:40 +00:00
|
|
|
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; }"
|
2017-08-03 18:30:22 +00:00
|
|
|
"function f(a) { a(); } f(foo);");
|
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
Handle<JSFunction> foo = GetFunction("foo");
|
|
|
|
// There should be one IC.
|
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2017-08-03 18:30:22 +00:00
|
|
|
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
2018-05-23 06:53:49 +00:00
|
|
|
HeapObject* heap_object;
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(nexus.GetFeedback()->GetHeapObjectIfWeak(&heap_object));
|
2018-05-23 06:53:49 +00:00
|
|
|
CHECK_EQ(*foo, heap_object);
|
2017-08-03 18:30:22 +00:00
|
|
|
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
// It should stay monomorphic even after a GC.
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
}
|
|
|
|
|
|
|
|
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 f(a) { a(); } f(Array);");
|
2016-07-13 07:58:40 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
// There should be one IC.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2014-10-28 16:05:08 +00:00
|
|
|
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
2018-05-23 06:53:49 +00:00
|
|
|
HeapObject* heap_object;
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(nexus.GetFeedback()->GetHeapObjectIfWeak(&heap_object));
|
2018-05-23 06:53:49 +00:00
|
|
|
CHECK_EQ(*isolate->array_function(), heap_object);
|
2014-10-28 16:05:08 +00:00
|
|
|
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
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
|
|
|
|
2018-09-17 08:44:19 +00:00
|
|
|
size_t GetFeedbackVectorLength(Isolate* isolate, const char* src,
|
|
|
|
bool with_oneshot_opt) {
|
|
|
|
i::FLAG_enable_one_shot_optimization = with_oneshot_opt;
|
|
|
|
i::Handle<i::Object> i_object = v8::Utils::OpenHandle(*CompileRun(src));
|
|
|
|
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(i_object);
|
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
|
|
|
return feedback_vector->length();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(OneShotCallICSlotCount) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
i::FLAG_compilation_cache = false;
|
|
|
|
|
|
|
|
const char* no_call = R"(
|
|
|
|
function f1() {};
|
|
|
|
function f2() {};
|
|
|
|
(function() {
|
|
|
|
return arguments.callee;
|
|
|
|
})();
|
|
|
|
)";
|
|
|
|
// len = 2 * 1 ldaNamed property
|
|
|
|
CHECK_EQ(GetFeedbackVectorLength(isolate, no_call, false), 2);
|
|
|
|
// no slots of named property loads/stores in one shot
|
|
|
|
CHECK_EQ(GetFeedbackVectorLength(isolate, no_call, true), 0);
|
|
|
|
|
|
|
|
const char* single_call = R"(
|
|
|
|
function f1() {};
|
|
|
|
function f2() {};
|
|
|
|
(function() {
|
|
|
|
f1();
|
|
|
|
return arguments.callee;
|
|
|
|
})();
|
|
|
|
)";
|
|
|
|
// len = 2 * 1 ldaNamed Slot + 2 * 1 CachedGlobalSlot + 2 * 1 CallICSlot
|
|
|
|
CHECK_EQ(GetFeedbackVectorLength(isolate, single_call, false), 6);
|
|
|
|
// len = 2 * 1 CachedGlobalSlot
|
|
|
|
CHECK_EQ(GetFeedbackVectorLength(isolate, single_call, true), 2);
|
|
|
|
|
|
|
|
const char* multiple_calls = R"(
|
|
|
|
function f1() {};
|
|
|
|
function f2() {};
|
|
|
|
(function() {
|
|
|
|
f1();
|
|
|
|
f2();
|
|
|
|
f1();
|
|
|
|
f2();
|
|
|
|
return arguments.callee;
|
|
|
|
})();
|
|
|
|
)";
|
|
|
|
// len = 2 * 1 ldaNamedSlot + 2 * 2 CachedGlobalSlot (one for each unique
|
|
|
|
// function) + 2 * 4 CallICSlot (one for each function call)
|
|
|
|
CHECK_EQ(GetFeedbackVectorLength(isolate, multiple_calls, false), 14);
|
|
|
|
// CachedGlobalSlot (one for each unique function)
|
|
|
|
// len = 2 * 2 CachedGlobalSlot (one for each unique function)
|
|
|
|
CHECK_EQ(GetFeedbackVectorLength(isolate, multiple_calls, true), 4);
|
|
|
|
}
|
|
|
|
|
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.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2016-05-24 11:53:13 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
CompileRun("f(foo); f(foo);");
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
2017-12-08 12:56:58 +00:00
|
|
|
CHECK_EQ(3, nexus.GetCallCount());
|
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());
|
2017-12-08 12:56:58 +00:00
|
|
|
CHECK_EQ(4, nexus.GetCallCount());
|
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");
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
2016-09-14 03:22:56 +00:00
|
|
|
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2016-09-14 03:22:56 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(feedback_vector->Get(slot)->IsWeak());
|
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());
|
2017-12-08 12:56:58 +00:00
|
|
|
CHECK_EQ(3, nexus.GetCallCount());
|
2016-09-14 03:22:56 +00:00
|
|
|
|
|
|
|
// Send the IC megamorphic, but we should still have incrementing counts.
|
|
|
|
CompileRun("f(function() {});");
|
|
|
|
CHECK_EQ(GENERIC, nexus.StateFromFeedback());
|
2017-12-08 12:56:58 +00:00
|
|
|
CHECK_EQ(4, nexus.GetCallCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(VectorSpeculationMode) {
|
|
|
|
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() {}"
|
|
|
|
"function f(a) { new a(); } f(Foo);");
|
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
|
|
|
|
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2017-12-08 14:07:56 +00:00
|
|
|
CHECK_EQ(SpeculationMode::kAllowSpeculation, nexus.GetSpeculationMode());
|
2017-12-08 12:56:58 +00:00
|
|
|
|
|
|
|
CompileRun("f(Foo); f(Foo);");
|
|
|
|
CHECK_EQ(3, nexus.GetCallCount());
|
2017-12-08 14:07:56 +00:00
|
|
|
CHECK_EQ(SpeculationMode::kAllowSpeculation, nexus.GetSpeculationMode());
|
2017-12-08 12:56:58 +00:00
|
|
|
|
2017-12-08 14:07:56 +00:00
|
|
|
nexus.SetSpeculationMode(SpeculationMode::kDisallowSpeculation);
|
|
|
|
CHECK_EQ(SpeculationMode::kDisallowSpeculation, nexus.GetSpeculationMode());
|
2018-02-12 06:28:08 +00:00
|
|
|
CHECK_EQ(3, nexus.GetCallCount());
|
|
|
|
|
2017-12-08 14:07:56 +00:00
|
|
|
nexus.SetSpeculationMode(SpeculationMode::kAllowSpeculation);
|
|
|
|
CHECK_EQ(SpeculationMode::kAllowSpeculation, nexus.GetSpeculationMode());
|
2018-02-12 06:28:08 +00:00
|
|
|
CHECK_EQ(3, nexus.GetCallCount());
|
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.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2014-11-27 16:36:18 +00:00
|
|
|
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());
|
2017-05-09 22:36:00 +00:00
|
|
|
MapHandles maps;
|
2017-04-28 10:43:34 +00:00
|
|
|
nexus.ExtractMaps(&maps);
|
2017-05-09 22:36:00 +00:00
|
|
|
CHECK_EQ(4, maps.size());
|
2014-11-27 16:36:18 +00:00
|
|
|
|
|
|
|
// 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.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
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
|
|
|
|
2017-02-07 09:03:16 +00:00
|
|
|
TEST(VectorLoadGlobalICSlotSharing) {
|
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();
|
|
|
|
|
2017-02-07 09:03:16 +00:00
|
|
|
// Function f has 5 LoadGlobalICs: 3 for {o} references outside of "typeof"
|
|
|
|
// operator and 2 for {o} references inside "typeof" operator.
|
2015-03-12 09:22:47 +00:00
|
|
|
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;"
|
2017-02-07 09:03:16 +00:00
|
|
|
" var y = typeof o;"
|
|
|
|
" return o , typeof o, x , y, o;"
|
2015-03-12 09:22:47 +00:00
|
|
|
"}"
|
|
|
|
"f();");
|
2015-10-26 13:10:08 +00:00
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
2017-02-07 09:03:16 +00:00
|
|
|
// There should be two IC slots for {o} references outside and inside
|
|
|
|
// typeof operator respectively.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
2017-02-07 09:03:16 +00:00
|
|
|
CHECK_EQ(2, helper.slot_count());
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kLoadGlobalInsideTypeof);
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot1 = helper.slot(0);
|
|
|
|
FeedbackSlot slot2 = helper.slot(1);
|
2017-02-07 09:03:16 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC,
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus(feedback_vector, slot1).StateFromFeedback());
|
2017-02-07 09:03:16 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC,
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus(feedback_vector, slot2).StateFromFeedback());
|
2015-03-12 09:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), isolate);
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2015-01-15 12:52:33 +00:00
|
|
|
CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
|
|
|
CompileRun("f(34)");
|
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
// Verify that the monomorphic map is the one we expect.
|
2018-07-04 09:10:05 +00:00
|
|
|
Map* number_map = ReadOnlyRoots(heap).heap_number_map();
|
2015-01-15 12:52:33 +00:00
|
|
|
CHECK_EQ(number_map, nexus.FindFirstMap());
|
|
|
|
|
|
|
|
// Now go polymorphic on o.
|
|
|
|
CompileRun("f(o)");
|
|
|
|
CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback());
|
|
|
|
|
2017-05-09 22:36:00 +00:00
|
|
|
MapHandles maps;
|
2017-04-28 10:43:34 +00:00
|
|
|
nexus.ExtractMaps(&maps);
|
2017-05-09 22:36:00 +00:00
|
|
|
CHECK_EQ(2, maps.size());
|
2015-01-15 12:52:33 +00:00
|
|
|
|
|
|
|
// 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;
|
2017-05-09 22:36:00 +00:00
|
|
|
for (Handle<Map> current : maps) {
|
2015-01-15 12:52:33 +00:00
|
|
|
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());
|
2017-05-09 22:36:00 +00:00
|
|
|
MapHandles maps2;
|
2017-04-28 10:43:34 +00:00
|
|
|
nexus.ExtractMaps(&maps2);
|
2017-05-09 22:36:00 +00:00
|
|
|
CHECK_EQ(2, maps2.size());
|
2015-01-15 12:52:33 +00:00
|
|
|
}
|
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.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> 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);
|
2018-03-20 15:16:25 +00:00
|
|
|
CHECK_EQ(3, helper.slot_count());
|
2017-03-23 16:46:53 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kStoreGlobalSloppy);
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
2018-03-20 15:16:25 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
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) {"
|
2017-02-06 09:31:52 +00:00
|
|
|
" 'use strict';"
|
2015-10-01 13:48:05 +00:00
|
|
|
" 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.
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(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(2, helper.slot_count());
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
2017-02-17 15:15:07 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kStoreNamedStrict);
|
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.
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(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(5, helper.slot_count());
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kCall);
|
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
2017-02-17 15:15:07 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackSlotKind::kStoreNamedSloppy);
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 3, FeedbackSlotKind::kCall);
|
|
|
|
CHECK_SLOT_KIND(helper, 4, FeedbackSlotKind::kLoadProperty);
|
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.
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(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(3, helper.slot_count());
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kStoreKeyedSloppy);
|
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackSlotKind::kLoadKeyed);
|
2017-02-06 09:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
CompileRun(
|
|
|
|
"function testkeyedprop(x) {"
|
|
|
|
" 'use strict';"
|
|
|
|
" x[0] = a;"
|
|
|
|
" return x[0];"
|
|
|
|
"}"
|
|
|
|
"testkeyedprop([0, 1, 2]);");
|
|
|
|
|
|
|
|
Handle<JSFunction> f = GetFunction("testkeyedprop");
|
|
|
|
|
|
|
|
// 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.
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(f->feedback_vector(), isolate);
|
2017-02-06 09:31:52 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
|
|
|
CHECK_EQ(3, helper.slot_count());
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kStoreKeyedStrict);
|
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackSlotKind::kLoadKeyed);
|
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) {"
|
2017-02-06 09:31:52 +00:00
|
|
|
" 'use strict';"
|
2015-10-01 13:48:05 +00:00
|
|
|
" 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.
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(f->feedback_vector(), isolate);
|
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());
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kLoadGlobalNotInsideTypeof);
|
2017-02-17 15:15:07 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kStoreNamedStrict);
|
|
|
|
CHECK_SLOT_KIND(helper, 2, FeedbackSlotKind::kStoreNamedStrict);
|
|
|
|
CHECK_SLOT_KIND(helper, 3, FeedbackSlotKind::kStoreNamedStrict);
|
2017-10-19 15:12:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 4, FeedbackSlotKind::kBinaryOp);
|
2017-02-07 17:49:58 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 5, FeedbackSlotKind::kLoadProperty);
|
2017-10-19 15:12:42 +00:00
|
|
|
CHECK_SLOT_KIND(helper, 6, FeedbackSlotKind::kLoadProperty);
|
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.
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(f->feedback_vector(), f->GetIsolate());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
|
|
|
CHECK_EQ(1, helper.slot_count());
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(0);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, slot);
|
2015-09-04 08:36:29 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
2015-07-30 10:37:58 +00:00
|
|
|
}
|
2015-09-30 13:46:56 +00:00
|
|
|
|
2017-02-17 15:15:07 +00:00
|
|
|
TEST(StoreOwnIC) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
|
|
|
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"function f(v) {"
|
|
|
|
" return {a: 0, b: v, c: 0};"
|
|
|
|
"}"
|
|
|
|
"f(1);"
|
|
|
|
"f(2);"
|
|
|
|
"f(3);");
|
|
|
|
Handle<JSFunction> f = GetFunction("f");
|
|
|
|
// There should be one IC slot.
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(f->feedback_vector(), f->GetIsolate());
|
2017-02-17 15:15:07 +00:00
|
|
|
FeedbackVectorHelper helper(feedback_vector);
|
|
|
|
CHECK_EQ(2, helper.slot_count());
|
|
|
|
CHECK_SLOT_KIND(helper, 0, FeedbackSlotKind::kLiteral);
|
|
|
|
CHECK_SLOT_KIND(helper, 1, FeedbackSlotKind::kStoreOwnNamed);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(feedback_vector, helper.slot(1));
|
2017-02-17 15:15:07 +00:00
|
|
|
CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
|
|
|
|
}
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace
|
2017-08-11 11:22:28 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|