e0b18b9022
This is a reland of a0728e869b
Original change's description:
> [d8] Remove maximum workers limitation
>
> This CL refactors the lifetime management of the v8::Worker C++ object
> and in the process lifts the 100 maximum worker limitation. To do this,
> it uses a Managed<v8::Worker> heap object and attaches the managed to
> the API worker object.
>
> R=mstarzinger@chromium.org
> BUG=v8:9524
>
> Change-Id: I279b7aeb6645a87f9108ee6f572105739721cef4
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1715453
> Commit-Queue: Ben Titzer <titzer@chromium.org>
> Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#62932}
Bug: v8:9524
Change-Id: I7d903fb12ddb00909a9429455f46c55db2fd02de
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1722562
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62974}
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
// Copyright 2014 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/base/platform/platform.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace v8 {
|
|
namespace base {
|
|
|
|
TEST(OS, GetCurrentProcessId) {
|
|
#if V8_OS_POSIX
|
|
EXPECT_EQ(static_cast<int>(getpid()), OS::GetCurrentProcessId());
|
|
#endif
|
|
|
|
#if V8_OS_WIN
|
|
EXPECT_EQ(static_cast<int>(::GetCurrentProcessId()),
|
|
OS::GetCurrentProcessId());
|
|
#endif
|
|
}
|
|
|
|
|
|
namespace {
|
|
|
|
class ThreadLocalStorageTest : public Thread, public ::testing::Test {
|
|
public:
|
|
ThreadLocalStorageTest() : Thread(Options("ThreadLocalStorageTest")) {
|
|
for (size_t i = 0; i < arraysize(keys_); ++i) {
|
|
keys_[i] = Thread::CreateThreadLocalKey();
|
|
}
|
|
}
|
|
~ThreadLocalStorageTest() override {
|
|
for (size_t i = 0; i < arraysize(keys_); ++i) {
|
|
Thread::DeleteThreadLocalKey(keys_[i]);
|
|
}
|
|
}
|
|
|
|
void Run() final {
|
|
for (size_t i = 0; i < arraysize(keys_); i++) {
|
|
CHECK(!Thread::HasThreadLocal(keys_[i]));
|
|
}
|
|
for (size_t i = 0; i < arraysize(keys_); i++) {
|
|
Thread::SetThreadLocal(keys_[i], GetValue(i));
|
|
}
|
|
for (size_t i = 0; i < arraysize(keys_); i++) {
|
|
CHECK(Thread::HasThreadLocal(keys_[i]));
|
|
}
|
|
for (size_t i = 0; i < arraysize(keys_); i++) {
|
|
CHECK_EQ(GetValue(i), Thread::GetThreadLocal(keys_[i]));
|
|
CHECK_EQ(GetValue(i), Thread::GetExistingThreadLocal(keys_[i]));
|
|
}
|
|
for (size_t i = 0; i < arraysize(keys_); i++) {
|
|
Thread::SetThreadLocal(keys_[i], GetValue(arraysize(keys_) - i - 1));
|
|
}
|
|
for (size_t i = 0; i < arraysize(keys_); i++) {
|
|
CHECK(Thread::HasThreadLocal(keys_[i]));
|
|
}
|
|
for (size_t i = 0; i < arraysize(keys_); i++) {
|
|
CHECK_EQ(GetValue(arraysize(keys_) - i - 1),
|
|
Thread::GetThreadLocal(keys_[i]));
|
|
CHECK_EQ(GetValue(arraysize(keys_) - i - 1),
|
|
Thread::GetExistingThreadLocal(keys_[i]));
|
|
}
|
|
}
|
|
|
|
private:
|
|
static void* GetValue(size_t x) {
|
|
return bit_cast<void*>(static_cast<uintptr_t>(x + 1));
|
|
}
|
|
|
|
// Older versions of Android have fewer TLS slots (nominally 64, but the
|
|
// system uses "about 5 of them" itself).
|
|
Thread::LocalStorageKey keys_[32];
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
TEST_F(ThreadLocalStorageTest, DoTest) {
|
|
Run();
|
|
CHECK(Start());
|
|
Join();
|
|
}
|
|
|
|
} // namespace base
|
|
} // namespace v8
|