Fix a bug when creating a HDeoptimization instruction.
We need to copy the environment, instead of just pointing
to an existing one. Otherwise, if the instruction that initially
holds the environemnt gets removed from the graph, any update
to an instruction in that environment will not be reflected in it.
bug:20058506
Change-Id: I2a62476d0851ecbc3707c0da395d8502ee437422
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 6827cd0..f764eb4 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -1192,7 +1192,17 @@
bool HasEnvironment() const { return environment_ != nullptr; }
HEnvironment* GetEnvironment() const { return environment_; }
- void SetEnvironment(HEnvironment* environment) { environment_ = environment; }
+ // Set the `environment_` field. Raw because this method does not
+ // update the uses lists.
+ void SetRawEnvironment(HEnvironment* environment) { environment_ = environment; }
+
+ // Set the environment of this instruction, copying it from `environment`. While
+ // copying, the uses lists are being updated.
+ void CopyEnvironmentFrom(HEnvironment* environment) {
+ ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena();
+ environment_ = new (allocator) HEnvironment(allocator, environment->Size());
+ environment_->CopyFrom(environment);
+ }
// Returns the number of entries in the environment. Typically, that is the
// number of dex registers in a method. It could be more in case of inlining.