| 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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 bool_value = Bool::New(false); | 1098 bool_value = Bool::New(false); |
| 1099 object_store->set_false_value(bool_value); | 1099 object_store->set_false_value(bool_value); |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 | 1102 |
| 1103 void Object::Print() const { | 1103 void Object::Print() const { |
| 1104 OS::Print("%s\n", ToCString()); | 1104 OS::Print("%s\n", ToCString()); |
| 1105 } | 1105 } |
| 1106 | 1106 |
| 1107 | 1107 |
| 1108 RawString* Object::DictionaryName() const { |
| 1109 return String::null(); |
| 1110 } |
| 1111 |
| 1112 |
| 1108 void Object::InitializeObject(uword address, intptr_t class_id, intptr_t size) { | 1113 void Object::InitializeObject(uword address, intptr_t class_id, intptr_t size) { |
| 1109 // TODO(iposva): Get a proper halt instruction from the assembler which | 1114 // TODO(iposva): Get a proper halt instruction from the assembler which |
| 1110 // would be needed here for code objects. | 1115 // would be needed here for code objects. |
| 1111 uword initial_value = reinterpret_cast<uword>(null_); | 1116 uword initial_value = reinterpret_cast<uword>(null_); |
| 1112 uword cur = address; | 1117 uword cur = address; |
| 1113 uword end = address + size; | 1118 uword end = address + size; |
| 1114 while (cur < end) { | 1119 while (cur < end) { |
| 1115 *reinterpret_cast<uword*>(cur) = initial_value; | 1120 *reinterpret_cast<uword*>(cur) = initial_value; |
| 1116 cur += kWordSize; | 1121 cur += kWordSize; |
| 1117 } | 1122 } |
| (...skipping 4874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5992 void Library::GrowDictionary(const Array& dict, intptr_t dict_size) const { | 5997 void Library::GrowDictionary(const Array& dict, intptr_t dict_size) const { |
| 5993 // TODO(iposva): Avoid exponential growth. | 5998 // TODO(iposva): Avoid exponential growth. |
| 5994 intptr_t new_dict_size = dict_size * 2; | 5999 intptr_t new_dict_size = dict_size * 2; |
| 5995 const Array& new_dict = | 6000 const Array& new_dict = |
| 5996 Array::Handle(Array::New(new_dict_size + 1, Heap::kOld)); | 6001 Array::Handle(Array::New(new_dict_size + 1, Heap::kOld)); |
| 5997 // Rehash all elements from the original dictionary | 6002 // Rehash all elements from the original dictionary |
| 5998 // to the newly allocated array. | 6003 // to the newly allocated array. |
| 5999 Object& entry = Class::Handle(); | 6004 Object& entry = Class::Handle(); |
| 6000 String& entry_name = String::Handle(); | 6005 String& entry_name = String::Handle(); |
| 6001 Object& new_entry = Object::Handle(); | 6006 Object& new_entry = Object::Handle(); |
| 6002 Class& cls = Class::Handle(); | |
| 6003 Function& func = Function::Handle(); | |
| 6004 Field& field = Field::Handle(); | |
| 6005 LibraryPrefix& prefix = LibraryPrefix::Handle(); | |
| 6006 for (intptr_t i = 0; i < dict_size; i++) { | 6007 for (intptr_t i = 0; i < dict_size; i++) { |
| 6007 entry = dict.At(i); | 6008 entry = dict.At(i); |
| 6008 if (!entry.IsNull()) { | 6009 if (!entry.IsNull()) { |
| 6009 if (entry.IsClass()) { | 6010 entry_name = entry.DictionaryName(); |
| 6010 cls ^= entry.raw(); | 6011 ASSERT(!entry_name.IsNull()); |
| 6011 entry_name = cls.Name(); | |
| 6012 } else if (entry.IsFunction()) { | |
| 6013 func ^= entry.raw(); | |
| 6014 entry_name = func.name(); | |
| 6015 } else if (entry.IsField()) { | |
| 6016 field ^= entry.raw(); | |
| 6017 entry_name = field.name(); | |
| 6018 } else if (entry.IsLibraryPrefix()) { | |
| 6019 prefix ^= entry.raw(); | |
| 6020 entry_name = prefix.name(); | |
| 6021 } else { | |
| 6022 UNREACHABLE(); | |
| 6023 } | |
| 6024 intptr_t hash = entry_name.Hash(); | 6012 intptr_t hash = entry_name.Hash(); |
| 6025 intptr_t index = hash % new_dict_size; | 6013 intptr_t index = hash % new_dict_size; |
| 6026 new_entry = new_dict.At(index); | 6014 new_entry = new_dict.At(index); |
| 6027 while (!new_entry.IsNull()) { | 6015 while (!new_entry.IsNull()) { |
| 6028 index = (index + 1) % new_dict_size; // Move to next element. | 6016 index = (index + 1) % new_dict_size; // Move to next element. |
| 6029 new_entry = new_dict.At(index); | 6017 new_entry = new_dict.At(index); |
| 6030 } | 6018 } |
| 6031 new_dict.SetAt(index, entry); | 6019 new_dict.SetAt(index, entry); |
| 6032 } | 6020 } |
| 6033 } | 6021 } |
| 6034 // Copy used count. | 6022 // Copy used count. |
| 6035 new_entry = dict.At(dict_size); | 6023 new_entry = dict.At(dict_size); |
| 6036 new_dict.SetAt(new_dict_size, new_entry); | 6024 new_dict.SetAt(new_dict_size, new_entry); |
| 6037 // Remember the new dictionary now. | 6025 // Remember the new dictionary now. |
| 6038 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); | 6026 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); |
| 6039 } | 6027 } |
| 6040 | 6028 |
| 6041 | 6029 |
| 6042 void Library::AddObject(const Object& obj, const String& name) const { | 6030 void Library::AddObject(const Object& obj, const String& name) const { |
| 6043 ASSERT(obj.IsClass() || | 6031 ASSERT(obj.IsClass() || |
| 6044 obj.IsFunction() || | 6032 obj.IsFunction() || |
| 6045 obj.IsField() || | 6033 obj.IsField() || |
| 6046 obj.IsLibraryPrefix()); | 6034 obj.IsLibraryPrefix()); |
| 6047 ASSERT((LookupLocalObject(name) == Object::null()) || | 6035 ASSERT(name.Equals(String::Handle(obj.DictionaryName()))); |
| 6048 ((obj.IsLibraryPrefix() || | 6036 ASSERT(LookupLocalObject(name) == Object::null()); |
| 6049 (obj.IsClass() && | |
| 6050 Class::CheckedHandle(obj.raw()).IsCanonicalSignatureClass())) && | |
| 6051 (LookupLocalObject(name) == Object::null()))); | |
| 6052 const Array& dict = Array::Handle(dictionary()); | 6037 const Array& dict = Array::Handle(dictionary()); |
| 6053 intptr_t dict_size = dict.Length() - 1; | 6038 intptr_t dict_size = dict.Length() - 1; |
| 6054 intptr_t index = name.Hash() % dict_size; | 6039 intptr_t index = name.Hash() % dict_size; |
| 6055 | 6040 |
| 6056 Object& entry = Object::Handle(); | 6041 Object& entry = Object::Handle(); |
| 6057 entry = dict.At(index); | 6042 entry = dict.At(index); |
| 6058 // An empty spot will be found because we keep the hash set at most 75% full. | 6043 // An empty spot will be found because we keep the hash set at most 75% full. |
| 6059 while (!entry.IsNull()) { | 6044 while (!entry.IsNull()) { |
| 6060 index = (index + 1) % dict_size; | 6045 index = (index + 1) % dict_size; |
| 6061 entry = dict.At(index); | 6046 entry = dict.At(index); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 6085 Isolate* isolate = Isolate::Current(); | 6070 Isolate* isolate = Isolate::Current(); |
| 6086 const Array& dict = Array::Handle(isolate, dictionary()); | 6071 const Array& dict = Array::Handle(isolate, dictionary()); |
| 6087 intptr_t dict_size = dict.Length() - 1; | 6072 intptr_t dict_size = dict.Length() - 1; |
| 6088 *index = name.Hash() % dict_size; | 6073 *index = name.Hash() % dict_size; |
| 6089 | 6074 |
| 6090 Object& entry = Object::Handle(isolate); | 6075 Object& entry = Object::Handle(isolate); |
| 6091 String& entry_name = String::Handle(isolate); | 6076 String& entry_name = String::Handle(isolate); |
| 6092 entry = dict.At(*index); | 6077 entry = dict.At(*index); |
| 6093 // Search the entry in the hash set. | 6078 // Search the entry in the hash set. |
| 6094 while (!entry.IsNull()) { | 6079 while (!entry.IsNull()) { |
| 6095 if (entry.IsClass()) { | 6080 entry_name = entry.DictionaryName(); |
| 6096 entry_name = Class::Cast(entry).Name(); | 6081 ASSERT(!entry_name.IsNull()); |
| 6097 } else if (entry.IsFunction()) { | 6082 if (entry_name.Equals(name)) { |
| 6098 entry_name = Function::Cast(entry).name(); | |
| 6099 } else if (entry.IsField()) { | |
| 6100 entry_name = Field::Cast(entry).name(); | |
| 6101 } else if (entry.IsLibraryPrefix()) { | |
| 6102 entry_name = LibraryPrefix::Cast(entry).name(); | |
| 6103 } else { | |
| 6104 UNREACHABLE(); | |
| 6105 } | |
| 6106 if (entry_name.Equals(name)) { | |
| 6107 return entry.raw(); | 6083 return entry.raw(); |
| 6108 } | 6084 } |
| 6109 *index = (*index + 1) % dict_size; | 6085 *index = (*index + 1) % dict_size; |
| 6110 entry = dict.At(*index); | 6086 entry = dict.At(*index); |
| 6111 } | 6087 } |
| 6112 return Object::null(); | 6088 return Object::null(); |
| 6113 } | 6089 } |
| 6114 | 6090 |
| 6115 | 6091 |
| 6116 void Library::ReplaceObject(const Object& obj, const String& name) const { | 6092 void Library::ReplaceObject(const Object& obj, const String& name) const { |
| (...skipping 5690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11807 } | 11783 } |
| 11808 return result.raw(); | 11784 return result.raw(); |
| 11809 } | 11785 } |
| 11810 | 11786 |
| 11811 | 11787 |
| 11812 const char* WeakProperty::ToCString() const { | 11788 const char* WeakProperty::ToCString() const { |
| 11813 return "_WeakProperty"; | 11789 return "_WeakProperty"; |
| 11814 } | 11790 } |
| 11815 | 11791 |
| 11816 } // namespace dart | 11792 } // namespace dart |
| OLD | NEW |