Update test/benchmarks/cpp/BUILD.gn and test/benchmarks/cpp/cppgc/BUILD.gn so that fast_api_benchmark and other C++ benchmarks can be built in a Chrome checkout (build_with_chromium) in addition to a standalone V8 checkout: - Use relative paths (../../..:v8, ../../..:v8_libbase, etc.) instead of root-relative paths (//:v8) which point to the Chromium root in a Chrome checkout. - Add ../../..:internal_config_base to benchmark targets so V8 include paths are configured when building in Chromium. - Depend on //third_party/google_benchmark when build_with_chromium is true instead of //third_party/google_benchmark_chrome. - Add //build/config/compiler:no_exit_time_destructors to cppgc benchmarks. - Include "benchmark/benchmark.h" via the benchmark_config include_dirs instead of hardcoding the third_party/google_benchmark_chrome path. TAG=agy CONV=33ee5221-0921-45d8-bcc0-6413b5599ef7 Change-Id: Ia6cf7c1b8651b7808046003c16139b9c48570d01 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8657242 Commit-Queue: Andreas Haas <ahaas@chromium.org> Reviewed-by: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/main@{#111149}
88 lines
2.3 KiB
C++
88 lines
2.3 KiB
C++
// 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 "benchmark/benchmark.h"
|
|
#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-internal/globals.h"
|
|
#include "src/heap/cppgc-internal/heap.h"
|
|
#include "test/benchmarks/cpp/cppgc/benchmark_utils.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
|