v8/test/unittests/objects/microtask-queue-unittest.cc
Yang Guo 0a82012523 Revert "Implement Faster MicrotaskQueue Step 2"
This reverts commit 1d726111ab.

Reason for revert: This breaks a layout test, and blocks V8 roll

https://ci.chromium.org/p/chromium/builders/luci.chromium.try/win7_chromium_rel_ng/135831

Original change's description:
> Implement Faster MicrotaskQueue Step 2
> 
> This is an implementation of https://bit.ly/v8-faster-microtask-queues
> step 2.
> 
> This CL overhauls MicrotaskQueue class, the previous one is on V8 heap,
> and the new one is on C++ heap.
> 
> Benchmark:
> This CL improves a benchmark score around promise by 5~23%.
> https://github.com/v8/promise-performance-tests
> https://docs.google.com/spreadsheets/d/1HtwZGzUAGJYg87VmYhV9hLdvfddlCtC6Oz0iOj-WwQA/edit#gid=1952666737
> 
> Bug: chromium:887920, v8:7253
> Change-Id: I1f26e02c45ae60ae39d1ccc168daa98bca4663d9
> Reviewed-on: https://chromium-review.googlesource.com/c/1290751
> Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Reviewed-by: Adam Klein <adamk@chromium.org>
> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#57681}

TBR=ulan@chromium.org,adamk@chromium.org,yangguo@chromium.org,ishell@chromium.org,bmeurer@chromium.org,tzik@chromium.org

Change-Id: I639882a95fe63c029a2e53d610dc4133d1ac48f2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:887920, v8:7253
Reviewed-on: https://chromium-review.googlesource.com/c/1347473
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57711}
2018-11-22 08:16:23 +00:00

56 lines
1.8 KiB
C++

// Copyright 2018 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/objects/microtask-queue-inl.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
void NoopCallback(void*) {}
class MicrotaskQueueTest : public TestWithIsolate {
public:
Handle<Microtask> NewMicrotask() {
MicrotaskCallback callback = &NoopCallback;
void* data = nullptr;
return factory()->NewCallbackTask(
factory()->NewForeign(reinterpret_cast<Address>(callback)),
factory()->NewForeign(reinterpret_cast<Address>(data)));
}
};
TEST_F(MicrotaskQueueTest, EnqueueMicrotask) {
Handle<MicrotaskQueue> microtask_queue = factory()->NewMicrotaskQueue();
Handle<Microtask> microtask = NewMicrotask();
EXPECT_EQ(0, microtask_queue->pending_microtask_count());
MicrotaskQueue::EnqueueMicrotask(isolate(), microtask_queue, microtask);
EXPECT_EQ(1, microtask_queue->pending_microtask_count());
ASSERT_LE(1, microtask_queue->queue()->length());
EXPECT_EQ(*microtask, microtask_queue->queue()->get(0));
std::vector<Handle<Microtask>> microtasks;
microtasks.push_back(microtask);
// Queue microtasks until the reallocation happens.
int queue_capacity = microtask_queue->queue()->length();
for (int i = 0; i < queue_capacity; ++i) {
microtask = NewMicrotask();
MicrotaskQueue::EnqueueMicrotask(isolate(), microtask_queue, microtask);
microtasks.push_back(microtask);
}
int num_tasks = static_cast<int>(microtasks.size());
EXPECT_EQ(num_tasks, microtask_queue->pending_microtask_count());
ASSERT_LE(num_tasks, microtask_queue->queue()->length());
for (int i = 0; i < num_tasks; ++i) {
EXPECT_EQ(*microtasks[i], microtask_queue->queue()->get(i));
}
}
} // namespace internal
} // namespace v8