| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 13083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13094 } | 13094 } |
| 13095 | 13095 |
| 13096 | 13096 |
| 13097 RawObject* Instance::Evaluate(const String& expr, | 13097 RawObject* Instance::Evaluate(const String& expr, |
| 13098 const Array& param_names, | 13098 const Array& param_names, |
| 13099 const Array& param_values) const { | 13099 const Array& param_values) const { |
| 13100 const Class& cls = Class::Handle(clazz()); | 13100 const Class& cls = Class::Handle(clazz()); |
| 13101 const Function& eval_func = | 13101 const Function& eval_func = |
| 13102 Function::Handle(EvaluateHelper(cls, expr, param_names, false)); | 13102 Function::Handle(EvaluateHelper(cls, expr, param_names, false)); |
| 13103 const Array& args = Array::Handle(Array::New(1 + param_values.Length())); | 13103 const Array& args = Array::Handle(Array::New(1 + param_values.Length())); |
| 13104 Object& param = Object::Handle(); | 13104 PassiveObject& param = PassiveObject::Handle(); |
| 13105 args.SetAt(0, *this); | 13105 args.SetAt(0, *this); |
| 13106 for (intptr_t i = 0; i < param_values.Length(); i++) { | 13106 for (intptr_t i = 0; i < param_values.Length(); i++) { |
| 13107 param = param_values.At(i); | 13107 param = param_values.At(i); |
| 13108 args.SetAt(i + 1, param); | 13108 args.SetAt(i + 1, param); |
| 13109 } | 13109 } |
| 13110 const Object& result = | 13110 return DartEntry::InvokeFunction(eval_func, args); |
| 13111 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); | |
| 13112 return result.raw(); | |
| 13113 } | 13111 } |
| 13114 | 13112 |
| 13115 | 13113 |
| 13116 RawObject* Instance::HashCode() const { | 13114 RawObject* Instance::HashCode() const { |
| 13117 // TODO(koda): Optimize for all builtin classes and all classes | 13115 // TODO(koda): Optimize for all builtin classes and all classes |
| 13118 // that do not override hashCode. | 13116 // that do not override hashCode. |
| 13119 return DartLibraryCalls::HashCode(*this); | 13117 return DartLibraryCalls::HashCode(*this); |
| 13120 } | 13118 } |
| 13121 | 13119 |
| 13122 | 13120 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13333 other_type_arguments = other.arguments(); | 13331 other_type_arguments = other.arguments(); |
| 13334 } | 13332 } |
| 13335 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, | 13333 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, |
| 13336 bound_error); | 13334 bound_error); |
| 13337 } | 13335 } |
| 13338 | 13336 |
| 13339 | 13337 |
| 13340 bool Instance::OperatorEquals(const Instance& other) const { | 13338 bool Instance::OperatorEquals(const Instance& other) const { |
| 13341 // TODO(koda): Optimize for all builtin classes and all classes | 13339 // TODO(koda): Optimize for all builtin classes and all classes |
| 13342 // that do not override operator==. | 13340 // that do not override operator==. |
| 13343 const Object& result = | 13341 return DartLibraryCalls::Equals(*this, other) == Object::bool_true().raw(); |
| 13344 Object::Handle(DartLibraryCalls::Equals(*this, other)); | |
| 13345 return result.raw() == Object::bool_true().raw(); | |
| 13346 } | 13342 } |
| 13347 | 13343 |
| 13348 | 13344 |
| 13349 bool Instance::IsIdenticalTo(const Instance& other) const { | 13345 bool Instance::IsIdenticalTo(const Instance& other) const { |
| 13350 if (raw() == other.raw()) return true; | 13346 if (raw() == other.raw()) return true; |
| 13351 if (IsInteger() && other.IsInteger()) { | 13347 if (IsInteger() && other.IsInteger()) { |
| 13352 return Integer::Cast(*this).Equals(other); | 13348 return Integer::Cast(*this).Equals(other); |
| 13353 } | 13349 } |
| 13354 if (IsDouble() && other.IsDouble()) { | 13350 if (IsDouble() && other.IsDouble()) { |
| 13355 return Double::Cast(*this).CanonicalizeEquals(other); | 13351 return Double::Cast(*this).CanonicalizeEquals(other); |
| (...skipping 4758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18114 Object& element = Object::Handle(At(index)); | 18110 Object& element = Object::Handle(At(index)); |
| 18115 jselement.AddProperty("value", element); | 18111 jselement.AddProperty("value", element); |
| 18116 } | 18112 } |
| 18117 } | 18113 } |
| 18118 } | 18114 } |
| 18119 | 18115 |
| 18120 | 18116 |
| 18121 RawArray* Array::Grow(const Array& source, | 18117 RawArray* Array::Grow(const Array& source, |
| 18122 intptr_t new_length, | 18118 intptr_t new_length, |
| 18123 Heap::Space space) { | 18119 Heap::Space space) { |
| 18124 const Array& result = Array::Handle(Array::New(new_length, space)); | 18120 Isolate* isolate = Isolate::Current(); |
| 18121 const Array& result = Array::Handle(isolate, Array::New(new_length, space)); |
| 18125 intptr_t len = 0; | 18122 intptr_t len = 0; |
| 18126 if (!source.IsNull()) { | 18123 if (!source.IsNull()) { |
| 18127 len = source.Length(); | 18124 len = source.Length(); |
| 18128 result.SetTypeArguments(TypeArguments::Handle(source.GetTypeArguments())); | 18125 result.SetTypeArguments( |
| 18126 TypeArguments::Handle(isolate, source.GetTypeArguments())); |
| 18129 } | 18127 } |
| 18130 ASSERT(new_length >= len); // Cannot copy 'source' into new array. | 18128 ASSERT(new_length >= len); // Cannot copy 'source' into new array. |
| 18131 ASSERT(new_length != len); // Unnecessary copying of array. | 18129 ASSERT(new_length != len); // Unnecessary copying of array. |
| 18132 Object& obj = Object::Handle(); | 18130 PassiveObject& obj = PassiveObject::Handle(isolate); |
| 18133 for (int i = 0; i < len; i++) { | 18131 for (int i = 0; i < len; i++) { |
| 18134 obj = source.At(i); | 18132 obj = source.At(i); |
| 18135 result.SetAt(i, obj); | 18133 result.SetAt(i, obj); |
| 18136 } | 18134 } |
| 18137 return result.raw(); | 18135 return result.raw(); |
| 18138 } | 18136 } |
| 18139 | 18137 |
| 18140 | 18138 |
| 18141 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { | 18139 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { |
| 18142 ASSERT(!growable_array.IsNull()); | 18140 ASSERT(!growable_array.IsNull()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18242 Array::Handle(Array::Grow(contents, new_capacity, space)); | 18240 Array::Handle(Array::Grow(contents, new_capacity, space)); |
| 18243 StorePointer(&(raw_ptr()->data_), new_contents.raw()); | 18241 StorePointer(&(raw_ptr()->data_), new_contents.raw()); |
| 18244 } | 18242 } |
| 18245 | 18243 |
| 18246 | 18244 |
| 18247 RawObject* GrowableObjectArray::RemoveLast() const { | 18245 RawObject* GrowableObjectArray::RemoveLast() const { |
| 18248 ASSERT(!IsNull()); | 18246 ASSERT(!IsNull()); |
| 18249 ASSERT(Length() > 0); | 18247 ASSERT(Length() > 0); |
| 18250 intptr_t index = Length() - 1; | 18248 intptr_t index = Length() - 1; |
| 18251 const Array& contents = Array::Handle(data()); | 18249 const Array& contents = Array::Handle(data()); |
| 18252 const Object& obj = Object::Handle(contents.At(index)); | 18250 const PassiveObject& obj = PassiveObject::Handle(contents.At(index)); |
| 18253 contents.SetAt(index, Object::null_object()); | 18251 contents.SetAt(index, Object::null_object()); |
| 18254 SetLength(index); | 18252 SetLength(index); |
| 18255 return obj.raw(); | 18253 return obj.raw(); |
| 18256 } | 18254 } |
| 18257 | 18255 |
| 18258 | 18256 |
| 18259 bool GrowableObjectArray::CanonicalizeEquals(const Instance& other) const { | 18257 bool GrowableObjectArray::CanonicalizeEquals(const Instance& other) const { |
| 18260 // If both handles point to the same raw instance they are equal. | 18258 // If both handles point to the same raw instance they are equal. |
| 18261 if (this->raw() == other.raw()) { | 18259 if (this->raw() == other.raw()) { |
| 18262 return true; | 18260 return true; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18404 if (!map.UpdateOrInsert(key, value)) { | 18402 if (!map.UpdateOrInsert(key, value)) { |
| 18405 SetModified(); | 18403 SetModified(); |
| 18406 } | 18404 } |
| 18407 StorePointer(&raw_ptr()->data_, map.Release().raw()); | 18405 StorePointer(&raw_ptr()->data_, map.Release().raw()); |
| 18408 } | 18406 } |
| 18409 | 18407 |
| 18410 | 18408 |
| 18411 RawObject* LinkedHashMap::LookUp(const Object& key) const { | 18409 RawObject* LinkedHashMap::LookUp(const Object& key) const { |
| 18412 ASSERT(!IsNull()); | 18410 ASSERT(!IsNull()); |
| 18413 EnumIndexDefaultMap map(data()); | 18411 EnumIndexDefaultMap map(data()); |
| 18414 const Object& result = Object::Handle(map.GetOrNull(key)); | 18412 { |
| 18415 ASSERT(map.Release().raw() == data()); | 18413 NoGCScope no_gc; |
| 18416 return result.raw(); | 18414 RawObject* result = map.GetOrNull(key); |
| 18415 ASSERT(map.Release().raw() == data()); |
| 18416 return result; |
| 18417 } |
| 18417 } | 18418 } |
| 18418 | 18419 |
| 18419 | 18420 |
| 18420 bool LinkedHashMap::Contains(const Object& key) const { | 18421 bool LinkedHashMap::Contains(const Object& key) const { |
| 18421 ASSERT(!IsNull()); | 18422 ASSERT(!IsNull()); |
| 18422 EnumIndexDefaultMap map(data()); | 18423 EnumIndexDefaultMap map(data()); |
| 18423 bool result = map.ContainsKey(key); | 18424 bool result = map.ContainsKey(key); |
| 18424 ASSERT(map.Release().raw() == data()); | 18425 ASSERT(map.Release().raw() == data()); |
| 18425 return result; | 18426 return result; |
| 18426 } | 18427 } |
| 18427 | 18428 |
| 18428 | 18429 |
| 18429 RawObject* LinkedHashMap::Remove(const Object& key) const { | 18430 RawObject* LinkedHashMap::Remove(const Object& key) const { |
| 18430 ASSERT(!IsNull()); | 18431 ASSERT(!IsNull()); |
| 18431 EnumIndexDefaultMap map(data()); | 18432 EnumIndexDefaultMap map(data()); |
| 18432 // TODO(koda): Make 'Remove' also return the old value. | 18433 // TODO(koda): Make 'Remove' also return the old value. |
| 18433 const Object& result = Object::Handle(map.GetOrNull(key)); | 18434 const PassiveObject& result = PassiveObject::Handle(map.GetOrNull(key)); |
| 18434 if (map.Remove(key)) { | 18435 if (map.Remove(key)) { |
| 18435 SetModified(); | 18436 SetModified(); |
| 18436 } | 18437 } |
| 18437 StorePointer(&raw_ptr()->data_, map.Release().raw()); | 18438 StorePointer(&raw_ptr()->data_, map.Release().raw()); |
| 18438 return result.raw(); | 18439 return result.raw(); |
| 18439 } | 18440 } |
| 18440 | 18441 |
| 18441 | 18442 |
| 18442 void LinkedHashMap::Clear() const { | 18443 void LinkedHashMap::Clear() const { |
| 18443 ASSERT(!IsNull()); | 18444 ASSERT(!IsNull()); |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19099 intptr_t old_length = Length(); | 19100 intptr_t old_length = Length(); |
| 19100 intptr_t new_length = old_length + pc_offset_list.Length() - start_index; | 19101 intptr_t new_length = old_length + pc_offset_list.Length() - start_index; |
| 19101 if (new_length == old_length) { | 19102 if (new_length == old_length) { |
| 19102 // Nothing to append. Avoid work and an assert that growing arrays always | 19103 // Nothing to append. Avoid work and an assert that growing arrays always |
| 19103 // increases their size. | 19104 // increases their size. |
| 19104 return; | 19105 return; |
| 19105 } | 19106 } |
| 19106 | 19107 |
| 19107 // Grow the arrays for code, pc_offset pairs to accommodate the new stack | 19108 // Grow the arrays for code, pc_offset pairs to accommodate the new stack |
| 19108 // frames. | 19109 // frames. |
| 19109 Array& code_array = Array::Handle(raw_ptr()->code_array_); | 19110 Isolate* isolate = Isolate::Current(); |
| 19110 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); | 19111 Array& code_array = Array::Handle(isolate, raw_ptr()->code_array_); |
| 19112 Array& pc_offset_array = Array::Handle(isolate, raw_ptr()->pc_offset_array_); |
| 19111 code_array = Array::Grow(code_array, new_length); | 19113 code_array = Array::Grow(code_array, new_length); |
| 19112 pc_offset_array = Array::Grow(pc_offset_array, new_length); | 19114 pc_offset_array = Array::Grow(pc_offset_array, new_length); |
| 19113 set_code_array(code_array); | 19115 set_code_array(code_array); |
| 19114 set_pc_offset_array(pc_offset_array); | 19116 set_pc_offset_array(pc_offset_array); |
| 19115 // Now append the new function and code list to the existing arrays. | 19117 // Now append the new function and code list to the existing arrays. |
| 19116 intptr_t j = start_index; | 19118 intptr_t j = start_index; |
| 19117 Object& obj = Object::Handle(); | 19119 PassiveObject& obj = PassiveObject::Handle(isolate); |
| 19118 for (intptr_t i = old_length; i < new_length; i++, j++) { | 19120 for (intptr_t i = old_length; i < new_length; i++, j++) { |
| 19119 obj = code_list.At(j); | 19121 obj = code_list.At(j); |
| 19120 code_array.SetAt(i, obj); | 19122 code_array.SetAt(i, obj); |
| 19121 obj = pc_offset_list.At(j); | 19123 obj = pc_offset_list.At(j); |
| 19122 pc_offset_array.SetAt(i, obj); | 19124 pc_offset_array.SetAt(i, obj); |
| 19123 } | 19125 } |
| 19124 } | 19126 } |
| 19125 | 19127 |
| 19126 | 19128 |
| 19127 void Stacktrace::SetCatchStacktrace(const Array& code_array, | 19129 void Stacktrace::SetCatchStacktrace(const Array& code_array, |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19580 return tag_label.ToCString(); | 19582 return tag_label.ToCString(); |
| 19581 } | 19583 } |
| 19582 | 19584 |
| 19583 | 19585 |
| 19584 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19586 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 19585 Instance::PrintJSONImpl(stream, ref); | 19587 Instance::PrintJSONImpl(stream, ref); |
| 19586 } | 19588 } |
| 19587 | 19589 |
| 19588 | 19590 |
| 19589 } // namespace dart | 19591 } // namespace dart |
| OLD | NEW |