| 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/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/execution.h" | 10 #include "src/execution.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 CcTest::InitializeVM(); | 193 CcTest::InitializeVM(); |
| 194 LocalContext context; | 194 LocalContext context; |
| 195 v8::HandleScope scope(context->GetIsolate()); | 195 v8::HandleScope scope(context->GetIsolate()); |
| 196 Isolate* isolate = CcTest::i_isolate(); | 196 Isolate* isolate = CcTest::i_isolate(); |
| 197 Heap* heap = isolate->heap(); | 197 Heap* heap = isolate->heap(); |
| 198 | 198 |
| 199 // Make sure function f has a call that uses a type feedback slot. | 199 // Make sure function f has a call that uses a type feedback slot. |
| 200 CompileRun( | 200 CompileRun( |
| 201 "function fun() {};" | 201 "function fun() {};" |
| 202 "function f(a) { a(); } f(fun);"); | 202 "function f(a) { a(); } f(fun);"); |
| 203 Handle<JSFunction> f = v8::Utils::OpenHandle( | 203 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 204 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 204 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
| 205 // There should be one IC. | 205 // There should be one IC. |
| 206 Handle<Code> code = handle(f->shared()->code(), isolate); | 206 Handle<Code> code = handle(f->shared()->code(), isolate); |
| 207 TypeFeedbackInfo* feedback_info = | 207 TypeFeedbackInfo* feedback_info = |
| 208 TypeFeedbackInfo::cast(code->type_feedback_info()); | 208 TypeFeedbackInfo::cast(code->type_feedback_info()); |
| 209 CHECK_EQ(1, feedback_info->ic_total_count()); | 209 CHECK_EQ(1, feedback_info->ic_total_count()); |
| 210 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); | 210 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); |
| 211 CHECK_EQ(0, feedback_info->ic_generic_count()); | 211 CHECK_EQ(0, feedback_info->ic_generic_count()); |
| 212 Handle<TypeFeedbackVector> feedback_vector = | 212 Handle<TypeFeedbackVector> feedback_vector = |
| 213 handle(f->shared()->feedback_vector(), isolate); | 213 handle(f->shared()->feedback_vector(), isolate); |
| 214 FeedbackVectorHelper helper(feedback_vector); | 214 FeedbackVectorHelper helper(feedback_vector); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 CcTest::InitializeVM(); | 248 CcTest::InitializeVM(); |
| 249 LocalContext context; | 249 LocalContext context; |
| 250 v8::HandleScope scope(context->GetIsolate()); | 250 v8::HandleScope scope(context->GetIsolate()); |
| 251 Isolate* isolate = CcTest::i_isolate(); | 251 Isolate* isolate = CcTest::i_isolate(); |
| 252 Heap* heap = isolate->heap(); | 252 Heap* heap = isolate->heap(); |
| 253 | 253 |
| 254 // Make sure function f has a call that uses a type feedback slot. | 254 // Make sure function f has a call that uses a type feedback slot. |
| 255 CompileRun( | 255 CompileRun( |
| 256 "function foo() { return 17; }" | 256 "function foo() { return 17; }" |
| 257 "function f(a) { a(); } f(foo);"); | 257 "function f(a) { a(); } f(foo);"); |
| 258 Handle<JSFunction> f = v8::Utils::OpenHandle( | 258 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 259 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 259 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
| 260 // There should be one IC. | 260 // There should be one IC. |
| 261 Handle<TypeFeedbackVector> feedback_vector = | 261 Handle<TypeFeedbackVector> feedback_vector = |
| 262 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 262 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 263 FeedbackVectorSlot slot(0); | 263 FeedbackVectorSlot slot(0); |
| 264 CallICNexus nexus(feedback_vector, slot); | 264 CallICNexus nexus(feedback_vector, slot); |
| 265 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 265 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 266 // CallIC doesn't return map feedback. | 266 // CallIC doesn't return map feedback. |
| 267 CHECK(!nexus.FindFirstMap()); | 267 CHECK(!nexus.FindFirstMap()); |
| 268 | 268 |
| 269 CompileRun("f(function() { return 16; })"); | 269 CompileRun("f(function() { return 16; })"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 290 CcTest::InitializeVM(); | 290 CcTest::InitializeVM(); |
| 291 LocalContext context; | 291 LocalContext context; |
| 292 v8::HandleScope scope(context->GetIsolate()); | 292 v8::HandleScope scope(context->GetIsolate()); |
| 293 Isolate* isolate = CcTest::i_isolate(); | 293 Isolate* isolate = CcTest::i_isolate(); |
| 294 Heap* heap = isolate->heap(); | 294 Heap* heap = isolate->heap(); |
| 295 | 295 |
| 296 // Make sure function f has a call that uses a type feedback slot. | 296 // Make sure function f has a call that uses a type feedback slot. |
| 297 CompileRun( | 297 CompileRun( |
| 298 "var o = { foo: 3 };" | 298 "var o = { foo: 3 };" |
| 299 "function f(a) { return a.foo; } f(o);"); | 299 "function f(a) { return a.foo; } f(o);"); |
| 300 Handle<JSFunction> f = v8::Utils::OpenHandle( | 300 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 301 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 301 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
| 302 // There should be one IC. | 302 // There should be one IC. |
| 303 Handle<TypeFeedbackVector> feedback_vector = | 303 Handle<TypeFeedbackVector> feedback_vector = |
| 304 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 304 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 305 FeedbackVectorSlot slot(0); | 305 FeedbackVectorSlot slot(0); |
| 306 LoadICNexus nexus(feedback_vector, slot); | 306 LoadICNexus nexus(feedback_vector, slot); |
| 307 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); | 307 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); |
| 308 | 308 |
| 309 CompileRun("f(o)"); | 309 CompileRun("f(o)"); |
| 310 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 310 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 311 // Verify that the monomorphic map is the one we expect. | 311 // Verify that the monomorphic map is the one we expect. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 // Function f has 3 LoadICs, one for each o, but the ICs share the same | 349 // Function f has 3 LoadICs, one for each o, but the ICs share the same |
| 350 // feedback vector IC slot. | 350 // feedback vector IC slot. |
| 351 CompileRun( | 351 CompileRun( |
| 352 "o = 10;" | 352 "o = 10;" |
| 353 "function f() {" | 353 "function f() {" |
| 354 " var x = o + 10;" | 354 " var x = o + 10;" |
| 355 " return o + x + o;" | 355 " return o + x + o;" |
| 356 "}" | 356 "}" |
| 357 "f();"); | 357 "f();"); |
| 358 Handle<JSFunction> f = v8::Utils::OpenHandle( | 358 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 359 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 359 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
| 360 // There should be one IC slot. | 360 // There should be one IC slot. |
| 361 Handle<TypeFeedbackVector> feedback_vector = | 361 Handle<TypeFeedbackVector> feedback_vector = |
| 362 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 362 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 363 FeedbackVectorHelper helper(feedback_vector); | 363 FeedbackVectorHelper helper(feedback_vector); |
| 364 CHECK_EQ(1, helper.slot_count()); | 364 CHECK_EQ(1, helper.slot_count()); |
| 365 FeedbackVectorSlot slot(0); | 365 FeedbackVectorSlot slot(0); |
| 366 LoadICNexus nexus(feedback_vector, slot); | 366 LoadICNexus nexus(feedback_vector, slot); |
| 367 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 367 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 | 370 |
| 371 TEST(VectorLoadICOnSmi) { | 371 TEST(VectorLoadICOnSmi) { |
| 372 if (i::FLAG_always_opt) return; | 372 if (i::FLAG_always_opt) return; |
| 373 CcTest::InitializeVM(); | 373 CcTest::InitializeVM(); |
| 374 LocalContext context; | 374 LocalContext context; |
| 375 v8::HandleScope scope(context->GetIsolate()); | 375 v8::HandleScope scope(context->GetIsolate()); |
| 376 Isolate* isolate = CcTest::i_isolate(); | 376 Isolate* isolate = CcTest::i_isolate(); |
| 377 Heap* heap = isolate->heap(); | 377 Heap* heap = isolate->heap(); |
| 378 | 378 |
| 379 // Make sure function f has a call that uses a type feedback slot. | 379 // Make sure function f has a call that uses a type feedback slot. |
| 380 CompileRun( | 380 CompileRun( |
| 381 "var o = { foo: 3 };" | 381 "var o = { foo: 3 };" |
| 382 "function f(a) { return a.foo; } f(o);"); | 382 "function f(a) { return a.foo; } f(o);"); |
| 383 Handle<JSFunction> f = v8::Utils::OpenHandle( | 383 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 384 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 384 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
| 385 // There should be one IC. | 385 // There should be one IC. |
| 386 Handle<TypeFeedbackVector> feedback_vector = | 386 Handle<TypeFeedbackVector> feedback_vector = |
| 387 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 387 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 388 FeedbackVectorSlot slot(0); | 388 FeedbackVectorSlot slot(0); |
| 389 LoadICNexus nexus(feedback_vector, slot); | 389 LoadICNexus nexus(feedback_vector, slot); |
| 390 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); | 390 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); |
| 391 | 391 |
| 392 CompileRun("f(34)"); | 392 CompileRun("f(34)"); |
| 393 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 393 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 394 // Verify that the monomorphic map is the one we expect. | 394 // Verify that the monomorphic map is the one we expect. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 420 // The degree of polymorphism doesn't change. | 420 // The degree of polymorphism doesn't change. |
| 421 CompileRun("f(100)"); | 421 CompileRun("f(100)"); |
| 422 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); | 422 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); |
| 423 MapHandleList maps2; | 423 MapHandleList maps2; |
| 424 nexus.FindAllMaps(&maps2); | 424 nexus.FindAllMaps(&maps2); |
| 425 CHECK_EQ(2, maps2.length()); | 425 CHECK_EQ(2, maps2.length()); |
| 426 } | 426 } |
| 427 | 427 |
| 428 | 428 |
| 429 static Handle<JSFunction> GetFunction(const char* name) { | 429 static Handle<JSFunction> GetFunction(const char* name) { |
| 430 Handle<JSFunction> f = v8::Utils::OpenHandle( | 430 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 431 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str(name)))); | 431 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str(name))))); |
| 432 return f; | 432 return f; |
| 433 } | 433 } |
| 434 | 434 |
| 435 | 435 |
| 436 TEST(ReferenceContextAllocatesNoSlots) { | 436 TEST(ReferenceContextAllocatesNoSlots) { |
| 437 if (i::FLAG_always_opt) return; | 437 if (i::FLAG_always_opt) return; |
| 438 CcTest::InitializeVM(); | 438 CcTest::InitializeVM(); |
| 439 LocalContext context; | 439 LocalContext context; |
| 440 v8::HandleScope scope(context->GetIsolate()); | 440 v8::HandleScope scope(context->GetIsolate()); |
| 441 Isolate* isolate = CcTest::i_isolate(); | 441 Isolate* isolate = CcTest::i_isolate(); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 // There should be one IC slot. | 595 // There should be one IC slot. |
| 596 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); | 596 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); |
| 597 FeedbackVectorHelper helper(feedback_vector); | 597 FeedbackVectorHelper helper(feedback_vector); |
| 598 CHECK_EQ(1, helper.slot_count()); | 598 CHECK_EQ(1, helper.slot_count()); |
| 599 FeedbackVectorSlot slot(0); | 599 FeedbackVectorSlot slot(0); |
| 600 StoreICNexus nexus(feedback_vector, slot); | 600 StoreICNexus nexus(feedback_vector, slot); |
| 601 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 601 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 602 } | 602 } |
| 603 | 603 |
| 604 } // namespace | 604 } // namespace |
| OLD | NEW |