| 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 virtual ~AllocationSiteContext() {} | 47 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 virtual bool ShouldCreateMemento(Handle<JSObject> object) { return false; } |
| 54 bool activated() const { return activated_; } | |
| 55 | 53 |
| 56 // Returns the AllocationSite that matches this scope. | 54 // Returns the AllocationSite that matches this scope. |
| 57 virtual Handle<AllocationSite> EnterNewScope() = 0; | 55 virtual Handle<AllocationSite> EnterNewScope() = 0; |
| 58 | 56 |
| 59 // scope_site should be the handle returned by the matching EnterNewScope() | 57 // scope_site should be the handle returned by the matching EnterNewScope() |
| 60 virtual void ExitScope(Handle<AllocationSite> scope_site, | 58 virtual void ExitScope(Handle<AllocationSite> scope_site, |
| 61 Handle<JSObject> object) = 0; | 59 Handle<JSObject> object) = 0; |
| 62 | 60 |
| 63 protected: | 61 protected: |
| 64 void update_current_site(AllocationSite* site) { | 62 void update_current_site(AllocationSite* site) { |
| 65 *(current_.location()) = site; | 63 *(current_.location()) = site; |
| 66 } | 64 } |
| 67 | 65 |
| 68 Isolate* isolate() { return isolate_; } | 66 Isolate* isolate() { return isolate_; } |
| 69 void InitializeTraversal(Handle<AllocationSite> site) { | 67 void InitializeTraversal(Handle<AllocationSite> site) { |
| 70 top_ = site; | 68 top_ = site; |
| 71 current_ = Handle<AllocationSite>(*top_, isolate()); | 69 current_ = Handle<AllocationSite>(*top_, isolate()); |
| 72 } | 70 } |
| 73 | 71 |
| 74 private: | 72 private: |
| 75 Isolate* isolate_; | 73 Isolate* isolate_; |
| 76 Handle<AllocationSite> top_; | 74 Handle<AllocationSite> top_; |
| 77 Handle<AllocationSite> current_; | 75 Handle<AllocationSite> current_; |
| 78 bool activated_; | |
| 79 }; | 76 }; |
| 80 | 77 |
| 81 | 78 |
| 82 // AllocationSiteCreationContext aids in the creation of AllocationSites to | 79 // AllocationSiteCreationContext aids in the creation of AllocationSites to |
| 83 // accompany object literals. | 80 // accompany object literals. |
| 84 class AllocationSiteCreationContext : public AllocationSiteContext { | 81 class AllocationSiteCreationContext : public AllocationSiteContext { |
| 85 public: | 82 public: |
| 86 explicit AllocationSiteCreationContext(Isolate* isolate) | 83 explicit AllocationSiteCreationContext(Isolate* isolate) |
| 87 : AllocationSiteContext(isolate, true) { } | 84 : AllocationSiteContext(isolate) { } |
| 88 | 85 |
| 89 virtual Handle<AllocationSite> EnterNewScope() V8_OVERRIDE; | 86 virtual Handle<AllocationSite> EnterNewScope() V8_OVERRIDE; |
| 90 virtual void ExitScope(Handle<AllocationSite> site, | 87 virtual void ExitScope(Handle<AllocationSite> site, |
| 91 Handle<JSObject> object) V8_OVERRIDE; | 88 Handle<JSObject> object) V8_OVERRIDE; |
| 92 }; | 89 }; |
| 93 | 90 |
| 94 | 91 |
| 95 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed | 92 // AllocationSiteUsageContext aids in the creation of AllocationMementos placed |
| 96 // behind some/all components of a copied object literal. | 93 // behind some/all components of a copied object literal. |
| 97 class AllocationSiteUsageContext : public AllocationSiteContext { | 94 class AllocationSiteUsageContext : public AllocationSiteContext { |
| 98 public: | 95 public: |
| 99 AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site, | 96 AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site, |
| 100 bool activated) | 97 bool activated) |
| 101 : AllocationSiteContext(isolate, activated), | 98 : AllocationSiteContext(isolate), |
| 102 top_site_(site) { } | 99 top_site_(site), |
| 100 activated_(activated) { } |
| 103 | 101 |
| 102 virtual bool ShouldCreateMemento(Handle<JSObject> object) V8_OVERRIDE; |
| 104 virtual Handle<AllocationSite> EnterNewScope() V8_OVERRIDE; | 103 virtual Handle<AllocationSite> EnterNewScope() V8_OVERRIDE; |
| 105 virtual void ExitScope(Handle<AllocationSite> site, | 104 virtual void ExitScope(Handle<AllocationSite> site, |
| 106 Handle<JSObject> object) V8_OVERRIDE; | 105 Handle<JSObject> object) V8_OVERRIDE; |
| 107 | 106 |
| 108 private: | 107 private: |
| 109 Handle<AllocationSite> top_site_; | 108 Handle<AllocationSite> top_site_; |
| 109 bool activated_; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 | 112 |
| 113 } } // namespace v8::internal | 113 } } // namespace v8::internal |
| 114 | 114 |
| 115 #endif // V8_ALLOCATION_SITE_SCOPES_H_ | 115 #endif // V8_ALLOCATION_SITE_SCOPES_H_ |
| OLD | NEW |