mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 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: |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 44 | explicit AllocationSiteContext(Isolate* isolate) { |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 45 | isolate_ = isolate; |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 46 | }; |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 47 | |
| 48 | Handle<AllocationSite> top() { return top_; } |
| 49 | Handle<AllocationSite> current() { return current_; } |
| 50 | |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 51 | bool ShouldCreateMemento(Handle<JSObject> object) { return false; } |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 52 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 53 | Isolate* isolate() { return isolate_; } |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 54 | |
| 55 | protected: |
| 56 | void update_current_site(AllocationSite* site) { |
| 57 | *(current_.location()) = site; |
| 58 | } |
| 59 | |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 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_; |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | |
| 72 | // AllocationSiteCreationContext aids in the creation of AllocationSites to |
| 73 | // accompany object literals. |
| 74 | class AllocationSiteCreationContext : public AllocationSiteContext { |
| 75 | public: |
| 76 | explicit AllocationSiteCreationContext(Isolate* isolate) |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 77 | : AllocationSiteContext(isolate) { } |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 78 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 79 | Handle<AllocationSite> EnterNewScope(); |
| 80 | void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 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: |
| 88 | AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site, |
| 89 | bool activated) |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 90 | : AllocationSiteContext(isolate), |
| 91 | top_site_(site), |
| 92 | activated_(activated) { } |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 93 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 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 | |
| 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 | } |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 113 | |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 114 | bool ShouldCreateMemento(Handle<JSObject> object); |
| 115 | |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 116 | private: |
| 117 | Handle<AllocationSite> top_site_; |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 118 | bool activated_; |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | |
| 122 | } } // namespace v8::internal |
| 123 | |
| 124 | #endif // V8_ALLOCATION_SITE_SCOPES_H_ |