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 #ifndef VM_RAW_OBJECT_H_ | 5 #ifndef VM_RAW_OBJECT_H_ |
6 #define VM_RAW_OBJECT_H_ | 6 #define VM_RAW_OBJECT_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/atomic.h" | 9 #include "vm/atomic.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
11 #include "vm/snapshot.h" | 11 #include "vm/snapshot.h" |
12 #include "vm/token.h" | 12 #include "vm/token.h" |
| 13 #include "vm/token_descriptor.h" |
13 #include "vm/verified_memory.h" | 14 #include "vm/verified_memory.h" |
14 | 15 |
15 namespace dart { | 16 namespace dart { |
16 | 17 |
17 // Macrobatics to define the Object hierarchy of VM implementation classes. | 18 // Macrobatics to define the Object hierarchy of VM implementation classes. |
18 #define CLASS_LIST_NO_OBJECT_NOR_STRING_NOR_ARRAY(V) \ | 19 #define CLASS_LIST_NO_OBJECT_NOR_STRING_NOR_ARRAY(V) \ |
19 V(Class) \ | 20 V(Class) \ |
20 V(UnresolvedClass) \ | 21 V(UnresolvedClass) \ |
21 V(TypeArguments) \ | 22 V(TypeArguments) \ |
22 V(PatchClass) \ | 23 V(PatchClass) \ |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 RawObject* canonical_types_; // An array of canonicalized types of this class | 669 RawObject* canonical_types_; // An array of canonicalized types of this class |
669 // or the canonical type. | 670 // or the canonical type. |
670 RawArray* invocation_dispatcher_cache_; // Cache for dispatcher functions. | 671 RawArray* invocation_dispatcher_cache_; // Cache for dispatcher functions. |
671 RawArray* cha_codes_; // CHA optimized codes. | 672 RawArray* cha_codes_; // CHA optimized codes. |
672 RawCode* allocation_stub_; // Stub code for allocation of instances. | 673 RawCode* allocation_stub_; // Stub code for allocation of instances. |
673 RawObject** to() { | 674 RawObject** to() { |
674 return reinterpret_cast<RawObject**>(&ptr()->allocation_stub_); | 675 return reinterpret_cast<RawObject**>(&ptr()->allocation_stub_); |
675 } | 676 } |
676 | 677 |
677 cpp_vtable handle_vtable_; | 678 cpp_vtable handle_vtable_; |
678 int32_t token_pos_; | 679 TokenDescriptor token_pos_; |
679 int32_t instance_size_in_words_; // Size if fixed len or 0 if variable len. | 680 int32_t instance_size_in_words_; // Size if fixed len or 0 if variable len. |
680 int32_t type_arguments_field_offset_in_words_; // Offset of type args fld. | 681 int32_t type_arguments_field_offset_in_words_; // Offset of type args fld. |
681 int32_t next_field_offset_in_words_; // Offset of the next instance field. | 682 int32_t next_field_offset_in_words_; // Offset of the next instance field. |
682 classid_t id_; // Class Id, also index in the class table. | 683 classid_t id_; // Class Id, also index in the class table. |
683 int16_t num_type_arguments_; // Number of type arguments in flattened vector. | 684 int16_t num_type_arguments_; // Number of type arguments in flattened vector. |
684 int16_t num_own_type_arguments_; // Number of non-overlapping type arguments. | 685 int16_t num_own_type_arguments_; // Number of non-overlapping type arguments. |
685 uint16_t num_native_fields_; // Number of native fields in class. | 686 uint16_t num_native_fields_; // Number of native fields in class. |
686 uint16_t state_bits_; | 687 uint16_t state_bits_; |
687 | 688 |
688 friend class Instance; | 689 friend class Instance; |
689 friend class Object; | 690 friend class Object; |
690 friend class RawInstance; | 691 friend class RawInstance; |
691 friend class RawInstructions; | 692 friend class RawInstructions; |
692 friend class SnapshotReader; | 693 friend class SnapshotReader; |
693 }; | 694 }; |
694 | 695 |
695 | 696 |
696 class RawUnresolvedClass : public RawObject { | 697 class RawUnresolvedClass : public RawObject { |
697 RAW_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass); | 698 RAW_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass); |
698 | 699 |
699 RawObject** from() { | 700 RawObject** from() { |
700 return reinterpret_cast<RawObject**>(&ptr()->library_prefix_); | 701 return reinterpret_cast<RawObject**>(&ptr()->library_prefix_); |
701 } | 702 } |
702 RawLibraryPrefix* library_prefix_; // Library prefix qualifier for the ident. | 703 RawLibraryPrefix* library_prefix_; // Library prefix qualifier for the ident. |
703 RawString* ident_; // Name of the unresolved identifier. | 704 RawString* ident_; // Name of the unresolved identifier. |
704 RawObject** to() { | 705 RawObject** to() { |
705 return reinterpret_cast<RawObject**>(&ptr()->ident_); | 706 return reinterpret_cast<RawObject**>(&ptr()->ident_); |
706 } | 707 } |
707 int32_t token_pos_; | 708 TokenDescriptor token_pos_; |
708 }; | 709 }; |
709 | 710 |
710 | 711 |
711 class RawTypeArguments : public RawObject { | 712 class RawTypeArguments : public RawObject { |
712 private: | 713 private: |
713 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeArguments); | 714 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeArguments); |
714 | 715 |
715 RawObject** from() { | 716 RawObject** from() { |
716 return reinterpret_cast<RawObject**>(&ptr()->instantiations_); | 717 return reinterpret_cast<RawObject**>(&ptr()->instantiations_); |
717 } | 718 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 RawObject** to_no_code() { | 807 RawObject** to_no_code() { |
807 return reinterpret_cast<RawObject**>(&ptr()->ic_data_array_); | 808 return reinterpret_cast<RawObject**>(&ptr()->ic_data_array_); |
808 } | 809 } |
809 RawCode* code_; // Currently active code. | 810 RawCode* code_; // Currently active code. |
810 RawCode* unoptimized_code_; // Unoptimized code, keep it after optimization. | 811 RawCode* unoptimized_code_; // Unoptimized code, keep it after optimization. |
811 RawObject** to() { | 812 RawObject** to() { |
812 return reinterpret_cast<RawObject**>(&ptr()->unoptimized_code_); | 813 return reinterpret_cast<RawObject**>(&ptr()->unoptimized_code_); |
813 } | 814 } |
814 uword entry_point_; | 815 uword entry_point_; |
815 | 816 |
816 int32_t token_pos_; | 817 TokenDescriptor token_pos_; |
817 int32_t end_token_pos_; | 818 TokenDescriptor end_token_pos_; |
818 int32_t usage_counter_; // Incremented while function is running. | 819 int32_t usage_counter_; // Incremented while function is running. |
819 int16_t num_fixed_parameters_; | 820 int16_t num_fixed_parameters_; |
820 int16_t num_optional_parameters_; // > 0: positional; < 0: named. | 821 int16_t num_optional_parameters_; // > 0: positional; < 0: named. |
821 int16_t deoptimization_counter_; | 822 int16_t deoptimization_counter_; |
822 uint32_t kind_tag_; // See Function::KindTagBits. | 823 uint32_t kind_tag_; // See Function::KindTagBits. |
823 uint16_t optimized_instruction_count_; | 824 uint16_t optimized_instruction_count_; |
824 uint16_t optimized_call_site_count_; | 825 uint16_t optimized_call_site_count_; |
825 }; | 826 }; |
826 | 827 |
827 | 828 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 } initializer_; | 884 } initializer_; |
884 RawObject** to_precompiled_snapshot() { | 885 RawObject** to_precompiled_snapshot() { |
885 return reinterpret_cast<RawObject**>(&ptr()->initializer_); | 886 return reinterpret_cast<RawObject**>(&ptr()->initializer_); |
886 } | 887 } |
887 RawArray* dependent_code_; | 888 RawArray* dependent_code_; |
888 RawSmi* guarded_list_length_; | 889 RawSmi* guarded_list_length_; |
889 RawObject** to() { | 890 RawObject** to() { |
890 return reinterpret_cast<RawObject**>(&ptr()->guarded_list_length_); | 891 return reinterpret_cast<RawObject**>(&ptr()->guarded_list_length_); |
891 } | 892 } |
892 | 893 |
893 int32_t token_pos_; | 894 TokenDescriptor token_pos_; |
894 classid_t guarded_cid_; | 895 classid_t guarded_cid_; |
895 classid_t is_nullable_; // kNullCid if field can contain null value and | 896 classid_t is_nullable_; // kNullCid if field can contain null value and |
896 // any other value otherwise. | 897 // any other value otherwise. |
897 // Offset to the guarded length field inside an instance of class matching | 898 // Offset to the guarded length field inside an instance of class matching |
898 // guarded_cid_. Stored corrected by -kHeapObjectTag to simplify code | 899 // guarded_cid_. Stored corrected by -kHeapObjectTag to simplify code |
899 // generated on platforms with weak addressing modes (ARM, MIPS). | 900 // generated on platforms with weak addressing modes (ARM, MIPS). |
900 int8_t guarded_list_length_in_object_offset_; | 901 int8_t guarded_list_length_in_object_offset_; |
901 | 902 |
902 uint8_t kind_bits_; // static, final, const, has initializer.... | 903 uint8_t kind_bits_; // static, final, const, has initializer.... |
903 }; | 904 }; |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 kIndexBias = 1 << (kIndexSize - 1), | 1270 kIndexBias = 1 << (kIndexSize - 1), |
1270 kMaxIndex = (1 << (kIndexSize - 1)) - 1, | 1271 kMaxIndex = (1 << (kIndexSize - 1)) - 1, |
1271 }; | 1272 }; |
1272 | 1273 |
1273 class IndexBits : public BitField<int32_t, kIndexPos, kIndexSize> {}; | 1274 class IndexBits : public BitField<int32_t, kIndexPos, kIndexSize> {}; |
1274 class KindBits : public BitField<int8_t, kKindPos, kKindSize>{}; | 1275 class KindBits : public BitField<int8_t, kKindPos, kKindSize>{}; |
1275 | 1276 |
1276 struct VarInfo { | 1277 struct VarInfo { |
1277 int32_t index_kind; // Bitfield for slot index on stack or in context, | 1278 int32_t index_kind; // Bitfield for slot index on stack or in context, |
1278 // and Entry kind of type VarInfoKind. | 1279 // and Entry kind of type VarInfoKind. |
1279 int32_t begin_pos; // Token position of scope start. | 1280 TokenDescriptor begin_pos; // Token position of scope start. |
1280 int32_t end_pos; // Token position of scope end. | 1281 TokenDescriptor end_pos; // Token position of scope end. |
1281 int16_t scope_id; // Scope to which the variable belongs. | 1282 int16_t scope_id; // Scope to which the variable belongs. |
1282 | 1283 |
1283 VarInfoKind kind() const { | 1284 VarInfoKind kind() const { |
1284 return static_cast<VarInfoKind>(KindBits::decode(index_kind)); | 1285 return static_cast<VarInfoKind>(KindBits::decode(index_kind)); |
1285 } | 1286 } |
1286 void set_kind(VarInfoKind kind) { | 1287 void set_kind(VarInfoKind kind) { |
1287 index_kind = KindBits::update(kind, index_kind); | 1288 index_kind = KindBits::update(kind, index_kind); |
1288 } | 1289 } |
1289 int32_t index() const { | 1290 int32_t index() const { |
1290 return IndexBits::decode(index_kind) - kIndexBias; | 1291 return IndexBits::decode(index_kind) - kIndexBias; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 RawObject** from() { | 1486 RawObject** from() { |
1486 return reinterpret_cast<RawObject**>(&ptr()->previous_error_); | 1487 return reinterpret_cast<RawObject**>(&ptr()->previous_error_); |
1487 } | 1488 } |
1488 RawError* previous_error_; // May be null. | 1489 RawError* previous_error_; // May be null. |
1489 RawScript* script_; | 1490 RawScript* script_; |
1490 RawString* message_; | 1491 RawString* message_; |
1491 RawString* formatted_message_; // Incl. previous error's formatted message. | 1492 RawString* formatted_message_; // Incl. previous error's formatted message. |
1492 RawObject** to() { | 1493 RawObject** to() { |
1493 return reinterpret_cast<RawObject**>(&ptr()->formatted_message_); | 1494 return reinterpret_cast<RawObject**>(&ptr()->formatted_message_); |
1494 } | 1495 } |
1495 int32_t token_pos_; // Source position in script_. | 1496 TokenDescriptor token_pos_; // Source position in script_. |
1496 bool report_after_token_; // Report message at or after the token. | 1497 bool report_after_token_; // Report message at or after the token. |
1497 int8_t kind_; // Of type LanguageError::Kind. | 1498 int8_t kind_; // Of type LanguageError::Kind. |
1498 }; | 1499 }; |
1499 | 1500 |
1500 | 1501 |
1501 class RawUnhandledException : public RawError { | 1502 class RawUnhandledException : public RawError { |
1502 RAW_HEAP_OBJECT_IMPLEMENTATION(UnhandledException); | 1503 RAW_HEAP_OBJECT_IMPLEMENTATION(UnhandledException); |
1503 | 1504 |
1504 RawObject** from() { | 1505 RawObject** from() { |
1505 return reinterpret_cast<RawObject**>(&ptr()->exception_); | 1506 return reinterpret_cast<RawObject**>(&ptr()->exception_); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 | 1574 |
1574 RawObject** from() { | 1575 RawObject** from() { |
1575 return reinterpret_cast<RawObject**>(&ptr()->type_class_); | 1576 return reinterpret_cast<RawObject**>(&ptr()->type_class_); |
1576 } | 1577 } |
1577 RawObject* type_class_; // Either resolved class or unresolved class. | 1578 RawObject* type_class_; // Either resolved class or unresolved class. |
1578 RawTypeArguments* arguments_; | 1579 RawTypeArguments* arguments_; |
1579 RawLanguageError* error_; // Error object if type is malformed or malbounded. | 1580 RawLanguageError* error_; // Error object if type is malformed or malbounded. |
1580 RawObject** to() { | 1581 RawObject** to() { |
1581 return reinterpret_cast<RawObject**>(&ptr()->error_); | 1582 return reinterpret_cast<RawObject**>(&ptr()->error_); |
1582 } | 1583 } |
1583 int32_t token_pos_; | 1584 TokenDescriptor token_pos_; |
1584 int8_t type_state_; | 1585 int8_t type_state_; |
1585 }; | 1586 }; |
1586 | 1587 |
1587 | 1588 |
1588 class RawFunctionType : public RawAbstractType { | 1589 class RawFunctionType : public RawAbstractType { |
1589 private: | 1590 private: |
1590 RAW_HEAP_OBJECT_IMPLEMENTATION(FunctionType); | 1591 RAW_HEAP_OBJECT_IMPLEMENTATION(FunctionType); |
1591 | 1592 |
1592 RawObject** from() { | 1593 RawObject** from() { |
1593 return reinterpret_cast<RawObject**>(&ptr()->scope_class_); | 1594 return reinterpret_cast<RawObject**>(&ptr()->scope_class_); |
1594 } | 1595 } |
1595 RawClass* scope_class_; | 1596 RawClass* scope_class_; |
1596 RawTypeArguments* arguments_; | 1597 RawTypeArguments* arguments_; |
1597 RawFunction* signature_; | 1598 RawFunction* signature_; |
1598 RawLanguageError* error_; // Error object if type is malformed or malbounded. | 1599 RawLanguageError* error_; // Error object if type is malformed or malbounded. |
1599 RawObject** to() { | 1600 RawObject** to() { |
1600 return reinterpret_cast<RawObject**>(&ptr()->error_); | 1601 return reinterpret_cast<RawObject**>(&ptr()->error_); |
1601 } | 1602 } |
1602 int32_t token_pos_; | 1603 TokenDescriptor token_pos_; |
1603 int8_t type_state_; | 1604 int8_t type_state_; |
1604 }; | 1605 }; |
1605 | 1606 |
1606 | 1607 |
1607 class RawTypeRef : public RawAbstractType { | 1608 class RawTypeRef : public RawAbstractType { |
1608 private: | 1609 private: |
1609 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeRef); | 1610 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeRef); |
1610 | 1611 |
1611 RawObject** from() { | 1612 RawObject** from() { |
1612 return reinterpret_cast<RawObject**>(&ptr()->type_); | 1613 return reinterpret_cast<RawObject**>(&ptr()->type_); |
1613 } | 1614 } |
1614 RawAbstractType* type_; // The referenced type. | 1615 RawAbstractType* type_; // The referenced type. |
1615 RawObject** to() { | 1616 RawObject** to() { |
1616 return reinterpret_cast<RawObject**>(&ptr()->type_); | 1617 return reinterpret_cast<RawObject**>(&ptr()->type_); |
1617 } | 1618 } |
1618 }; | 1619 }; |
1619 | 1620 |
1620 | 1621 |
1621 class RawTypeParameter : public RawAbstractType { | 1622 class RawTypeParameter : public RawAbstractType { |
1622 private: | 1623 private: |
1623 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeParameter); | 1624 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeParameter); |
1624 | 1625 |
1625 RawObject** from() { | 1626 RawObject** from() { |
1626 return reinterpret_cast<RawObject**>(&ptr()->parameterized_class_); | 1627 return reinterpret_cast<RawObject**>(&ptr()->parameterized_class_); |
1627 } | 1628 } |
1628 RawClass* parameterized_class_; | 1629 RawClass* parameterized_class_; |
1629 RawString* name_; | 1630 RawString* name_; |
1630 RawAbstractType* bound_; // ObjectType if no explicit bound specified. | 1631 RawAbstractType* bound_; // ObjectType if no explicit bound specified. |
1631 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->bound_); } | 1632 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->bound_); } |
1632 int32_t token_pos_; | 1633 TokenDescriptor token_pos_; |
1633 int16_t index_; | 1634 int16_t index_; |
1634 int8_t type_state_; | 1635 int8_t type_state_; |
1635 }; | 1636 }; |
1636 | 1637 |
1637 | 1638 |
1638 class RawBoundedType : public RawAbstractType { | 1639 class RawBoundedType : public RawAbstractType { |
1639 private: | 1640 private: |
1640 RAW_HEAP_OBJECT_IMPLEMENTATION(BoundedType); | 1641 RAW_HEAP_OBJECT_IMPLEMENTATION(BoundedType); |
1641 | 1642 |
1642 RawObject** from() { | 1643 RawObject** from() { |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2330 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 2331 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
2331 kTypedDataInt8ArrayViewCid + 15); | 2332 kTypedDataInt8ArrayViewCid + 15); |
2332 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); | 2333 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); |
2333 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); | 2334 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); |
2334 return (kNullCid - kTypedDataInt8ArrayCid); | 2335 return (kNullCid - kTypedDataInt8ArrayCid); |
2335 } | 2336 } |
2336 | 2337 |
2337 } // namespace dart | 2338 } // namespace dart |
2338 | 2339 |
2339 #endif // VM_RAW_OBJECT_H_ | 2340 #endif // VM_RAW_OBJECT_H_ |
OLD | NEW |