1 // Copyright 2013 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/allocation-site-scopes.h" 6 #include "src/factory.h" 7 #include "src/isolate.h" 8 #include "src/objects-inl.h" 9 10 namespace v8 { 11 namespace internal { 12 13 14 Handle<AllocationSite> AllocationSiteCreationContext::EnterNewScope() { 15 Handle<AllocationSite> scope_site; 16 if (top().is_null()) { 17 // We are creating the top level AllocationSite as opposed to a nested 18 // AllocationSite. 19 InitializeTraversal(isolate()->factory()->NewAllocationSite()); 20 scope_site = Handle<AllocationSite>(*top(), isolate()); 21 if (FLAG_trace_creation_allocation_sites) { 22 PrintF("*** Creating top level AllocationSite %p\n", 23 static_cast<void*>(*scope_site)); 24 } 25 } else { 26 DCHECK(!current().is_null()); 27 scope_site = isolate()->factory()->NewAllocationSite(); 28 if (FLAG_trace_creation_allocation_sites) { 29 PrintF("Creating nested site (top, current, new) (%p, %p, %p)\n", 30 static_cast<void*>(*top()), 31 static_cast<void*>(*current()), 32 static_cast<void*>(*scope_site)); 33 } 34 current()->set_nested_site(*scope_site); 35 update_current_site(*scope_site); 36 } 37 DCHECK(!scope_site.is_null()); 38 return scope_site; 39 } 40 41 42 void AllocationSiteCreationContext::ExitScope( 43 Handle<AllocationSite> scope_site, 44 Handle<JSObject> object) { 45 if (!object.is_null()) { 46 bool top_level = !scope_site.is_null() && 47 top().is_identical_to(scope_site); 48 49 scope_site->set_transition_info(*object); 50 if (FLAG_trace_creation_allocation_sites) { 51 if (top_level) { 52 PrintF("*** Setting AllocationSite %p transition_info %p\n", 53 static_cast<void*>(*scope_site), 54 static_cast<void*>(*object)); 55 } else { 56 PrintF("Setting AllocationSite (%p, %p) transition_info %p\n", 57 static_cast<void*>(*top()), 58 static_cast<void*>(*scope_site), 59 static_cast<void*>(*object)); 60 } 61 } 62 } 63 } 64 65 66 bool AllocationSiteUsageContext::ShouldCreateMemento(Handle<JSObject> object) { 67 if (activated_ && AllocationSite::CanTrack(object->map()->instance_type())) { 68 if (FLAG_allocation_site_pretenuring || 69 AllocationSite::GetMode(object->GetElementsKind()) == 70 TRACK_ALLOCATION_SITE) { 71 if (FLAG_trace_creation_allocation_sites) { 72 PrintF("*** Creating Memento for %s %p\n", 73 object->IsJSArray() ? "JSArray" : "JSObject", 74 static_cast<void*>(*object)); 75 } 76 return true; 77 } 78 } 79 return false; 80 } 81 82 } // namespace internal 83 } // namespace v8 84