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

Unified Diff: src/ia32/lithium-ia32.cc

Issue 93803003: Fixed Lithium environment generation bug for captured objects (created (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years 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
« no previous file with comments | « src/ia32/lithium-ia32.h ('k') | src/x64/lithium-x64.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ia32/lithium-ia32.cc
diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc
index 6e720f118d498d3bd5086a31a59f03577f169b95..6d20ffc4896cff83d1948cdf3a28c674a515d6da 100644
--- a/src/ia32/lithium-ia32.cc
+++ b/src/ia32/lithium-ia32.cc
@@ -1024,14 +1024,15 @@ LEnvironment* LChunkBuilder::CreateEnvironment(
hydrogen_env->entry(),
zone());
int argument_index = *argument_index_accumulator;
- int object_index = objects_to_materialize->length();
+
+ // Store the environment description into the environment
+ // (with holes for nested objects)
for (int i = 0; i < hydrogen_env->length(); ++i) {
if (hydrogen_env->is_special_index(i)) continue;
LOperand* op;
HValue* value = hydrogen_env->values()->at(i);
if (value->IsArgumentsObject() || value->IsCapturedObject()) {
- objects_to_materialize->Add(value, zone());
op = LEnvironment::materialization_marker();
} else if (value->IsPushArgument()) {
op = new(zone()) LArgument(argument_index++);
@@ -1043,36 +1044,13 @@ LEnvironment* LChunkBuilder::CreateEnvironment(
value->CheckFlag(HInstruction::kUint32));
}
- for (int i = object_index; i < objects_to_materialize->length(); ++i) {
- HValue* object_to_materialize = objects_to_materialize->at(i);
- int previously_materialized_object = -1;
- for (int prev = 0; prev < i; ++prev) {
- if (objects_to_materialize->at(prev) == objects_to_materialize->at(i)) {
- previously_materialized_object = prev;
- break;
- }
- }
- int length = object_to_materialize->OperandCount();
- bool is_arguments = object_to_materialize->IsArgumentsObject();
- if (previously_materialized_object >= 0) {
- result->AddDuplicateObject(previously_materialized_object);
- continue;
- } else {
- result->AddNewObject(is_arguments ? length - 1 : length, is_arguments);
- }
- for (int i = is_arguments ? 1 : 0; i < length; ++i) {
- LOperand* op;
- HValue* value = object_to_materialize->OperandAt(i);
- if (value->IsArgumentsObject() || value->IsCapturedObject()) {
- objects_to_materialize->Add(value, zone());
- op = LEnvironment::materialization_marker();
- } else {
- ASSERT(!value->IsPushArgument());
- op = UseAny(value);
- }
- result->AddValue(op,
- value->representation(),
- value->CheckFlag(HInstruction::kUint32));
+ // Recursively store the nested objects into the environment
+ for (int i = 0; i < hydrogen_env->length(); ++i) {
+ if (hydrogen_env->is_special_index(i)) continue;
+
+ HValue* value = hydrogen_env->values()->at(i);
+ if (value->IsArgumentsObject() || value->IsCapturedObject()) {
+ AddObjectToMaterialize(value, objects_to_materialize, result);
}
}
@@ -1084,6 +1062,77 @@ LEnvironment* LChunkBuilder::CreateEnvironment(
}
+// Add an object to the supplied environment and object materialization list.
+//
+// Notes:
+//
+// We are building three lists here:
+//
+// 1. In the result->object_mapping_ list (added to by the
+// LEnvironment::Add*Object methods), we store the lengths (number
+// of fields) of the captured objects in depth-first traversal order, or
+// in case of duplicated objects, we store the index to the duplicate object
+// (with a tag to differentiate between captured and duplicated objects).
+//
+// 2. The object fields are stored in the result->values_ list
+// (added to by the LEnvironment.AddValue method) sequentially as lists
+// of fields with holes for nested objects (the holes will be expanded
+// later by LCodegen::AddToTranslation according to the
+// LEnvironment.object_mapping_ list).
+//
+// 3. The auxiliary objects_to_materialize array stores the hydrogen values
+// in the same order as result->object_mapping_ list. This is used
+// to detect duplicate values and calculate the corresponding object index.
+void LChunkBuilder::AddObjectToMaterialize(HValue* value,
+ ZoneList<HValue*>* objects_to_materialize, LEnvironment* result) {
titzer 2013/12/20 13:38:57 AFAICT, this method is an exact duplicate on all t
+ int object_index = objects_to_materialize->length();
+ // Store the hydrogen value into the de-duplication array
+ objects_to_materialize->Add(value, zone());
+ // Find out whether we are storing a duplicated value
+ int previously_materialized_object = -1;
+ for (int prev = 0; prev < object_index; ++prev) {
+ if (objects_to_materialize->at(prev) == value) {
+ previously_materialized_object = prev;
+ break;
+ }
+ }
+ // Store the captured object length (or duplicated object index)
+ // into the environment. For duplicated objects, we stop here.
+ int length = value->OperandCount();
+ bool is_arguments = value->IsArgumentsObject();
+ if (previously_materialized_object >= 0) {
+ result->AddDuplicateObject(previously_materialized_object);
+ return;
+ } else {
+ result->AddNewObject(is_arguments ? length - 1 : length, is_arguments);
+ }
+ // Store the captured object's fields into the environment
+ for (int i = is_arguments ? 1 : 0; i < length; ++i) {
+ LOperand* op;
+ HValue* arg_value = value->OperandAt(i);
+ if (arg_value->IsArgumentsObject() || arg_value->IsCapturedObject()) {
+ // Insert a hole for nested objects
+ op = LEnvironment::materialization_marker();
+ } else {
+ ASSERT(!arg_value->IsPushArgument());
+ // For ordinary values, tell the register allocator we need the value
+ // to be alive here
+ op = UseAny(arg_value);
+ }
+ result->AddValue(op,
+ arg_value->representation(),
+ arg_value->CheckFlag(HInstruction::kUint32));
+ }
+ // Recursively store all the nested captured objects into the environment
+ for (int i = is_arguments ? 1 : 0; i < length; ++i) {
+ HValue* arg_value = value->OperandAt(i);
+ if (arg_value->IsArgumentsObject() || arg_value->IsCapturedObject()) {
+ AddObjectToMaterialize(arg_value, objects_to_materialize, result);
+ }
+ }
+}
+
+
LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
return new(zone()) LGoto(instr->FirstSuccessor());
}
« no previous file with comments | « src/ia32/lithium-ia32.h ('k') | src/x64/lithium-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698