| 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 23 matching lines...) Expand all Loading... |
| 34 #include "zone.h" | 34 #include "zone.h" |
| 35 | 35 |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 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 explicit AllocationSiteContext(Isolate* isolate) { |
| 45 isolate_ = isolate; | 45 isolate_ = isolate; |
| 46 activated_ = activated; | |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 Handle<AllocationSite> top() { return top_; } | 48 Handle<AllocationSite> top() { return top_; } |
| 50 Handle<AllocationSite> current() { return current_; } | 49 Handle<AllocationSite> current() { return current_; } |
| 51 | 50 |
| 52 // If activated, then recursively create mementos | 51 bool ShouldCreateMemento(Handle<JSObject> object) { return false; } |
| 53 bool activated() const { return activated_; } | |
| 54 | 52 |
| 55 Isolate* isolate() { return isolate_; } | 53 Isolate* isolate() { return isolate_; } |
| 56 | 54 |
| 57 protected: | 55 protected: |
| 58 void update_current_site(AllocationSite* site) { | 56 void update_current_site(AllocationSite* site) { |
| 59 *(current_.location()) = site; | 57 *(current_.location()) = site; |
| 60 } | 58 } |
| 61 | 59 |
| 62 void InitializeTraversal(Handle<AllocationSite> site) { | 60 void InitializeTraversal(Handle<AllocationSite> site) { |
| 63 top_ = site; | 61 top_ = site; |
| 64 current_ = Handle<AllocationSite>(*top_, isolate()); | 62 current_ = Handle<AllocationSite>(*top_, isolate()); |
| 65 } | 63 } |
| 66 | 64 |
| 67 private: | 65 private: |
| 68 Isolate* isolate_; | 66 Isolate* isolate_; |
| 69 Handle<AllocationSite> top_; | 67 Handle<AllocationSite> top_; |
| 70 Handle<AllocationSite> current_; | 68 Handle<AllocationSite> current_; |
| 71 bool activated_; | |
| 72 }; | 69 }; |
| 73 | 70 |
| 74 | 71 |
| 75 // AllocationSiteCreationContext aids in the creation of AllocationSites to | 72 // AllocationSiteCreationContext aids in the creation of AllocationSites to |
| 76 // accompany object literals. | 73 // accompany object literals. |
| 77 class AllocationSiteCreationContext : public AllocationSiteContext { | 74 class AllocationSiteCreationContext : public AllocationSiteContext { |
| 78 public: | 75 public: |
| 79 explicit AllocationSiteCreationContext(Isolate* isolate) | 76 explicit AllocationSiteCreationContext(Isolate* isolate) |
| 80 : AllocationSiteContext(isolate, true) { } | 77 : AllocationSiteContext(isolate) { } |
| 81 | 78 |
| 82 Handle<AllocationSite> EnterNewScope(); | 79 Handle<AllocationSite> EnterNewScope(); |
| 83 void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object); | 80 void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object); |
| 84 }; | 81 }; |
| 85 | 82 |
| 86 | 83 |
| 87 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed | 84 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed |
| 88 // behind some/all components of a copied object literal. | 85 // behind some/all components of a copied object literal. |
| 89 class AllocationSiteUsageContext : public AllocationSiteContext { | 86 class AllocationSiteUsageContext : public AllocationSiteContext { |
| 90 public: | 87 public: |
| 91 AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site, | 88 AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site, |
| 92 bool activated) | 89 bool activated) |
| 93 : AllocationSiteContext(isolate, activated), | 90 : AllocationSiteContext(isolate), |
| 94 top_site_(site) { } | 91 top_site_(site), |
| 92 activated_(activated) { } |
| 95 | 93 |
| 96 inline Handle<AllocationSite> EnterNewScope() { | 94 inline Handle<AllocationSite> EnterNewScope() { |
| 97 if (top().is_null()) { | 95 if (top().is_null()) { |
| 98 InitializeTraversal(top_site_); | 96 InitializeTraversal(top_site_); |
| 99 } else { | 97 } else { |
| 100 // Advance current site | 98 // Advance current site |
| 101 Object* nested_site = current()->nested_site(); | 99 Object* nested_site = current()->nested_site(); |
| 102 // Something is wrong if we advance to the end of the list here. | 100 // Something is wrong if we advance to the end of the list here. |
| 103 ASSERT(nested_site->IsAllocationSite()); | 101 ASSERT(nested_site->IsAllocationSite()); |
| 104 update_current_site(AllocationSite::cast(nested_site)); | 102 update_current_site(AllocationSite::cast(nested_site)); |
| 105 } | 103 } |
| 106 return Handle<AllocationSite>(*current(), isolate()); | 104 return Handle<AllocationSite>(*current(), isolate()); |
| 107 } | 105 } |
| 108 | 106 |
| 109 inline void ExitScope(Handle<AllocationSite> scope_site, | 107 inline void ExitScope(Handle<AllocationSite> scope_site, |
| 110 Handle<JSObject> object) { | 108 Handle<JSObject> object) { |
| 111 // This assert ensures that we are pointing at the right sub-object in a | 109 // This assert ensures that we are pointing at the right sub-object in a |
| 112 // recursive walk of a nested literal. | 110 // recursive walk of a nested literal. |
| 113 ASSERT(object.is_null() || *object == scope_site->transition_info()); | 111 ASSERT(object.is_null() || *object == scope_site->transition_info()); |
| 114 } | 112 } |
| 115 | 113 |
| 114 bool ShouldCreateMemento(Handle<JSObject> object); |
| 115 |
| 116 private: | 116 private: |
| 117 Handle<AllocationSite> top_site_; | 117 Handle<AllocationSite> top_site_; |
| 118 bool activated_; |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 | 121 |
| 121 } } // namespace v8::internal | 122 } } // namespace v8::internal |
| 122 | 123 |
| 123 #endif // V8_ALLOCATION_SITE_SCOPES_H_ | 124 #endif // V8_ALLOCATION_SITE_SCOPES_H_ |
| OLD | NEW |