Files
v8/test/benchmarks/cpp/benchmark-utils.cc
Nikolaos Papaspyrou 9fcf2c75eb [test] Fix benchmark initialization
After https://crrev.com/c/6348469, V8::Initialize() calls
cppgc::InitializeProcess(), so the latter needs not be called
explicitly during benchmark initialization.

Change-Id: If4d429e5c776f530701d5a778c03da6644a9723a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6540508
Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/main@{#100238}
2025-05-13 04:46:44 -07:00

49 lines
1.5 KiB
C++

// Copyright 2024 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/benchmark-utils.h"
#include "include/cppgc/platform.h"
#include "include/libplatform/libplatform.h"
#include "include/v8-array-buffer.h"
#include "include/v8-cppgc.h"
#include "include/v8-initialization.h"
namespace v8::benchmarking {
// static
v8::Platform* BenchmarkWithIsolate::platform_;
// static
v8::Isolate* BenchmarkWithIsolate::v8_isolate_;
// static
v8::ArrayBuffer::Allocator* BenchmarkWithIsolate::v8_ab_allocator_;
// static
void BenchmarkWithIsolate::InitializeProcess() {
v8::V8::SetFlagsFromString("--allow-natives-syntax");
platform_ = v8::platform::NewDefaultPlatform().release();
v8::V8::InitializePlatform(platform_);
v8::V8::Initialize();
v8_ab_allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
auto heap = v8::CppHeap::Create(platform_, v8::CppHeapCreateParams({}));
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = v8_ab_allocator_;
create_params.cpp_heap = heap.release();
v8_isolate_ = v8::Isolate::New(create_params);
v8_isolate_->Enter();
}
// static
void BenchmarkWithIsolate::ShutdownProcess() {
v8_isolate_->Exit();
v8_isolate_->Dispose();
cppgc::ShutdownProcess();
v8::V8::Dispose();
v8::V8::DisposePlatform();
delete v8_ab_allocator_;
}
} // namespace v8::benchmarking