v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-external-memory-accounter.h
Go to the documentation of this file.
1// Copyright 2024 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 INCLUDE_EXTERNAL_MEMORY_ACCOUNTER_H_
6#define INCLUDE_EXTERNAL_MEMORY_ACCOUNTER_H_
7
8#include <stdint.h>
9
10#include "v8-isolate.h"
11
12namespace v8 {
13
14/**
15 * This class is used to give V8 an indication of the amount of externally
16 * allocated memory that is kept alive by JavaScript objects. V8 uses this to
17 * decide when to perform garbage collections. Registering externally allocated
18 * memory will trigger garbage collections more often than it would otherwise in
19 * an attempt to garbage collect the JavaScript objects that keep the externally
20 * allocated memory alive. Instances of ExternalMemoryAccounter check that the
21 * reported external memory is back to 0 on destruction.
22 */
24 public:
25 /**
26 * Returns the amount of external memory registered for `isolate`.
27 */
29 const Isolate* isolate);
30
37
38 /**
39 * Reports an increase of `size` bytes of external memory.
40 */
41 void Increase(Isolate* isolate, size_t size);
42 /**
43 * Reports an update of `delta` bytes of external memory.
44 */
45 void Update(Isolate* isolate, int64_t delta);
46 /**
47 * Reports an decrease of `size` bytes of external memory.
48 */
49 void Decrease(Isolate* isolate, size_t size);
50
51 private:
52#ifdef V8_ENABLE_MEMORY_ACCOUNTING_CHECKS
54 v8::Isolate* isolate_ = nullptr;
55#endif
56};
57
58} // namespace v8
59
60#endif // INCLUDE_EXTERNAL_MEMORY_ACCOUNTER_H_
ExternalMemoryAccounter & operator=(ExternalMemoryAccounter &&)
void Decrease(Isolate *isolate, size_t size)
ExternalMemoryAccounter & operator=(const ExternalMemoryAccounter &)=delete
static int64_t GetTotalAmountOfExternalAllocatedMemoryForTesting(const Isolate *isolate)
ExternalMemoryAccounter(ExternalMemoryAccounter &&)
ExternalMemoryAccounter(const ExternalMemoryAccounter &)=delete
void Update(Isolate *isolate, int64_t delta)
void Increase(Isolate *isolate, size_t size)
#define V8_EXPORT
Definition v8config.h:860