OLD | NEW |
(Empty) | |
| 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 #include "allocation-site-scopes.h" |
| 29 |
| 30 namespace v8 { |
| 31 namespace internal { |
| 32 |
| 33 |
| 34 AllocationSiteCreationScope::AllocationSiteCreationScope( |
| 35 AllocationSiteContext* context) { |
| 36 site_context_ = context; |
| 37 |
| 38 if (context->top().is_null()) { |
| 39 // We are creating the top level AllocationSite as opposed to a nested |
| 40 // AllocationSite. |
| 41 context->top_ = context->isolate_->factory()->NewAllocationSite(); |
| 42 ASSERT(!(context->top_->IsFailure())); |
| 43 context->current_ = Handle<AllocationSite>(*(context->top()), |
| 44 context->isolate_); |
| 45 current_ = Handle<AllocationSite>(*(context->top()), context->isolate_); |
| 46 if (FLAG_trace_creation_allocation_sites) { |
| 47 PrintF("*** Creating top level AllocationSite %p\n", |
| 48 static_cast<void*>(*current_)); |
| 49 } |
| 50 } else if (context->activated()) { |
| 51 ASSERT(!context->current().is_null()); |
| 52 Handle<AllocationSite> new_site = |
| 53 context->isolate_->factory()->NewAllocationSite(); |
| 54 ASSERT(!new_site->IsFailure()); |
| 55 if (FLAG_trace_creation_allocation_sites) { |
| 56 PrintF("Creating nested site (top, current, new) (%p, %p, %p)\n", |
| 57 static_cast<void*>(*(context->top())), |
| 58 static_cast<void*>(*(context->current())), |
| 59 static_cast<void*>(*new_site)); |
| 60 } |
| 61 context->current()->set_nested_site(*new_site); |
| 62 context->set_current(*new_site); |
| 63 current_ = Handle<AllocationSite>(*new_site, context->isolate_); |
| 64 } |
| 65 } |
| 66 |
| 67 |
| 68 Handle<Object> AllocationSiteCreationScope::RecordTransitionInfo( |
| 69 Handle<Object> transition_info) { |
| 70 if (!transition_info.is_null() && !transition_info->IsFailure()) { |
| 71 bool top_level = !current_.is_null() && |
| 72 site_context_->top().is_identical_to(current_); |
| 73 |
| 74 if (top_level || site_context_->activated()) { |
| 75 current_->set_transition_info(*transition_info); |
| 76 if (FLAG_trace_creation_allocation_sites) { |
| 77 if (top_level) { |
| 78 PrintF("*** Setting AllocationSite %p transition_info %p\n", |
| 79 static_cast<void*>(*current_), |
| 80 static_cast<void*>(*transition_info)); |
| 81 } else { |
| 82 PrintF("Setting AllocationSite (%p, %p) transition_info %p\n", |
| 83 static_cast<void*>(*(site_context_->top())), |
| 84 static_cast<void*>(*current_), |
| 85 static_cast<void*>(*transition_info)); |
| 86 } |
| 87 } |
| 88 } |
| 89 } |
| 90 return transition_info; |
| 91 } |
| 92 |
| 93 |
| 94 AllocationSiteUsageScope::AllocationSiteUsageScope( |
| 95 AllocationSiteContext* context, |
| 96 Handle<Object> expected_transition_info) { |
| 97 ASSERT(!context->top().is_null()); |
| 98 |
| 99 // Advance current site if activated. |
| 100 if (context->activated()) { |
| 101 Object* nested_site = context->current_->nested_site(); |
| 102 // Something is wrong if we advance to the end of the list here. |
| 103 ASSERT(nested_site->IsAllocationSite()); |
| 104 AllocationSite* casted_site = AllocationSite::cast(nested_site); |
| 105 context->set_current(casted_site); |
| 106 |
| 107 // This assert ensures that we are pointing at the right sub-object |
| 108 // in a recursive walk of a nested literal. It's the only |
| 109 // usage of parameter expected_transition_info. |
| 110 ASSERT(*expected_transition_info == casted_site->transition_info()); |
| 111 } |
| 112 } |
| 113 |
| 114 |
| 115 AllocationSiteUsageScope::AllocationSiteUsageScope( |
| 116 AllocationSiteContext* context, |
| 117 Handle<AllocationSite> top, |
| 118 Handle<Object> expected_transition_info) { |
| 119 ASSERT(context->top().is_null()); |
| 120 context->top_ = top; |
| 121 if (context->activated()) { |
| 122 // We only need current_ to be a handle if we are using the field. |
| 123 // We only use the field in the recursive case. |
| 124 context->current_ = Handle<AllocationSite>(*top, context->isolate_); |
| 125 } |
| 126 |
| 127 // This assert ensures that we are pointing at the right object in the |
| 128 // allocation site during a recursive walk of a nested literal. It's the only |
| 129 // usage of parameter expected_transition_info. |
| 130 ASSERT(*expected_transition_info == top->transition_info()); |
| 131 } |
| 132 |
| 133 } } // namespace v8::internal |
OLD | NEW |