v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
weak-code-registry.cc
Go to the documentation of this file.
1// Copyright 2021 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
6
10
11namespace v8 {
12namespace internal {
13
14namespace {
15
16void Untrack(CodeEntry* entry) {
17 if (Address** heap_object_location_address =
18 entry->heap_object_location_address()) {
19 GlobalHandles::Destroy(*heap_object_location_address);
20 *heap_object_location_address = nullptr;
21 }
22}
23
24} // namespace
25
31
32 Address** heap_object_location_address =
34 *heap_object_location_address = handle.location();
35 GlobalHandles::MakeWeak(heap_object_location_address);
36
37 entries_.push_back(entry);
38}
39
41 std::vector<CodeEntry*> alive_entries;
42 for (CodeEntry* entry : entries_) {
43 // Mark the CodeEntry as being deleted on the heap if the heap object
44 // location was nulled, indicating the object was freed.
45 if (!*entry->heap_object_location_address()) {
46 if (listener) {
47 listener->OnHeapObjectDeletion(entry);
48 }
49 } else {
50 alive_entries.push_back(entry);
51 }
52 }
53 entries_ = std::move(alive_entries);
54}
55
57 for (CodeEntry* entry : entries_) {
58 Untrack(entry);
59 }
60 entries_.clear();
61}
62
63} // namespace internal
64} // namespace v8
Address ** heap_object_location_address()
static void Destroy(Address *location)
static void MakeWeak(Address *location, void *parameter, WeakCallbackInfo< void >::Callback weak_callback, v8::WeakCallbackType type)
IndirectHandle< Object > Create(Tagged< Object > value)
GlobalHandles * global_handles() const
Definition isolate.h:1416
void Sweep(Listener *listener)
void Track(CodeEntry *entry, DirectHandle< AbstractCode > code)
std::vector< CodeEntry * > entries_
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
#define DCHECK(condition)
Definition logging.h:482
virtual void OnHeapObjectDeletion(CodeEntry *entry)=0