OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 #include "test/cctest/cctest.h" |
| 7 |
| 8 #include "src/api.h" |
| 9 #include "src/debug.h" |
| 10 #include "src/execution.h" |
| 11 #include "src/factory.h" |
| 12 #include "src/global-handles.h" |
| 13 #include "src/macro-assembler.h" |
| 14 #include "src/objects.h" |
| 15 |
| 16 using namespace v8::internal; |
| 17 |
| 18 namespace { |
| 19 |
| 20 TEST(VectorStructure) { |
| 21 LocalContext context; |
| 22 v8::HandleScope scope(context->GetIsolate()); |
| 23 Isolate* isolate = CcTest::i_isolate(); |
| 24 Factory* factory = isolate->factory(); |
| 25 |
| 26 // Empty vectors are the empty fixed array. |
| 27 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(0, 0); |
| 28 CHECK(Handle<FixedArray>::cast(vector) |
| 29 .is_identical_to(factory->empty_fixed_array())); |
| 30 // Which can nonetheless be queried. |
| 31 CHECK_EQ(0, vector->ic_with_type_info_count()); |
| 32 CHECK_EQ(0, vector->ic_generic_count()); |
| 33 CHECK_EQ(0, vector->Slots()); |
| 34 CHECK_EQ(0, vector->ICSlots()); |
| 35 |
| 36 vector = factory->NewTypeFeedbackVector(1, 0); |
| 37 CHECK_EQ(1, vector->Slots()); |
| 38 CHECK_EQ(0, vector->ICSlots()); |
| 39 |
| 40 vector = factory->NewTypeFeedbackVector(0, 1); |
| 41 CHECK_EQ(0, vector->Slots()); |
| 42 CHECK_EQ(1, vector->ICSlots()); |
| 43 |
| 44 vector = factory->NewTypeFeedbackVector(3, 5); |
| 45 CHECK_EQ(3, vector->Slots()); |
| 46 CHECK_EQ(5, vector->ICSlots()); |
| 47 |
| 48 int index = vector->GetIndex(FeedbackVectorSlot(0)); |
| 49 CHECK_EQ(TypeFeedbackVector::kReservedIndexCount, index); |
| 50 CHECK(FeedbackVectorSlot(0) == vector->ToSlot(index)); |
| 51 |
| 52 index = vector->GetIndex(FeedbackVectorICSlot(0)); |
| 53 CHECK_EQ(index, TypeFeedbackVector::kReservedIndexCount + 3); |
| 54 CHECK(FeedbackVectorICSlot(0) == vector->ToICSlot(index)); |
| 55 |
| 56 CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + 3 + 5, vector->length()); |
| 57 } |
| 58 |
| 59 |
| 60 TEST(VectorICProfilerStatistics) { |
| 61 if (i::FLAG_always_opt) return; |
| 62 CcTest::InitializeVM(); |
| 63 LocalContext context; |
| 64 v8::HandleScope scope(context->GetIsolate()); |
| 65 Isolate* isolate = CcTest::i_isolate(); |
| 66 Heap* heap = isolate->heap(); |
| 67 |
| 68 // Make sure function f has a call that uses a type feedback slot. |
| 69 CompileRun( |
| 70 "function fun() {};" |
| 71 "function f(a) { a(); } f(fun);"); |
| 72 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 73 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 74 // There should be one IC. |
| 75 Code* code = f->shared()->code(); |
| 76 TypeFeedbackInfo* feedback_info = |
| 77 TypeFeedbackInfo::cast(code->type_feedback_info()); |
| 78 CHECK_EQ(1, feedback_info->ic_total_count()); |
| 79 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); |
| 80 CHECK_EQ(0, feedback_info->ic_generic_count()); |
| 81 TypeFeedbackVector* feedback_vector = f->shared()->feedback_vector(); |
| 82 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
| 83 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 84 |
| 85 // Now send the information generic. |
| 86 CompileRun("f(Object);"); |
| 87 feedback_vector = f->shared()->feedback_vector(); |
| 88 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); |
| 89 CHECK_EQ(1, feedback_vector->ic_generic_count()); |
| 90 |
| 91 // A collection will make the site uninitialized again. |
| 92 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 93 feedback_vector = f->shared()->feedback_vector(); |
| 94 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); |
| 95 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 96 |
| 97 // The Array function is special. A call to array remains monomorphic |
| 98 // and isn't cleared by gc because an AllocationSite is being held. |
| 99 CompileRun("f(Array);"); |
| 100 feedback_vector = f->shared()->feedback_vector(); |
| 101 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
| 102 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 103 |
| 104 CHECK(feedback_vector->Get(FeedbackVectorICSlot(0))->IsAllocationSite()); |
| 105 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 106 feedback_vector = f->shared()->feedback_vector(); |
| 107 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
| 108 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 109 CHECK(feedback_vector->Get(FeedbackVectorICSlot(0))->IsAllocationSite()); |
| 110 } |
| 111 } |
OLD | NEW |