3f9ff062b0
This is a reland of 80f5dfda01
. A condition
in pipeline.cc was inverted, which lead to a CSA verifier error.
Original change's description:
> [no-wasm] Exclude src/wasm from compilation
>
> This is the biggest chunk, including
> - all of src/wasm,
> - torque file for wasm objects,
> - torque file for wasm builtins,
> - wasm builtins,
> - wasm runtime functions,
> - int64 lowering,
> - simd scala lowering,
> - WasmGraphBuilder (TF graph construction for wasm),
> - wasm frame types,
> - wasm interrupts,
> - the JSWasmCall opcode,
> - wasm backing store allocation.
>
> Those components are all recursively entangled, so I found no way to
> split this change up further.
>
> Some includes that were recursively included by wasm headers needed to
> be added explicitly now.
>
> backing-store-unittest.cc is renamed to wasm-backing-store-unittest.cc
> because it only tests wasm backing stores. This file is excluded from
> no-wasm builds then.
>
> R=jkummerow@chromium.org, jgruber@chromium.org, mlippautz@chromium.org, petermarshall@chromium.org
>
> Bug: v8:11238
> Change-Id: I7558f2d12d2dd6c65128c4de7b79173668c80b2b
> Cq-Include-Trybots: luci.v8.try:v8_linux64_no_wasm_compile_rel
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2742955
> Commit-Queue: Clemens Backes <clemensb@chromium.org>
> Reviewed-by: Peter Marshall <petermarshall@chromium.org>
> Reviewed-by: Toon Verwaest <verwaest@chromium.org>
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#73344}
TBR=jgruber@chromium.org
Bug: v8:11238
Change-Id: I20bd2847a59c68738b5a336cd42582b7b1499585
Cq-Include-Trybots: luci.v8.try:v8_linux64_no_wasm_compile_rel
Cq-Include-Trybots: luci.v8.try:v8_linux_verify_csa_rel_ng
Cq-Include-Trybots: luci.v8.try:v8_linux64_verify_csa_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2752867
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73348}
134 lines
4.5 KiB
C++
134 lines
4.5 KiB
C++
// Copyright 2019 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 "src/objects/backing-store.h"
|
|
#include "test/unittests/test-utils.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
class BackingStoreTest : public TestWithIsolate {};
|
|
|
|
TEST_F(BackingStoreTest, GrowWasmMemoryInPlace) {
|
|
auto backing_store =
|
|
BackingStore::AllocateWasmMemory(isolate(), 1, 2, SharedFlag::kNotShared);
|
|
CHECK(backing_store);
|
|
EXPECT_TRUE(backing_store->is_wasm_memory());
|
|
EXPECT_EQ(1 * wasm::kWasmPageSize, backing_store->byte_length());
|
|
EXPECT_EQ(2 * wasm::kWasmPageSize, backing_store->byte_capacity());
|
|
|
|
base::Optional<size_t> result =
|
|
backing_store->GrowWasmMemoryInPlace(isolate(), 1, 2);
|
|
EXPECT_TRUE(result.has_value());
|
|
EXPECT_EQ(result.value(), 1u);
|
|
EXPECT_EQ(2 * wasm::kWasmPageSize, backing_store->byte_length());
|
|
}
|
|
|
|
TEST_F(BackingStoreTest, GrowWasmMemoryInPlace_neg) {
|
|
auto backing_store =
|
|
BackingStore::AllocateWasmMemory(isolate(), 1, 2, SharedFlag::kNotShared);
|
|
CHECK(backing_store);
|
|
EXPECT_TRUE(backing_store->is_wasm_memory());
|
|
EXPECT_EQ(1 * wasm::kWasmPageSize, backing_store->byte_length());
|
|
EXPECT_EQ(2 * wasm::kWasmPageSize, backing_store->byte_capacity());
|
|
|
|
base::Optional<size_t> result =
|
|
backing_store->GrowWasmMemoryInPlace(isolate(), 2, 2);
|
|
EXPECT_FALSE(result.has_value());
|
|
EXPECT_EQ(1 * wasm::kWasmPageSize, backing_store->byte_length());
|
|
}
|
|
|
|
TEST_F(BackingStoreTest, GrowSharedWasmMemoryInPlace) {
|
|
auto backing_store =
|
|
BackingStore::AllocateWasmMemory(isolate(), 2, 3, SharedFlag::kShared);
|
|
CHECK(backing_store);
|
|
EXPECT_TRUE(backing_store->is_wasm_memory());
|
|
EXPECT_EQ(2 * wasm::kWasmPageSize, backing_store->byte_length());
|
|
EXPECT_EQ(3 * wasm::kWasmPageSize, backing_store->byte_capacity());
|
|
|
|
base::Optional<size_t> result =
|
|
backing_store->GrowWasmMemoryInPlace(isolate(), 1, 3);
|
|
EXPECT_TRUE(result.has_value());
|
|
EXPECT_EQ(result.value(), 2u);
|
|
EXPECT_EQ(3 * wasm::kWasmPageSize, backing_store->byte_length());
|
|
}
|
|
|
|
TEST_F(BackingStoreTest, CopyWasmMemory) {
|
|
auto bs1 =
|
|
BackingStore::AllocateWasmMemory(isolate(), 1, 2, SharedFlag::kNotShared);
|
|
CHECK(bs1);
|
|
EXPECT_TRUE(bs1->is_wasm_memory());
|
|
EXPECT_EQ(1 * wasm::kWasmPageSize, bs1->byte_length());
|
|
EXPECT_EQ(2 * wasm::kWasmPageSize, bs1->byte_capacity());
|
|
|
|
auto bs2 = bs1->CopyWasmMemory(isolate(), 3);
|
|
EXPECT_TRUE(bs2->is_wasm_memory());
|
|
EXPECT_EQ(3 * wasm::kWasmPageSize, bs2->byte_length());
|
|
EXPECT_EQ(3 * wasm::kWasmPageSize, bs2->byte_capacity());
|
|
}
|
|
|
|
class GrowerThread : public base::Thread {
|
|
public:
|
|
GrowerThread(Isolate* isolate, uint32_t increment, uint32_t max,
|
|
std::shared_ptr<BackingStore> backing_store)
|
|
: base::Thread(base::Thread::Options("GrowerThread")),
|
|
isolate_(isolate),
|
|
increment_(increment),
|
|
max_(max),
|
|
backing_store_(backing_store) {}
|
|
|
|
void Run() override {
|
|
size_t max_length = max_ * wasm::kWasmPageSize;
|
|
while (true) {
|
|
size_t current_length = backing_store_->byte_length();
|
|
if (current_length >= max_length) break;
|
|
base::Optional<size_t> result =
|
|
backing_store_->GrowWasmMemoryInPlace(isolate_, increment_, max_);
|
|
size_t new_length = backing_store_->byte_length();
|
|
if (result.has_value()) {
|
|
CHECK_LE(current_length / wasm::kWasmPageSize, result.value());
|
|
CHECK_GE(new_length, current_length + increment_);
|
|
} else {
|
|
CHECK_EQ(max_length, new_length);
|
|
}
|
|
}
|
|
}
|
|
|
|
private:
|
|
Isolate* isolate_;
|
|
uint32_t increment_;
|
|
uint32_t max_;
|
|
std::shared_ptr<BackingStore> backing_store_;
|
|
};
|
|
|
|
TEST_F(BackingStoreTest, RacyGrowWasmMemoryInPlace) {
|
|
constexpr int kNumThreads = 10;
|
|
constexpr int kMaxPages = 1024;
|
|
GrowerThread* threads[kNumThreads];
|
|
|
|
std::shared_ptr<BackingStore> backing_store =
|
|
BackingStore::AllocateWasmMemory(isolate(), 0, kMaxPages,
|
|
SharedFlag::kShared);
|
|
|
|
for (int i = 0; i < kNumThreads; i++) {
|
|
threads[i] = new GrowerThread(isolate(), 1, kMaxPages, backing_store);
|
|
CHECK(threads[i]->Start());
|
|
}
|
|
|
|
for (int i = 0; i < kNumThreads; i++) {
|
|
threads[i]->Join();
|
|
}
|
|
|
|
EXPECT_EQ(kMaxPages * wasm::kWasmPageSize, backing_store->byte_length());
|
|
|
|
for (int i = 0; i < kNumThreads; i++) {
|
|
delete threads[i];
|
|
}
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|