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 3370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3381 | 3381 |
3382 static void CheckVectorICCleared(Handle<JSFunction> f, int ic_slot_index) { | 3382 static void CheckVectorICCleared(Handle<JSFunction> f, int ic_slot_index) { |
3383 Handle<TypeFeedbackVector> vector = | 3383 Handle<TypeFeedbackVector> vector = |
3384 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); | 3384 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); |
3385 FeedbackVectorICSlot slot(ic_slot_index); | 3385 FeedbackVectorICSlot slot(ic_slot_index); |
3386 LoadICNexus nexus(vector, slot); | 3386 LoadICNexus nexus(vector, slot); |
3387 CHECK(IC::IsCleared(&nexus)); | 3387 CHECK(IC::IsCleared(&nexus)); |
3388 } | 3388 } |
3389 | 3389 |
3390 | 3390 |
| 3391 TEST(IncrementalMarkingPreservesMonomorphicConstructor) { |
| 3392 if (i::FLAG_always_opt) return; |
| 3393 CcTest::InitializeVM(); |
| 3394 v8::HandleScope scope(CcTest::isolate()); |
| 3395 |
| 3396 // Prepare function f that contains a monomorphic IC for object |
| 3397 // originating from the same native context. |
| 3398 CompileRun( |
| 3399 "function fun() { this.x = 1; };" |
| 3400 "function f(o) { return new o(); } f(fun); f(fun);"); |
| 3401 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3402 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3403 |
| 3404 |
| 3405 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector()); |
| 3406 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); |
| 3407 |
| 3408 SimulateIncrementalMarking(CcTest::heap()); |
| 3409 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 3410 |
| 3411 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); |
| 3412 } |
| 3413 |
| 3414 |
| 3415 TEST(IncrementalMarkingClearsMonomorphicConstructor) { |
| 3416 if (i::FLAG_always_opt) return; |
| 3417 CcTest::InitializeVM(); |
| 3418 Isolate* isolate = CcTest::i_isolate(); |
| 3419 v8::HandleScope scope(CcTest::isolate()); |
| 3420 v8::Local<v8::Value> fun1; |
| 3421 |
| 3422 { |
| 3423 LocalContext env; |
| 3424 CompileRun("function fun() { this.x = 1; };"); |
| 3425 fun1 = env->Global()->Get(v8_str("fun")); |
| 3426 } |
| 3427 |
| 3428 // Prepare function f that contains a monomorphic constructor for object |
| 3429 // originating from a different native context. |
| 3430 CcTest::global()->Set(v8_str("fun1"), fun1); |
| 3431 CompileRun( |
| 3432 "function fun() { this.x = 1; };" |
| 3433 "function f(o) { return new o(); } f(fun1); f(fun1);"); |
| 3434 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3435 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3436 |
| 3437 |
| 3438 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector()); |
| 3439 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); |
| 3440 |
| 3441 // Fire context dispose notification. |
| 3442 CcTest::isolate()->ContextDisposedNotification(); |
| 3443 SimulateIncrementalMarking(CcTest::heap()); |
| 3444 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 3445 |
| 3446 CHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(isolate), |
| 3447 vector->Get(FeedbackVectorSlot(0))); |
| 3448 } |
| 3449 |
| 3450 |
3391 TEST(IncrementalMarkingPreservesMonomorphicIC) { | 3451 TEST(IncrementalMarkingPreservesMonomorphicIC) { |
3392 if (i::FLAG_always_opt) return; | 3452 if (i::FLAG_always_opt) return; |
3393 CcTest::InitializeVM(); | 3453 CcTest::InitializeVM(); |
3394 v8::HandleScope scope(CcTest::isolate()); | 3454 v8::HandleScope scope(CcTest::isolate()); |
3395 | 3455 |
3396 // Prepare function f that contains a monomorphic IC for object | 3456 // Prepare function f that contains a monomorphic IC for object |
3397 // originating from the same native context. | 3457 // originating from the same native context. |
3398 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3458 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
3399 "function f(o) { return o.x; } f(obj); f(obj);"); | 3459 "function f(o) { return o.x; } f(obj); f(obj);"); |
3400 Handle<JSFunction> f = | 3460 Handle<JSFunction> f = |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4409 static void ClearWeakIC(const v8::WeakCallbackData<v8::Object, void>& data) { | 4469 static void ClearWeakIC(const v8::WeakCallbackData<v8::Object, void>& data) { |
4410 printf("clear weak is called\n"); | 4470 printf("clear weak is called\n"); |
4411 weak_ic_cleared = true; | 4471 weak_ic_cleared = true; |
4412 v8::Persistent<v8::Value>* p = | 4472 v8::Persistent<v8::Value>* p = |
4413 reinterpret_cast<v8::Persistent<v8::Value>*>(data.GetParameter()); | 4473 reinterpret_cast<v8::Persistent<v8::Value>*>(data.GetParameter()); |
4414 CHECK(p->IsNearDeath()); | 4474 CHECK(p->IsNearDeath()); |
4415 p->Reset(); | 4475 p->Reset(); |
4416 } | 4476 } |
4417 | 4477 |
4418 | 4478 |
| 4479 TEST(WeakFunctionInConstructor) { |
| 4480 if (i::FLAG_always_opt) return; |
| 4481 i::FLAG_stress_compaction = false; |
| 4482 CcTest::InitializeVM(); |
| 4483 v8::Isolate* isolate = CcTest::isolate(); |
| 4484 v8::HandleScope scope(isolate); |
| 4485 CompileRun( |
| 4486 "function createObj(obj) {" |
| 4487 " return new obj();" |
| 4488 "}"); |
| 4489 Handle<JSFunction> createObj = |
| 4490 v8::Utils::OpenHandle(*v8::Handle<v8::Function>::Cast( |
| 4491 CcTest::global()->Get(v8_str("createObj")))); |
| 4492 |
| 4493 v8::Persistent<v8::Object> garbage; |
| 4494 { |
| 4495 v8::HandleScope scope(isolate); |
| 4496 const char* source = |
| 4497 " (function() {" |
| 4498 " function hat() { this.x = 5; }" |
| 4499 " createObj(hat);" |
| 4500 " createObj(hat);" |
| 4501 " return hat;" |
| 4502 " })();"; |
| 4503 garbage.Reset(isolate, CompileRun(source)->ToObject(isolate)); |
| 4504 } |
| 4505 weak_ic_cleared = false; |
| 4506 garbage.SetWeak(static_cast<void*>(&garbage), &ClearWeakIC); |
| 4507 Heap* heap = CcTest::i_isolate()->heap(); |
| 4508 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 4509 CHECK(weak_ic_cleared); |
| 4510 |
| 4511 // We've determined the constructor in createObj has had it's weak cell |
| 4512 // cleared. Now, verify that one additional call with a new function |
| 4513 // allows monomorphicity. |
| 4514 Handle<TypeFeedbackVector> feedback_vector = Handle<TypeFeedbackVector>( |
| 4515 createObj->shared()->feedback_vector(), CcTest::i_isolate()); |
| 4516 for (int i = 0; i < 20; i++) { |
| 4517 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); |
| 4518 CHECK(slot_value->IsWeakCell()); |
| 4519 if (WeakCell::cast(slot_value)->cleared()) break; |
| 4520 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 4521 } |
| 4522 |
| 4523 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); |
| 4524 CHECK(slot_value->IsWeakCell() && WeakCell::cast(slot_value)->cleared()); |
| 4525 CompileRun( |
| 4526 "function coat() { this.x = 6; }" |
| 4527 "createObj(coat);"); |
| 4528 slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); |
| 4529 CHECK(slot_value->IsWeakCell() && !WeakCell::cast(slot_value)->cleared()); |
| 4530 } |
| 4531 |
| 4532 |
4419 // Checks that the value returned by execution of the source is weak. | 4533 // Checks that the value returned by execution of the source is weak. |
4420 void CheckWeakness(const char* source) { | 4534 void CheckWeakness(const char* source) { |
4421 i::FLAG_stress_compaction = false; | 4535 i::FLAG_stress_compaction = false; |
4422 CcTest::InitializeVM(); | 4536 CcTest::InitializeVM(); |
4423 v8::Isolate* isolate = CcTest::isolate(); | 4537 v8::Isolate* isolate = CcTest::isolate(); |
4424 v8::HandleScope scope(isolate); | 4538 v8::HandleScope scope(isolate); |
4425 v8::Persistent<v8::Object> garbage; | 4539 v8::Persistent<v8::Object> garbage; |
4426 { | 4540 { |
4427 v8::HandleScope scope(isolate); | 4541 v8::HandleScope scope(isolate); |
4428 garbage.Reset(isolate, CompileRun(source)->ToObject(isolate)); | 4542 garbage.Reset(isolate, CompileRun(source)->ToObject(isolate)); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5178 | 5292 |
5179 TEST(WritableVsImmortalRoots) { | 5293 TEST(WritableVsImmortalRoots) { |
5180 for (int i = 0; i < Heap::kStrongRootListLength; ++i) { | 5294 for (int i = 0; i < Heap::kStrongRootListLength; ++i) { |
5181 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); | 5295 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); |
5182 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index); | 5296 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index); |
5183 bool immortal = Heap::RootIsImmortalImmovable(root_index); | 5297 bool immortal = Heap::RootIsImmortalImmovable(root_index); |
5184 // A root value can be writable, immortal, or neither, but not both. | 5298 // A root value can be writable, immortal, or neither, but not both. |
5185 CHECK(!immortal || !writable); | 5299 CHECK(!immortal || !writable); |
5186 } | 5300 } |
5187 } | 5301 } |
OLD | NEW |