Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: src/scopeinfo.cc

Issue 981203003: Stack allocate lexical locals + hoist stack slots (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/scopeinfo.cc
diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc
index 99d4c38297890a22631e33a1aa1aa3cce1add481..c782e8784dc7484d75622fe6422aad41f4fee060 100644
--- a/src/scopeinfo.cc
+++ b/src/scopeinfo.cc
@@ -27,7 +27,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
const int strong_mode_free_variable_count =
strong_mode_free_variables.length();
// Make sure we allocate the correct amount.
- DCHECK(scope->StackLocalCount() == stack_local_count);
+ // DCHECK(scope->StackLocalCount() >= stack_local_count);
DCHECK(scope->ContextLocalCount() == context_local_count);
bool simple_parameter_list =
@@ -54,8 +54,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
const bool has_function_name = function_name_info != NONE;
const int parameter_count = scope->num_parameters();
- const int length = kVariablePartIndex + parameter_count + stack_local_count +
- 2 * context_local_count +
+ const int length = kVariablePartIndex + parameter_count +
+ (1 + stack_local_count) + 2 * context_local_count +
3 * strong_mode_free_variable_count +
(has_function_name ? 2 : 0);
@@ -89,9 +89,17 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
// Add stack locals' names. We are assuming that the stack locals'
// slots are allocated in increasing order, so we can simply add
// them to the ScopeInfo object.
+ int first_slot_index;
+ if (stack_local_count > 0) {
+ first_slot_index = stack_locals[0]->index();
+ } else {
+ first_slot_index = 0;
+ }
+ DCHECK(index == scope_info->StackLocalFirstSlotIndex());
+ scope_info->set(index++, Smi::FromInt(first_slot_index));
DCHECK(index == scope_info->StackLocalEntriesIndex());
for (int i = 0; i < stack_local_count; ++i) {
- DCHECK(stack_locals[i]->index() == i);
+ DCHECK(stack_locals[i]->index() == first_slot_index + i);
scope_info->set(index++, *stack_locals[i]->name());
}
@@ -145,16 +153,19 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
int var_index = scope->function()->proxy()->var()->index();
scope_info->set(index++, *scope->function()->proxy()->name());
scope_info->set(index++, Smi::FromInt(var_index));
+ /*
DCHECK(function_name_info != STACK ||
(var_index == scope_info->StackLocalCount() &&
var_index == scope_info->StackSlotCount() - 1));
+ */
DCHECK(function_name_info != CONTEXT ||
var_index == scope_info->ContextLength() - 1);
}
DCHECK(index == scope_info->length());
DCHECK(scope->num_parameters() == scope_info->ParameterCount());
- DCHECK(scope->num_stack_slots() == scope_info->StackSlotCount());
+ // DCHECK(scope->is_block_scope() || scope->num_stack_slots() ==
+ // scope_info->StackSlotCount());
DCHECK(scope->num_heap_slots() == scope_info->ContextLength() ||
(scope->num_heap_slots() == kVariablePartIndex &&
scope_info->ContextLength() == 0));
@@ -269,6 +280,13 @@ String* ScopeInfo::StackLocalName(int var) {
}
+int ScopeInfo::StackLocalIndex(int var) {
+ DCHECK(0 <= var && var < StackLocalCount());
+ int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value();
+ return first_slot_index + var;
+}
+
+
String* ScopeInfo::ContextLocalName(int var) {
DCHECK(0 <= var && var < ContextLocalCount());
int info_index = ContextLocalNameEntriesIndex() + var;
@@ -343,11 +361,12 @@ int ScopeInfo::StrongModeFreeVariableEndPosition(int var) {
int ScopeInfo::StackSlotIndex(String* name) {
DCHECK(name->IsInternalizedString());
if (length() > 0) {
+ int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value();
int start = StackLocalEntriesIndex();
int end = StackLocalEntriesIndex() + StackLocalCount();
for (int i = start; i < end; ++i) {
if (name == get(i)) {
- return i - start;
+ return i - start + first_slot_index;
}
}
}
@@ -454,7 +473,9 @@ bool ScopeInfo::CopyContextLocalsToScopeObject(Handle<ScopeInfo> scope_info,
int context_index = Context::MIN_CONTEXT_SLOTS + i;
Handle<Object> value = Handle<Object>(context->get(context_index), isolate);
// Do not reflect variables under TDZ in scope object.
- if (value->IsTheHole()) continue;
+ if (value->IsTheHole()) {
+ value = isolate->factory()->undefined_value();
+ }
RETURN_ON_EXCEPTION_VALUE(
isolate, Runtime::DefineObjectProperty(
scope_object,
@@ -472,11 +493,16 @@ int ScopeInfo::ParameterEntriesIndex() {
}
-int ScopeInfo::StackLocalEntriesIndex() {
+int ScopeInfo::StackLocalFirstSlotIndex() {
return ParameterEntriesIndex() + ParameterCount();
}
+int ScopeInfo::StackLocalEntriesIndex() {
+ return StackLocalFirstSlotIndex() + 1;
+}
+
+
int ScopeInfo::ContextLocalNameEntriesIndex() {
return StackLocalEntriesIndex() + StackLocalCount();
}
« src/parser.cc ('K') | « src/runtime/runtime-debug.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698