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