v8/test/unittests/heap/local-heap-unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
1.8 KiB
C++
Raw Normal View History

// 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();
Reland "[heap] Introduce LocalIsolate for main thread" This is a reland of e95e1b62342659b8c7dda5ce3d3a2f13f554342d After landing https://crrev.com/c/2546682, this CL can be relanded without changes. Original change's description: > [heap] Introduce LocalIsolate for main thread > > Add a LocalIsolate for the main thread to Isolate. This LocalIsolate is > kept alive during the whole lifetime of the Isolate. The main thread > LocalIsolate starts in the Running state in contrast to the background > thread LocalIsolates (those start in Parked). > > Code paths in Turbofan that used to create a LocalIsolate on the main > thread can now simply use the main thread LocalIsolate. > > LocalIsolate for the main thread will help in reducing differences > between the main and background threads. The goal is that the main > thread behaves more like a background thread. > > The main thread LocalIsolate should also make it simpler to share code > between main thread and background threads by using LocalIsolate for > both. > > Bug: v8:10315 > Change-Id: I7fd61d305a6fd7079e2319d75c291c1021e70018 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509593 > Reviewed-by: Simon Zünd <szuend@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Reviewed-by: Leszek Swirski <leszeks@chromium.org> > Reviewed-by: Georg Neis <neis@chromium.org> > Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> > Cr-Commit-Position: refs/heads/master@{#71226} Bug: v8:10315 Change-Id: I418b1217aeac4f3c44a0aa514dea9864f8a58656 TBR: szuend@chromium.org, yangguo@chromium.org, ulan@chromium.org, leszeks@chromium.org, neis@chromium.org Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2543399 Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/master@{#71274}
2020-11-17 10:16:09 +00:00
CHECK(heap->safepoint()->ContainsAnyLocalHeap());
}
TEST_F(LocalHeapTest, Current) {
Heap* heap = i_isolate()->heap();
CHECK_NULL(LocalHeap::Current());
{
LocalHeap lh(heap, ThreadKind::kMain);
Reland "[heap] Introduce LocalIsolate for main thread" This is a reland of e95e1b62342659b8c7dda5ce3d3a2f13f554342d After landing https://crrev.com/c/2546682, this CL can be relanded without changes. Original change's description: > [heap] Introduce LocalIsolate for main thread > > Add a LocalIsolate for the main thread to Isolate. This LocalIsolate is > kept alive during the whole lifetime of the Isolate. The main thread > LocalIsolate starts in the Running state in contrast to the background > thread LocalIsolates (those start in Parked). > > Code paths in Turbofan that used to create a LocalIsolate on the main > thread can now simply use the main thread LocalIsolate. > > LocalIsolate for the main thread will help in reducing differences > between the main and background threads. The goal is that the main > thread behaves more like a background thread. > > The main thread LocalIsolate should also make it simpler to share code > between main thread and background threads by using LocalIsolate for > both. > > Bug: v8:10315 > Change-Id: I7fd61d305a6fd7079e2319d75c291c1021e70018 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509593 > Reviewed-by: Simon Zünd <szuend@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Reviewed-by: Leszek Swirski <leszeks@chromium.org> > Reviewed-by: Georg Neis <neis@chromium.org> > Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> > Cr-Commit-Position: refs/heads/master@{#71226} Bug: v8:10315 Change-Id: I418b1217aeac4f3c44a0aa514dea9864f8a58656 TBR: szuend@chromium.org, yangguo@chromium.org, ulan@chromium.org, leszeks@chromium.org, neis@chromium.org Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2543399 Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/master@{#71274}
2020-11-17 10:16:09 +00:00
CHECK_NULL(LocalHeap::Current());
}
CHECK_NULL(LocalHeap::Current());
{
LocalHeap lh(heap, ThreadKind::kMain);
Reland "[heap] Introduce LocalIsolate for main thread" This is a reland of e95e1b62342659b8c7dda5ce3d3a2f13f554342d After landing https://crrev.com/c/2546682, this CL can be relanded without changes. Original change's description: > [heap] Introduce LocalIsolate for main thread > > Add a LocalIsolate for the main thread to Isolate. This LocalIsolate is > kept alive during the whole lifetime of the Isolate. The main thread > LocalIsolate starts in the Running state in contrast to the background > thread LocalIsolates (those start in Parked). > > Code paths in Turbofan that used to create a LocalIsolate on the main > thread can now simply use the main thread LocalIsolate. > > LocalIsolate for the main thread will help in reducing differences > between the main and background threads. The goal is that the main > thread behaves more like a background thread. > > The main thread LocalIsolate should also make it simpler to share code > between main thread and background threads by using LocalIsolate for > both. > > Bug: v8:10315 > Change-Id: I7fd61d305a6fd7079e2319d75c291c1021e70018 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509593 > Reviewed-by: Simon Zünd <szuend@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Reviewed-by: Leszek Swirski <leszeks@chromium.org> > Reviewed-by: Georg Neis <neis@chromium.org> > Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> > Cr-Commit-Position: refs/heads/master@{#71226} Bug: v8:10315 Change-Id: I418b1217aeac4f3c44a0aa514dea9864f8a58656 TBR: szuend@chromium.org, yangguo@chromium.org, ulan@chromium.org, leszeks@chromium.org, neis@chromium.org Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2543399 Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/master@{#71274}
2020-11-17 10:16:09 +00:00
CHECK_NULL(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_, ThreadKind::kBackground);
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, ThreadKind::kMain);
auto thread = std::make_unique<BackgroundThread>(heap);
CHECK(thread->Start());
Reland "[heap] Introduce LocalIsolate for main thread" This is a reland of e95e1b62342659b8c7dda5ce3d3a2f13f554342d After landing https://crrev.com/c/2546682, this CL can be relanded without changes. Original change's description: > [heap] Introduce LocalIsolate for main thread > > Add a LocalIsolate for the main thread to Isolate. This LocalIsolate is > kept alive during the whole lifetime of the Isolate. The main thread > LocalIsolate starts in the Running state in contrast to the background > thread LocalIsolates (those start in Parked). > > Code paths in Turbofan that used to create a LocalIsolate on the main > thread can now simply use the main thread LocalIsolate. > > LocalIsolate for the main thread will help in reducing differences > between the main and background threads. The goal is that the main > thread behaves more like a background thread. > > The main thread LocalIsolate should also make it simpler to share code > between main thread and background threads by using LocalIsolate for > both. > > Bug: v8:10315 > Change-Id: I7fd61d305a6fd7079e2319d75c291c1021e70018 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509593 > Reviewed-by: Simon Zünd <szuend@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Reviewed-by: Leszek Swirski <leszeks@chromium.org> > Reviewed-by: Georg Neis <neis@chromium.org> > Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> > Cr-Commit-Position: refs/heads/master@{#71226} Bug: v8:10315 Change-Id: I418b1217aeac4f3c44a0aa514dea9864f8a58656 TBR: szuend@chromium.org, yangguo@chromium.org, ulan@chromium.org, leszeks@chromium.org, neis@chromium.org Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2543399 Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/master@{#71274}
2020-11-17 10:16:09 +00:00
CHECK_NULL(LocalHeap::Current());
thread->Join();
Reland "[heap] Introduce LocalIsolate for main thread" This is a reland of e95e1b62342659b8c7dda5ce3d3a2f13f554342d After landing https://crrev.com/c/2546682, this CL can be relanded without changes. Original change's description: > [heap] Introduce LocalIsolate for main thread > > Add a LocalIsolate for the main thread to Isolate. This LocalIsolate is > kept alive during the whole lifetime of the Isolate. The main thread > LocalIsolate starts in the Running state in contrast to the background > thread LocalIsolates (those start in Parked). > > Code paths in Turbofan that used to create a LocalIsolate on the main > thread can now simply use the main thread LocalIsolate. > > LocalIsolate for the main thread will help in reducing differences > between the main and background threads. The goal is that the main > thread behaves more like a background thread. > > The main thread LocalIsolate should also make it simpler to share code > between main thread and background threads by using LocalIsolate for > both. > > Bug: v8:10315 > Change-Id: I7fd61d305a6fd7079e2319d75c291c1021e70018 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509593 > Reviewed-by: Simon Zünd <szuend@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Reviewed-by: Leszek Swirski <leszeks@chromium.org> > Reviewed-by: Georg Neis <neis@chromium.org> > Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> > Cr-Commit-Position: refs/heads/master@{#71226} Bug: v8:10315 Change-Id: I418b1217aeac4f3c44a0aa514dea9864f8a58656 TBR: szuend@chromium.org, yangguo@chromium.org, ulan@chromium.org, leszeks@chromium.org, neis@chromium.org Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2543399 Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/master@{#71274}
2020-11-17 10:16:09 +00:00
CHECK_NULL(LocalHeap::Current());
}
CHECK_NULL(LocalHeap::Current());
}
} // namespace internal
} // namespace v8