OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/deferred_objects.h" | 5 #include "vm/deferred_objects.h" |
6 | 6 |
7 #include "vm/deopt_instructions.h" | 7 #include "vm/deopt_instructions.h" |
8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if (FLAG_trace_deoptimization_verbose) { | 90 if (FLAG_trace_deoptimization_verbose) { |
91 const Class& cls = Class::Handle(Isolate::Current()->class_table()->At( | 91 const Class& cls = Class::Handle(Isolate::Current()->class_table()->At( |
92 Object::Handle(obj->object()).GetClassId())); | 92 Object::Handle(obj->object()).GetClassId())); |
93 OS::PrintErr("writing instance of class %s ref at %" Px ".\n", | 93 OS::PrintErr("writing instance of class %s ref at %" Px ".\n", |
94 cls.ToCString(), | 94 cls.ToCString(), |
95 reinterpret_cast<uword>(slot())); | 95 reinterpret_cast<uword>(slot())); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 RawInstance* DeferredObject::object() { | 100 RawObject* DeferredObject::object() { |
101 if (object_ == NULL) { | 101 if (object_ == NULL) { |
102 Create(); | 102 Create(); |
103 } | 103 } |
104 return object_->raw(); | 104 return object_->raw(); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 void DeferredObject::Create() { | 108 void DeferredObject::Create() { |
109 if (object_ != NULL) { | 109 if (object_ != NULL) { |
110 return; | 110 return; |
111 } | 111 } |
112 | 112 |
113 Class& cls = Class::Handle(); | 113 Class& cls = Class::Handle(); |
114 cls ^= GetClass(); | 114 cls ^= GetClass(); |
115 | 115 |
116 if (FLAG_trace_deoptimization_verbose) { | 116 if (cls.raw() == Object::context_class()) { |
117 OS::PrintErr("materializing instance of %s (%" Px ", %" Pd " fields)\n", | 117 intptr_t num_variables = Smi::Cast(Object::Handle(GetLength())).Value(); |
118 cls.ToCString(), | 118 if (FLAG_trace_deoptimization_verbose) { |
119 reinterpret_cast<uword>(args_), | 119 OS::PrintErr( |
120 field_count_); | 120 "materializing context of length %" Pd " (%" Px ", %" Pd " vars)\n", |
| 121 num_variables, |
| 122 reinterpret_cast<uword>(args_), |
| 123 field_count_); |
| 124 } |
| 125 object_ = &Context::ZoneHandle(Context::New(num_variables)); |
| 126 |
| 127 } else { |
| 128 if (FLAG_trace_deoptimization_verbose) { |
| 129 OS::PrintErr("materializing instance of %s (%" Px ", %" Pd " fields)\n", |
| 130 cls.ToCString(), |
| 131 reinterpret_cast<uword>(args_), |
| 132 field_count_); |
| 133 } |
| 134 |
| 135 object_ = &Instance::ZoneHandle(Instance::New(cls)); |
121 } | 136 } |
122 | |
123 object_ = &Instance::ZoneHandle(Instance::New(cls)); | |
124 } | 137 } |
125 | 138 |
126 | 139 |
| 140 static intptr_t ToContextIndex(intptr_t offset_in_bytes) { |
| 141 intptr_t result = (offset_in_bytes - Context::variable_offset(0)) / kWordSize; |
| 142 ASSERT(result >= 0); |
| 143 return result; |
| 144 } |
| 145 |
| 146 |
127 void DeferredObject::Fill() { | 147 void DeferredObject::Fill() { |
128 Create(); // Ensure instance is created. | 148 Create(); // Ensure instance is created. |
129 | 149 |
130 Class& cls = Class::Handle(); | 150 Class& cls = Class::Handle(); |
131 cls ^= GetClass(); | 151 cls ^= GetClass(); |
132 | 152 |
133 const Instance& obj = *object_; | 153 if (cls.raw() == Object::context_class()) { |
| 154 const Context& context = Context::Cast(*object_); |
134 | 155 |
135 Smi& offset = Smi::Handle(); | 156 Smi& offset = Smi::Handle(); |
136 Field& field = Field::Handle(); | 157 Object& value = Object::Handle(); |
137 Object& value = Object::Handle(); | |
138 const Array& offset_map = Array::Handle(cls.OffsetToFieldMap()); | |
139 | 158 |
140 for (intptr_t i = 0; i < field_count_; i++) { | 159 for (intptr_t i = 0; i < field_count_; i++) { |
141 offset ^= GetFieldOffset(i); | 160 offset ^= GetFieldOffset(i); |
142 field ^= offset_map.At(offset.Value() / kWordSize); | 161 if (offset.Value() == Context::parent_offset()) { |
143 value = GetValue(i); | 162 // Copy parent. |
144 if (!field.IsNull()) { | 163 Context& parent = Context::Handle(); |
145 obj.SetField(field, value); | 164 parent ^= GetValue(i); |
146 if (FLAG_trace_deoptimization_verbose) { | 165 context.set_parent(parent); |
147 OS::PrintErr(" %s <- %s\n", | 166 if (FLAG_trace_deoptimization_verbose) { |
148 String::Handle(field.name()).ToCString(), | 167 OS::PrintErr(" ctx@parent (offset %" Pd ") <- %s\n", |
149 value.ToCString()); | 168 offset.Value(), |
| 169 value.ToCString()); |
| 170 } |
| 171 } else { |
| 172 intptr_t context_index = ToContextIndex(offset.Value()); |
| 173 value = GetValue(i); |
| 174 context.SetAt(context_index, value); |
| 175 if (FLAG_trace_deoptimization_verbose) { |
| 176 OS::PrintErr(" ctx@%" Pd " (offset %" Pd ") <- %s\n", |
| 177 context_index, |
| 178 offset.Value(), |
| 179 value.ToCString()); |
| 180 } |
150 } | 181 } |
151 } else { | 182 } |
152 ASSERT(cls.IsSignatureClass() || | 183 } else { |
153 (offset.Value() == cls.type_arguments_field_offset())); | 184 const Instance& obj = Instance::Cast(*object_); |
154 obj.SetFieldAtOffset(offset.Value(), value); | 185 |
155 if (FLAG_trace_deoptimization_verbose) { | 186 Smi& offset = Smi::Handle(); |
156 OS::PrintErr(" null Field @ offset(%" Pd ") <- %s\n", | 187 Field& field = Field::Handle(); |
157 offset.Value(), | 188 Object& value = Object::Handle(); |
158 value.ToCString()); | 189 const Array& offset_map = Array::Handle(cls.OffsetToFieldMap()); |
| 190 |
| 191 for (intptr_t i = 0; i < field_count_; i++) { |
| 192 offset ^= GetFieldOffset(i); |
| 193 field ^= offset_map.At(offset.Value() / kWordSize); |
| 194 value = GetValue(i); |
| 195 if (!field.IsNull()) { |
| 196 obj.SetField(field, value); |
| 197 if (FLAG_trace_deoptimization_verbose) { |
| 198 OS::PrintErr(" %s <- %s\n", |
| 199 String::Handle(field.name()).ToCString(), |
| 200 value.ToCString()); |
| 201 } |
| 202 } else { |
| 203 ASSERT(cls.IsSignatureClass() || |
| 204 (offset.Value() == cls.type_arguments_field_offset())); |
| 205 obj.SetFieldAtOffset(offset.Value(), value); |
| 206 if (FLAG_trace_deoptimization_verbose) { |
| 207 OS::PrintErr(" null Field @ offset(%" Pd ") <- %s\n", |
| 208 offset.Value(), |
| 209 value.ToCString()); |
| 210 } |
159 } | 211 } |
160 } | 212 } |
161 } | 213 } |
162 } | 214 } |
163 | 215 |
164 } // namespace dart | 216 } // namespace dart |
OLD | NEW |