v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocation-site-scopes.h
Go to the documentation of this file.
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 #ifndef V8_ALLOCATION_SITE_SCOPES_H_
29 #define V8_ALLOCATION_SITE_SCOPES_H_
30 
31 #include "ast.h"
32 #include "handles.h"
33 #include "objects.h"
34 #include "zone.h"
35 
36 namespace v8 {
37 namespace internal {
38 
39 
40 // AllocationSiteContext is the base class for walking and copying a nested
41 // boilerplate with AllocationSite and AllocationMemento support.
43  public:
45  isolate_ = isolate;
46  };
47 
48  Handle<AllocationSite> top() { return top_; }
49  Handle<AllocationSite> current() { return current_; }
50 
51  bool ShouldCreateMemento(Handle<JSObject> object) { return false; }
52 
53  Isolate* isolate() { return isolate_; }
54 
55  protected:
57  *(current_.location()) = site;
58  }
59 
61  top_ = site;
62  current_ = Handle<AllocationSite>(*top_, isolate());
63  }
64 
65  private:
66  Isolate* isolate_;
68  Handle<AllocationSite> current_;
69 };
70 
71 
72 // AllocationSiteCreationContext aids in the creation of AllocationSites to
73 // accompany object literals.
75  public:
77  : AllocationSiteContext(isolate) { }
78 
81 };
82 
83 
84 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed
85 // behind some/all components of a copied object literal.
87  public:
89  bool activated)
90  : AllocationSiteContext(isolate),
91  top_site_(site),
92  activated_(activated) { }
93 
95  if (top().is_null()) {
96  InitializeTraversal(top_site_);
97  } else {
98  // Advance current site
99  Object* nested_site = current()->nested_site();
100  // Something is wrong if we advance to the end of the list here.
101  ASSERT(nested_site->IsAllocationSite());
103  }
104  return Handle<AllocationSite>(*current(), isolate());
105  }
106 
107  inline void ExitScope(Handle<AllocationSite> scope_site,
108  Handle<JSObject> object) {
109  // This assert ensures that we are pointing at the right sub-object in a
110  // recursive walk of a nested literal.
111  ASSERT(object.is_null() || *object == scope_site->transition_info());
112  }
113 
115 
116  private:
117  Handle<AllocationSite> top_site_;
118  bool activated_;
119 };
120 
121 
122 } } // namespace v8::internal
123 
124 #endif // V8_ALLOCATION_SITE_SCOPES_H_
bool ShouldCreateMemento(Handle< JSObject > object)
static AllocationSite * cast(Object *obj)
#define ASSERT(condition)
Definition: checks.h:329
void update_current_site(AllocationSite *site)
AllocationSiteUsageContext(Isolate *isolate, Handle< AllocationSite > site, bool activated)
void InitializeTraversal(Handle< AllocationSite > site)
void ExitScope(Handle< AllocationSite > scope_site, Handle< JSObject > object)
bool ShouldCreateMemento(Handle< JSObject > object)
void ExitScope(Handle< AllocationSite > site, Handle< JSObject > object)