 Chromium Code Reviews
 Chromium Code Reviews Issue 650073002:
  vector-based ICs did not update type feedback counts correctly.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 650073002:
  vector-based ICs did not update type feedback counts correctly.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| Index: test/cctest/test-feedback-vector.cc | 
| diff --git a/test/cctest/test-feedback-vector.cc b/test/cctest/test-feedback-vector.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..48458dd7323a1be16300c97ec81f93b88964cc0f | 
| --- /dev/null | 
| +++ b/test/cctest/test-feedback-vector.cc | 
| @@ -0,0 +1,164 @@ | 
| +// Copyright 2011 the V8 project authors. All rights reserved. | 
| 
Jakob Kummerow
2014/10/14 15:27:20
nit: 2014, and use the short license header please
 
mvstanton
2014/10/16 10:54:15
Done.
 | 
| +// 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. | 
| + | 
| +#include "src/v8.h" | 
| +#include "test/cctest/cctest.h" | 
| + | 
| +#include "src/api.h" | 
| +#include "src/debug.h" | 
| +#include "src/execution.h" | 
| +#include "src/factory.h" | 
| +#include "src/global-handles.h" | 
| +#include "src/macro-assembler.h" | 
| +#include "src/objects.h" | 
| + | 
| +using namespace v8::internal; | 
| + | 
| +namespace { | 
| + | 
| +TEST(VectorStructure) { | 
| + LocalContext context; | 
| + v8::HandleScope scope(context->GetIsolate()); | 
| + Isolate* isolate = CcTest::i_isolate(); | 
| + Factory* factory = isolate->factory(); | 
| + | 
| + // Empty vectors are the empty fixed array. | 
| + Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(0, 0); | 
| + CHECK(Handle<FixedArray>::cast(vector) | 
| + .is_identical_to(factory->empty_fixed_array())); | 
| + // Which can nonetheless be queried. | 
| + CHECK_EQ(0, vector->ic_with_type_info_count()); | 
| + CHECK_EQ(0, vector->ic_generic_count()); | 
| + CHECK_EQ(0, vector->Slots()); | 
| + CHECK_EQ(0, vector->ICSlots()); | 
| + | 
| + vector = factory->NewTypeFeedbackVector(1, 0); | 
| + CHECK_EQ(1, vector->Slots()); | 
| + CHECK_EQ(0, vector->ICSlots()); | 
| + | 
| + vector = factory->NewTypeFeedbackVector(0, 1); | 
| + CHECK_EQ(0, vector->Slots()); | 
| + CHECK_EQ(1, vector->ICSlots()); | 
| + | 
| + vector = factory->NewTypeFeedbackVector(3, 5); | 
| + CHECK_EQ(3, vector->Slots()); | 
| + CHECK_EQ(5, vector->ICSlots()); | 
| + | 
| + int index = vector->GetIndex(FeedbackVectorSlot(0)); | 
| + CHECK_EQ(index, TypeFeedbackVector::kReservedIndexCount); | 
| 
Jakob Kummerow
2014/10/14 15:27:20
nit: order is "expected, actual".
 
mvstanton
2014/10/16 10:54:15
Done.
 | 
| + CHECK(FeedbackVectorSlot(0) == vector->ToSlot(index)); | 
| + | 
| + index = vector->GetIndex(FeedbackVectorICSlot(0)); | 
| + CHECK_EQ(index, TypeFeedbackVector::kReservedIndexCount + 3); | 
| + CHECK(FeedbackVectorICSlot(0) == vector->ToICSlot(index)); | 
| + | 
| + CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + 3 + 5, vector->length()); | 
| +} | 
| + | 
| + | 
| +TEST(VectorClearing) { | 
| + LocalContext context; | 
| + v8::HandleScope scope(context->GetIsolate()); | 
| + Isolate* isolate = CcTest::i_isolate(); | 
| + Factory* factory = isolate->factory(); | 
| + | 
| + // Empty vectors are the empty fixed array. | 
| 
Jakob Kummerow
2014/10/14 15:27:20
comment out of place?
 
mvstanton
2014/10/16 10:54:15
Done.
 | 
| + Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(5, 1); | 
| + | 
| + // Fill with information | 
| + vector->Set(FeedbackVectorSlot(0), Smi::FromInt(1)); | 
| + vector->Set(FeedbackVectorSlot(1), *factory->fixed_array_map()); | 
| + vector->Set(FeedbackVectorSlot(2), *factory->NewAllocationSite()); | 
| + | 
| + vector->Set(FeedbackVectorICSlot(0), *factory->fixed_array_map()); | 
| + | 
| + vector->ClearSlots(); | 
| + | 
| + // The feedback vector slots are cleared. The ic slots are not. | 
| + // AllocationSites are granted an exemption from clearing, as are | 
| + // smis. | 
| + CHECK_EQ(vector->Get(FeedbackVectorSlot(0)), Smi::FromInt(1)); | 
| 
Jakob Kummerow
2014/10/14 15:27:20
nit: order is "expected, actual" (again below).
 
mvstanton
2014/10/16 10:54:15
Done.
 
mvstanton
2014/10/16 10:54:16
Done.
 | 
| + CHECK_EQ(vector->Get(FeedbackVectorSlot(1)), | 
| + *TypeFeedbackVector::UninitializedSentinel(isolate)); | 
| + CHECK(vector->Get(FeedbackVectorSlot(2))->IsAllocationSite()); | 
| + | 
| + CHECK_EQ(vector->Get(FeedbackVectorICSlot(0)), *factory->fixed_array_map()); | 
| +} | 
| + | 
| + | 
| +TEST(VectorICProfilerStatistics) { | 
| + if (i::FLAG_always_opt) return; | 
| + 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( | 
| + "function fun() {};" | 
| + "function f(a) { a(); } f(fun);"); | 
| + Handle<JSFunction> f = v8::Utils::OpenHandle( | 
| + *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 
| + // There should be one IC. | 
| + Code* code = f->shared()->code(); | 
| + TypeFeedbackInfo* feedback_info = | 
| + TypeFeedbackInfo::cast(code->type_feedback_info()); | 
| + CHECK_EQ(1, feedback_info->ic_total_count()); | 
| + CHECK_EQ(0, feedback_info->ic_with_type_info_count()); | 
| + CHECK_EQ(0, feedback_info->ic_generic_count()); | 
| + TypeFeedbackVector* feedback_vector = f->shared()->feedback_vector(); | 
| + CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 
| + CHECK_EQ(0, feedback_vector->ic_generic_count()); | 
| + | 
| + // Now send the information generic. | 
| + CompileRun("f(Object);"); | 
| + feedback_vector = f->shared()->feedback_vector(); | 
| + CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); | 
| + CHECK_EQ(1, feedback_vector->ic_generic_count()); | 
| + | 
| + // A collection will make the site uninitialized again. | 
| + heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 
| + feedback_vector = f->shared()->feedback_vector(); | 
| + CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); | 
| + CHECK_EQ(0, feedback_vector->ic_generic_count()); | 
| + | 
| + // The Array function is special. A call to array remains monomorphic | 
| + // and isn't cleared by gc because an AllocationSite is being held. | 
| + CompileRun("f(Array);"); | 
| + feedback_vector = f->shared()->feedback_vector(); | 
| + CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 
| + CHECK_EQ(0, feedback_vector->ic_generic_count()); | 
| + | 
| + CHECK(feedback_vector->Get(FeedbackVectorICSlot(0))->IsAllocationSite()); | 
| + heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 
| + feedback_vector = f->shared()->feedback_vector(); | 
| + CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 
| + CHECK_EQ(0, feedback_vector->ic_generic_count()); | 
| + CHECK(feedback_vector->Get(FeedbackVectorICSlot(0))->IsAllocationSite()); | 
| +} | 
| +} |