@@ -3550,7 +3550,8 @@ Address TranslatedState::DecompressIfNeeded(intptr_t value) {
3550
3550
}
3551
3551
}
3552
3552
3553
- TranslatedState::TranslatedState (const JavaScriptFrame* frame) {
3553
+ TranslatedState::TranslatedState (const JavaScriptFrame* frame)
3554
+ : purpose_(kFrameInspection ) {
3554
3555
int deopt_index = Safepoint::kNoDeoptimizationIndex ;
3555
3556
DeoptimizationData data =
3556
3557
static_cast <const OptimizedFrame*>(frame)->GetDeoptimizationData (
@@ -3947,25 +3948,63 @@ void TranslatedState::EnsureCapturedObjectAllocatedAt(
3947
3948
}
3948
3949
3949
3950
default :
3950
- CHECK (map->IsJSObjectMap ());
3951
3951
EnsureJSObjectAllocated (slot, map);
3952
- TranslatedValue* properties_slot = &(frame->values_ [value_index]);
3953
- value_index++;
3952
+ int remaining_children_count = slot->GetChildrenCount () - 1 ;
3953
+
3954
+ TranslatedValue* properties_slot = frame->ValueAt (value_index);
3955
+ value_index++, remaining_children_count--;
3954
3956
if (properties_slot->kind () == TranslatedValue::kCapturedObject ) {
3955
- // If we are materializing the property array, make sure we put
3956
- // the mutable heap numbers at the right places.
3957
+ // We are materializing the property array, so make sure we put the
3958
+ // mutable heap numbers at the right places.
3957
3959
EnsurePropertiesAllocatedAndMarked (properties_slot, map);
3958
3960
EnsureChildrenAllocated (properties_slot->GetChildrenCount (), frame,
3959
3961
&value_index, worklist);
3962
+ } else {
3963
+ CHECK_EQ (properties_slot->kind (), TranslatedValue::kTagged );
3960
3964
}
3961
- // Make sure all the remaining children (after the map and properties) are
3962
- // allocated.
3963
- return EnsureChildrenAllocated (slot->GetChildrenCount () - 2 , frame,
3965
+
3966
+ TranslatedValue* elements_slot = frame->ValueAt (value_index);
3967
+ value_index++, remaining_children_count--;
3968
+ if (elements_slot->kind () == TranslatedValue::kCapturedObject ||
3969
+ !map->IsJSArrayMap ()) {
3970
+ // Handle this case with the other remaining children below.
3971
+ value_index--, remaining_children_count++;
3972
+ } else {
3973
+ CHECK_EQ (elements_slot->kind (), TranslatedValue::kTagged );
3974
+ elements_slot->GetValue ();
3975
+ if (purpose_ == kFrameInspection ) {
3976
+ // We are materializing a JSArray for the purpose of frame inspection.
3977
+ // If we were to construct it with the above elements value then an
3978
+ // actual deopt later on might create another JSArray instance with
3979
+ // the same elements store. That would violate the key assumption
3980
+ // behind left-trimming.
3981
+ elements_slot->ReplaceElementsArrayWithCopy ();
3982
+ }
3983
+ }
3984
+
3985
+ // Make sure all the remaining children (after the map, properties store,
3986
+ // and possibly elements store) are allocated.
3987
+ return EnsureChildrenAllocated (remaining_children_count, frame,
3964
3988
&value_index, worklist);
3965
3989
}
3966
3990
UNREACHABLE ();
3967
3991
}
3968
3992
3993
+ void TranslatedValue::ReplaceElementsArrayWithCopy () {
3994
+ DCHECK_EQ (kind (), TranslatedValue::kTagged );
3995
+ DCHECK_EQ (materialization_state (), TranslatedValue::kFinished );
3996
+ auto elements = Handle <FixedArrayBase>::cast (GetValue ());
3997
+ DCHECK (elements->IsFixedArray () || elements->IsFixedDoubleArray ());
3998
+ if (elements->IsFixedDoubleArray ()) {
3999
+ DCHECK (!elements->IsCowArray ());
4000
+ set_storage (isolate ()->factory ()->CopyFixedDoubleArray (
4001
+ Handle <FixedDoubleArray>::cast (elements)));
4002
+ } else if (!elements->IsCowArray ()) {
4003
+ set_storage (isolate ()->factory ()->CopyFixedArray (
4004
+ Handle <FixedArray>::cast (elements)));
4005
+ }
4006
+ }
4007
+
3969
4008
void TranslatedState::EnsureChildrenAllocated (int count, TranslatedFrame* frame,
3970
4009
int * value_index,
3971
4010
std::stack<int >* worklist) {
@@ -4030,6 +4069,7 @@ Handle<ByteArray> TranslatedState::AllocateStorageFor(TranslatedValue* slot) {
4030
4069
4031
4070
void TranslatedState::EnsureJSObjectAllocated (TranslatedValue* slot,
4032
4071
Handle <Map> map) {
4072
+ CHECK (map->IsJSObjectMap ());
4033
4073
CHECK_EQ (map->instance_size (), slot->GetChildrenCount () * kTaggedSize );
4034
4074
4035
4075
Handle <ByteArray> object_storage = AllocateStorageFor (slot);
0 commit comments