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 4412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4423 iso->SetReferenceFromGroup(id4, g1s1.handle); | 4423 iso->SetReferenceFromGroup(id4, g1s1.handle); |
4424 } | 4424 } |
4425 | 4425 |
4426 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 4426 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
4427 | 4427 |
4428 // All objects should be gone. 9 global handles in total. | 4428 // All objects should be gone. 9 global handles in total. |
4429 CHECK_EQ(9, counter.NumberOfWeakCalls()); | 4429 CHECK_EQ(9, counter.NumberOfWeakCalls()); |
4430 } | 4430 } |
4431 | 4431 |
4432 | 4432 |
| 4433 THREADED_TEST(WeakRootsSurviveTwoRoundsOfGC) { |
| 4434 LocalContext env; |
| 4435 v8::Isolate* iso = env->GetIsolate(); |
| 4436 HandleScope scope(iso); |
| 4437 |
| 4438 WeakCallCounter counter(1234); |
| 4439 |
| 4440 WeakCallCounterAndPersistent<Value> weak_obj(&counter); |
| 4441 |
| 4442 // Create a weak object that references a internalized string. |
| 4443 { |
| 4444 HandleScope scope(iso); |
| 4445 weak_obj.handle.Reset(iso, Object::New(iso)); |
| 4446 weak_obj.handle.SetWeak(&weak_obj, &WeakPointerCallback); |
| 4447 CHECK(weak_obj.handle.IsWeak()); |
| 4448 Local<Object>::New(iso, weak_obj.handle.As<Object>())->Set( |
| 4449 v8_str("x"), |
| 4450 String::NewFromUtf8(iso, "magic cookie", String::kInternalizedString)); |
| 4451 } |
| 4452 // Do a single full GC |
| 4453 i::Isolate* i_iso = reinterpret_cast<v8::internal::Isolate*>(iso); |
| 4454 i::Heap* heap = i_iso->heap(); |
| 4455 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 4456 |
| 4457 // We should have received the weak callback. |
| 4458 CHECK_EQ(1, counter.NumberOfWeakCalls()); |
| 4459 |
| 4460 // Check that the string is still alive. |
| 4461 { |
| 4462 HandleScope scope(iso); |
| 4463 i::MaybeHandle<i::String> magic_string = |
| 4464 i::StringTable::LookupStringIfExists( |
| 4465 i_iso, |
| 4466 v8::Utils::OpenHandle(*String::NewFromUtf8(iso, "magic cookie"))); |
| 4467 magic_string.Check(); |
| 4468 } |
| 4469 } |
| 4470 |
| 4471 |
4433 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures | 4472 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures |
4434 // on the buildbots, so was made non-threaded for the time being. | 4473 // on the buildbots, so was made non-threaded for the time being. |
4435 TEST(ApiObjectGroupsCycleForScavenger) { | 4474 TEST(ApiObjectGroupsCycleForScavenger) { |
4436 i::FLAG_stress_compaction = false; | 4475 i::FLAG_stress_compaction = false; |
4437 i::FLAG_gc_global = false; | 4476 i::FLAG_gc_global = false; |
4438 LocalContext env; | 4477 LocalContext env; |
4439 v8::Isolate* iso = env->GetIsolate(); | 4478 v8::Isolate* iso = env->GetIsolate(); |
4440 HandleScope scope(iso); | 4479 HandleScope scope(iso); |
4441 | 4480 |
4442 WeakCallCounter counter(1234); | 4481 WeakCallCounter counter(1234); |
(...skipping 19986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24429 v8::HandleScope scope(CcTest::isolate()); | 24468 v8::HandleScope scope(CcTest::isolate()); |
24430 RandomLengthOneByteResource* r = | 24469 RandomLengthOneByteResource* r = |
24431 new RandomLengthOneByteResource(i::String::kMaxLength); | 24470 new RandomLengthOneByteResource(i::String::kMaxLength); |
24432 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); | 24471 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); |
24433 CHECK(!str.IsEmpty()); | 24472 CHECK(!str.IsEmpty()); |
24434 v8::TryCatch try_catch; | 24473 v8::TryCatch try_catch; |
24435 v8::Local<v8::String> result = v8::String::Concat(str, str); | 24474 v8::Local<v8::String> result = v8::String::Concat(str, str); |
24436 CHECK(result.IsEmpty()); | 24475 CHECK(result.IsEmpty()); |
24437 CHECK(!try_catch.HasCaught()); | 24476 CHECK(!try_catch.HasCaught()); |
24438 } | 24477 } |
OLD | NEW |