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

Side by Side Diff: runtime/vm/object.cc

Issue 512933002: Use PassiveObject were possible. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 13078 matching lines...) Expand 10 before | Expand all | Expand 10 after
13089 } 13089 }
13090 13090
13091 13091
13092 RawObject* Instance::Evaluate(const String& expr, 13092 RawObject* Instance::Evaluate(const String& expr,
13093 const Array& param_names, 13093 const Array& param_names,
13094 const Array& param_values) const { 13094 const Array& param_values) const {
13095 const Class& cls = Class::Handle(clazz()); 13095 const Class& cls = Class::Handle(clazz());
13096 const Function& eval_func = 13096 const Function& eval_func =
13097 Function::Handle(EvaluateHelper(cls, expr, param_names, false)); 13097 Function::Handle(EvaluateHelper(cls, expr, param_names, false));
13098 const Array& args = Array::Handle(Array::New(1 + param_values.Length())); 13098 const Array& args = Array::Handle(Array::New(1 + param_values.Length()));
13099 Object& param = Object::Handle(); 13099 PassiveObject& param = PassiveObject::Handle();
13100 args.SetAt(0, *this); 13100 args.SetAt(0, *this);
13101 for (intptr_t i = 0; i < param_values.Length(); i++) { 13101 for (intptr_t i = 0; i < param_values.Length(); i++) {
13102 param = param_values.At(i); 13102 param = param_values.At(i);
13103 args.SetAt(i + 1, param); 13103 args.SetAt(i + 1, param);
13104 } 13104 }
13105 const Object& result = 13105 const PassiveObject& result =
13106 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); 13106 PassiveObject::Handle(DartEntry::InvokeFunction(eval_func, args));
13107 return result.raw(); 13107 return result.raw();
13108 } 13108 }
13109 13109
13110 13110
13111 RawObject* Instance::HashCode() const { 13111 RawObject* Instance::HashCode() const {
13112 // TODO(koda): Optimize for all builtin classes and all classes 13112 // TODO(koda): Optimize for all builtin classes and all classes
13113 // that do not override hashCode. 13113 // that do not override hashCode.
13114 return DartLibraryCalls::HashCode(*this); 13114 return DartLibraryCalls::HashCode(*this);
13115 } 13115 }
13116 13116
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
13328 other_type_arguments = other.arguments(); 13328 other_type_arguments = other.arguments();
13329 } 13329 }
13330 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, 13330 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments,
13331 bound_error); 13331 bound_error);
13332 } 13332 }
13333 13333
13334 13334
13335 bool Instance::OperatorEquals(const Instance& other) const { 13335 bool Instance::OperatorEquals(const Instance& other) const {
13336 // TODO(koda): Optimize for all builtin classes and all classes 13336 // TODO(koda): Optimize for all builtin classes and all classes
13337 // that do not override operator==. 13337 // that do not override operator==.
13338 const Object& result = 13338 const PassiveObject& result =
13339 Object::Handle(DartLibraryCalls::Equals(*this, other)); 13339 PassiveObject::Handle(DartLibraryCalls::Equals(*this, other));
13340 return result.raw() == Object::bool_true().raw(); 13340 return result.raw() == Object::bool_true().raw();
Ivan Posva 2014/08/28 19:31:53 I don't think we need to wrap it in a handle to co
siva 2014/08/29 00:17:01 Done.
13341 } 13341 }
13342 13342
13343 13343
13344 bool Instance::IsIdenticalTo(const Instance& other) const { 13344 bool Instance::IsIdenticalTo(const Instance& other) const {
13345 if (raw() == other.raw()) return true; 13345 if (raw() == other.raw()) return true;
13346 if (IsInteger() && other.IsInteger()) { 13346 if (IsInteger() && other.IsInteger()) {
13347 return Integer::Cast(*this).Equals(other); 13347 return Integer::Cast(*this).Equals(other);
13348 } 13348 }
13349 if (IsDouble() && other.IsDouble()) { 13349 if (IsDouble() && other.IsDouble()) {
13350 return Double::Cast(*this).CanonicalizeEquals(other); 13350 return Double::Cast(*this).CanonicalizeEquals(other);
(...skipping 4755 matching lines...) Expand 10 before | Expand all | Expand 10 after
18106 JSONObject jselement(&jsarr); 18106 JSONObject jselement(&jsarr);
18107 jselement.AddProperty("index", index); 18107 jselement.AddProperty("index", index);
18108 18108
18109 Object& element = Object::Handle(At(index)); 18109 Object& element = Object::Handle(At(index));
18110 jselement.AddProperty("value", element); 18110 jselement.AddProperty("value", element);
18111 } 18111 }
18112 } 18112 }
18113 } 18113 }
18114 18114
18115 18115
18116 RawArray* Array::Grow(const Array& source, 18116 RawArray* Array::Grow(const Array& source,
Ivan Posva 2014/08/28 19:31:53 Should we be requiring the isolate be passed into
siva 2014/08/29 00:17:01 I added a local variable isolate and used that in
18117 intptr_t new_length, 18117 intptr_t new_length,
18118 Heap::Space space) { 18118 Heap::Space space) {
18119 const Array& result = Array::Handle(Array::New(new_length, space)); 18119 const Array& result = Array::Handle(Array::New(new_length, space));
18120 intptr_t len = 0; 18120 intptr_t len = 0;
18121 if (!source.IsNull()) { 18121 if (!source.IsNull()) {
18122 len = source.Length(); 18122 len = source.Length();
18123 result.SetTypeArguments(TypeArguments::Handle(source.GetTypeArguments())); 18123 result.SetTypeArguments(TypeArguments::Handle(source.GetTypeArguments()));
18124 } 18124 }
18125 ASSERT(new_length >= len); // Cannot copy 'source' into new array. 18125 ASSERT(new_length >= len); // Cannot copy 'source' into new array.
18126 ASSERT(new_length != len); // Unnecessary copying of array. 18126 ASSERT(new_length != len); // Unnecessary copying of array.
18127 Object& obj = Object::Handle(); 18127 PassiveObject& obj = PassiveObject::Handle();
18128 for (int i = 0; i < len; i++) { 18128 for (int i = 0; i < len; i++) {
18129 obj = source.At(i); 18129 obj = source.At(i);
18130 result.SetAt(i, obj); 18130 result.SetAt(i, obj);
18131 } 18131 }
18132 return result.raw(); 18132 return result.raw();
18133 } 18133 }
18134 18134
18135 18135
18136 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { 18136 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) {
18137 ASSERT(!growable_array.IsNull()); 18137 ASSERT(!growable_array.IsNull());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
18237 Array::Handle(Array::Grow(contents, new_capacity, space)); 18237 Array::Handle(Array::Grow(contents, new_capacity, space));
18238 StorePointer(&(raw_ptr()->data_), new_contents.raw()); 18238 StorePointer(&(raw_ptr()->data_), new_contents.raw());
18239 } 18239 }
18240 18240
18241 18241
18242 RawObject* GrowableObjectArray::RemoveLast() const { 18242 RawObject* GrowableObjectArray::RemoveLast() const {
18243 ASSERT(!IsNull()); 18243 ASSERT(!IsNull());
18244 ASSERT(Length() > 0); 18244 ASSERT(Length() > 0);
18245 intptr_t index = Length() - 1; 18245 intptr_t index = Length() - 1;
18246 const Array& contents = Array::Handle(data()); 18246 const Array& contents = Array::Handle(data());
18247 const Object& obj = Object::Handle(contents.At(index)); 18247 const PassiveObject& obj = PassiveObject::Handle(contents.At(index));
18248 contents.SetAt(index, Object::null_object()); 18248 contents.SetAt(index, Object::null_object());
18249 SetLength(index); 18249 SetLength(index);
18250 return obj.raw(); 18250 return obj.raw();
18251 } 18251 }
18252 18252
18253 18253
18254 bool GrowableObjectArray::CanonicalizeEquals(const Instance& other) const { 18254 bool GrowableObjectArray::CanonicalizeEquals(const Instance& other) const {
18255 // If both handles point to the same raw instance they are equal. 18255 // If both handles point to the same raw instance they are equal.
18256 if (this->raw() == other.raw()) { 18256 if (this->raw() == other.raw()) {
18257 return true; 18257 return true;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
18399 if (!map.UpdateOrInsert(key, value)) { 18399 if (!map.UpdateOrInsert(key, value)) {
18400 SetModified(); 18400 SetModified();
18401 } 18401 }
18402 StorePointer(&raw_ptr()->data_, map.Release().raw()); 18402 StorePointer(&raw_ptr()->data_, map.Release().raw());
18403 } 18403 }
18404 18404
18405 18405
18406 RawObject* LinkedHashMap::LookUp(const Object& key) const { 18406 RawObject* LinkedHashMap::LookUp(const Object& key) const {
18407 ASSERT(!IsNull()); 18407 ASSERT(!IsNull());
18408 EnumIndexDefaultMap map(data()); 18408 EnumIndexDefaultMap map(data());
18409 const Object& result = Object::Handle(map.GetOrNull(key)); 18409 const PassiveObject& result = PassiveObject::Handle(map.GetOrNull(key));
18410 ASSERT(map.Release().raw() == data()); 18410 ASSERT(map.Release().raw() == data());
Ivan Posva 2014/08/28 19:31:53 You could stick the ASSERT in a NoGCScope and then
siva 2014/08/29 00:17:01 Done.
18411 return result.raw(); 18411 return result.raw();
18412 } 18412 }
18413 18413
18414 18414
18415 bool LinkedHashMap::Contains(const Object& key) const { 18415 bool LinkedHashMap::Contains(const Object& key) const {
18416 ASSERT(!IsNull()); 18416 ASSERT(!IsNull());
18417 EnumIndexDefaultMap map(data()); 18417 EnumIndexDefaultMap map(data());
18418 bool result = map.ContainsKey(key); 18418 bool result = map.ContainsKey(key);
18419 ASSERT(map.Release().raw() == data()); 18419 ASSERT(map.Release().raw() == data());
18420 return result; 18420 return result;
18421 } 18421 }
18422 18422
18423 18423
18424 RawObject* LinkedHashMap::Remove(const Object& key) const { 18424 RawObject* LinkedHashMap::Remove(const Object& key) const {
18425 ASSERT(!IsNull()); 18425 ASSERT(!IsNull());
18426 EnumIndexDefaultMap map(data()); 18426 EnumIndexDefaultMap map(data());
18427 // TODO(koda): Make 'Remove' also return the old value. 18427 // TODO(koda): Make 'Remove' also return the old value.
18428 const Object& result = Object::Handle(map.GetOrNull(key)); 18428 const PassiveObject& result = PassiveObject::Handle(map.GetOrNull(key));
18429 if (map.Remove(key)) { 18429 if (map.Remove(key)) {
18430 SetModified(); 18430 SetModified();
18431 } 18431 }
18432 StorePointer(&raw_ptr()->data_, map.Release().raw()); 18432 StorePointer(&raw_ptr()->data_, map.Release().raw());
18433 return result.raw(); 18433 return result.raw();
18434 } 18434 }
18435 18435
18436 18436
18437 void LinkedHashMap::Clear() const { 18437 void LinkedHashMap::Clear() const {
18438 ASSERT(!IsNull()); 18438 ASSERT(!IsNull());
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
19079 } 19079 }
19080 result.set_code_array(code_array); 19080 result.set_code_array(code_array);
19081 result.set_pc_offset_array(pc_offset_array); 19081 result.set_pc_offset_array(pc_offset_array);
19082 result.SetCatchStacktrace(Object::empty_array(), 19082 result.SetCatchStacktrace(Object::empty_array(),
19083 Object::empty_array()); 19083 Object::empty_array());
19084 result.set_expand_inlined(true); // default. 19084 result.set_expand_inlined(true); // default.
19085 return result.raw(); 19085 return result.raw();
19086 } 19086 }
19087 19087
19088 19088
19089 void Stacktrace::Append(const Array& code_list, 19089 void Stacktrace::Append(const Array& code_list,
Ivan Posva 2014/08/28 19:31:53 Pass in isolate over here?
siva 2014/08/29 00:17:01 I added a local variable isolate and used that in
19090 const Array& pc_offset_list, 19090 const Array& pc_offset_list,
19091 const intptr_t start_index) const { 19091 const intptr_t start_index) const {
19092 ASSERT(start_index <= code_list.Length()); 19092 ASSERT(start_index <= code_list.Length());
19093 ASSERT(pc_offset_list.Length() == code_list.Length()); 19093 ASSERT(pc_offset_list.Length() == code_list.Length());
19094 intptr_t old_length = Length(); 19094 intptr_t old_length = Length();
19095 intptr_t new_length = old_length + pc_offset_list.Length() - start_index; 19095 intptr_t new_length = old_length + pc_offset_list.Length() - start_index;
19096 if (new_length == old_length) { 19096 if (new_length == old_length) {
19097 // Nothing to append. Avoid work and an assert that growing arrays always 19097 // Nothing to append. Avoid work and an assert that growing arrays always
19098 // increases their size. 19098 // increases their size.
19099 return; 19099 return;
19100 } 19100 }
19101 19101
19102 // Grow the arrays for code, pc_offset pairs to accommodate the new stack 19102 // Grow the arrays for code, pc_offset pairs to accommodate the new stack
19103 // frames. 19103 // frames.
19104 Array& code_array = Array::Handle(raw_ptr()->code_array_); 19104 Array& code_array = Array::Handle(raw_ptr()->code_array_);
19105 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); 19105 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_);
19106 code_array = Array::Grow(code_array, new_length); 19106 code_array = Array::Grow(code_array, new_length);
19107 pc_offset_array = Array::Grow(pc_offset_array, new_length); 19107 pc_offset_array = Array::Grow(pc_offset_array, new_length);
19108 set_code_array(code_array); 19108 set_code_array(code_array);
19109 set_pc_offset_array(pc_offset_array); 19109 set_pc_offset_array(pc_offset_array);
19110 // Now append the new function and code list to the existing arrays. 19110 // Now append the new function and code list to the existing arrays.
19111 intptr_t j = start_index; 19111 intptr_t j = start_index;
19112 Object& obj = Object::Handle(); 19112 PassiveObject& obj = PassiveObject::Handle();
19113 for (intptr_t i = old_length; i < new_length; i++, j++) { 19113 for (intptr_t i = old_length; i < new_length; i++, j++) {
19114 obj = code_list.At(j); 19114 obj = code_list.At(j);
19115 code_array.SetAt(i, obj); 19115 code_array.SetAt(i, obj);
19116 obj = pc_offset_list.At(j); 19116 obj = pc_offset_list.At(j);
19117 pc_offset_array.SetAt(i, obj); 19117 pc_offset_array.SetAt(i, obj);
19118 } 19118 }
19119 } 19119 }
19120 19120
19121 19121
19122 void Stacktrace::SetCatchStacktrace(const Array& code_array, 19122 void Stacktrace::SetCatchStacktrace(const Array& code_array,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
19575 return tag_label.ToCString(); 19575 return tag_label.ToCString();
19576 } 19576 }
19577 19577
19578 19578
19579 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 19579 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
19580 Instance::PrintJSONImpl(stream, ref); 19580 Instance::PrintJSONImpl(stream, ref);
19581 } 19581 }
19582 19582
19583 19583
19584 } // namespace dart 19584 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698