6e6f6d09bb
This is needed for write-barrier and persistent-handle code that does not otherwise get an instance of LocalHeap Bug: v8:10315 Change-Id: I480e31f32141510f2f9e678af3449d5841e3156e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2284492 Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/master@{#68720}
85 lines
1.8 KiB
C++
85 lines
1.8 KiB
C++
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/heap/local-heap.h"
|
|
#include "src/heap/heap.h"
|
|
#include "src/heap/safepoint.h"
|
|
#include "test/unittests/test-utils.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
using LocalHeapTest = TestWithIsolate;
|
|
|
|
TEST_F(LocalHeapTest, Initialize) {
|
|
Heap* heap = i_isolate()->heap();
|
|
|
|
CHECK(!heap->safepoint()->ContainsAnyLocalHeap());
|
|
|
|
{
|
|
LocalHeap lh(heap);
|
|
CHECK(heap->safepoint()->ContainsLocalHeap(&lh));
|
|
}
|
|
|
|
CHECK(!heap->safepoint()->ContainsAnyLocalHeap());
|
|
}
|
|
|
|
TEST_F(LocalHeapTest, Current) {
|
|
Heap* heap = i_isolate()->heap();
|
|
|
|
CHECK_NULL(LocalHeap::Current());
|
|
|
|
{
|
|
LocalHeap lh(heap);
|
|
CHECK_EQ(&lh, LocalHeap::Current());
|
|
}
|
|
|
|
CHECK_NULL(LocalHeap::Current());
|
|
|
|
{
|
|
LocalHeap lh(heap);
|
|
CHECK_EQ(&lh, LocalHeap::Current());
|
|
}
|
|
|
|
CHECK_NULL(LocalHeap::Current());
|
|
}
|
|
|
|
namespace {
|
|
class BackgroundThread final : public v8::base::Thread {
|
|
public:
|
|
explicit BackgroundThread(Heap* heap)
|
|
: v8::base::Thread(base::Thread::Options("BackgroundThread")),
|
|
heap_(heap) {}
|
|
|
|
void Run() override {
|
|
CHECK_NULL(LocalHeap::Current());
|
|
{
|
|
LocalHeap lh(heap_);
|
|
CHECK_EQ(&lh, LocalHeap::Current());
|
|
}
|
|
CHECK_NULL(LocalHeap::Current());
|
|
}
|
|
|
|
Heap* heap_;
|
|
};
|
|
} // anonymous namespace
|
|
|
|
TEST_F(LocalHeapTest, CurrentBackground) {
|
|
Heap* heap = i_isolate()->heap();
|
|
CHECK_NULL(LocalHeap::Current());
|
|
{
|
|
LocalHeap lh(heap);
|
|
auto thread = std::make_unique<BackgroundThread>(heap);
|
|
CHECK(thread->Start());
|
|
CHECK_EQ(&lh, LocalHeap::Current());
|
|
thread->Join();
|
|
CHECK_EQ(&lh, LocalHeap::Current());
|
|
}
|
|
CHECK_NULL(LocalHeap::Current());
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|