| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 225 |
| 226 Class fake; | 226 Class fake; |
| 227 // Initialization from Class::New<Class>. | 227 // Initialization from Class::New<Class>. |
| 228 // Directly set raw_ to break a circular dependency: SetRaw will attempt | 228 // Directly set raw_ to break a circular dependency: SetRaw will attempt |
| 229 // to lookup class class in the class table where it is not registered yet. | 229 // to lookup class class in the class table where it is not registered yet. |
| 230 cls.raw_ = class_class_; | 230 cls.raw_ = class_class_; |
| 231 cls.set_handle_vtable(fake.vtable()); | 231 cls.set_handle_vtable(fake.vtable()); |
| 232 cls.set_instance_size(Class::InstanceSize()); | 232 cls.set_instance_size(Class::InstanceSize()); |
| 233 cls.set_next_field_offset(Class::InstanceSize()); | 233 cls.set_next_field_offset(Class::InstanceSize()); |
| 234 cls.set_id(Class::kClassId); | 234 cls.set_id(Class::kClassId); |
| 235 cls.raw_ptr()->is_const_ = false; | 235 cls.raw_ptr()->state_bits_ = 0; |
| 236 cls.raw_ptr()->is_interface_ = false; | |
| 237 cls.set_is_finalized(); | 236 cls.set_is_finalized(); |
| 238 cls.raw_ptr()->type_arguments_instance_field_offset_ = | 237 cls.raw_ptr()->type_arguments_instance_field_offset_ = |
| 239 Class::kNoTypeArguments; | 238 Class::kNoTypeArguments; |
| 240 cls.raw_ptr()->num_native_fields_ = 0; | 239 cls.raw_ptr()->num_native_fields_ = 0; |
| 241 cls.InitEmptyFields(); | 240 cls.InitEmptyFields(); |
| 242 isolate->class_table()->Register(cls); | 241 isolate->class_table()->Register(cls); |
| 243 } | 242 } |
| 244 | 243 |
| 245 // Allocate and initialize the null class. | 244 // Allocate and initialize the null class. |
| 246 cls = Class::New<Instance>(kNullCid); | 245 cls = Class::New<Instance>(kNullCid); |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 NoGCScope no_gc; | 1190 NoGCScope no_gc; |
| 1192 result ^= raw; | 1191 result ^= raw; |
| 1193 } | 1192 } |
| 1194 FakeObject fake; | 1193 FakeObject fake; |
| 1195 result.set_handle_vtable(fake.vtable()); | 1194 result.set_handle_vtable(fake.vtable()); |
| 1196 result.set_instance_size(FakeObject::InstanceSize()); | 1195 result.set_instance_size(FakeObject::InstanceSize()); |
| 1197 result.set_next_field_offset(FakeObject::InstanceSize()); | 1196 result.set_next_field_offset(FakeObject::InstanceSize()); |
| 1198 result.set_id((FakeObject::kClassId != kInstanceCid && | 1197 result.set_id((FakeObject::kClassId != kInstanceCid && |
| 1199 FakeObject::kClassId != kClosureCid) ? | 1198 FakeObject::kClassId != kClosureCid) ? |
| 1200 FakeObject::kClassId : kIllegalCid); | 1199 FakeObject::kClassId : kIllegalCid); |
| 1201 result.raw_ptr()->is_const_ = false; | 1200 result.raw_ptr()->state_bits_ = 0; |
| 1202 result.raw_ptr()->is_interface_ = false; | |
| 1203 // VM backed classes are almost ready: run checks and resolve class | 1201 // VM backed classes are almost ready: run checks and resolve class |
| 1204 // references, but do not recompute size. | 1202 // references, but do not recompute size. |
| 1205 result.raw_ptr()->class_state_ = RawClass::kPreFinalized; | 1203 result.set_is_prefinalized(); |
| 1206 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1204 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
| 1207 result.raw_ptr()->num_native_fields_ = 0; | 1205 result.raw_ptr()->num_native_fields_ = 0; |
| 1208 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; | 1206 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; |
| 1209 result.InitEmptyFields(); | 1207 result.InitEmptyFields(); |
| 1210 Isolate::Current()->class_table()->Register(result); | 1208 Isolate::Current()->class_table()->Register(result); |
| 1211 return result.raw(); | 1209 return result.raw(); |
| 1212 } | 1210 } |
| 1213 | 1211 |
| 1214 | 1212 |
| 1215 // Initialize class fields of type Array with empty array. | 1213 // Initialize class fields of type Array with empty array. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 return closure.raw(); | 1291 return closure.raw(); |
| 1294 } | 1292 } |
| 1295 | 1293 |
| 1296 | 1294 |
| 1297 void Class::set_signature_function(const Function& value) const { | 1295 void Class::set_signature_function(const Function& value) const { |
| 1298 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 1296 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
| 1299 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 1297 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
| 1300 } | 1298 } |
| 1301 | 1299 |
| 1302 | 1300 |
| 1303 void Class::set_class_state(int8_t state) const { | 1301 void Class::set_class_state(RawClass::ClassState state) const { |
| 1304 ASSERT((state == RawClass::kAllocated) || | 1302 ASSERT((state == RawClass::kAllocated) || |
| 1305 (state == RawClass::kPreFinalized) || | 1303 (state == RawClass::kPreFinalized) || |
| 1306 (state == RawClass::kFinalized)); | 1304 (state == RawClass::kFinalized)); |
| 1307 raw_ptr()->class_state_ = state; | 1305 uword bits = raw_ptr()->state_bits_; |
| 1306 raw_ptr()->state_bits_ = StateBits::update(state, bits); |
| 1307 } |
| 1308 |
| 1309 |
| 1310 void Class::set_state_bits(uint8_t bits) const { |
| 1311 raw_ptr()->state_bits_ = bits; |
| 1308 } | 1312 } |
| 1309 | 1313 |
| 1310 | 1314 |
| 1311 void Class::set_library(const Library& value) const { | 1315 void Class::set_library(const Library& value) const { |
| 1312 StorePointer(&raw_ptr()->library_, value.raw()); | 1316 StorePointer(&raw_ptr()->library_, value.raw()); |
| 1313 } | 1317 } |
| 1314 | 1318 |
| 1315 | 1319 |
| 1316 void Class::set_type_parameters(const TypeArguments& value) const { | 1320 void Class::set_type_parameters(const TypeArguments& value) const { |
| 1317 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | 1321 StorePointer(&raw_ptr()->type_parameters_, value.raw()); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 Heap::kOld); | 1575 Heap::kOld); |
| 1572 NoGCScope no_gc; | 1576 NoGCScope no_gc; |
| 1573 result ^= raw; | 1577 result ^= raw; |
| 1574 } | 1578 } |
| 1575 FakeInstance fake; | 1579 FakeInstance fake; |
| 1576 ASSERT(fake.IsInstance()); | 1580 ASSERT(fake.IsInstance()); |
| 1577 result.set_handle_vtable(fake.vtable()); | 1581 result.set_handle_vtable(fake.vtable()); |
| 1578 result.set_instance_size(FakeInstance::InstanceSize()); | 1582 result.set_instance_size(FakeInstance::InstanceSize()); |
| 1579 result.set_next_field_offset(FakeInstance::InstanceSize()); | 1583 result.set_next_field_offset(FakeInstance::InstanceSize()); |
| 1580 result.set_id(index); | 1584 result.set_id(index); |
| 1581 result.raw_ptr()->is_const_ = false; | 1585 result.raw_ptr()->state_bits_ = 0; |
| 1582 result.raw_ptr()->is_interface_ = false; | |
| 1583 result.raw_ptr()->class_state_ = RawClass::kAllocated; | |
| 1584 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1586 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
| 1585 result.raw_ptr()->num_native_fields_ = 0; | 1587 result.raw_ptr()->num_native_fields_ = 0; |
| 1586 result.InitEmptyFields(); | 1588 result.InitEmptyFields(); |
| 1587 Isolate::Current()->class_table()->Register(result); | 1589 Isolate::Current()->class_table()->Register(result); |
| 1588 return result.raw(); | 1590 return result.raw(); |
| 1589 } | 1591 } |
| 1590 | 1592 |
| 1591 | 1593 |
| 1592 template <class FakeInstance> | 1594 template <class FakeInstance> |
| 1593 RawClass* Class::New(const String& name, | 1595 RawClass* Class::New(const String& name, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 } | 1729 } |
| 1728 | 1730 |
| 1729 | 1731 |
| 1730 void Class::set_token_pos(intptr_t token_pos) const { | 1732 void Class::set_token_pos(intptr_t token_pos) const { |
| 1731 ASSERT(token_pos >= 0); | 1733 ASSERT(token_pos >= 0); |
| 1732 raw_ptr()->token_pos_ = token_pos; | 1734 raw_ptr()->token_pos_ = token_pos; |
| 1733 } | 1735 } |
| 1734 | 1736 |
| 1735 | 1737 |
| 1736 void Class::set_is_interface() const { | 1738 void Class::set_is_interface() const { |
| 1737 raw_ptr()->is_interface_ = true; | 1739 uword bits = raw_ptr()->state_bits_; |
| 1740 raw_ptr()->state_bits_ = InterfaceBit::update(true, bits); |
| 1738 } | 1741 } |
| 1739 | 1742 |
| 1740 | 1743 |
| 1741 void Class::set_is_const() const { | 1744 void Class::set_is_const() const { |
| 1742 raw_ptr()->is_const_ = true; | 1745 uword bits = raw_ptr()->state_bits_; |
| 1746 raw_ptr()->state_bits_ = ConstBit::update(true, bits); |
| 1743 } | 1747 } |
| 1744 | 1748 |
| 1745 | 1749 |
| 1746 void Class::set_is_finalized() const { | 1750 void Class::set_is_finalized() const { |
| 1747 ASSERT(!is_finalized()); | 1751 ASSERT(!is_finalized()); |
| 1748 set_class_state(RawClass::kFinalized); | 1752 uword bits = raw_ptr()->state_bits_; |
| 1753 raw_ptr()->state_bits_ = StateBits::update(RawClass::kFinalized, bits); |
| 1749 } | 1754 } |
| 1750 | 1755 |
| 1751 | 1756 |
| 1752 void Class::set_is_prefinalized() const { | 1757 void Class::set_is_prefinalized() const { |
| 1753 ASSERT(!is_finalized()); | 1758 ASSERT(!is_finalized()); |
| 1754 set_class_state(RawClass::kPreFinalized); | 1759 uword bits = raw_ptr()->state_bits_; |
| 1760 raw_ptr()->state_bits_ = StateBits::update(RawClass::kPreFinalized, bits); |
| 1755 } | 1761 } |
| 1756 | 1762 |
| 1757 | 1763 |
| 1758 void Class::set_interfaces(const Array& value) const { | 1764 void Class::set_interfaces(const Array& value) const { |
| 1759 // Verification and resolving of interfaces occurs in finalizer. | 1765 // Verification and resolving of interfaces occurs in finalizer. |
| 1760 ASSERT(!value.IsNull()); | 1766 ASSERT(!value.IsNull()); |
| 1761 StorePointer(&raw_ptr()->interfaces_, value.raw()); | 1767 StorePointer(&raw_ptr()->interfaces_, value.raw()); |
| 1762 } | 1768 } |
| 1763 | 1769 |
| 1764 | 1770 |
| (...skipping 9448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11213 const char* JSRegExp::ToCString() const { | 11219 const char* JSRegExp::ToCString() const { |
| 11214 const String& str = String::Handle(pattern()); | 11220 const String& str = String::Handle(pattern()); |
| 11215 const char* format = "JSRegExp: pattern=%s flags=%s"; | 11221 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 11216 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 11222 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 11217 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 11223 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 11218 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 11224 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 11219 return chars; | 11225 return chars; |
| 11220 } | 11226 } |
| 11221 | 11227 |
| 11222 } // namespace dart | 11228 } // namespace dart |
| OLD | NEW |