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..3f7dcd751f438a865f19cf61cd0690e8cb6dd7bb |
--- /dev/null |
+++ b/src/allocation-site-scopes.cc |
@@ -0,0 +1,134 @@ |
+// 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" |
Hannes Payer (out of office)
2013/10/11 12:55:44
newline
mvstanton
2013/10/11 13:41:47
Done.
|
+#define PTR(x) reinterpret_cast<void*>((x)) |
Hannes Payer (out of office)
2013/10/11 12:55:44
I am not a fan of macros, can we just use the cast
mvstanton
2013/10/11 13:41:47
Done.
|
+ |
+namespace v8 { |
+namespace internal { |
+ |
+ |
+AllocationSiteCreationScope::AllocationSiteCreationScope( |
+ AllocationSiteContext* context) { |
+ site_context_ = context; |
+ |
+ if (context->top().is_null()) { |
+ // top level |
Hannes Payer (out of office)
2013/10/11 12:55:44
Make a proper comment out of this comment or remov
mvstanton
2013/10/11 13:41:47
Done.
|
+ 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", |
+ PTR(*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", |
+ PTR(*(context->top())), |
+ PTR(*(context->current())), |
+ PTR(*new_site)); |
+ } |
+ context->current()->set_nested_site(*new_site); |
+ *context->current_.location() = *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", |
+ PTR(*current_), |
+ PTR(*transition_info)); |
+ } else { |
+ PrintF("Setting AllocationSite (%p, %p) transition_info %p\n", |
+ PTR(*(site_context_->top())), |
+ PTR(*current_), |
+ PTR(*transition_info)); |
+ } |
+ } |
+ } |
+ } |
+ return transition_info; |
+} |
+ |
+ |
+AllocationSiteUsageScope::AllocationSiteUsageScope( |
+ AllocationSiteContext* context, |
+ Handle<Object> expected_transition_info) { |
+ ASSERT(!context->top().is_null()); |
+ |
+ // Advance current if activated |
Hannes Payer (out of office)
2013/10/11 12:55:44
finish with "."
mvstanton
2013/10/11 13:41:47
Done.
|
+ if (context->activated()) { |
+ Object* nested_site = context->current_->nested_site(); |
+ // Something is wrong if we advance to the end of the list here |
Hannes Payer (out of office)
2013/10/11 12:55:44
finish with "."
mvstanton
2013/10/11 13:41:47
Done.
|
+ ASSERT(nested_site->IsAllocationSite()); |
+ AllocationSite* casted_site = AllocationSite::cast(nested_site); |
+ *context->current_.location() = 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 |
Hannes Payer (out of office)
2013/10/11 12:55:44
finish with "."
mvstanton
2013/10/11 13:41:47
Done.
|
+ // in 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 |