Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: test/cctest/test-heap.cc

Issue 1029093002: v8:3539 - hold constructor feedback in weak cells (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 3369 matching lines...) Expand 10 before | Expand all | Expand 10 after
3380 3380
3381 static void CheckVectorICCleared(Handle<JSFunction> f, int ic_slot_index) { 3381 static void CheckVectorICCleared(Handle<JSFunction> f, int ic_slot_index) {
3382 Handle<TypeFeedbackVector> vector = 3382 Handle<TypeFeedbackVector> vector =
3383 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); 3383 Handle<TypeFeedbackVector>(f->shared()->feedback_vector());
3384 FeedbackVectorICSlot slot(ic_slot_index); 3384 FeedbackVectorICSlot slot(ic_slot_index);
3385 LoadICNexus nexus(vector, slot); 3385 LoadICNexus nexus(vector, slot);
3386 CHECK(IC::IsCleared(&nexus)); 3386 CHECK(IC::IsCleared(&nexus));
3387 } 3387 }
3388 3388
3389 3389
3390 TEST(IncrementalMarkingPreservesMonomorphicConstructor) {
3391 if (i::FLAG_always_opt) return;
3392 CcTest::InitializeVM();
3393 v8::HandleScope scope(CcTest::isolate());
3394
3395 // Prepare function f that contains a monomorphic IC for object
3396 // originating from the same native context.
3397 CompileRun(
3398 "function fun() { this.x = 1; };"
3399 "function f(o) { return new o(); } f(fun); f(fun);");
3400 Handle<JSFunction> f = v8::Utils::OpenHandle(
3401 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))));
3402
3403
3404 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector());
3405 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell());
3406
3407 SimulateIncrementalMarking(CcTest::heap());
3408 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
3409
3410 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell());
3411 }
3412
3413
3414 TEST(IncrementalMarkingClearsMonomorphicConstructor) {
3415 if (i::FLAG_always_opt) return;
3416 CcTest::InitializeVM();
3417 Isolate* isolate = CcTest::i_isolate();
3418 v8::HandleScope scope(CcTest::isolate());
3419 v8::Local<v8::Value> fun1;
3420
3421 {
3422 LocalContext env;
3423 CompileRun("function fun() { this.x = 1; };");
3424 fun1 = env->Global()->Get(v8_str("fun"));
3425 }
3426
3427 // Prepare function f that contains a monomorphic constructor for object
3428 // originating from a different native context.
3429 CcTest::global()->Set(v8_str("fun1"), fun1);
3430 CompileRun(
3431 "function fun() { this.x = 1; };"
3432 "function f(o) { return new o(); } f(fun1); f(fun1);");
3433 Handle<JSFunction> f = v8::Utils::OpenHandle(
3434 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))));
3435
3436
3437 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector());
3438 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell());
3439
3440 // Fire context dispose notification.
3441 CcTest::isolate()->ContextDisposedNotification();
3442 SimulateIncrementalMarking(CcTest::heap());
3443 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
3444
3445 CHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(isolate),
3446 vector->Get(FeedbackVectorSlot(0)));
3447 }
3448
3449
3390 TEST(IncrementalMarkingPreservesMonomorphicIC) { 3450 TEST(IncrementalMarkingPreservesMonomorphicIC) {
3391 if (i::FLAG_always_opt) return; 3451 if (i::FLAG_always_opt) return;
3392 CcTest::InitializeVM(); 3452 CcTest::InitializeVM();
3393 v8::HandleScope scope(CcTest::isolate()); 3453 v8::HandleScope scope(CcTest::isolate());
3394 3454
3395 // Prepare function f that contains a monomorphic IC for object 3455 // Prepare function f that contains a monomorphic IC for object
3396 // originating from the same native context. 3456 // originating from the same native context.
3397 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" 3457 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"
3398 "function f(o) { return o.x; } f(obj); f(obj);"); 3458 "function f(o) { return o.x; } f(obj); f(obj);");
3399 Handle<JSFunction> f = 3459 Handle<JSFunction> f =
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
4408 static void ClearWeakIC(const v8::WeakCallbackData<v8::Object, void>& data) { 4468 static void ClearWeakIC(const v8::WeakCallbackData<v8::Object, void>& data) {
4409 printf("clear weak is called\n"); 4469 printf("clear weak is called\n");
4410 weak_ic_cleared = true; 4470 weak_ic_cleared = true;
4411 v8::Persistent<v8::Value>* p = 4471 v8::Persistent<v8::Value>* p =
4412 reinterpret_cast<v8::Persistent<v8::Value>*>(data.GetParameter()); 4472 reinterpret_cast<v8::Persistent<v8::Value>*>(data.GetParameter());
4413 CHECK(p->IsNearDeath()); 4473 CHECK(p->IsNearDeath());
4414 p->Reset(); 4474 p->Reset();
4415 } 4475 }
4416 4476
4417 4477
4478 TEST(WeakFunctionInConstructor) {
4479 if (i::FLAG_always_opt) return;
4480 i::FLAG_stress_compaction = false;
4481 CcTest::InitializeVM();
4482 v8::Isolate* isolate = CcTest::isolate();
4483 v8::HandleScope scope(isolate);
4484 CompileRun(
4485 "function createObj(obj) {"
4486 " return new obj();"
4487 "}");
4488 Handle<JSFunction> createObj =
4489 v8::Utils::OpenHandle(*v8::Handle<v8::Function>::Cast(
4490 CcTest::global()->Get(v8_str("createObj"))));
4491
4492 v8::Persistent<v8::Object> garbage;
4493 {
4494 v8::HandleScope scope(isolate);
4495 const char* source =
4496 " (function() {"
4497 " function hat() { this.x = 5; }"
4498 " createObj(hat);"
4499 " createObj(hat);"
4500 " return hat;"
4501 " })();";
4502 garbage.Reset(isolate, CompileRun(source)->ToObject(isolate));
4503 }
4504 weak_ic_cleared = false;
4505 garbage.SetWeak(static_cast<void*>(&garbage), &ClearWeakIC);
4506 Heap* heap = CcTest::i_isolate()->heap();
4507 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
4508 CHECK(weak_ic_cleared);
4509
4510 // We've determined the constructor in createObj has had it's weak cell
4511 // cleared. Now, verify that one additional call with a new function
4512 // allows monomorphicity.
4513 Handle<TypeFeedbackVector> feedback_vector = Handle<TypeFeedbackVector>(
4514 createObj->shared()->feedback_vector(), CcTest::i_isolate());
4515 for (int i = 0; i < 20; i++) {
4516 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0));
4517 CHECK(slot_value->IsWeakCell());
4518 if (WeakCell::cast(slot_value)->cleared()) break;
4519 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
4520 }
4521
4522 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0));
4523 CHECK(slot_value->IsWeakCell() && WeakCell::cast(slot_value)->cleared());
4524 CompileRun(
4525 "function coat() { this.x = 6; }"
4526 "createObj(coat);");
4527 slot_value = feedback_vector->Get(FeedbackVectorSlot(0));
4528 CHECK(slot_value->IsWeakCell() && !WeakCell::cast(slot_value)->cleared());
4529 }
4530
4531
4418 // Checks that the value returned by execution of the source is weak. 4532 // Checks that the value returned by execution of the source is weak.
4419 void CheckWeakness(const char* source) { 4533 void CheckWeakness(const char* source) {
4420 i::FLAG_stress_compaction = false; 4534 i::FLAG_stress_compaction = false;
4421 CcTest::InitializeVM(); 4535 CcTest::InitializeVM();
4422 v8::Isolate* isolate = CcTest::isolate(); 4536 v8::Isolate* isolate = CcTest::isolate();
4423 v8::HandleScope scope(isolate); 4537 v8::HandleScope scope(isolate);
4424 v8::Persistent<v8::Object> garbage; 4538 v8::Persistent<v8::Object> garbage;
4425 { 4539 {
4426 v8::HandleScope scope(isolate); 4540 v8::HandleScope scope(isolate);
4427 garbage.Reset(isolate, CompileRun(source)->ToObject(isolate)); 4541 garbage.Reset(isolate, CompileRun(source)->ToObject(isolate));
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
5191 5305
5192 TEST(WritableVsImmortalRoots) { 5306 TEST(WritableVsImmortalRoots) {
5193 for (int i = 0; i < Heap::kStrongRootListLength; ++i) { 5307 for (int i = 0; i < Heap::kStrongRootListLength; ++i) {
5194 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); 5308 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
5195 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index); 5309 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index);
5196 bool immortal = Heap::RootIsImmortalImmovable(root_index); 5310 bool immortal = Heap::RootIsImmortalImmovable(root_index);
5197 // A root value can be writable, immortal, or neither, but not both. 5311 // A root value can be writable, immortal, or neither, but not both.
5198 CHECK(!immortal || !writable); 5312 CHECK(!immortal || !writable);
5199 } 5313 }
5200 } 5314 }
OLDNEW
« src/arm/code-stubs-arm.cc ('K') | « test/cctest/test-feedback-vector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698