| 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 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 NoGCScope no_gc; | 1178 NoGCScope no_gc; |
| 1180 result ^= raw; | 1179 result ^= raw; |
| 1181 } | 1180 } |
| 1182 FakeObject fake; | 1181 FakeObject fake; |
| 1183 result.set_handle_vtable(fake.vtable()); | 1182 result.set_handle_vtable(fake.vtable()); |
| 1184 result.set_instance_size(FakeObject::InstanceSize()); | 1183 result.set_instance_size(FakeObject::InstanceSize()); |
| 1185 result.set_next_field_offset(FakeObject::InstanceSize()); | 1184 result.set_next_field_offset(FakeObject::InstanceSize()); |
| 1186 result.set_id((FakeObject::kClassId != kInstanceCid && | 1185 result.set_id((FakeObject::kClassId != kInstanceCid && |
| 1187 FakeObject::kClassId != kClosureCid) ? | 1186 FakeObject::kClassId != kClosureCid) ? |
| 1188 FakeObject::kClassId : kIllegalCid); | 1187 FakeObject::kClassId : kIllegalCid); |
| 1189 result.raw_ptr()->is_const_ = false; | 1188 result.raw_ptr()->state_bits_ = 0; |
| 1190 result.raw_ptr()->is_interface_ = false; | |
| 1191 // VM backed classes are almost ready: run checks and resolve class | 1189 // VM backed classes are almost ready: run checks and resolve class |
| 1192 // references, but do not recompute size. | 1190 // references, but do not recompute size. |
| 1193 result.raw_ptr()->class_state_ = RawClass::kPreFinalized; | 1191 result.set_is_prefinalized(); |
| 1194 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1192 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
| 1195 result.raw_ptr()->num_native_fields_ = 0; | 1193 result.raw_ptr()->num_native_fields_ = 0; |
| 1196 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; | 1194 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; |
| 1197 result.InitEmptyFields(); | 1195 result.InitEmptyFields(); |
| 1198 Isolate::Current()->class_table()->Register(result); | 1196 Isolate::Current()->class_table()->Register(result); |
| 1199 return result.raw(); | 1197 return result.raw(); |
| 1200 } | 1198 } |
| 1201 | 1199 |
| 1202 | 1200 |
| 1203 // Initialize class fields of type Array with empty array. | 1201 // Initialize class fields of type Array with empty array. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 return closure.raw(); | 1279 return closure.raw(); |
| 1282 } | 1280 } |
| 1283 | 1281 |
| 1284 | 1282 |
| 1285 void Class::set_signature_function(const Function& value) const { | 1283 void Class::set_signature_function(const Function& value) const { |
| 1286 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 1284 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
| 1287 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 1285 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
| 1288 } | 1286 } |
| 1289 | 1287 |
| 1290 | 1288 |
| 1291 void Class::set_class_state(int8_t state) const { | 1289 void Class::set_class_state(RawClass::ClassState state) const { |
| 1292 ASSERT((state == RawClass::kAllocated) || | 1290 ASSERT((state == RawClass::kAllocated) || |
| 1293 (state == RawClass::kPreFinalized) || | 1291 (state == RawClass::kPreFinalized) || |
| 1294 (state == RawClass::kFinalized)); | 1292 (state == RawClass::kFinalized)); |
| 1295 raw_ptr()->class_state_ = state; | 1293 uword bits = raw_ptr()->state_bits_; |
| 1294 raw_ptr()->state_bits_ = StateBits::update(state, bits); |
| 1295 } |
| 1296 |
| 1297 |
| 1298 void Class::set_state_bits(uint8_t bits) const { |
| 1299 raw_ptr()->state_bits_ = bits; |
| 1296 } | 1300 } |
| 1297 | 1301 |
| 1298 | 1302 |
| 1299 void Class::set_library(const Library& value) const { | 1303 void Class::set_library(const Library& value) const { |
| 1300 StorePointer(&raw_ptr()->library_, value.raw()); | 1304 StorePointer(&raw_ptr()->library_, value.raw()); |
| 1301 } | 1305 } |
| 1302 | 1306 |
| 1303 | 1307 |
| 1304 void Class::set_type_parameters(const TypeArguments& value) const { | 1308 void Class::set_type_parameters(const TypeArguments& value) const { |
| 1305 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | 1309 StorePointer(&raw_ptr()->type_parameters_, value.raw()); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 Heap::kOld); | 1563 Heap::kOld); |
| 1560 NoGCScope no_gc; | 1564 NoGCScope no_gc; |
| 1561 result ^= raw; | 1565 result ^= raw; |
| 1562 } | 1566 } |
| 1563 FakeInstance fake; | 1567 FakeInstance fake; |
| 1564 ASSERT(fake.IsInstance()); | 1568 ASSERT(fake.IsInstance()); |
| 1565 result.set_handle_vtable(fake.vtable()); | 1569 result.set_handle_vtable(fake.vtable()); |
| 1566 result.set_instance_size(FakeInstance::InstanceSize()); | 1570 result.set_instance_size(FakeInstance::InstanceSize()); |
| 1567 result.set_next_field_offset(FakeInstance::InstanceSize()); | 1571 result.set_next_field_offset(FakeInstance::InstanceSize()); |
| 1568 result.set_id(index); | 1572 result.set_id(index); |
| 1569 result.raw_ptr()->is_const_ = false; | 1573 result.raw_ptr()->state_bits_ = 0; |
| 1570 result.raw_ptr()->is_interface_ = false; | |
| 1571 result.raw_ptr()->class_state_ = RawClass::kAllocated; | |
| 1572 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1574 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
| 1573 result.raw_ptr()->num_native_fields_ = 0; | 1575 result.raw_ptr()->num_native_fields_ = 0; |
| 1574 result.InitEmptyFields(); | 1576 result.InitEmptyFields(); |
| 1575 Isolate::Current()->class_table()->Register(result); | 1577 Isolate::Current()->class_table()->Register(result); |
| 1576 return result.raw(); | 1578 return result.raw(); |
| 1577 } | 1579 } |
| 1578 | 1580 |
| 1579 | 1581 |
| 1580 template <class FakeInstance> | 1582 template <class FakeInstance> |
| 1581 RawClass* Class::New(const String& name, | 1583 RawClass* Class::New(const String& name, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1715 } | 1717 } |
| 1716 | 1718 |
| 1717 | 1719 |
| 1718 void Class::set_token_pos(intptr_t token_pos) const { | 1720 void Class::set_token_pos(intptr_t token_pos) const { |
| 1719 ASSERT(token_pos >= 0); | 1721 ASSERT(token_pos >= 0); |
| 1720 raw_ptr()->token_pos_ = token_pos; | 1722 raw_ptr()->token_pos_ = token_pos; |
| 1721 } | 1723 } |
| 1722 | 1724 |
| 1723 | 1725 |
| 1724 void Class::set_is_interface() const { | 1726 void Class::set_is_interface() const { |
| 1725 raw_ptr()->is_interface_ = true; | 1727 uword bits = raw_ptr()->state_bits_; |
| 1728 raw_ptr()->state_bits_ = InterfaceBit::update(true, bits); |
| 1726 } | 1729 } |
| 1727 | 1730 |
| 1728 | 1731 |
| 1729 void Class::set_is_const() const { | 1732 void Class::set_is_const() const { |
| 1730 raw_ptr()->is_const_ = true; | 1733 uword bits = raw_ptr()->state_bits_; |
| 1734 raw_ptr()->state_bits_ = ConstBit::update(true, bits); |
| 1731 } | 1735 } |
| 1732 | 1736 |
| 1733 | 1737 |
| 1734 void Class::set_is_finalized() const { | 1738 void Class::set_is_finalized() const { |
| 1735 ASSERT(!is_finalized()); | 1739 ASSERT(!is_finalized()); |
| 1736 set_class_state(RawClass::kFinalized); | 1740 uword bits = raw_ptr()->state_bits_; |
| 1741 raw_ptr()->state_bits_ = StateBits::update(RawClass::kFinalized, bits); |
| 1737 } | 1742 } |
| 1738 | 1743 |
| 1739 | 1744 |
| 1740 void Class::set_is_prefinalized() const { | 1745 void Class::set_is_prefinalized() const { |
| 1741 ASSERT(!is_finalized()); | 1746 ASSERT(!is_finalized()); |
| 1742 set_class_state(RawClass::kPreFinalized); | 1747 uword bits = raw_ptr()->state_bits_; |
| 1748 raw_ptr()->state_bits_ = StateBits::update(RawClass::kPreFinalized, bits); |
| 1743 } | 1749 } |
| 1744 | 1750 |
| 1745 | 1751 |
| 1746 void Class::set_interfaces(const Array& value) const { | 1752 void Class::set_interfaces(const Array& value) const { |
| 1747 // Verification and resolving of interfaces occurs in finalizer. | 1753 // Verification and resolving of interfaces occurs in finalizer. |
| 1748 ASSERT(!value.IsNull()); | 1754 ASSERT(!value.IsNull()); |
| 1749 StorePointer(&raw_ptr()->interfaces_, value.raw()); | 1755 StorePointer(&raw_ptr()->interfaces_, value.raw()); |
| 1750 } | 1756 } |
| 1751 | 1757 |
| 1752 | 1758 |
| (...skipping 9448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11201 const char* JSRegExp::ToCString() const { | 11207 const char* JSRegExp::ToCString() const { |
| 11202 const String& str = String::Handle(pattern()); | 11208 const String& str = String::Handle(pattern()); |
| 11203 const char* format = "JSRegExp: pattern=%s flags=%s"; | 11209 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 11204 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 11210 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 11205 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 11211 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 11206 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 11212 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 11207 return chars; | 11213 return chars; |
| 11208 } | 11214 } |
| 11209 | 11215 |
| 11210 } // namespace dart | 11216 } // namespace dart |
| OLD | NEW |