Line data Source code
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_ALLOCATION_SITE_SCOPES_INL_H_
6 : #define V8_ALLOCATION_SITE_SCOPES_INL_H_
7 :
8 : #include "src/allocation-site-scopes.h"
9 :
10 : #include "src/objects/allocation-site-inl.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 819399 : void AllocationSiteContext::InitializeTraversal(Handle<AllocationSite> site) {
16 819399 : top_ = site;
17 : // {current_} is updated in place to not create unnecessary Handles, hence
18 : // we initially need a separate handle.
19 819399 : current_ = Handle<AllocationSite>::New(*top_, isolate());
20 819399 : }
21 :
22 1341414 : Handle<AllocationSite> AllocationSiteUsageContext::EnterNewScope() {
23 1341414 : if (top().is_null()) {
24 723022 : 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 1341415 : return Handle<AllocationSite>(*current(), isolate());
32 : }
33 :
34 : void 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 :
41 1627092 : bool AllocationSiteUsageContext::ShouldCreateMemento(Handle<JSObject> object) {
42 3130304 : if (activated_ && AllocationSite::CanTrack(object->map()->instance_type())) {
43 1503211 : 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_ALLOCATION_SITE_SCOPES_INL_H_
|