| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ScriptWrappableVisitor.h" | 5 #include "bindings/core/v8/ScriptWrappableVisitor.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ToV8.h" | 7 #include "bindings/core/v8/ToV8.h" |
| 8 #include "bindings/core/v8/TraceWrapperV8Reference.h" | 8 #include "bindings/core/v8/TraceWrapperV8Reference.h" |
| 9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
| 10 #include "bindings/core/v8/V8GCController.h" | 10 #include "bindings/core/v8/V8GCController.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 EXPECT_TRUE(visitor->getMarkingDeque()->isEmpty()); | 52 EXPECT_TRUE(visitor->getMarkingDeque()->isEmpty()); |
| 53 EXPECT_FALSE(targetHeader->isWrapperHeaderMarked()); | 53 EXPECT_FALSE(targetHeader->isWrapperHeaderMarked()); |
| 54 EXPECT_FALSE(dependencyHeader->isWrapperHeaderMarked()); | 54 EXPECT_FALSE(dependencyHeader->isWrapperHeaderMarked()); |
| 55 | 55 |
| 56 std::pair<void*, void*> pair = std::make_pair( | 56 std::pair<void*, void*> pair = std::make_pair( |
| 57 const_cast<WrapperTypeInfo*>(target->wrapperTypeInfo()), target); | 57 const_cast<WrapperTypeInfo*>(target->wrapperTypeInfo()), target); |
| 58 visitor->RegisterV8Reference(pair); | 58 visitor->RegisterV8Reference(pair); |
| 59 EXPECT_EQ(visitor->getMarkingDeque()->size(), 1ul); | 59 EXPECT_EQ(visitor->getMarkingDeque()->size(), 1ul); |
| 60 | 60 |
| 61 visitor->AdvanceTracing( | 61 visitor->AdvanceTracing( |
| 62 0, v8::EmbedderHeapTracer::AdvanceTracingActions( | 62 0, |
| 63 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); | 63 v8::EmbedderHeapTracer::AdvanceTracingActions( |
| 64 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); |
| 64 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 65 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 65 EXPECT_EQ(visitor->getMarkingDeque()->size(), 0ul); | 66 EXPECT_EQ(visitor->getMarkingDeque()->size(), 0ul); |
| 66 EXPECT_TRUE(targetHeader->isWrapperHeaderMarked()); | 67 EXPECT_TRUE(targetHeader->isWrapperHeaderMarked()); |
| 67 EXPECT_TRUE(dependencyHeader->isWrapperHeaderMarked()); | 68 EXPECT_TRUE(dependencyHeader->isWrapperHeaderMarked()); |
| 68 | 69 |
| 69 visitor->AbortTracing(); | 70 visitor->AbortTracing(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 TEST(ScriptWrappableVisitorTest, OilpanCollectObjectsNotReachableFromV8) { | 73 TEST(ScriptWrappableVisitorTest, OilpanCollectObjectsNotReachableFromV8) { |
| 73 V8TestingScope scope; | 74 V8TestingScope scope; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 v8::Local<v8::String> str = | 320 v8::Local<v8::String> str = |
| 320 v8::String::NewFromUtf8(scope.isolate(), "teststring", | 321 v8::String::NewFromUtf8(scope.isolate(), "teststring", |
| 321 v8::NewStringType::kNormal, sizeof("teststring")) | 322 v8::NewStringType::kNormal, sizeof("teststring")) |
| 322 .ToLocalChecked(); | 323 .ToLocalChecked(); |
| 323 HandleContainer* container = HandleContainer::create(); | 324 HandleContainer* container = HandleContainer::create(); |
| 324 CHECK_EQ(0u, rawVisitor->numberOfMarkedWrappers()); | 325 CHECK_EQ(0u, rawVisitor->numberOfMarkedWrappers()); |
| 325 container->setValue(scope.isolate(), str); | 326 container->setValue(scope.isolate(), str); |
| 326 CHECK_EQ(0u, rawVisitor->numberOfMarkedWrappers()); | 327 CHECK_EQ(0u, rawVisitor->numberOfMarkedWrappers()); |
| 327 // Gracefully terminate tracing. | 328 // Gracefully terminate tracing. |
| 328 rawVisitor->AdvanceTracing( | 329 rawVisitor->AdvanceTracing( |
| 329 0, v8::EmbedderHeapTracer::AdvanceTracingActions( | 330 0, |
| 330 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); | 331 v8::EmbedderHeapTracer::AdvanceTracingActions( |
| 332 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); |
| 331 rawVisitor->AbortTracing(); | 333 rawVisitor->AbortTracing(); |
| 332 } | 334 } |
| 333 | 335 |
| 334 TEST(ScriptWrappableVisitorTest, WriteBarrierTriggersOnMarkedContainer) { | 336 TEST(ScriptWrappableVisitorTest, WriteBarrierTriggersOnMarkedContainer) { |
| 335 V8TestingScope scope; | 337 V8TestingScope scope; |
| 336 auto rawVisitor = new InterceptingScriptWrappableVisitor(scope.isolate()); | 338 auto rawVisitor = new InterceptingScriptWrappableVisitor(scope.isolate()); |
| 337 swapInNewVisitor(scope.isolate(), rawVisitor); | 339 swapInNewVisitor(scope.isolate(), rawVisitor); |
| 338 rawVisitor->TracePrologue(); | 340 rawVisitor->TracePrologue(); |
| 339 v8::Local<v8::String> str = | 341 v8::Local<v8::String> str = |
| 340 v8::String::NewFromUtf8(scope.isolate(), "teststring", | 342 v8::String::NewFromUtf8(scope.isolate(), "teststring", |
| 341 v8::NewStringType::kNormal, sizeof("teststring")) | 343 v8::NewStringType::kNormal, sizeof("teststring")) |
| 342 .ToLocalChecked(); | 344 .ToLocalChecked(); |
| 343 HandleContainer* container = HandleContainer::create(); | 345 HandleContainer* container = HandleContainer::create(); |
| 344 HeapObjectHeader::fromPayload(container)->markWrapperHeader(); | 346 HeapObjectHeader::fromPayload(container)->markWrapperHeader(); |
| 345 CHECK_EQ(0u, rawVisitor->numberOfMarkedWrappers()); | 347 CHECK_EQ(0u, rawVisitor->numberOfMarkedWrappers()); |
| 346 container->setValue(scope.isolate(), str); | 348 container->setValue(scope.isolate(), str); |
| 347 CHECK_EQ(1u, rawVisitor->numberOfMarkedWrappers()); | 349 CHECK_EQ(1u, rawVisitor->numberOfMarkedWrappers()); |
| 348 // Gracefully terminate tracing. | 350 // Gracefully terminate tracing. |
| 349 rawVisitor->AdvanceTracing( | 351 rawVisitor->AdvanceTracing( |
| 350 0, v8::EmbedderHeapTracer::AdvanceTracingActions( | 352 0, |
| 351 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); | 353 v8::EmbedderHeapTracer::AdvanceTracingActions( |
| 354 v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); |
| 352 rawVisitor->AbortTracing(); | 355 rawVisitor->AbortTracing(); |
| 353 } | 356 } |
| 354 | 357 |
| 355 TEST(ScriptWrappableVisitorTest, VtableAtObjectStart) { | 358 TEST(ScriptWrappableVisitorTest, VtableAtObjectStart) { |
| 356 // This test makes sure that the subobject v8::EmbedderHeapTracer is placed | 359 // This test makes sure that the subobject v8::EmbedderHeapTracer is placed |
| 357 // at the start of a ScriptWrappableVisitor object. We do this to mitigate | 360 // at the start of a ScriptWrappableVisitor object. We do this to mitigate |
| 358 // potential problems that could be caused by LTO when passing | 361 // potential problems that could be caused by LTO when passing |
| 359 // v8::EmbedderHeapTracer across the API boundary. | 362 // v8::EmbedderHeapTracer across the API boundary. |
| 360 V8TestingScope scope; | 363 V8TestingScope scope; |
| 361 std::unique_ptr<blink::ScriptWrappableVisitor> visitor( | 364 std::unique_ptr<blink::ScriptWrappableVisitor> visitor( |
| 362 new ScriptWrappableVisitor(scope.isolate())); | 365 new ScriptWrappableVisitor(scope.isolate())); |
| 363 CHECK_EQ( | 366 CHECK_EQ( |
| 364 static_cast<void*>(visitor.get()), | 367 static_cast<void*>(visitor.get()), |
| 365 static_cast<void*>(dynamic_cast<v8::EmbedderHeapTracer*>(visitor.get()))); | 368 static_cast<void*>(dynamic_cast<v8::EmbedderHeapTracer*>(visitor.get()))); |
| 366 } | 369 } |
| 367 | 370 |
| 368 } // namespace blink | 371 } // namespace blink |
| OLD | NEW |