Index: src/allocation-site-scopes.cc |
diff --git a/src/allocation-site-scopes.cc b/src/allocation-site-scopes.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cd3da594c4512aed60fc233c2b6640a0f344f7a9 |
--- /dev/null |
+++ b/src/allocation-site-scopes.cc |
@@ -0,0 +1,133 @@ |
+// Copyright 2013 the V8 project authors. All rights reserved. |
+// Redistribution and use in source and binary forms, with or without |
+// modification, are permitted provided that the following conditions are |
+// met: |
+// |
+// * Redistributions of source code must retain the above copyright |
+// notice, this list of conditions and the following disclaimer. |
+// * Redistributions in binary form must reproduce the above |
+// copyright notice, this list of conditions and the following |
+// disclaimer in the documentation and/or other materials provided |
+// with the distribution. |
+// * Neither the name of Google Inc. nor the names of its |
+// contributors may be used to endorse or promote products derived |
+// from this software without specific prior written permission. |
+// |
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ |
+#include "allocation-site-scopes.h" |
+ |
+namespace v8 { |
+namespace internal { |
+ |
+ |
+AllocationSiteCreationScope::AllocationSiteCreationScope( |
+ AllocationSiteContext* context) { |
+ site_context_ = context; |
+ |
+ if (context->top().is_null()) { |
+ // We are creating the top level AllocationSite as opposed to a nested |
+ // AllocationSite. |
+ context->top_ = context->isolate_->factory()->NewAllocationSite(); |
+ ASSERT(!(context->top_->IsFailure())); |
+ context->current_ = Handle<AllocationSite>(*(context->top()), |
+ context->isolate_); |
+ current_ = Handle<AllocationSite>(*(context->top()), context->isolate_); |
+ if (FLAG_trace_creation_allocation_sites) { |
+ PrintF("*** Creating top level AllocationSite %p\n", |
+ static_cast<void*>(*current_)); |
+ } |
+ } else if (context->activated()) { |
+ ASSERT(!context->current().is_null()); |
+ Handle<AllocationSite> new_site = |
+ context->isolate_->factory()->NewAllocationSite(); |
+ ASSERT(!new_site->IsFailure()); |
+ if (FLAG_trace_creation_allocation_sites) { |
+ PrintF("Creating nested site (top, current, new) (%p, %p, %p)\n", |
+ static_cast<void*>(*(context->top())), |
+ static_cast<void*>(*(context->current())), |
+ static_cast<void*>(*new_site)); |
+ } |
+ context->current()->set_nested_site(*new_site); |
+ context->set_current(*new_site); |
+ current_ = Handle<AllocationSite>(*new_site, context->isolate_); |
+ } |
+} |
+ |
+ |
+Handle<Object> AllocationSiteCreationScope::RecordTransitionInfo( |
+ Handle<Object> transition_info) { |
+ if (!transition_info.is_null() && !transition_info->IsFailure()) { |
+ bool top_level = !current_.is_null() && |
+ site_context_->top().is_identical_to(current_); |
+ |
+ if (top_level || site_context_->activated()) { |
+ current_->set_transition_info(*transition_info); |
+ if (FLAG_trace_creation_allocation_sites) { |
+ if (top_level) { |
+ PrintF("*** Setting AllocationSite %p transition_info %p\n", |
+ static_cast<void*>(*current_), |
+ static_cast<void*>(*transition_info)); |
+ } else { |
+ PrintF("Setting AllocationSite (%p, %p) transition_info %p\n", |
+ static_cast<void*>(*(site_context_->top())), |
+ static_cast<void*>(*current_), |
+ static_cast<void*>(*transition_info)); |
+ } |
+ } |
+ } |
+ } |
+ return transition_info; |
+} |
+ |
+ |
+AllocationSiteUsageScope::AllocationSiteUsageScope( |
+ AllocationSiteContext* context, |
+ Handle<Object> expected_transition_info) { |
+ ASSERT(!context->top().is_null()); |
+ |
+ // Advance current site if activated. |
+ if (context->activated()) { |
+ Object* nested_site = context->current_->nested_site(); |
+ // Something is wrong if we advance to the end of the list here. |
+ ASSERT(nested_site->IsAllocationSite()); |
+ AllocationSite* casted_site = AllocationSite::cast(nested_site); |
+ context->set_current(casted_site); |
+ |
+ // This assert ensures that we are pointing at the right sub-object |
+ // in a recursive walk of a nested literal. It's the only |
+ // usage of parameter expected_transition_info. |
+ ASSERT(*expected_transition_info == casted_site->transition_info()); |
+ } |
+} |
+ |
+ |
+AllocationSiteUsageScope::AllocationSiteUsageScope( |
+ AllocationSiteContext* context, |
+ Handle<AllocationSite> top, |
+ Handle<Object> expected_transition_info) { |
+ ASSERT(context->top().is_null()); |
+ context->top_ = top; |
+ if (context->activated()) { |
+ // We only need current_ to be a handle if we are using the field. |
+ // We only use the field in the recursive case. |
+ context->current_ = Handle<AllocationSite>(*top, context->isolate_); |
+ } |
+ |
+ // This assert ensures that we are pointing at the right object in the |
+ // allocation site during a recursive walk of a nested literal. It's the only |
+ // usage of parameter expected_transition_info. |
+ ASSERT(*expected_transition_info == top->transition_info()); |
+} |
+ |
+} } // namespace v8::internal |