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 #ifndef V8_OBJECTS_ALLOCATION_SITE_SCOPES_INL_H_ 6 #define V8_OBJECTS_ALLOCATION_SITE_SCOPES_INL_H_ 7 8 #include "src/objects/allocation-site-scopes.h" 9 10 #include "src/objects/allocation-site-inl.h" 11 12 namespace v8 { 13 namespace internal { 14 InitializeTraversal(Handle<AllocationSite> site)15void AllocationSiteContext::InitializeTraversal(Handle<AllocationSite> site) { 16 top_ = site; 17 // {current_} is updated in place to not create unnecessary Handles, hence 18 // we initially need a separate handle. 19 current_ = Handle<AllocationSite>::New(*top_, isolate()); 20 } 21 EnterNewScope()22Handle<AllocationSite> AllocationSiteUsageContext::EnterNewScope() { 23 if (top().is_null()) { 24 InitializeTraversal(top_site_); 25 } else { 26 // Advance current site 27 Object nested_site = current()->nested_site(); 28 // Something is wrong if we advance to the end of the list here. 29 update_current_site(AllocationSite::cast(nested_site)); 30 } 31 return Handle<AllocationSite>(*current(), isolate()); 32 } 33 ExitScope(Handle<AllocationSite> scope_site,Handle<JSObject> object)34void AllocationSiteUsageContext::ExitScope(Handle<AllocationSite> scope_site, 35 Handle<JSObject> object) { 36 // This assert ensures that we are pointing at the right sub-object in a 37 // recursive walk of a nested literal. 38 DCHECK(object.is_null() || *object == scope_site->boilerplate()); 39 } 40 ShouldCreateMemento(Handle<JSObject> object)41bool AllocationSiteUsageContext::ShouldCreateMemento(Handle<JSObject> object) { 42 if (activated_ && AllocationSite::CanTrack(object->map().instance_type())) { 43 if (FLAG_allocation_site_pretenuring || 44 AllocationSite::ShouldTrack(object->GetElementsKind())) { 45 if (FLAG_trace_creation_allocation_sites) { 46 PrintF("*** Creating Memento for %s %p\n", 47 object->IsJSArray() ? "JSArray" : "JSObject", 48 reinterpret_cast<void*>(object->ptr())); 49 } 50 return true; 51 } 52 } 53 return false; 54 } 55 56 } // namespace internal 57 } // namespace v8 58 59 #endif // V8_OBJECTS_ALLOCATION_SITE_SCOPES_INL_H_ 60