• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) { current_.PatchValue(site); }
31 
32   inline void InitializeTraversal(Handle<AllocationSite> site);
33 
34  private:
35   Isolate* isolate_;
36   Handle<AllocationSite> top_;
37   Handle<AllocationSite> current_;
38 };
39 
40 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed
41 // behind some/all components of a copied object literal.
42 class AllocationSiteUsageContext : public AllocationSiteContext {
43  public:
AllocationSiteUsageContext(Isolate * isolate,Handle<AllocationSite> site,bool activated)44   AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site,
45                              bool activated)
46       : AllocationSiteContext(isolate),
47         top_site_(site),
48         activated_(activated) {}
49 
50   inline Handle<AllocationSite> EnterNewScope();
51 
52   inline void ExitScope(Handle<AllocationSite> scope_site,
53                         Handle<JSObject> object);
54 
55   inline bool ShouldCreateMemento(Handle<JSObject> object);
56 
57   static const bool kCopying = true;
58 
59  private:
60   Handle<AllocationSite> top_site_;
61   bool activated_;
62 };
63 
64 }  // namespace internal
65 }  // namespace v8
66 
67 #endif  // V8_OBJECTS_ALLOCATION_SITE_SCOPES_H_
68