Commit c51a81e7 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[api] Deprecate CopyablePersistentTraits

Anyone using CopyablePersistentTraits should be using v8::Global, so
deprecate it and fix the uses in V8.

Bug: v8:12915
Change-Id: I25e6f2a03e070db9e9af9bbd9ea8cbc0f838c5ac
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3669254Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81001}
parent 4e834927
......@@ -254,7 +254,7 @@ class NonCopyablePersistentTraits {
* This will clone the contents of storage cell, but not any of the flags, etc.
*/
template <class T>
struct CopyablePersistentTraits {
struct V8_DEPRECATED("Use v8::Global instead") CopyablePersistentTraits {
using CopyablePersistent = Persistent<T, CopyablePersistentTraits<T>>;
static const bool kResetInDestructor = true;
template <class S, class M>
......
......@@ -331,6 +331,9 @@ class V8_EXPORT CpuProfilingOptions {
unsigned max_samples = kNoSampleLimit, int sampling_interval_us = 0,
MaybeLocal<Context> filter_context = MaybeLocal<Context>());
CpuProfilingOptions(CpuProfilingOptions&&) = default;
CpuProfilingOptions& operator=(CpuProfilingOptions&&) = default;
CpuProfilingMode mode() const { return mode_; }
unsigned max_samples() const { return max_samples_; }
int sampling_interval_us() const { return sampling_interval_us_; }
......@@ -344,7 +347,7 @@ class V8_EXPORT CpuProfilingOptions {
CpuProfilingMode mode_;
unsigned max_samples_;
int sampling_interval_us_;
CopyablePersistentTraits<Context>::CopyablePersistent filter_context_;
Global<Context> filter_context_;
};
/**
......
......@@ -237,18 +237,7 @@ class V8_EXPORT WasmModuleObjectBuilderStreaming final {
WasmModuleObjectBuilderStreaming&&) = default;
Isolate* v8_isolate_ = nullptr;
#if V8_CC_MSVC
/**
* We don't need the static Copy API, so the default
* NonCopyablePersistentTraits would be sufficient, however,
* MSVC eagerly instantiates the Copy.
* We ensure we don't use Copy, however, by compiling with the
* defaults everywhere else.
*/
Persistent<Promise, CopyablePersistentTraits<Promise>> promise_;
#else
Persistent<Promise> promise_;
#endif
v8::Global<Promise> promise_;
std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
};
......
......@@ -9935,14 +9935,14 @@ CpuProfilingResult CpuProfiler::Start(
CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate) {
return reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
options, std::move(delegate));
std::move(options), std::move(delegate));
}
CpuProfilingResult CpuProfiler::Start(
Local<String> title, CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate) {
return reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
*Utils::OpenHandle(*title), options, std::move(delegate));
*Utils::OpenHandle(*title), std::move(options), std::move(delegate));
}
CpuProfilingResult CpuProfiler::Start(Local<String> title,
......@@ -9951,7 +9951,7 @@ CpuProfilingResult CpuProfiler::Start(Local<String> title,
kLeafNodeLineNumbers,
record_samples ? CpuProfilingOptions::kNoSampleLimit : 0);
return reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
*Utils::OpenHandle(*title), options);
*Utils::OpenHandle(*title), std::move(options));
}
CpuProfilingResult CpuProfiler::Start(Local<String> title,
......@@ -9960,13 +9960,13 @@ CpuProfilingResult CpuProfiler::Start(Local<String> title,
unsigned max_samples) {
CpuProfilingOptions options(mode, record_samples ? max_samples : 0);
return reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
*Utils::OpenHandle(*title), options);
*Utils::OpenHandle(*title), std::move(options));
}
CpuProfilingStatus CpuProfiler::StartProfiling(
Local<String> title, CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate) {
return Start(title, options, std::move(delegate)).status;
return Start(title, std::move(options), std::move(delegate)).status;
}
CpuProfilingStatus CpuProfiler::StartProfiling(Local<String> title,
......
......@@ -266,9 +266,9 @@ class Utils {
template <class From, class To>
static inline Local<To> Convert(v8::internal::Handle<From> obj);
template <class T, class M>
template <class T>
static inline v8::internal::Handle<v8::internal::Object> OpenPersistent(
const v8::Persistent<T, M>& persistent) {
const v8::PersistentBase<T>& persistent) {
return v8::internal::Handle<v8::internal::Object>(
reinterpret_cast<v8::internal::Address*>(persistent.val_));
}
......
......@@ -5621,8 +5621,8 @@ int Shell::Main(int argc, char* argv[]) {
CpuProfiler* cpu_profiler;
if (options.cpu_profiler) {
cpu_profiler = CpuProfiler::New(isolate);
CpuProfilingOptions profile_options;
cpu_profiler->StartProfiling(String::Empty(isolate), profile_options);
cpu_profiler->StartProfiling(String::Empty(isolate),
CpuProfilingOptions{});
}
if (options.stress_opt) {
......
......@@ -2337,9 +2337,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
std::shared_ptr<CompilationStatistics> turbo_statistics_;
std::shared_ptr<metrics::Recorder> metrics_recorder_;
uintptr_t last_recorder_context_id_ = 0;
std::unordered_map<
uintptr_t,
Persistent<v8::Context, v8::CopyablePersistentTraits<v8::Context>>>
std::unordered_map<uintptr_t, v8::Global<v8::Context>>
recorder_context_id_map_;
size_t last_long_task_stats_counter_ = 0;
......
......@@ -602,14 +602,14 @@ size_t CpuProfiler::GetEstimatedMemoryUsage() const {
CpuProfilingResult CpuProfiler::StartProfiling(
CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate) {
return StartProfiling(nullptr, options, std::move(delegate));
return StartProfiling(nullptr, std::move(options), std::move(delegate));
}
CpuProfilingResult CpuProfiler::StartProfiling(
const char* title, CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate) {
CpuProfilingResult result =
profiles_->StartProfiling(title, options, std::move(delegate));
profiles_->StartProfiling(title, std::move(options), std::move(delegate));
// TODO(nicodubus): Revisit logic for if we want to do anything different for
// kAlreadyStarted
......@@ -626,7 +626,7 @@ CpuProfilingResult CpuProfiler::StartProfiling(
CpuProfilingResult CpuProfiler::StartProfiling(
String title, CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate) {
return StartProfiling(profiles_->GetName(title), options,
return StartProfiling(profiles_->GetName(title), std::move(options),
std::move(delegate));
}
......
......@@ -576,7 +576,7 @@ CpuProfile::CpuProfile(CpuProfiler* profiler, ProfilerId id, const char* title,
CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate)
: title_(title),
options_(options),
options_(std::move(options)),
delegate_(std::move(delegate)),
start_time_(base::TimeTicks::Now()),
top_down_(profiler->isolate(), profiler->code_entries()),
......@@ -906,7 +906,8 @@ CpuProfilingResult CpuProfilesCollection::StartProfilingForTesting(
CpuProfilingResult CpuProfilesCollection::StartProfiling(
const char* title, CpuProfilingOptions options,
std::unique_ptr<DiscardedSamplesDelegate> delegate) {
return StartProfiling(++last_id_, title, options, std::move(delegate));
return StartProfiling(++last_id_, title, std::move(options),
std::move(delegate));
}
CpuProfilingResult CpuProfilesCollection::StartProfiling(
......@@ -936,8 +937,8 @@ CpuProfilingResult CpuProfilesCollection::StartProfiling(
}
}
CpuProfile* profile =
new CpuProfile(profiler_, id, title, options, std::move(delegate));
CpuProfile* profile = new CpuProfile(profiler_, id, title, std::move(options),
std::move(delegate));
current_profiles_.emplace_back(profile);
current_profiles_semaphore_.Signal();
......
......@@ -13354,35 +13354,6 @@ TEST(DontLeakGlobalObjects) {
}
}
TEST(CopyablePersistent) {
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
i::GlobalHandles* globals =
reinterpret_cast<i::Isolate*>(isolate)->global_handles();
size_t initial_handles = globals->handles_count();
using CopyableObject =
v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object>>;
{
CopyableObject handle1;
{
v8::HandleScope scope(isolate);
handle1.Reset(isolate, v8::Object::New(isolate));
}
CHECK_EQ(initial_handles + 1, globals->handles_count());
CopyableObject handle2;
handle2 = handle1;
CHECK(handle1 == handle2);
CHECK_EQ(initial_handles + 2, globals->handles_count());
CopyableObject handle3(handle2);
CHECK(handle1 == handle3);
CHECK_EQ(initial_handles + 3, globals->handles_count());
}
// Verify autodispose
CHECK_EQ(initial_handles, globals->handles_count());
}
static void WeakApiCallback(
const v8::WeakCallbackInfo<Persistent<v8::Object>>& data) {
data.GetParameter()->Reset();
......@@ -1505,8 +1505,8 @@ STREAM_TEST(TestProfilingMidStreaming) {
// Start profiler to force code logging.
v8::CpuProfiler* cpu_profiler = v8::CpuProfiler::New(isolate);
v8::CpuProfilingOptions profile_options;
cpu_profiler->StartProfiling(v8::String::Empty(isolate), profile_options);
cpu_profiler->StartProfiling(v8::String::Empty(isolate),
v8::CpuProfilingOptions{});
// Send incomplete wire bytes and start compilation.
tester.OnBytesReceived(buffer.begin(), buffer.end() - buffer.begin());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment