| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
| 7 | 7 |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/debug.h" | 9 #include "src/debug.h" |
| 10 #include "src/execution.h" | 10 #include "src/execution.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 Isolate* isolate = CcTest::i_isolate(); | 164 Isolate* isolate = CcTest::i_isolate(); |
| 165 Heap* heap = isolate->heap(); | 165 Heap* heap = isolate->heap(); |
| 166 | 166 |
| 167 // Make sure function f has a call that uses a type feedback slot. | 167 // Make sure function f has a call that uses a type feedback slot. |
| 168 CompileRun( | 168 CompileRun( |
| 169 "function fun() {};" | 169 "function fun() {};" |
| 170 "function f(a) { a(); } f(fun);"); | 170 "function f(a) { a(); } f(fun);"); |
| 171 Handle<JSFunction> f = v8::Utils::OpenHandle( | 171 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 172 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 172 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 173 // There should be one IC. | 173 // There should be one IC. |
| 174 Handle<Code> code = handle(f->shared()->code(), isolate); | 174 Code* code = f->shared()->code(); |
| 175 TypeFeedbackInfo* feedback_info = | 175 TypeFeedbackInfo* feedback_info = |
| 176 TypeFeedbackInfo::cast(code->type_feedback_info()); | 176 TypeFeedbackInfo::cast(code->type_feedback_info()); |
| 177 CHECK_EQ(1, feedback_info->ic_total_count()); | 177 CHECK_EQ(1, feedback_info->ic_total_count()); |
| 178 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); | 178 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); |
| 179 CHECK_EQ(0, feedback_info->ic_generic_count()); | 179 CHECK_EQ(0, feedback_info->ic_generic_count()); |
| 180 Handle<TypeFeedbackVector> feedback_vector = | 180 TypeFeedbackVector* feedback_vector = f->shared()->feedback_vector(); |
| 181 handle(f->shared()->feedback_vector(), isolate); | |
| 182 int ic_slot = 0; | |
| 183 CallICNexus nexus(feedback_vector, FeedbackVectorICSlot(ic_slot)); | |
| 184 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 181 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
| 185 CHECK_EQ(0, feedback_vector->ic_generic_count()); | 182 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 186 | 183 |
| 187 // Now send the information generic. | 184 // Now send the information generic. |
| 188 CompileRun("f(Object);"); | 185 CompileRun("f(Object);"); |
| 186 feedback_vector = f->shared()->feedback_vector(); |
| 189 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); | 187 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); |
| 190 CHECK_EQ(1, feedback_vector->ic_generic_count()); | 188 CHECK_EQ(1, feedback_vector->ic_generic_count()); |
| 191 | 189 |
| 192 // A collection will not affect the site. | 190 // A collection will make the site uninitialized again. |
| 193 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 191 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 192 feedback_vector = f->shared()->feedback_vector(); |
| 194 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); | 193 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); |
| 195 CHECK_EQ(1, feedback_vector->ic_generic_count()); | 194 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 196 | 195 |
| 197 // The Array function is special. A call to array remains monomorphic | 196 // The Array function is special. A call to array remains monomorphic |
| 198 // and isn't cleared by gc because an AllocationSite is being held. | 197 // and isn't cleared by gc because an AllocationSite is being held. |
| 199 // Clear the IC manually in order to test this case. | |
| 200 nexus.Clear(*code); | |
| 201 CompileRun("f(Array);"); | 198 CompileRun("f(Array);"); |
| 199 feedback_vector = f->shared()->feedback_vector(); |
| 202 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 200 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
| 203 CHECK_EQ(0, feedback_vector->ic_generic_count()); | 201 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 204 | 202 |
| 205 | 203 int ic_slot = 0; |
| 206 CHECK(nexus.GetFeedback()->IsAllocationSite()); | 204 CHECK( |
| 205 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite()); |
| 207 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 206 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 207 feedback_vector = f->shared()->feedback_vector(); |
| 208 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 208 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
| 209 CHECK_EQ(0, feedback_vector->ic_generic_count()); | 209 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 210 CHECK(nexus.GetFeedback()->IsAllocationSite()); | 210 CHECK( |
| 211 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite()); |
| 211 } | 212 } |
| 212 | 213 |
| 213 | 214 |
| 214 TEST(VectorCallICStates) { | 215 TEST(VectorCallICStates) { |
| 215 if (i::FLAG_always_opt) return; | 216 if (i::FLAG_always_opt) return; |
| 216 CcTest::InitializeVM(); | 217 CcTest::InitializeVM(); |
| 217 LocalContext context; | 218 LocalContext context; |
| 218 v8::HandleScope scope(context->GetIsolate()); | 219 v8::HandleScope scope(context->GetIsolate()); |
| 219 Isolate* isolate = CcTest::i_isolate(); | 220 Isolate* isolate = CcTest::i_isolate(); |
| 220 Heap* heap = isolate->heap(); | 221 Heap* heap = isolate->heap(); |
| 221 | 222 |
| 222 // Make sure function f has a call that uses a type feedback slot. | 223 // Make sure function f has a call that uses a type feedback slot. |
| 223 CompileRun( | 224 CompileRun( |
| 224 "function foo() { return 17; }" | 225 "function foo() { return 17; }" |
| 225 "function f(a) { a(); } f(foo);"); | 226 "function f(a) { a(); } f(foo);"); |
| 226 Handle<JSFunction> f = v8::Utils::OpenHandle( | 227 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 227 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 228 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 228 // There should be one IC. | 229 // There should be one IC. |
| 229 Handle<TypeFeedbackVector> feedback_vector = | 230 Handle<TypeFeedbackVector> feedback_vector = |
| 230 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 231 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 231 FeedbackVectorICSlot slot(0); | 232 FeedbackVectorICSlot slot(0); |
| 232 CallICNexus nexus(feedback_vector, slot); | 233 CallICNexus nexus(feedback_vector, slot); |
| 233 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 234 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 234 // CallIC doesn't return map feedback. | 235 // CallIC doesn't return map feedback. |
| 235 CHECK_EQ(NULL, nexus.FindFirstMap()); | 236 CHECK_EQ(NULL, nexus.FindFirstMap()); |
| 236 | 237 |
| 237 CompileRun("f(function() { return 16; })"); | 238 CompileRun("f(function() { return 16; })"); |
| 238 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); | 239 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); |
| 239 | 240 |
| 240 // After a collection, state should remain GENERIC. | 241 // After a collection, state should be reset to UNINITIALIZED. |
| 241 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 242 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 242 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); | 243 CHECK_EQ(UNINITIALIZED, nexus.StateFromFeedback()); |
| 243 | 244 |
| 244 // A call to Array is special, it contains an AllocationSite as feedback. | 245 // Array is special. It will remain monomorphic across gcs and it contains an |
| 245 // Clear the IC manually in order to test this case. | 246 // AllocationSite. |
| 246 nexus.Clear(f->shared()->code()); | |
| 247 CompileRun("f(Array)"); | 247 CompileRun("f(Array)"); |
| 248 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 248 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 249 CHECK(nexus.GetFeedback()->IsAllocationSite()); | 249 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot))->IsAllocationSite()); |
| 250 | 250 |
| 251 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 251 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 252 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 252 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 | 255 |
| 256 TEST(VectorLoadICStates) { | 256 TEST(VectorLoadICStates) { |
| 257 if (i::FLAG_always_opt || !i::FLAG_vector_ics) return; | 257 if (i::FLAG_always_opt || !i::FLAG_vector_ics) return; |
| 258 CcTest::InitializeVM(); | 258 CcTest::InitializeVM(); |
| 259 LocalContext context; | 259 LocalContext context; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 CHECK(number_map_found && o_map_found); | 357 CHECK(number_map_found && o_map_found); |
| 358 | 358 |
| 359 // The degree of polymorphism doesn't change. | 359 // The degree of polymorphism doesn't change. |
| 360 CompileRun("f(100)"); | 360 CompileRun("f(100)"); |
| 361 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); | 361 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); |
| 362 MapHandleList maps2; | 362 MapHandleList maps2; |
| 363 nexus.FindAllMaps(&maps2); | 363 nexus.FindAllMaps(&maps2); |
| 364 CHECK_EQ(2, maps2.length()); | 364 CHECK_EQ(2, maps2.length()); |
| 365 } | 365 } |
| 366 } | 366 } |
| OLD | NEW |