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