v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
memory-measurement.h
Go to the documentation of this file.
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_HEAP_MEMORY_MEASUREMENT_H_
6#define V8_HEAP_MEMORY_MEASUREMENT_H_
7
8#include <list>
9#include <unordered_map>
10
14#include "src/common/globals.h"
16#include "src/objects/map.h"
17#include "src/objects/objects.h"
18
19namespace v8 {
20namespace internal {
21
22class Heap;
23class NativeContextStats;
24
26 public:
27 explicit MemoryMeasurement(Isolate* isolate);
28
29 bool EnqueueRequest(std::unique_ptr<v8::MeasureMemoryDelegate> delegate,
31 const std::vector<Handle<NativeContext>> contexts);
32 std::vector<Address> StartProcessing();
33 void FinishProcessing(const NativeContextStats& stats);
34
35 static std::unique_ptr<v8::MeasureMemoryDelegate> DefaultDelegate(
36 v8::Isolate* isolate, v8::Local<v8::Context> context,
38
39 private:
40 static const int kGCTaskDelayInSeconds = 10;
41 struct Request {
42 std::unique_ptr<v8::MeasureMemoryDelegate> delegate;
44 std::vector<size_t> sizes;
45 size_t shared;
46 size_t wasm_code;
49 };
51 void ReportResults();
57
58 std::list<Request> received_;
59 std::list<Request> processing_;
60 std::list<Request> done_;
62 std::shared_ptr<v8::TaskRunner> task_runner_;
67};
68
69// Infers the native context for some of the heap objects.
71 public:
72 // The native_context parameter is both the input and output parameter.
73 // It should be initialized to the context that will be used for the object
74 // if the inference is not successful. The function performs more work if the
75 // context is the shared context.
76 V8_INLINE bool Infer(PtrComprCageBase cage_base, Tagged<Map> map,
77 Tagged<HeapObject> object, Address* native_context);
78};
79
80// Maintains mapping from native contexts to their sizes.
82 public:
83 V8_INLINE void IncrementSize(Address context, Tagged<Map> map,
84 Tagged<HeapObject> object, size_t size);
85
86 size_t Get(Address context) const {
87 const auto it = size_by_context_.find(context);
88 if (it == size_by_context_.end()) return 0;
89 return it->second;
90 }
91 void Clear();
92 void Merge(const NativeContextStats& other);
93
94 bool Empty() const { return size_by_context_.empty(); }
95
96 private:
97 V8_INLINE bool HasExternalBytes(Tagged<Map> map);
98 void IncrementExternalSize(Address context, Tagged<Map> map,
99 Tagged<HeapObject> object);
100 std::unordered_map<Address, size_t> size_by_context_;
101};
102
103} // namespace internal
104} // namespace v8
105
106#endif // V8_HEAP_MEMORY_MEASUREMENT_H_
std::vector< Address > StartProcessing()
bool EnqueueRequest(std::unique_ptr< v8::MeasureMemoryDelegate > delegate, v8::MeasureMemoryExecution execution, const std::vector< Handle< NativeContext > > contexts)
bool IsGCTaskPending(v8::MeasureMemoryExecution execution)
base::RandomNumberGenerator random_number_generator_
void FinishProcessing(const NativeContextStats &stats)
static std::unique_ptr< v8::MeasureMemoryDelegate > DefaultDelegate(v8::Isolate *isolate, v8::Local< v8::Context > context, v8::Local< v8::Promise::Resolver > promise, v8::MeasureMemoryMode mode)
std::shared_ptr< v8::TaskRunner > task_runner_
void SetGCTaskPending(v8::MeasureMemoryExecution execution)
void ScheduleGCTask(v8::MeasureMemoryExecution execution)
void SetGCTaskDone(v8::MeasureMemoryExecution execution)
std::unordered_map< Address, size_t > size_by_context_
size_t Get(Address context) const
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
MeasureMemoryExecution
MeasureMemoryMode
#define V8_EXPORT_PRIVATE
Definition macros.h:460
std::unique_ptr< v8::MeasureMemoryDelegate > delegate
#define V8_INLINE
Definition v8config.h:500