1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "allocation-site-scopes.h"
29
30 namespace v8 {
31 namespace internal {
32
33
EnterNewScope()34 Handle<AllocationSite> AllocationSiteCreationContext::EnterNewScope() {
35 Handle<AllocationSite> scope_site;
36 if (top().is_null()) {
37 // We are creating the top level AllocationSite as opposed to a nested
38 // AllocationSite.
39 InitializeTraversal(isolate()->factory()->NewAllocationSite());
40 scope_site = Handle<AllocationSite>(*top(), isolate());
41 if (FLAG_trace_creation_allocation_sites) {
42 PrintF("*** Creating top level AllocationSite %p\n",
43 static_cast<void*>(*scope_site));
44 }
45 } else {
46 ASSERT(!current().is_null());
47 scope_site = isolate()->factory()->NewAllocationSite();
48 if (FLAG_trace_creation_allocation_sites) {
49 PrintF("Creating nested site (top, current, new) (%p, %p, %p)\n",
50 static_cast<void*>(*top()),
51 static_cast<void*>(*current()),
52 static_cast<void*>(*scope_site));
53 }
54 current()->set_nested_site(*scope_site);
55 update_current_site(*scope_site);
56 }
57 ASSERT(!scope_site.is_null());
58 return scope_site;
59 }
60
61
ExitScope(Handle<AllocationSite> scope_site,Handle<JSObject> object)62 void AllocationSiteCreationContext::ExitScope(
63 Handle<AllocationSite> scope_site,
64 Handle<JSObject> object) {
65 if (!object.is_null() && !object->IsFailure()) {
66 bool top_level = !scope_site.is_null() &&
67 top().is_identical_to(scope_site);
68
69 scope_site->set_transition_info(*object);
70 if (FLAG_trace_creation_allocation_sites) {
71 if (top_level) {
72 PrintF("*** Setting AllocationSite %p transition_info %p\n",
73 static_cast<void*>(*scope_site),
74 static_cast<void*>(*object));
75 } else {
76 PrintF("Setting AllocationSite (%p, %p) transition_info %p\n",
77 static_cast<void*>(*top()),
78 static_cast<void*>(*scope_site),
79 static_cast<void*>(*object));
80 }
81 }
82 }
83 }
84
85
ShouldCreateMemento(Handle<JSObject> object)86 bool AllocationSiteUsageContext::ShouldCreateMemento(Handle<JSObject> object) {
87 if (activated_ && AllocationSite::CanTrack(object->map()->instance_type())) {
88 if (FLAG_allocation_site_pretenuring ||
89 AllocationSite::GetMode(object->GetElementsKind()) ==
90 TRACK_ALLOCATION_SITE) {
91 if (FLAG_trace_creation_allocation_sites) {
92 PrintF("*** Creating Memento for %s %p\n",
93 object->IsJSArray() ? "JSArray" : "JSObject",
94 static_cast<void*>(*object));
95 }
96 return true;
97 }
98 }
99 return false;
100 }
101
102 } } // namespace v8::internal
103