Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,77 @@
# 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.
import("../../../../gni/v8.gni")
group("gn_all") {
testonly = true
deps = []
if (v8_enable_google_benchmark) {
deps += [ ":cppgc_basic_benchmarks" ]
}
}
if (v8_enable_google_benchmark) {
v8_source_set("cppgc_benchmark_support") {
testonly = true
configs = [
"../../../..:external_config",
"../../../..:internal_config_base",
"../../../..:cppgc_base_config",
]
sources = [
"../../../../test/unittests/heap/cppgc/test-platform.cc",
"../../../../test/unittests/heap/cppgc/test-platform.h",
"benchmark_main.cc",
"benchmark_utils.cc",
"benchmark_utils.h",
]
public_deps = [ "//third_party/google_benchmark_chrome:google_benchmark" ]
if (cppgc_is_standalone) {
deps = [ "../../../..:cppgc_for_testing" ]
} else {
deps = [ "../../../..:v8_for_testing" ]
}
}
v8_executable("cppgc_basic_benchmarks") {
testonly = true
configs = [
"../../../..:external_config",
"../../../..:internal_config_base",
"../../../..:cppgc_base_config",
]
sources = [
"allocation_perf.cc",
"trace_perf.cc",
]
deps = [ ":cppgc_benchmark_support" ]
if (cppgc_is_standalone) {
deps += [ "../../../..:cppgc_for_testing" ]
} else {
deps += [ "../../../..:v8_for_testing" ]
}
}
v8_executable("cppgc_binary_trees_perf") {
testonly = true
configs = [
"../../../..:external_config",
"../../../..:internal_config_base",
"../../../..:cppgc_base_config",
]
sources = [ "binary-trees_perf.cc" ]
deps = [ ":cppgc_benchmark_support" ]
if (cppgc_is_standalone) {
deps += [ "../../../..:cppgc_for_testing" ]
} else {
deps += [ "../../../..:v8_for_testing" ]
}
}
}

View File

@ -0,0 +1,7 @@
include_rules = [
"+include/cppgc",
"+src/base",
"+src/heap/cppgc",
"+test/unittests/heap/cppgc",
"+third_party/google_benchmark_chrome/src/include/benchmark/benchmark.h",
]

View File

@ -0,0 +1,55 @@
// 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 "include/cppgc/allocation.h"
#include "include/cppgc/garbage-collected.h"
#include "include/cppgc/heap-consistency.h"
#include "src/base/macros.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap.h"
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "third_party/google_benchmark_chrome/src/include/benchmark/benchmark.h"
namespace cppgc {
namespace internal {
namespace {
using Allocate = testing::BenchmarkWithHeap;
class TinyObject final : public cppgc::GarbageCollected<TinyObject> {
public:
void Trace(cppgc::Visitor*) const {}
};
BENCHMARK_F(Allocate, Tiny)(benchmark::State& st) {
subtle::NoGarbageCollectionScope no_gc(*Heap::From(&heap()));
for (auto _ : st) {
USE(_);
TinyObject* result =
cppgc::MakeGarbageCollected<TinyObject>(heap().GetAllocationHandle());
benchmark::DoNotOptimize(result);
}
st.SetBytesProcessed(st.iterations() * sizeof(TinyObject));
}
class LargeObject final : public GarbageCollected<LargeObject> {
public:
void Trace(cppgc::Visitor*) const {}
char padding[kLargeObjectSizeThreshold + 1];
};
BENCHMARK_F(Allocate, Large)(benchmark::State& st) {
subtle::NoGarbageCollectionScope no_gc(*Heap::From(&heap()));
for (auto _ : st) {
USE(_);
LargeObject* result =
cppgc::MakeGarbageCollected<LargeObject>(heap().GetAllocationHandle());
benchmark::DoNotOptimize(result);
}
st.SetBytesProcessed(st.iterations() * sizeof(LargeObject));
}
} // namespace
} // namespace internal
} // namespace cppgc

View File

@ -0,0 +1,21 @@
// Copyright 2021 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 "include/cppgc/platform.h"
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "third_party/google_benchmark_chrome/src/include/benchmark/benchmark.h"
// Expanded macro BENCHMARK_MAIN() to allow per-process setup.
int main(int argc, char** argv) {
cppgc::internal::testing::BenchmarkWithHeap::InitializeProcess();
// Contents of BENCHMARK_MAIN().
{
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();
}
cppgc::internal::testing::BenchmarkWithHeap::ShutdownProcess();
return 0;
}

View File

@ -0,0 +1,31 @@
// Copyright 2021 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 "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "include/cppgc/platform.h"
#include "test/unittests/heap/cppgc/test-platform.h"
namespace cppgc {
namespace internal {
namespace testing {
// static
std::shared_ptr<testing::TestPlatform> BenchmarkWithHeap::platform_;
// static
void BenchmarkWithHeap::InitializeProcess() {
platform_ = std::make_shared<testing::TestPlatform>();
cppgc::InitializeProcess(platform_->GetPageAllocator());
}
// static
void BenchmarkWithHeap::ShutdownProcess() {
cppgc::ShutdownProcess();
platform_.reset();
}
} // namespace testing
} // namespace internal
} // namespace cppgc

View File

@ -0,0 +1,44 @@
// 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.
#ifndef TEST_BENCHMARK_CPP_CPPGC_BENCHMARK_UTILS_H_
#define TEST_BENCHMARK_CPP_CPPGC_BENCHMARK_UTILS_H_
#include "include/cppgc/heap.h"
#include "test/unittests/heap/cppgc/test-platform.h"
#include "third_party/google_benchmark_chrome/src/include/benchmark/benchmark.h"
namespace cppgc {
namespace internal {
namespace testing {
class BenchmarkWithHeap : public benchmark::Fixture {
public:
static void InitializeProcess();
static void ShutdownProcess();
protected:
void SetUp(::benchmark::State& state) override {
heap_ = cppgc::Heap::Create(GetPlatform());
}
void TearDown(::benchmark::State& state) override { heap_.reset(); }
cppgc::Heap& heap() const { return *heap_.get(); }
private:
static std::shared_ptr<testing::TestPlatform> GetPlatform() {
return platform_;
}
static std::shared_ptr<testing::TestPlatform> platform_;
std::unique_ptr<cppgc::Heap> heap_;
};
} // namespace testing
} // namespace internal
} // namespace cppgc
#endif // TEST_BENCHMARK_CPP_CPPGC_BENCHMARK_UTILS_H_

View File

@ -0,0 +1,105 @@
// Copyright 2021 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 <iostream>
#include "include/cppgc/allocation.h"
#include "include/cppgc/garbage-collected.h"
#include "include/cppgc/heap.h"
#include "include/cppgc/persistent.h"
#include "include/cppgc/visitor.h"
#include "src/base/macros.h"
#include "src/heap/cppgc/object-allocator.h"
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "third_party/google_benchmark_chrome/src/include/benchmark/benchmark.h"
namespace {
// Implementation of the binary trees benchmark of the computer language
// benchmarks game. See
// https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/binarytrees.html
class BinaryTrees : public cppgc::internal::testing::BenchmarkWithHeap {
public:
BinaryTrees() { Iterations(1); }
};
class TreeNode final : public cppgc::GarbageCollected<TreeNode> {
public:
void Trace(cppgc::Visitor* visitor) const {
visitor->Trace(left_);
visitor->Trace(right_);
}
const TreeNode* left() const { return left_; }
void set_left(TreeNode* node) { left_ = node; }
const TreeNode* right() const { return right_; }
void set_right(TreeNode* node) { right_ = node; }
size_t Check() const {
return left() ? left()->Check() + right()->Check() + 1 : 1;
}
private:
cppgc::Member<TreeNode> left_;
cppgc::Member<TreeNode> right_;
};
TreeNode* CreateTree(cppgc::AllocationHandle& alloc_handle, size_t depth) {
auto* node = cppgc::MakeGarbageCollected<TreeNode>(alloc_handle);
if (depth > 0) {
node->set_left(CreateTree(alloc_handle, depth - 1));
node->set_right(CreateTree(alloc_handle, depth - 1));
}
return node;
}
void Loop(cppgc::AllocationHandle& alloc_handle, size_t iterations,
size_t depth) {
size_t check = 0;
for (size_t item = 0; item < iterations; ++item) {
check += CreateTree(alloc_handle, depth)->Check();
}
std::cout << iterations << "\t trees of depth " << depth
<< "\t check: " << check << std::endl;
}
void Trees(cppgc::AllocationHandle& alloc_handle, size_t max_depth) {
// Keep the long-lived tree in a Persistent to allow for concurrent GC to
// immediately find it.
cppgc::Persistent<TreeNode> long_lived_tree =
CreateTree(alloc_handle, max_depth);
constexpr size_t kMinDepth = 4;
const size_t max_iterations = 16 << max_depth;
for (size_t depth = kMinDepth; depth <= max_depth; depth += 2) {
const size_t iterations = max_iterations >> depth;
Loop(alloc_handle, iterations, depth);
}
std::cout << "long lived tree of depth " << max_depth << "\t "
<< "check: " << long_lived_tree->Check() << "\n";
}
void RunBinaryTrees(cppgc::Heap& heap) {
const size_t max_depth = 21;
auto& alloc_handle = heap.GetAllocationHandle();
const size_t stretch_depth = max_depth + 1;
std::cout << "stretch tree of depth " << stretch_depth << "\t "
<< "check: " << CreateTree(alloc_handle, stretch_depth)->Check()
<< std::endl;
Trees(alloc_handle, max_depth);
}
} // namespace
BENCHMARK_F(BinaryTrees, V1)(benchmark::State& st) {
for (auto _ : st) {
USE(_);
RunBinaryTrees(heap());
}
}

View File

@ -0,0 +1,87 @@
// 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 "include/cppgc/allocation.h"
#include "include/cppgc/garbage-collected.h"
#include "include/cppgc/persistent.h"
#include "src/base/macros.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap.h"
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "third_party/google_benchmark_chrome/src/include/benchmark/benchmark.h"
#include "v8config.h"
namespace cppgc {
namespace internal {
namespace {
using Trace = testing::BenchmarkWithHeap;
class GCed : public cppgc::GarbageCollected<GCed> {
public:
virtual void Trace(Visitor*) const {}
};
class OtherPayload {
public:
virtual void* DummyGetter() { return nullptr; }
};
class Mixin : public GarbageCollectedMixin {
public:
void Trace(Visitor*) const override {}
};
class GCedWithMixin final : public GCed, public OtherPayload, public Mixin {
public:
void Trace(Visitor* visitor) const final {
GCed::Trace(visitor);
Mixin::Trace(visitor);
}
};
class Holder : public cppgc::GarbageCollected<Holder> {
public:
explicit Holder(GCedWithMixin* object)
: base_ref(object), mixin_ref(object) {}
virtual void Trace(Visitor* visitor) const {
visitor->Trace(base_ref);
visitor->Trace(mixin_ref);
}
cppgc::Member<GCedWithMixin> base_ref;
cppgc::Member<Mixin> mixin_ref;
};
template <typename T>
V8_NOINLINE void DispatchTrace(Visitor* visitor, T& ref) {
visitor->Trace(ref);
}
BENCHMARK_F(Trace, Static)(benchmark::State& st) {
cppgc::Persistent<Holder> holder(cppgc::MakeGarbageCollected<Holder>(
heap().GetAllocationHandle(), cppgc::MakeGarbageCollected<GCedWithMixin>(
heap().GetAllocationHandle())));
VisitorBase visitor;
for (auto _ : st) {
USE(_);
DispatchTrace(&visitor, holder->base_ref);
}
}
BENCHMARK_F(Trace, Dynamic)(benchmark::State& st) {
cppgc::Persistent<Holder> holder(cppgc::MakeGarbageCollected<Holder>(
heap().GetAllocationHandle(), cppgc::MakeGarbageCollected<GCedWithMixin>(
heap().GetAllocationHandle())));
VisitorBase visitor;
for (auto _ : st) {
USE(_);
DispatchTrace(&visitor, holder->mixin_ref);
}
}
} // namespace
} // namespace internal
} // namespace cppgc