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 #ifndef V8_OBJECTS_ALLOCATION_SITE_SCOPES_H_
6 #define V8_OBJECTS_ALLOCATION_SITE_SCOPES_H_
7 
8 #include "src/handles/handles.h"
9 #include "src/objects/allocation-site.h"
10 #include "src/objects/map.h"
11 #include "src/objects/objects.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 // AllocationSiteContext is the base class for walking and copying a nested
17 // boilerplate with AllocationSite and AllocationMemento support.
18 class AllocationSiteContext {
19  public:
AllocationSiteContext(Isolate * isolate)20   explicit AllocationSiteContext(Isolate* isolate) { isolate_ = isolate; }
21 
top()22   Handle<AllocationSite> top() { return top_; }
current()23   Handle<AllocationSite> current() { return current_; }
24 
ShouldCreateMemento(Handle<JSObject> object)25   bool ShouldCreateMemento(Handle<JSObject> object) { return false; }
26 
isolate()27   Isolate* isolate() { return isolate_; }
28 
29  protected:
update_current_site(AllocationSite site)30   void update_current_site(AllocationSite site) {
31     *(current_.location()) = site.ptr();
32   }
33 
34   inline void InitializeTraversal(Handle<AllocationSite> site);
35 
36  private:
37   Isolate* isolate_;
38   Handle<AllocationSite> top_;
39   Handle<AllocationSite> current_;
40 };
41 
42 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed
43 // behind some/all components of a copied object literal.
44 class AllocationSiteUsageContext : public AllocationSiteContext {
45  public:
AllocationSiteUsageContext(Isolate * isolate,Handle<AllocationSite> site,bool activated)46   AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site,
47                              bool activated)
48       : AllocationSiteContext(isolate),
49         top_site_(site),
50         activated_(activated) {}
51 
52   inline Handle<AllocationSite> EnterNewScope();
53 
54   inline void ExitScope(Handle<AllocationSite> scope_site,
55                         Handle<JSObject> object);
56 
57   inline bool ShouldCreateMemento(Handle<JSObject> object);
58 
59   static const bool kCopying = true;
60 
61  private:
62   Handle<AllocationSite> top_site_;
63   bool activated_;
64 };
65 
66 }  // namespace internal
67 }  // namespace v8
68 
69 #endif  // V8_OBJECTS_ALLOCATION_SITE_SCOPES_H_
70