OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3386 static void CheckVectorIC(Handle<JSFunction> f, int ic_slot_index, | 3386 static void CheckVectorIC(Handle<JSFunction> f, int ic_slot_index, |
3387 InlineCacheState desired_state) { | 3387 InlineCacheState desired_state) { |
3388 Handle<TypeFeedbackVector> vector = | 3388 Handle<TypeFeedbackVector> vector = |
3389 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); | 3389 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); |
3390 FeedbackVectorICSlot slot(ic_slot_index); | 3390 FeedbackVectorICSlot slot(ic_slot_index); |
3391 LoadICNexus nexus(vector, slot); | 3391 LoadICNexus nexus(vector, slot); |
3392 CHECK(nexus.StateFromFeedback() == desired_state); | 3392 CHECK(nexus.StateFromFeedback() == desired_state); |
3393 } | 3393 } |
3394 | 3394 |
3395 | 3395 |
3396 static void CheckVectorICCleared(Handle<JSFunction> f, int ic_slot_index) { | |
3397 Handle<TypeFeedbackVector> vector = | |
3398 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); | |
3399 FeedbackVectorICSlot slot(ic_slot_index); | |
3400 LoadICNexus nexus(vector, slot); | |
3401 CHECK(IC::IsCleared(&nexus)); | |
3402 } | |
3403 | |
3404 | |
3405 TEST(IncrementalMarkingPreservesMonomorphicIC) { | 3396 TEST(IncrementalMarkingPreservesMonomorphicIC) { |
3406 if (i::FLAG_always_opt) return; | 3397 if (i::FLAG_always_opt) return; |
3407 CcTest::InitializeVM(); | 3398 CcTest::InitializeVM(); |
3408 v8::HandleScope scope(CcTest::isolate()); | 3399 v8::HandleScope scope(CcTest::isolate()); |
3409 | 3400 |
3410 // Prepare function f that contains a monomorphic IC for object | 3401 // Prepare function f that contains a monomorphic IC for object |
3411 // originating from the same native context. | 3402 // originating from the same native context. |
3412 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3403 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
3413 "function f(o) { return o.x; } f(obj); f(obj);"); | 3404 "function f(o) { return o.x; } f(obj); f(obj);"); |
3414 Handle<JSFunction> f = | 3405 Handle<JSFunction> f = |
(...skipping 15 matching lines...) Expand all Loading... |
3430 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3421 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3431 if (FLAG_vector_ics) { | 3422 if (FLAG_vector_ics) { |
3432 CheckVectorIC(f, 0, MONOMORPHIC); | 3423 CheckVectorIC(f, 0, MONOMORPHIC); |
3433 CHECK(ic_after->ic_state() == DEFAULT); | 3424 CHECK(ic_after->ic_state() == DEFAULT); |
3434 } else { | 3425 } else { |
3435 CHECK(ic_after->ic_state() == MONOMORPHIC); | 3426 CHECK(ic_after->ic_state() == MONOMORPHIC); |
3436 } | 3427 } |
3437 } | 3428 } |
3438 | 3429 |
3439 | 3430 |
3440 TEST(IncrementalMarkingClearsMonomorphicIC) { | |
3441 if (i::FLAG_always_opt) return; | |
3442 CcTest::InitializeVM(); | |
3443 v8::HandleScope scope(CcTest::isolate()); | |
3444 v8::Local<v8::Value> obj1; | |
3445 | |
3446 { | |
3447 LocalContext env; | |
3448 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | |
3449 obj1 = env->Global()->Get(v8_str("obj")); | |
3450 } | |
3451 | |
3452 // Prepare function f that contains a monomorphic IC for object | |
3453 // originating from a different native context. | |
3454 CcTest::global()->Set(v8_str("obj1"), obj1); | |
3455 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | |
3456 Handle<JSFunction> f = | |
3457 v8::Utils::OpenHandle( | |
3458 *v8::Handle<v8::Function>::Cast( | |
3459 CcTest::global()->Get(v8_str("f")))); | |
3460 | |
3461 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3462 if (FLAG_vector_ics) { | |
3463 CheckVectorIC(f, 0, MONOMORPHIC); | |
3464 CHECK(ic_before->ic_state() == DEFAULT); | |
3465 } else { | |
3466 CHECK(ic_before->ic_state() == MONOMORPHIC); | |
3467 } | |
3468 | |
3469 // Fire context dispose notification. | |
3470 CcTest::isolate()->ContextDisposedNotification(); | |
3471 SimulateIncrementalMarking(CcTest::heap()); | |
3472 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | |
3473 | |
3474 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3475 if (FLAG_vector_ics) { | |
3476 CheckVectorICCleared(f, 0); | |
3477 CHECK(ic_after->ic_state() == DEFAULT); | |
3478 } else { | |
3479 CHECK(IC::IsCleared(ic_after)); | |
3480 } | |
3481 } | |
3482 | |
3483 | |
3484 TEST(IncrementalMarkingPreservesPolymorphicIC) { | 3431 TEST(IncrementalMarkingPreservesPolymorphicIC) { |
3485 if (i::FLAG_always_opt) return; | 3432 if (i::FLAG_always_opt) return; |
3486 CcTest::InitializeVM(); | 3433 CcTest::InitializeVM(); |
3487 v8::HandleScope scope(CcTest::isolate()); | 3434 v8::HandleScope scope(CcTest::isolate()); |
3488 v8::Local<v8::Value> obj1, obj2; | 3435 v8::Local<v8::Value> obj1, obj2; |
3489 | 3436 |
3490 { | 3437 { |
3491 LocalContext env; | 3438 LocalContext env; |
3492 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3439 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
3493 obj1 = env->Global()->Get(v8_str("obj")); | 3440 obj1 = env->Global()->Get(v8_str("obj")); |
(...skipping 28 matching lines...) Expand all Loading... |
3522 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3469 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3523 if (FLAG_vector_ics) { | 3470 if (FLAG_vector_ics) { |
3524 CheckVectorIC(f, 0, POLYMORPHIC); | 3471 CheckVectorIC(f, 0, POLYMORPHIC); |
3525 CHECK(ic_after->ic_state() == DEFAULT); | 3472 CHECK(ic_after->ic_state() == DEFAULT); |
3526 } else { | 3473 } else { |
3527 CHECK(ic_after->ic_state() == POLYMORPHIC); | 3474 CHECK(ic_after->ic_state() == POLYMORPHIC); |
3528 } | 3475 } |
3529 } | 3476 } |
3530 | 3477 |
3531 | 3478 |
3532 TEST(IncrementalMarkingClearsPolymorphicIC) { | |
3533 if (i::FLAG_always_opt) return; | |
3534 CcTest::InitializeVM(); | |
3535 v8::HandleScope scope(CcTest::isolate()); | |
3536 v8::Local<v8::Value> obj1, obj2; | |
3537 | |
3538 { | |
3539 LocalContext env; | |
3540 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | |
3541 obj1 = env->Global()->Get(v8_str("obj")); | |
3542 } | |
3543 | |
3544 { | |
3545 LocalContext env; | |
3546 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); | |
3547 obj2 = env->Global()->Get(v8_str("obj")); | |
3548 } | |
3549 | |
3550 // Prepare function f that contains a polymorphic IC for objects | |
3551 // originating from two different native contexts. | |
3552 CcTest::global()->Set(v8_str("obj1"), obj1); | |
3553 CcTest::global()->Set(v8_str("obj2"), obj2); | |
3554 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | |
3555 Handle<JSFunction> f = | |
3556 v8::Utils::OpenHandle( | |
3557 *v8::Handle<v8::Function>::Cast( | |
3558 CcTest::global()->Get(v8_str("f")))); | |
3559 | |
3560 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3561 if (FLAG_vector_ics) { | |
3562 CheckVectorIC(f, 0, POLYMORPHIC); | |
3563 CHECK(ic_before->ic_state() == DEFAULT); | |
3564 } else { | |
3565 CHECK(ic_before->ic_state() == POLYMORPHIC); | |
3566 } | |
3567 | |
3568 // Fire context dispose notification. | |
3569 CcTest::isolate()->ContextDisposedNotification(); | |
3570 SimulateIncrementalMarking(CcTest::heap()); | |
3571 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | |
3572 | |
3573 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3574 if (FLAG_vector_ics) { | |
3575 CheckVectorICCleared(f, 0); | |
3576 CHECK(ic_before->ic_state() == DEFAULT); | |
3577 } else { | |
3578 CHECK(IC::IsCleared(ic_after)); | |
3579 } | |
3580 } | |
3581 | |
3582 | |
3583 class SourceResource : public v8::String::ExternalOneByteStringResource { | 3479 class SourceResource : public v8::String::ExternalOneByteStringResource { |
3584 public: | 3480 public: |
3585 explicit SourceResource(const char* data) | 3481 explicit SourceResource(const char* data) |
3586 : data_(data), length_(strlen(data)) { } | 3482 : data_(data), length_(strlen(data)) { } |
3587 | 3483 |
3588 virtual void Dispose() { | 3484 virtual void Dispose() { |
3589 i::DeleteArray(data_); | 3485 i::DeleteArray(data_); |
3590 data_ = NULL; | 3486 data_ = NULL; |
3591 } | 3487 } |
3592 | 3488 |
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5088 #ifdef DEBUG | 4984 #ifdef DEBUG |
5089 TEST(PathTracer) { | 4985 TEST(PathTracer) { |
5090 CcTest::InitializeVM(); | 4986 CcTest::InitializeVM(); |
5091 v8::HandleScope scope(CcTest::isolate()); | 4987 v8::HandleScope scope(CcTest::isolate()); |
5092 | 4988 |
5093 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4989 v8::Local<v8::Value> result = CompileRun("'abc'"); |
5094 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4990 Handle<Object> o = v8::Utils::OpenHandle(*result); |
5095 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4991 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
5096 } | 4992 } |
5097 #endif // DEBUG | 4993 #endif // DEBUG |
OLD | NEW |