Line data Source code
1 : // Copyright 2018 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 : #include "src/objects/managed.h"
6 :
7 : namespace v8 {
8 : namespace internal {
9 :
10 : namespace {
11 : // Called by the GC in its second pass when a Managed<CppType> is
12 : // garbage collected.
13 5253820 : void ManagedObjectFinalizerSecondPass(const v8::WeakCallbackInfo<void>& data) {
14 : auto destructor =
15 : reinterpret_cast<ManagedPtrDestructor*>(data.GetParameter());
16 : Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
17 2626910 : isolate->UnregisterManagedPtrDestructor(destructor);
18 2626910 : int64_t adjustment = 0 - static_cast<int64_t>(destructor->estimated_size_);
19 2626910 : destructor->destructor_(destructor->shared_ptr_ptr_);
20 2626910 : delete destructor;
21 : data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory(adjustment);
22 2626910 : }
23 : } // namespace
24 :
25 : // Called by the GC in its first pass when a Managed<CppType> is
26 : // garbage collected.
27 5253820 : void ManagedObjectFinalizer(const v8::WeakCallbackInfo<void>& data) {
28 : auto destructor =
29 : reinterpret_cast<ManagedPtrDestructor*>(data.GetParameter());
30 2626910 : GlobalHandles::Destroy(destructor->global_handle_location_);
31 : // We need to do the main work as a second pass callback because
32 : // it can trigger garbage collection. The first pass callbacks
33 : // are not allowed to invoke V8 API.
34 : data.SetSecondPassCallback(&ManagedObjectFinalizerSecondPass);
35 2626910 : }
36 :
37 : } // namespace internal
38 178779 : } // namespace v8
|