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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 298 |
299 // Finally driven megamorphic. | 299 // Finally driven megamorphic. |
300 CompileRun("f({ blarg: 3, gran: 3, torino: 10, foo: 2 })"); | 300 CompileRun("f({ blarg: 3, gran: 3, torino: 10, foo: 2 })"); |
301 CHECK_EQ(MEGAMORPHIC, nexus.StateFromFeedback()); | 301 CHECK_EQ(MEGAMORPHIC, nexus.StateFromFeedback()); |
302 CHECK_EQ(NULL, nexus.FindFirstMap()); | 302 CHECK_EQ(NULL, nexus.FindFirstMap()); |
303 | 303 |
304 // After a collection, state should not be reset to PREMONOMORPHIC. | 304 // After a collection, state should not be reset to PREMONOMORPHIC. |
305 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 305 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
306 CHECK_EQ(MEGAMORPHIC, nexus.StateFromFeedback()); | 306 CHECK_EQ(MEGAMORPHIC, nexus.StateFromFeedback()); |
307 } | 307 } |
| 308 |
| 309 |
| 310 TEST(VectorLoadICOnSmi) { |
| 311 if (i::FLAG_always_opt || !i::FLAG_vector_ics) return; |
| 312 CcTest::InitializeVM(); |
| 313 LocalContext context; |
| 314 v8::HandleScope scope(context->GetIsolate()); |
| 315 Isolate* isolate = CcTest::i_isolate(); |
| 316 Heap* heap = isolate->heap(); |
| 317 |
| 318 // Make sure function f has a call that uses a type feedback slot. |
| 319 CompileRun( |
| 320 "var o = { foo: 3 };" |
| 321 "function f(a) { return a.foo; } f(o);"); |
| 322 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 323 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 324 // There should be one IC. |
| 325 Handle<TypeFeedbackVector> feedback_vector = |
| 326 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 327 FeedbackVectorICSlot slot(0); |
| 328 LoadICNexus nexus(feedback_vector, slot); |
| 329 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); |
| 330 |
| 331 CompileRun("f(34)"); |
| 332 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 333 // Verify that the monomorphic map is the one we expect. |
| 334 Map* number_map = heap->heap_number_map(); |
| 335 CHECK_EQ(number_map, nexus.FindFirstMap()); |
| 336 |
| 337 // Now go polymorphic on o. |
| 338 CompileRun("f(o)"); |
| 339 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); |
| 340 |
| 341 MapHandleList maps; |
| 342 nexus.FindAllMaps(&maps); |
| 343 CHECK_EQ(2, maps.length()); |
| 344 |
| 345 // One of the maps should be the o map. |
| 346 Handle<JSObject> o = v8::Utils::OpenHandle( |
| 347 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str("o")))); |
| 348 bool number_map_found = false; |
| 349 bool o_map_found = false; |
| 350 for (int i = 0; i < maps.length(); i++) { |
| 351 Handle<Map> current = maps[i]; |
| 352 if (*current == number_map) |
| 353 number_map_found = true; |
| 354 else if (*current == o->map()) |
| 355 o_map_found = true; |
| 356 } |
| 357 CHECK(number_map_found && o_map_found); |
| 358 |
| 359 // The degree of polymorphism doesn't change. |
| 360 CompileRun("f(100)"); |
| 361 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); |
| 362 MapHandleList maps2; |
| 363 nexus.FindAllMaps(&maps2); |
| 364 CHECK_EQ(2, maps2.length()); |
308 } | 365 } |
| 366 } |
OLD | NEW |