OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 | 39 |
40 // AllocationSiteContext is the base class for walking and copying a nested | 40 // AllocationSiteContext is the base class for walking and copying a nested |
41 // boilerplate with AllocationSite and AllocationMemento support. | 41 // boilerplate with AllocationSite and AllocationMemento support. |
42 class AllocationSiteContext { | 42 class AllocationSiteContext { |
43 public: | 43 public: |
44 AllocationSiteContext(Isolate* isolate, bool activated) { | 44 AllocationSiteContext(Isolate* isolate, bool activated) { |
45 isolate_ = isolate; | 45 isolate_ = isolate; |
46 activated_ = activated; | 46 activated_ = activated; |
47 }; | 47 }; |
48 virtual ~AllocationSiteContext() {} | |
49 | 48 |
50 Handle<AllocationSite> top() { return top_; } | 49 Handle<AllocationSite> top() { return top_; } |
51 Handle<AllocationSite> current() { return current_; } | 50 Handle<AllocationSite> current() { return current_; } |
52 | 51 |
53 // If activated, then recursively create mementos | 52 // If activated, then recursively create mementos |
54 bool activated() const { return activated_; } | 53 bool activated() const { return activated_; } |
55 | 54 |
56 // Returns the AllocationSite that matches this scope. | 55 Isolate* isolate() { return isolate_; } |
57 virtual Handle<AllocationSite> EnterNewScope() = 0; | |
58 | |
59 // scope_site should be the handle returned by the matching EnterNewScope() | |
60 virtual void ExitScope(Handle<AllocationSite> scope_site, | |
61 Handle<JSObject> object) = 0; | |
62 | 56 |
63 protected: | 57 protected: |
64 void update_current_site(AllocationSite* site) { | 58 void update_current_site(AllocationSite* site) { |
65 *(current_.location()) = site; | 59 *(current_.location()) = site; |
66 } | 60 } |
67 | 61 |
68 Isolate* isolate() { return isolate_; } | |
69 void InitializeTraversal(Handle<AllocationSite> site) { | 62 void InitializeTraversal(Handle<AllocationSite> site) { |
70 top_ = site; | 63 top_ = site; |
71 current_ = Handle<AllocationSite>(*top_, isolate()); | 64 current_ = Handle<AllocationSite>(*top_, isolate()); |
Michael Starzinger
2013/11/22 20:07:16
nit: If this is the only use-site of AllocationSit
mvstanton
2013/11/25 11:51:50
Hmm, the isolate does get used to access the facto
| |
72 } | 65 } |
73 | 66 |
74 private: | 67 private: |
75 Isolate* isolate_; | 68 Isolate* isolate_; |
76 Handle<AllocationSite> top_; | 69 Handle<AllocationSite> top_; |
77 Handle<AllocationSite> current_; | 70 Handle<AllocationSite> current_; |
78 bool activated_; | 71 bool activated_; |
79 }; | 72 }; |
80 | 73 |
81 | 74 |
82 // AllocationSiteCreationContext aids in the creation of AllocationSites to | 75 // AllocationSiteCreationContext aids in the creation of AllocationSites to |
83 // accompany object literals. | 76 // accompany object literals. |
84 class AllocationSiteCreationContext : public AllocationSiteContext { | 77 class AllocationSiteCreationContext : public AllocationSiteContext { |
85 public: | 78 public: |
86 explicit AllocationSiteCreationContext(Isolate* isolate) | 79 explicit AllocationSiteCreationContext(Isolate* isolate) |
87 : AllocationSiteContext(isolate, true) { } | 80 : AllocationSiteContext(isolate, true) { } |
88 | 81 |
89 virtual Handle<AllocationSite> EnterNewScope() V8_OVERRIDE; | 82 Handle<AllocationSite> EnterNewScope(); |
90 virtual void ExitScope(Handle<AllocationSite> site, | 83 void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object); |
91 Handle<JSObject> object) V8_OVERRIDE; | |
92 }; | 84 }; |
93 | 85 |
94 | 86 |
95 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed | 87 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed |
96 // behind some/all components of a copied object literal. | 88 // behind some/all components of a copied object literal. |
97 class AllocationSiteUsageContext : public AllocationSiteContext { | 89 class AllocationSiteUsageContext : public AllocationSiteContext { |
98 public: | 90 public: |
99 AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site, | 91 AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site, |
100 bool activated) | 92 bool activated) |
101 : AllocationSiteContext(isolate, activated), | 93 : AllocationSiteContext(isolate, activated), |
102 top_site_(site) { } | 94 top_site_(site) { } |
103 | 95 |
104 virtual Handle<AllocationSite> EnterNewScope() V8_OVERRIDE; | 96 inline Handle<AllocationSite> EnterNewScope() { |
105 virtual void ExitScope(Handle<AllocationSite> site, | 97 if (top().is_null()) { |
106 Handle<JSObject> object) V8_OVERRIDE; | 98 InitializeTraversal(top_site_); |
99 } else { | |
100 // Advance current site | |
101 Object* nested_site = current()->nested_site(); | |
102 // Something is wrong if we advance to the end of the list here. | |
103 ASSERT(nested_site->IsAllocationSite()); | |
104 update_current_site(AllocationSite::cast(nested_site)); | |
105 } | |
106 return Handle<AllocationSite>(*current(), isolate()); | |
107 } | |
108 | |
109 inline void ExitScope(Handle<AllocationSite> scope_site, | |
110 Handle<JSObject> object) { | |
111 // This assert ensures that we are pointing at the right sub-object in a | |
112 // recursive walk of a nested literal. | |
113 ASSERT(object.is_null() || *object == scope_site->transition_info()); | |
114 } | |
115 | |
Michael Starzinger
2013/11/22 20:07:16
nit: Only one empty new-line.
mvstanton
2013/11/25 11:51:50
Done.
| |
107 | 116 |
108 private: | 117 private: |
109 Handle<AllocationSite> top_site_; | 118 Handle<AllocationSite> top_site_; |
110 }; | 119 }; |
111 | 120 |
112 | 121 |
113 } } // namespace v8::internal | 122 } } // namespace v8::internal |
114 | 123 |
115 #endif // V8_ALLOCATION_SITE_SCOPES_H_ | 124 #endif // V8_ALLOCATION_SITE_SCOPES_H_ |
OLD | NEW |