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 4365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4376 iso->SetReferenceFromGroup(id4, g1s1.handle); | 4376 iso->SetReferenceFromGroup(id4, g1s1.handle); |
4377 } | 4377 } |
4378 | 4378 |
4379 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 4379 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
4380 | 4380 |
4381 // All objects should be gone. 9 global handles in total. | 4381 // All objects should be gone. 9 global handles in total. |
4382 CHECK_EQ(9, counter.NumberOfWeakCalls()); | 4382 CHECK_EQ(9, counter.NumberOfWeakCalls()); |
4383 } | 4383 } |
4384 | 4384 |
4385 | 4385 |
| 4386 THREADED_TEST(WeakRootsSurviveTwoRoundsOfGC) { |
| 4387 LocalContext env; |
| 4388 v8::Isolate* iso = env->GetIsolate(); |
| 4389 HandleScope scope(iso); |
| 4390 |
| 4391 WeakCallCounter counter(1234); |
| 4392 |
| 4393 WeakCallCounterAndPersistent<Value> weak_obj(&counter); |
| 4394 |
| 4395 // Create a weak object that references a internalized string. |
| 4396 { |
| 4397 HandleScope scope(iso); |
| 4398 weak_obj.handle.Reset(iso, Object::New(iso)); |
| 4399 weak_obj.handle.SetWeak(&weak_obj, &WeakPointerCallback); |
| 4400 CHECK(weak_obj.handle.IsWeak()); |
| 4401 Local<Object>::New(iso, weak_obj.handle.As<Object>())->Set( |
| 4402 v8_str("x"), |
| 4403 String::NewFromUtf8(iso, "magic cookie", String::kInternalizedString)); |
| 4404 } |
| 4405 // Do a single full GC |
| 4406 i::Isolate* i_iso = reinterpret_cast<v8::internal::Isolate*>(iso); |
| 4407 i::Heap* heap = i_iso->heap(); |
| 4408 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 4409 |
| 4410 // We should have received the weak callback. |
| 4411 CHECK_EQ(1, counter.NumberOfWeakCalls()); |
| 4412 |
| 4413 // Check that the string is still alive. |
| 4414 { |
| 4415 HandleScope scope(iso); |
| 4416 i::MaybeHandle<i::String> magic_string = |
| 4417 i::StringTable::LookupStringIfExists( |
| 4418 i_iso, |
| 4419 v8::Utils::OpenHandle(*String::NewFromUtf8(iso, "magic cookie"))); |
| 4420 magic_string.Check(); |
| 4421 } |
| 4422 } |
| 4423 |
| 4424 |
4386 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures | 4425 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures |
4387 // on the buildbots, so was made non-threaded for the time being. | 4426 // on the buildbots, so was made non-threaded for the time being. |
4388 TEST(ApiObjectGroupsCycleForScavenger) { | 4427 TEST(ApiObjectGroupsCycleForScavenger) { |
4389 i::FLAG_stress_compaction = false; | 4428 i::FLAG_stress_compaction = false; |
4390 i::FLAG_gc_global = false; | 4429 i::FLAG_gc_global = false; |
4391 LocalContext env; | 4430 LocalContext env; |
4392 v8::Isolate* iso = env->GetIsolate(); | 4431 v8::Isolate* iso = env->GetIsolate(); |
4393 HandleScope scope(iso); | 4432 HandleScope scope(iso); |
4394 | 4433 |
4395 WeakCallCounter counter(1234); | 4434 WeakCallCounter counter(1234); |
(...skipping 19986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24382 v8::HandleScope scope(CcTest::isolate()); | 24421 v8::HandleScope scope(CcTest::isolate()); |
24383 RandomLengthOneByteResource* r = | 24422 RandomLengthOneByteResource* r = |
24384 new RandomLengthOneByteResource(i::String::kMaxLength); | 24423 new RandomLengthOneByteResource(i::String::kMaxLength); |
24385 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); | 24424 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); |
24386 CHECK(!str.IsEmpty()); | 24425 CHECK(!str.IsEmpty()); |
24387 v8::TryCatch try_catch; | 24426 v8::TryCatch try_catch; |
24388 v8::Local<v8::String> result = v8::String::Concat(str, str); | 24427 v8::Local<v8::String> result = v8::String::Concat(str, str); |
24389 CHECK(result.IsEmpty()); | 24428 CHECK(result.IsEmpty()); |
24390 CHECK(!try_catch.HasCaught()); | 24429 CHECK(!try_catch.HasCaught()); |
24391 } | 24430 } |
OLD | NEW |