diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-12-10 16:19:40 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-12-10 16:01:50 +0000 |
commit | 51f6c2793adab2d864b3d2b360000ef8db1d3e92 (patch) | |
tree | 835b3b4446b012c75e80177cef9fbe6972cc7dbe /chromium/gin | |
parent | 6036726eb981b6c4b42047513b9d3f4ac865daac (diff) | |
download | qtwebengine-chromium-51f6c2793adab2d864b3d2b360000ef8db1d3e92.tar.gz |
BASELINE: Update Chromium to 71.0.3578.93
Change-Id: I6a32086c33670e1b033f8b10e6bf1fd4da1d105d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/gin')
-rw-r--r-- | chromium/gin/arguments.h | 4 | ||||
-rw-r--r-- | chromium/gin/array_buffer.cc | 21 | ||||
-rw-r--r-- | chromium/gin/interceptor_unittest.cc | 5 | ||||
-rw-r--r-- | chromium/gin/public/isolate_holder.h | 5 | ||||
-rw-r--r-- | chromium/gin/v8_initializer.cc | 107 | ||||
-rw-r--r-- | chromium/gin/v8_initializer.h | 22 | ||||
-rw-r--r-- | chromium/gin/v8_isolate_memory_dump_provider.cc | 117 | ||||
-rw-r--r-- | chromium/gin/v8_isolate_memory_dump_provider_unittest.cc | 51 | ||||
-rw-r--r-- | chromium/gin/v8_platform.cc | 18 |
9 files changed, 192 insertions, 158 deletions
diff --git a/chromium/gin/arguments.h b/chromium/gin/arguments.h index e793706f71c..234cf53502f 100644 --- a/chromium/gin/arguments.h +++ b/chromium/gin/arguments.h @@ -19,8 +19,8 @@ class GIN_EXPORT Arguments { explicit Arguments(const v8::FunctionCallbackInfo<v8::Value>& info); ~Arguments(); - template<typename T> - bool GetHolder(T* out) { + template <typename T> + bool GetHolder(T* out) const { return ConvertFromV8(isolate_, info_->Holder(), out); } diff --git a/chromium/gin/array_buffer.cc b/chromium/gin/array_buffer.cc index f84934bfd71..a02797e94f6 100644 --- a/chromium/gin/array_buffer.cc +++ b/chromium/gin/array_buffer.cc @@ -83,6 +83,7 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> { private: friend class base::RefCounted<Private>; + using DataDeleter = void (*)(void* data, size_t length, void* info); Private(v8::Isolate* isolate, v8::Local<v8::ArrayBuffer> array); ~Private(); @@ -95,9 +96,8 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> { v8::Isolate* isolate_; void* buffer_; size_t length_; - void* allocation_base_; - size_t allocation_length_; - v8::ArrayBuffer::Allocator::AllocationMode allocation_mode_; + DataDeleter deleter_; + void* deleter_data_; }; scoped_refptr<ArrayBuffer::Private> ArrayBuffer::Private::From( @@ -118,18 +118,10 @@ ArrayBuffer::Private::Private(v8::Isolate* isolate, // Take ownership of the array buffer. CHECK(!array->IsExternal()); v8::ArrayBuffer::Contents contents = array->Externalize(); - // We shouldn't receive large page-allocated array buffers. - CHECK_NE(v8::ArrayBuffer::Allocator::AllocationMode::kReservation, - contents.AllocationMode()); buffer_ = contents.Data(); length_ = contents.ByteLength(); - allocation_base_ = contents.AllocationBase(); - allocation_length_ = contents.AllocationLength(); - - DCHECK(reinterpret_cast<uintptr_t>(allocation_base_) <= - reinterpret_cast<uintptr_t>(buffer_)); - DCHECK(reinterpret_cast<uintptr_t>(buffer_) + length_ <= - reinterpret_cast<uintptr_t>(allocation_base_) + allocation_length_); + deleter_ = contents.Deleter(); + deleter_data_ = contents.DeleterData(); array->SetAlignedPointerInInternalField(kWrapperInfoIndex, &g_array_buffer_wrapper_info); @@ -141,8 +133,7 @@ ArrayBuffer::Private::Private(v8::Isolate* isolate, } ArrayBuffer::Private::~Private() { - PerIsolateData::From(isolate_)->allocator()->Free(allocation_base_, - allocation_length_); + deleter_(buffer_, length_, deleter_data_); } void ArrayBuffer::Private::FirstWeakCallback( diff --git a/chromium/gin/interceptor_unittest.cc b/chromium/gin/interceptor_unittest.cc index 4af449f961b..58f209a6023 100644 --- a/chromium/gin/interceptor_unittest.cc +++ b/chromium/gin/interceptor_unittest.cc @@ -39,7 +39,10 @@ class MyInterceptor : public Wrappable<MyInterceptor>, if (property == "value") { return ConvertToV8(isolate, value_); } else if (property == "func") { - return GetFunctionTemplate(isolate, "func")->GetFunction(); + v8::Local<v8::Context> context = isolate->GetCurrentContext(); + return GetFunctionTemplate(isolate, "func") + ->GetFunction(context) + .ToLocalChecked(); } else { return v8::Local<v8::Value>(); } diff --git a/chromium/gin/public/isolate_holder.h b/chromium/gin/public/isolate_holder.h index 6945a60181c..8cb2646bdd7 100644 --- a/chromium/gin/public/isolate_holder.h +++ b/chromium/gin/public/isolate_holder.h @@ -70,8 +70,9 @@ class GIN_EXPORT IsolateHolder { kUtility }; - IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, - IsolateType isolate_type); + explicit IsolateHolder( + scoped_refptr<base::SingleThreadTaskRunner> task_runner, + IsolateType isolate_type); IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, AccessMode access_mode, IsolateType isolate_type); diff --git a/chromium/gin/v8_initializer.cc b/chromium/gin/v8_initializer.cc index cf51b27dd99..48116401c0b 100644 --- a/chromium/gin/v8_initializer.cc +++ b/chromium/gin/v8_initializer.cc @@ -61,15 +61,6 @@ void GetMappedFileData(base::MemoryMappedFile* mapped_file, #if defined(V8_USE_EXTERNAL_STARTUP_DATA) -// File handles intentionally never closed. Not using File here because its -// Windows implementation guards against two instances owning the same -// PlatformFile (which we allow since we know it is never freed). -using OpenedFileMap = - std::map<const char*, - std::pair<base::PlatformFile, base::MemoryMappedFile::Region>>; -base::LazyInstance<OpenedFileMap>::Leaky g_opened_files = - LAZY_INSTANCE_INITIALIZER; - const char kNativesFileName[] = "natives_blob.bin"; #if defined(OS_ANDROID) @@ -120,21 +111,21 @@ void GetV8FilePath(const char* file_name, base::FilePath* path_out) { #endif } -bool MapV8File(base::PlatformFile platform_file, +bool MapV8File(base::File file, base::MemoryMappedFile::Region region, base::MemoryMappedFile** mmapped_file_out) { DCHECK(*mmapped_file_out == NULL); std::unique_ptr<base::MemoryMappedFile> mmapped_file( new base::MemoryMappedFile()); - if (mmapped_file->Initialize(base::File(platform_file), region)) { + if (mmapped_file->Initialize(std::move(file), region)) { *mmapped_file_out = mmapped_file.release(); return true; } return false; } -base::PlatformFile OpenV8File(const char* file_name, - base::MemoryMappedFile::Region* region_out) { +base::File OpenV8File(const char* file_name, + base::MemoryMappedFile::Region* region_out) { // Re-try logic here is motivated by http://crbug.com/479537 // for A/V on Windows (https://support.microsoft.com/en-us/kb/316609). @@ -197,20 +188,7 @@ base::PlatformFile OpenV8File(const char* file_name, UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", result, OpenV8FileResult::MAX_VALUE); - return file.TakePlatformFile(); -} - -OpenedFileMap::mapped_type& GetOpenedFile(const char* filename) { - OpenedFileMap& opened_files(g_opened_files.Get()); - auto result = opened_files.emplace(filename, OpenedFileMap::mapped_type()); - OpenedFileMap::mapped_type& opened_file = result.first->second; - bool is_new_file = result.second; - - // If we have no cache, try to open it and cache the result. - if (is_new_file) - opened_file.first = OpenV8File(filename, &opened_file.second); - - return opened_file; + return file; } enum LoadV8FileResult { @@ -221,16 +199,7 @@ enum LoadV8FileResult { V8_LOAD_MAX_VALUE }; -LoadV8FileResult MapOpenedFile(const OpenedFileMap::mapped_type& file_region, - base::MemoryMappedFile** mmapped_file_out) { - if (file_region.first == base::kInvalidPlatformFile) - return V8_LOAD_FAILED_OPEN; - if (!MapV8File(file_region.first, file_region.second, mmapped_file_out)) - return V8_LOAD_FAILED_MAP; - return V8_LOAD_SUCCESS; -} - -#endif // defined(V8_USE_EXTERNAL_STATUP_DATA) +#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) } // namespace @@ -309,13 +278,10 @@ void V8Initializer::LoadV8Snapshot(V8SnapshotFileType snapshot_file_type) { return; } - LoadV8FileResult result = - MapOpenedFile(GetOpenedFile(GetSnapshotFileName(snapshot_file_type)), - &g_mapped_snapshot); - // V8 can't start up without the source of the natives, but it can - // start up (slower) without the snapshot. - UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, - V8_LOAD_MAX_VALUE); + base::MemoryMappedFile::Region file_region; + base::File file = + OpenV8File(GetSnapshotFileName(snapshot_file_type), &file_region); + LoadV8SnapshotFromFile(std::move(file), &file_region, snapshot_file_type); } // static @@ -323,65 +289,56 @@ void V8Initializer::LoadV8Natives() { if (g_mapped_natives) return; - LoadV8FileResult result = MapOpenedFile(GetOpenedFile(kNativesFileName), - &g_mapped_natives); - if (result != V8_LOAD_SUCCESS) { - LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is " - << static_cast<int>(result); - } + base::MemoryMappedFile::Region file_region; + base::File file = OpenV8File(kNativesFileName, &file_region); + LoadV8NativesFromFile(std::move(file), &file_region); } // static -void V8Initializer::LoadV8SnapshotFromFD( - base::PlatformFile snapshot_pf, - int64_t snapshot_offset, - int64_t snapshot_size, +void V8Initializer::LoadV8SnapshotFromFile( + base::File snapshot_file, + base::MemoryMappedFile::Region* snapshot_file_region, V8SnapshotFileType snapshot_file_type) { if (g_mapped_snapshot) return; - if (snapshot_pf == base::kInvalidPlatformFile) + if (!snapshot_file.IsValid()) { + UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", + V8_LOAD_FAILED_OPEN, V8_LOAD_MAX_VALUE); return; + } - base::MemoryMappedFile::Region snapshot_region = + base::MemoryMappedFile::Region region = base::MemoryMappedFile::Region::kWholeFile; - if (snapshot_size != 0 || snapshot_offset != 0) { - snapshot_region.offset = snapshot_offset; - snapshot_region.size = snapshot_size; + if (snapshot_file_region) { + region = *snapshot_file_region; } LoadV8FileResult result = V8_LOAD_SUCCESS; - if (!MapV8File(snapshot_pf, snapshot_region, &g_mapped_snapshot)) + if (!MapV8File(std::move(snapshot_file), region, &g_mapped_snapshot)) result = V8_LOAD_FAILED_MAP; - if (result == V8_LOAD_SUCCESS) { - g_opened_files.Get()[GetSnapshotFileName(snapshot_file_type)] = - std::make_pair(snapshot_pf, snapshot_region); - } UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, V8_LOAD_MAX_VALUE); } // static -void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf, - int64_t natives_offset, - int64_t natives_size) { +void V8Initializer::LoadV8NativesFromFile( + base::File natives_file, + base::MemoryMappedFile::Region* natives_file_region) { if (g_mapped_natives) return; - CHECK_NE(natives_pf, base::kInvalidPlatformFile); + CHECK(natives_file.IsValid()); - base::MemoryMappedFile::Region natives_region = + base::MemoryMappedFile::Region region = base::MemoryMappedFile::Region::kWholeFile; - if (natives_size != 0 || natives_offset != 0) { - natives_region.offset = natives_offset; - natives_region.size = natives_size; + if (natives_file_region) { + region = *natives_file_region; } - if (!MapV8File(natives_pf, natives_region, &g_mapped_natives)) { + if (!MapV8File(std::move(natives_file), region, &g_mapped_natives)) { LOG(FATAL) << "Couldn't mmap v8 natives data file"; } - g_opened_files.Get()[kNativesFileName] = - std::make_pair(natives_pf, natives_region); } #if defined(OS_ANDROID) diff --git a/chromium/gin/v8_initializer.h b/chromium/gin/v8_initializer.h index 6f3265ba4d0..a749ccbecfc 100644 --- a/chromium/gin/v8_initializer.h +++ b/chromium/gin/v8_initializer.h @@ -50,20 +50,20 @@ class GIN_EXPORT V8Initializer { // so that it will not return if natives cannot be loaded. static void LoadV8Natives(); - // Load V8 snapshot from user provided platform file descriptors. - // The offset and size arguments, if non-zero, specify the portions - // of the files to be loaded. Since the VM can boot with or without + // Load V8 snapshot from user provided file. + // The region argument, if non-zero, specifies the portions + // of the files to be mapped. Since the VM can boot with or without // the snapshot, this function does not return a status. - static void LoadV8SnapshotFromFD(base::PlatformFile snapshot_fd, - int64_t snapshot_offset, - int64_t snapshot_size, - V8SnapshotFileType snapshot_file_type); - // Similar to LoadV8SnapshotFromFD, but for the source of the natives. + static void LoadV8SnapshotFromFile( + base::File snapshot_file, + base::MemoryMappedFile::Region* snapshot_file_region, + V8SnapshotFileType snapshot_file_type); + // Similar to LoadV8SnapshotFromFile, but for the source of the natives. // Without the natives we cannot continue, so this function contains // release mode asserts and won't return if it fails. - static void LoadV8NativesFromFD(base::PlatformFile natives_fd, - int64_t natives_offset, - int64_t natives_size); + static void LoadV8NativesFromFile( + base::File natives_file, + base::MemoryMappedFile::Region* natives_file_region); #if defined(OS_ANDROID) static base::FilePath GetNativesFilePath(); diff --git a/chromium/gin/v8_isolate_memory_dump_provider.cc b/chromium/gin/v8_isolate_memory_dump_provider.cc index 604c04d4635..fe14263836c 100644 --- a/chromium/gin/v8_isolate_memory_dump_provider.cc +++ b/chromium/gin/v8_isolate_memory_dump_provider.cc @@ -50,9 +50,8 @@ namespace { // Dump statistics related to code/bytecode when memory-infra.v8.code_stats is // enabled. -void DumpCodeStatistics( - base::trace_event::MemoryAllocatorDump* heap_spaces_dump, - IsolateHolder* isolate_holder) { +void DumpCodeStatistics(base::trace_event::MemoryAllocatorDump* dump, + IsolateHolder* isolate_holder) { // Collecting code statistics is an expensive operation (~10 ms) when // compared to other v8 metrics (< 1 ms). So, dump them only when // memory-infra.v8.code_stats is enabled. @@ -71,43 +70,49 @@ void DumpCodeStatistics( return; } - heap_spaces_dump->AddScalar( - "code_and_metadata_size", - base::trace_event::MemoryAllocatorDump::kUnitsBytes, - code_statistics.code_and_metadata_size()); - heap_spaces_dump->AddScalar( - "bytecode_and_metadata_size", - base::trace_event::MemoryAllocatorDump::kUnitsBytes, - code_statistics.bytecode_and_metadata_size()); - heap_spaces_dump->AddScalar( - "external_script_source_size", - base::trace_event::MemoryAllocatorDump::kUnitsBytes, - code_statistics.external_script_source_size()); + dump->AddScalar("code_and_metadata_size", + base::trace_event::MemoryAllocatorDump::kUnitsBytes, + code_statistics.code_and_metadata_size()); + dump->AddScalar("bytecode_and_metadata_size", + base::trace_event::MemoryAllocatorDump::kUnitsBytes, + code_statistics.bytecode_and_metadata_size()); + dump->AddScalar("external_script_source_size", + base::trace_event::MemoryAllocatorDump::kUnitsBytes, + code_statistics.external_script_source_size()); } // Dump the number of native and detached contexts. // The result looks as follows in the Chrome trace viewer: -// ====================================== -// Component object_count +// ======================================== +// Component object_count // - v8 -// - isolate +// - main // - contexts // - detached_context 10 // - native_context 20 -// ====================================== +// - workers +// - contexts +// - detached_context +// - isolate_0x1234 10 +// - native_context +// - isolate_0x1234 20 +// ======================================== void DumpContextStatistics( base::trace_event::ProcessMemoryDump* process_memory_dump, std::string dump_base_name, + std::string dump_name_suffix, size_t number_of_detached_contexts, size_t number_of_native_contexts) { std::string dump_name_prefix = dump_base_name + "/contexts"; - std::string native_context_name = dump_name_prefix + "/native_context"; + std::string native_context_name = + dump_name_prefix + "/native_context" + dump_name_suffix; auto* native_context_dump = process_memory_dump->CreateAllocatorDump(native_context_name); native_context_dump->AddScalar( "object_count", base::trace_event::MemoryAllocatorDump::kUnitsObjects, number_of_native_contexts); - std::string detached_context_name = dump_name_prefix + "/detached_context"; + std::string detached_context_name = + dump_name_prefix + "/detached_context" + dump_name_suffix; auto* detached_context_dump = process_memory_dump->CreateAllocatorDump(detached_context_name); detached_context_dump->AddScalar( @@ -115,20 +120,57 @@ void DumpContextStatistics( number_of_detached_contexts); } +std::string IsolateTypeString(IsolateHolder::IsolateType isolate_type) { + switch (isolate_type) { + case IsolateHolder::IsolateType::kBlinkMainThread: + return "main"; + case IsolateHolder::IsolateType::kBlinkWorkerThread: + return "workers"; + case IsolateHolder::IsolateType::kTest: + LOG(FATAL) << "Unreachable code"; + return "test"; + case IsolateHolder::IsolateType::kUtility: + return "utility"; + } + LOG(FATAL) << "Unreachable code"; +} + +bool CanHaveMultipleIsolates(IsolateHolder::IsolateType isolate_type) { + switch (isolate_type) { + case IsolateHolder::IsolateType::kBlinkMainThread: + return false; + case IsolateHolder::IsolateType::kBlinkWorkerThread: + return true; + case IsolateHolder::IsolateType::kTest: + LOG(FATAL) << "Unreachable code"; + return false; + case IsolateHolder::IsolateType::kUtility: + // PDFium and ProxyResolver create one isolate per process. + return false; + } + LOG(FATAL) << "Unreachable code"; +} + } // namespace anonymous void V8IsolateMemoryDumpProvider::DumpHeapStatistics( const base::trace_event::MemoryDumpArgs& args, base::trace_event::ProcessMemoryDump* process_memory_dump) { - std::string dump_base_name = base::StringPrintf( - "v8/isolate_0x%" PRIXPTR, + std::string isolate_name = base::StringPrintf( + "isolate_0x%" PRIXPTR, reinterpret_cast<uintptr_t>(isolate_holder_->isolate())); // Dump statistics of the heap's spaces. - std::string space_name_prefix = dump_base_name + "/heap_spaces"; v8::HeapStatistics heap_statistics; isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics); + IsolateHolder::IsolateType isolate_type = isolate_holder_->isolate_type(); + std::string dump_base_name = "v8/" + IsolateTypeString(isolate_type); + std::string dump_name_suffix = + CanHaveMultipleIsolates(isolate_type) ? "/" + isolate_name : ""; + + std::string space_name_prefix = dump_base_name + "/heap"; + size_t known_spaces_used_size = 0; size_t known_spaces_size = 0; size_t known_spaces_physical_size = 0; @@ -145,14 +187,15 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics( known_spaces_used_size += space_used_size; known_spaces_physical_size += space_physical_size; - std::string space_dump_name = - space_name_prefix + "/" + space_statistics.space_name(); + std::string space_dump_name = dump_base_name + "/heap/" + + space_statistics.space_name() + + dump_name_suffix; + auto* space_dump = process_memory_dump->CreateAllocatorDump(space_dump_name); space_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, base::trace_event::MemoryAllocatorDump::kUnitsBytes, space_physical_size); - space_dump->AddScalar("virtual_size", base::trace_event::MemoryAllocatorDump::kUnitsBytes, space_size); @@ -172,7 +215,7 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics( // resident values. if (heap_statistics.does_zap_garbage()) { auto* zap_dump = process_memory_dump->CreateAllocatorDump( - dump_base_name + "/zapped_for_debug"); + dump_base_name + "/zapped_for_debug" + dump_name_suffix); zap_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, base::trace_event::MemoryAllocatorDump::kUnitsBytes, heap_statistics.total_heap_size() - @@ -180,7 +223,7 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics( } // Dump statistics about malloced memory. - std::string malloc_name = dump_base_name + "/malloc"; + std::string malloc_name = dump_base_name + "/malloc" + dump_name_suffix; auto* malloc_dump = process_memory_dump->CreateAllocatorDump(malloc_name); malloc_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, base::trace_event::MemoryAllocatorDump::kUnitsBytes, @@ -196,17 +239,15 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics( system_allocator_name); } - DumpContextStatistics(process_memory_dump, dump_base_name, + DumpContextStatistics(process_memory_dump, dump_base_name, dump_name_suffix, heap_statistics.number_of_detached_contexts(), heap_statistics.number_of_native_contexts()); - // Add an empty row for the heap_spaces. This is to keep the shape of the - // dump stable, whether code stats are enabled or not. - auto* heap_spaces_dump = - process_memory_dump->CreateAllocatorDump(space_name_prefix); + auto* code_stats_dump = process_memory_dump->CreateAllocatorDump( + dump_base_name + "/code_stats" + dump_name_suffix); // Dump statistics related to code and bytecode if requested. - DumpCodeStatistics(heap_spaces_dump, isolate_holder_); + DumpCodeStatistics(code_stats_dump, isolate_holder_); // Dump object statistics only for detailed dumps. if (args.level_of_detail != @@ -217,7 +258,8 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics( // Dump statistics of the heap's live objects from last GC. // TODO(primiano): these should not be tracked in the same trace event as they // report stats for the last GC (not the current state). See crbug.com/498779. - std::string object_name_prefix = dump_base_name + "/heap_objects_at_last_gc"; + std::string object_name_prefix = + dump_base_name + "/heap_objects_at_last_gc" + dump_name_suffix; bool did_dump_object_stats = false; const size_t object_types = isolate_holder_->isolate()->NumberOfTrackedHeapObjectTypes(); @@ -256,7 +298,8 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics( if (did_dump_object_stats) { process_memory_dump->AddOwnershipEdge( process_memory_dump->CreateAllocatorDump(object_name_prefix)->guid(), - heap_spaces_dump->guid()); + process_memory_dump->GetOrCreateAllocatorDump(space_name_prefix) + ->guid()); } } diff --git a/chromium/gin/v8_isolate_memory_dump_provider_unittest.cc b/chromium/gin/v8_isolate_memory_dump_provider_unittest.cc index db9d1ebea26..a4241085b0d 100644 --- a/chromium/gin/v8_isolate_memory_dump_provider_unittest.cc +++ b/chromium/gin/v8_isolate_memory_dump_provider_unittest.cc @@ -6,6 +6,7 @@ #include <memory> +#include "base/threading/thread_task_runner_handle.h" #include "base/trace_event/process_memory_dump.h" #include "base/trace_event/trace_event.h" #include "gin/public/isolate_holder.h" @@ -15,6 +16,15 @@ namespace gin { typedef V8Test V8MemoryDumpProviderTest; +class V8MemoryDumpProviderWorkerTest : public V8MemoryDumpProviderTest { + protected: + std::unique_ptr<IsolateHolder> CreateIsolateHolder() const override { + return std::make_unique<gin::IsolateHolder>( + base::ThreadTaskRunnerHandle::Get(), + gin::IsolateHolder::IsolateType::kBlinkWorkerThread); + } +}; + // Checks if the dump provider runs without crashing and dumps root objects. TEST_F(V8MemoryDumpProviderTest, DumpStatistics) { // Sets the track objects flag for dumping object statistics. Since this is @@ -38,12 +48,13 @@ TEST_F(V8MemoryDumpProviderTest, DumpStatistics) { bool did_dump_objects_stats = false; for (const auto& name_dump : allocator_dumps) { const std::string& name = name_dump.first; - if (name.find("v8/isolate") != std::string::npos) { + if (name.find("v8/main") != std::string::npos) { did_dump_isolate_stats = true; } - if (name.find("heap_spaces") != std::string::npos) { + if (name.find("v8/main/heap") != std::string::npos) { did_dump_space_stats = true; - } else if (name.find("heap_objects") != std::string::npos) { + } + if (name.find("v8/main/heap_objects") != std::string::npos) { did_dump_objects_stats = true; } } @@ -67,10 +78,38 @@ TEST_F(V8MemoryDumpProviderTest, DumpContextStatistics) { bool did_dump_native_contexts = false; for (const auto& name_dump : allocator_dumps) { const std::string& name = name_dump.first; - if (name.find("contexts/detached_context") != std::string::npos) { + if (name.find("main/contexts/detached_context") != std::string::npos) { + did_dump_detached_contexts = true; + } + if (name.find("main/contexts/native_context") != std::string::npos) { + did_dump_native_contexts = true; + } + } + + ASSERT_TRUE(did_dump_detached_contexts); + ASSERT_TRUE(did_dump_native_contexts); +} + +TEST_F(V8MemoryDumpProviderWorkerTest, DumpContextStatistics) { + base::trace_event::MemoryDumpArgs dump_args = { + base::trace_event::MemoryDumpLevelOfDetail::LIGHT}; + std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( + new base::trace_event::ProcessMemoryDump(dump_args)); + instance_->isolate_memory_dump_provider_for_testing()->OnMemoryDump( + dump_args, process_memory_dump.get()); + const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& + allocator_dumps = process_memory_dump->allocator_dumps(); + + bool did_dump_detached_contexts = false; + bool did_dump_native_contexts = false; + for (const auto& name_dump : allocator_dumps) { + const std::string& name = name_dump.first; + if (name.find("workers/contexts/detached_context/isolate_0x") != + std::string::npos) { did_dump_detached_contexts = true; } - if (name.find("contexts/native_context") != std::string::npos) { + if (name.find("workers/contexts/native_context/isolate_0x") != + std::string::npos) { did_dump_native_contexts = true; } } @@ -101,7 +140,7 @@ TEST_F(V8MemoryDumpProviderTest, DumpCodeStatistics) { for (const auto& name_dump : allocator_dumps) { const std::string& name = name_dump.first; - if (name.find("heap_spaces") != std::string::npos) { + if (name.find("code_stats") != std::string::npos) { for (const base::trace_event::MemoryAllocatorDump::Entry& entry : name_dump.second->entries()) { if (entry.name == "bytecode_and_metadata_size") { diff --git a/chromium/gin/v8_platform.cc b/chromium/gin/v8_platform.cc index 84555603f58..0f42722c2fc 100644 --- a/chromium/gin/v8_platform.cc +++ b/chromium/gin/v8_platform.cc @@ -60,7 +60,14 @@ class ConvertableToTraceFormatWrapper final class EnabledStateObserverImpl final : public base::trace_event::TraceLog::EnabledStateObserver { public: - EnabledStateObserverImpl() = default; + EnabledStateObserverImpl() { + base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this); + } + + ~EnabledStateObserverImpl() override { + base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver( + this); + } void OnTraceLogEnabled() final { base::AutoLock lock(mutex_); @@ -80,12 +87,9 @@ class EnabledStateObserverImpl final { base::AutoLock lock(mutex_); DCHECK(!observers_.count(observer)); - if (observers_.empty()) { - base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver( - this); - } observers_.insert(observer); } + // Fire the observer if recording is already in progress. if (base::trace_event::TraceLog::GetInstance()->IsEnabled()) observer->OnTraceEnabled(); @@ -95,10 +99,6 @@ class EnabledStateObserverImpl final base::AutoLock lock(mutex_); DCHECK(observers_.count(observer) == 1); observers_.erase(observer); - if (observers_.empty()) { - base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver( - this); - } } private: |