• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
42 class AllocationSiteContext {
43  public:
AllocationSiteContext(Isolate * isolate)44   explicit AllocationSiteContext(Isolate* isolate) {
45     isolate_ = isolate;
46   };
47 
top()48   Handle<AllocationSite> top() { return top_; }
current()49   Handle<AllocationSite> current() { return current_; }
50 
ShouldCreateMemento(Handle<JSObject> object)51   bool ShouldCreateMemento(Handle<JSObject> object) { return false; }
52 
isolate()53   Isolate* isolate() { return isolate_; }
54 
55  protected:
update_current_site(AllocationSite * site)56   void update_current_site(AllocationSite* site) {
57     *(current_.location()) = site;
58   }
59 
InitializeTraversal(Handle<AllocationSite> site)60   void InitializeTraversal(Handle<AllocationSite> site) {
61     top_ = site;
62     current_ = Handle<AllocationSite>(*top_, isolate());
63   }
64 
65  private:
66   Isolate* isolate_;
67   Handle<AllocationSite> top_;
68   Handle<AllocationSite> current_;
69 };
70 
71 
72 // AllocationSiteCreationContext aids in the creation of AllocationSites to
73 // accompany object literals.
74 class AllocationSiteCreationContext : public AllocationSiteContext {
75  public:
AllocationSiteCreationContext(Isolate * isolate)76   explicit AllocationSiteCreationContext(Isolate* isolate)
77       : AllocationSiteContext(isolate) { }
78 
79   Handle<AllocationSite> EnterNewScope();
80   void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object);
81 };
82 
83 
84 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed
85 // behind some/all components of a copied object literal.
86 class AllocationSiteUsageContext : public AllocationSiteContext {
87  public:
AllocationSiteUsageContext(Isolate * isolate,Handle<AllocationSite> site,bool activated)88   AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site,
89                              bool activated)
90       : AllocationSiteContext(isolate),
91         top_site_(site),
92         activated_(activated) { }
93 
EnterNewScope()94   inline Handle<AllocationSite> EnterNewScope() {
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());
102       update_current_site(AllocationSite::cast(nested_site));
103     }
104     return Handle<AllocationSite>(*current(), isolate());
105   }
106 
ExitScope(Handle<AllocationSite> scope_site,Handle<JSObject> object)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 
114   bool ShouldCreateMemento(Handle<JSObject> object);
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_
125