| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 177 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 178 // There should be one IC. | 178 // There should be one IC. |
| 179 Handle<Code> code = handle(f->shared()->code(), isolate); | 179 Handle<Code> code = handle(f->shared()->code(), isolate); |
| 180 TypeFeedbackInfo* feedback_info = | 180 TypeFeedbackInfo* feedback_info = |
| 181 TypeFeedbackInfo::cast(code->type_feedback_info()); | 181 TypeFeedbackInfo::cast(code->type_feedback_info()); |
| 182 CHECK_EQ(1, feedback_info->ic_total_count()); | 182 CHECK_EQ(1, feedback_info->ic_total_count()); |
| 183 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); | 183 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); |
| 184 CHECK_EQ(0, feedback_info->ic_generic_count()); | 184 CHECK_EQ(0, feedback_info->ic_generic_count()); |
| 185 Handle<TypeFeedbackVector> feedback_vector = | 185 Handle<TypeFeedbackVector> feedback_vector = |
| 186 handle(f->shared()->feedback_vector(), isolate); | 186 handle(f->shared()->feedback_vector(), isolate); |
| 187 int ic_slot = 0; | 187 int ic_slot = 1; |
| 188 CallICNexus nexus(feedback_vector, FeedbackVectorICSlot(ic_slot)); | 188 CallICNexus nexus(feedback_vector, FeedbackVectorICSlot(ic_slot)); |
| 189 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 189 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
| 190 CHECK_EQ(0, feedback_vector->ic_generic_count()); | 190 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
| 191 | 191 |
| 192 // Now send the information generic. | 192 // Now send the information generic. |
| 193 CompileRun("f(Object);"); | 193 CompileRun("f(Object);"); |
| 194 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); | 194 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); |
| 195 CHECK_EQ(1, feedback_vector->ic_generic_count()); | 195 CHECK_EQ(1, feedback_vector->ic_generic_count()); |
| 196 | 196 |
| 197 // A collection will not affect the site. | 197 // A collection will not affect the site. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 226 | 226 |
| 227 // Make sure function f has a call that uses a type feedback slot. | 227 // Make sure function f has a call that uses a type feedback slot. |
| 228 CompileRun( | 228 CompileRun( |
| 229 "function foo() { return 17; }" | 229 "function foo() { return 17; }" |
| 230 "function f(a) { a(); } f(foo);"); | 230 "function f(a) { a(); } f(foo);"); |
| 231 Handle<JSFunction> f = v8::Utils::OpenHandle( | 231 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 232 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 232 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 233 // There should be one IC. | 233 // There should be one IC. |
| 234 Handle<TypeFeedbackVector> feedback_vector = | 234 Handle<TypeFeedbackVector> feedback_vector = |
| 235 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 235 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 236 FeedbackVectorICSlot slot(0); | 236 FeedbackVectorICSlot slot(1); |
| 237 CallICNexus nexus(feedback_vector, slot); | 237 CallICNexus nexus(feedback_vector, slot); |
| 238 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 238 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 239 // CallIC doesn't return map feedback. | 239 // CallIC doesn't return map feedback. |
| 240 CHECK(!nexus.FindFirstMap()); | 240 CHECK(!nexus.FindFirstMap()); |
| 241 | 241 |
| 242 CompileRun("f(function() { return 16; })"); | 242 CompileRun("f(function() { return 16; })"); |
| 243 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); | 243 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); |
| 244 | 244 |
| 245 // After a collection, state should remain GENERIC. | 245 // After a collection, state should remain GENERIC. |
| 246 heap->CollectAllGarbage(); | 246 heap->CollectAllGarbage(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 268 | 268 |
| 269 // Make sure function f has a call that uses a type feedback slot. | 269 // Make sure function f has a call that uses a type feedback slot. |
| 270 CompileRun( | 270 CompileRun( |
| 271 "var o = { foo: 3 };" | 271 "var o = { foo: 3 };" |
| 272 "function f(a) { return a.foo; } f(o);"); | 272 "function f(a) { return a.foo; } f(o);"); |
| 273 Handle<JSFunction> f = v8::Utils::OpenHandle( | 273 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 274 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 274 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 275 // There should be one IC. | 275 // There should be one IC. |
| 276 Handle<TypeFeedbackVector> feedback_vector = | 276 Handle<TypeFeedbackVector> feedback_vector = |
| 277 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 277 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 278 FeedbackVectorICSlot slot(0); | 278 FeedbackVectorICSlot slot(1); |
| 279 LoadICNexus nexus(feedback_vector, slot); | 279 LoadICNexus nexus(feedback_vector, slot); |
| 280 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); | 280 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); |
| 281 | 281 |
| 282 CompileRun("f(o)"); | 282 CompileRun("f(o)"); |
| 283 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 283 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 284 // Verify that the monomorphic map is the one we expect. | 284 // Verify that the monomorphic map is the one we expect. |
| 285 Handle<JSObject> o = v8::Utils::OpenHandle( | 285 Handle<JSObject> o = v8::Utils::OpenHandle( |
| 286 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str("o")))); | 286 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str("o")))); |
| 287 CHECK_EQ(o->map(), nexus.FindFirstMap()); | 287 CHECK_EQ(o->map(), nexus.FindFirstMap()); |
| 288 | 288 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 "function f() {" | 326 "function f() {" |
| 327 " var x = o + 10;" | 327 " var x = o + 10;" |
| 328 " return o + x + o;" | 328 " return o + x + o;" |
| 329 "}" | 329 "}" |
| 330 "f();"); | 330 "f();"); |
| 331 Handle<JSFunction> f = v8::Utils::OpenHandle( | 331 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 332 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 332 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 333 // There should be one IC slot. | 333 // There should be one IC slot. |
| 334 Handle<TypeFeedbackVector> feedback_vector = | 334 Handle<TypeFeedbackVector> feedback_vector = |
| 335 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 335 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 336 CHECK_EQ(1, feedback_vector->ICSlots()); | 336 CHECK_EQ(2, feedback_vector->ICSlots()); |
| 337 FeedbackVectorICSlot slot(0); | 337 FeedbackVectorICSlot slot(1); |
| 338 LoadICNexus nexus(feedback_vector, slot); | 338 LoadICNexus nexus(feedback_vector, slot); |
| 339 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 339 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 340 } | 340 } |
| 341 | 341 |
| 342 | 342 |
| 343 TEST(VectorLoadICOnSmi) { | 343 TEST(VectorLoadICOnSmi) { |
| 344 if (i::FLAG_always_opt || !i::FLAG_vector_ics) return; | 344 if (i::FLAG_always_opt || !i::FLAG_vector_ics) return; |
| 345 CcTest::InitializeVM(); | 345 CcTest::InitializeVM(); |
| 346 LocalContext context; | 346 LocalContext context; |
| 347 v8::HandleScope scope(context->GetIsolate()); | 347 v8::HandleScope scope(context->GetIsolate()); |
| 348 Isolate* isolate = CcTest::i_isolate(); | 348 Isolate* isolate = CcTest::i_isolate(); |
| 349 Heap* heap = isolate->heap(); | 349 Heap* heap = isolate->heap(); |
| 350 | 350 |
| 351 // Make sure function f has a call that uses a type feedback slot. | 351 // Make sure function f has a call that uses a type feedback slot. |
| 352 CompileRun( | 352 CompileRun( |
| 353 "var o = { foo: 3 };" | 353 "var o = { foo: 3 };" |
| 354 "function f(a) { return a.foo; } f(o);"); | 354 "function f(a) { return a.foo; } f(o);"); |
| 355 Handle<JSFunction> f = v8::Utils::OpenHandle( | 355 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 356 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 356 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 357 // There should be one IC. | 357 // There should be one IC. |
| 358 Handle<TypeFeedbackVector> feedback_vector = | 358 Handle<TypeFeedbackVector> feedback_vector = |
| 359 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 359 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 360 FeedbackVectorICSlot slot(0); | 360 FeedbackVectorICSlot slot(1); |
| 361 LoadICNexus nexus(feedback_vector, slot); | 361 LoadICNexus nexus(feedback_vector, slot); |
| 362 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); | 362 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); |
| 363 | 363 |
| 364 CompileRun("f(34)"); | 364 CompileRun("f(34)"); |
| 365 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 365 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 366 // Verify that the monomorphic map is the one we expect. | 366 // Verify that the monomorphic map is the one we expect. |
| 367 Map* number_map = heap->heap_number_map(); | 367 Map* number_map = heap->heap_number_map(); |
| 368 CHECK_EQ(number_map, nexus.FindFirstMap()); | 368 CHECK_EQ(number_map, nexus.FindFirstMap()); |
| 369 | 369 |
| 370 // Now go polymorphic on o. | 370 // Now go polymorphic on o. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 390 CHECK(number_map_found && o_map_found); | 390 CHECK(number_map_found && o_map_found); |
| 391 | 391 |
| 392 // The degree of polymorphism doesn't change. | 392 // The degree of polymorphism doesn't change. |
| 393 CompileRun("f(100)"); | 393 CompileRun("f(100)"); |
| 394 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); | 394 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); |
| 395 MapHandleList maps2; | 395 MapHandleList maps2; |
| 396 nexus.FindAllMaps(&maps2); | 396 nexus.FindAllMaps(&maps2); |
| 397 CHECK_EQ(2, maps2.length()); | 397 CHECK_EQ(2, maps2.length()); |
| 398 } | 398 } |
| 399 } | 399 } |
| OLD | NEW |