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/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/token.h" | 10 #include "vm/token.h" |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 RawArray* static_calls_target_table_; // (code-offset, function, code). | 845 RawArray* static_calls_target_table_; // (code-offset, function, code). |
846 RawArray* stackmaps_; | 846 RawArray* stackmaps_; |
847 RawLocalVarDescriptors* var_descriptors_; | 847 RawLocalVarDescriptors* var_descriptors_; |
848 RawArray* comments_; | 848 RawArray* comments_; |
849 RawObject** to() { | 849 RawObject** to() { |
850 return reinterpret_cast<RawObject**>(&ptr()->comments_); | 850 return reinterpret_cast<RawObject**>(&ptr()->comments_); |
851 } | 851 } |
852 | 852 |
853 // Compilation timestamp. | 853 // Compilation timestamp. |
854 int64_t compile_timestamp_; | 854 int64_t compile_timestamp_; |
855 intptr_t pointer_offsets_length_; | 855 |
| 856 // state_bits_ is a bitfield with three fields: |
| 857 // The optimized bit, the alive bit, and a count of the number of pointer |
| 858 // offsets. |
856 // Alive: If true, the embedded object pointers will be visited during GC. | 859 // Alive: If true, the embedded object pointers will be visited during GC. |
857 // This field cannot be shorter because of alignment issues on x64 | 860 int32_t state_bits_; |
858 // architectures. | |
859 intptr_t state_bits_; // state, is_optimized, is_alive. | |
860 | 861 |
861 // PC offsets for code patching. | 862 // PC offsets for code patching. |
862 intptr_t entry_patch_pc_offset_; | 863 int32_t entry_patch_pc_offset_; |
863 intptr_t patch_code_pc_offset_; | 864 int32_t patch_code_pc_offset_; |
864 intptr_t lazy_deopt_pc_offset_; | 865 int32_t lazy_deopt_pc_offset_; |
865 | 866 |
866 // Variable length data follows here. | 867 // Variable length data follows here. |
867 int32_t* data() { OPEN_ARRAY_START(int32_t, int32_t); } | 868 int32_t* data() { OPEN_ARRAY_START(int32_t, int32_t); } |
868 | 869 |
869 friend class StackFrame; | 870 friend class StackFrame; |
870 friend class MarkingVisitor; | 871 friend class MarkingVisitor; |
871 friend class Function; | 872 friend class Function; |
872 }; | 873 }; |
873 | 874 |
874 | 875 |
875 class RawInstructions : public RawObject { | 876 class RawInstructions : public RawObject { |
876 RAW_HEAP_OBJECT_IMPLEMENTATION(Instructions); | 877 RAW_HEAP_OBJECT_IMPLEMENTATION(Instructions); |
877 | 878 |
878 RawObject** from() { | 879 RawObject** from() { |
879 return reinterpret_cast<RawObject**>(&ptr()->code_); | 880 return reinterpret_cast<RawObject**>(&ptr()->code_); |
880 } | 881 } |
881 RawCode* code_; | 882 RawCode* code_; |
882 RawArray* object_pool_; | 883 RawArray* object_pool_; |
883 RawObject** to() { | 884 RawObject** to() { |
884 return reinterpret_cast<RawObject**>(&ptr()->object_pool_); | 885 return reinterpret_cast<RawObject**>(&ptr()->object_pool_); |
885 } | 886 } |
886 intptr_t size_; | 887 int32_t size_; |
887 | 888 |
888 // Variable length data follows here. | 889 // Variable length data follows here. |
889 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } | 890 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } |
890 | 891 |
891 // Private helper function used while visiting stack frames. The | 892 // Private helper function used while visiting stack frames. The |
892 // code which iterates over dart frames is also called during GC and | 893 // code which iterates over dart frames is also called during GC and |
893 // is not allowed to create handles. | 894 // is not allowed to create handles. |
894 static bool ContainsPC(RawObject* raw_obj, uword pc); | 895 static bool ContainsPC(RawObject* raw_obj, uword pc); |
895 | 896 |
896 friend class RawCode; | 897 friend class RawCode; |
897 friend class Code; | 898 friend class Code; |
898 friend class StackFrame; | 899 friend class StackFrame; |
899 friend class MarkingVisitor; | 900 friend class MarkingVisitor; |
900 friend class Function; | 901 friend class Function; |
901 }; | 902 }; |
902 | 903 |
903 | 904 |
904 class RawPcDescriptors : public RawObject { | 905 class RawPcDescriptors : public RawObject { |
905 RAW_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors); | 906 RAW_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors); |
906 | 907 |
907 intptr_t length_; // Number of descriptors. | 908 int32_t length_; // Number of descriptors. |
908 | 909 |
909 struct PcDescriptorRec { | 910 struct PcDescriptorRec { |
910 uword pc; | 911 uword pc; |
911 int32_t deopt_id; | 912 int32_t deopt_id; |
912 int32_t token_pos; // Or deopt reason. | 913 int32_t token_pos; // Or deopt reason. |
913 int16_t try_index; // Or deopt index. | 914 int16_t try_index; // Or deopt index. |
914 int8_t kind; | 915 int8_t kind; |
915 }; | 916 }; |
916 | 917 |
917 // Variable length data follows here. | 918 // Variable length data follows here. |
918 PcDescriptorRec* data() { OPEN_ARRAY_START(PcDescriptorRec, intptr_t); } | 919 PcDescriptorRec* data() { OPEN_ARRAY_START(PcDescriptorRec, intptr_t); } |
919 | 920 |
920 friend class Object; | 921 friend class Object; |
921 }; | 922 }; |
922 | 923 |
923 | 924 |
924 // Stackmap is an immutable representation of the layout of the stack at a | 925 // Stackmap is an immutable representation of the layout of the stack at a |
925 // PC. The stack map representation consists of a bit map which marks each | 926 // PC. The stack map representation consists of a bit map which marks each |
926 // live object index starting from the base of the frame. | 927 // live object index starting from the base of the frame. |
927 // | 928 // |
928 // The Stackmap also consists of a link to the code object corresponding to | 929 // The Stackmap also consists of a link to the code object corresponding to |
929 // the frame which the stack map is describing. The bit map representation | 930 // the frame which the stack map is describing. The bit map representation |
930 // is optimized for dense and small bit maps, without any upper bound. | 931 // is optimized for dense and small bit maps, without any upper bound. |
931 class RawStackmap : public RawObject { | 932 class RawStackmap : public RawObject { |
932 RAW_HEAP_OBJECT_IMPLEMENTATION(Stackmap); | 933 RAW_HEAP_OBJECT_IMPLEMENTATION(Stackmap); |
933 | 934 |
934 // TODO(kmillikin): We need a small number of bits to encode the register | 935 // TODO(kmillikin): We need a small number of bits to encode the register |
935 // count. Consider packing them in with the length. | 936 // count. Consider packing them in with the length. |
936 intptr_t length_; // Length of payload, in bits. | 937 int32_t length_; // Length of payload, in bits. |
937 intptr_t register_bit_count_; // Live register bits, included in length_. | 938 int32_t register_bit_count_; // Live register bits, included in length_. |
938 | 939 |
939 uword pc_; // PC corresponding to this stack map representation. | 940 // Offset from code entry point corresponding to this stack map |
| 941 // representation. |
| 942 uint32_t pc_offset_; |
940 | 943 |
941 // Variable length data follows here (bitmap of the stack layout). | 944 // Variable length data follows here (bitmap of the stack layout). |
942 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } | 945 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } |
943 }; | 946 }; |
944 | 947 |
945 | 948 |
946 class RawLocalVarDescriptors : public RawObject { | 949 class RawLocalVarDescriptors : public RawObject { |
947 public: | 950 public: |
948 enum VarInfoKind { | 951 enum VarInfoKind { |
949 kStackVar = 1, | 952 kStackVar = 1, |
950 kContextVar, | 953 kContextVar, |
951 kContextLevel, | 954 kContextLevel, |
952 kSavedEntryContext, | 955 kSavedEntryContext, |
953 kSavedCurrentContext | 956 kSavedCurrentContext |
954 }; | 957 }; |
955 | 958 |
| 959 enum { |
| 960 kKindPos = 0, |
| 961 kKindSize = 8, |
| 962 kIndexPos = 9, |
| 963 // Since there are 24 bits for the stack slot index, Functions can have |
| 964 // only ~16.7 million stack slots. |
| 965 kIndexSize = 24, |
| 966 kMaxIndex = (1 << (kIndexSize - 1)) - 1, |
| 967 }; |
| 968 |
| 969 // The index can be < 0. |
| 970 class IndexBits { |
| 971 public: |
| 972 static bool is_valid(int32_t val) { |
| 973 return Utils::IsInt(24, val); |
| 974 } |
| 975 static int32_t update(int32_t val, int32_t orig) { |
| 976 ASSERT(is_valid(val)); |
| 977 const int32_t v = val & ((1 << kIndexSize) - 1); |
| 978 return Bits::update(v, orig); |
| 979 } |
| 980 static int32_t decode(int32_t val) { |
| 981 const int32_t v = Bits::decode(val); |
| 982 return (v << kIndexPos) >> kIndexPos; // Sign-extend. |
| 983 } |
| 984 private: |
| 985 class Bits : public BitField<int32_t, kIndexPos, kIndexSize> {}; |
| 986 }; |
| 987 |
| 988 class KindBits : public BitField<int8_t, kKindPos, kKindSize>{}; |
| 989 |
956 struct VarInfo { | 990 struct VarInfo { |
957 intptr_t index; // Slot index on stack or in context. | 991 int32_t index_kind; // Bitfield for slot index on stack or in context, |
958 intptr_t begin_pos; // Token position of scope start. | 992 // and Entry kind of type VarInfoKind. |
959 intptr_t end_pos; // Token position of scope end. | 993 int32_t begin_pos; // Token position of scope start. |
| 994 int32_t end_pos; // Token position of scope end. |
960 int16_t scope_id; // Scope to which the variable belongs. | 995 int16_t scope_id; // Scope to which the variable belongs. |
961 int8_t kind; // Entry kind of type VarInfoKind. | |
962 }; | 996 }; |
963 | 997 |
964 private: | 998 private: |
965 RAW_HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors); | 999 RAW_HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors); |
966 intptr_t length_; // Number of descriptors. | |
967 RawArray* names_; // Array of [length_] variable names. | 1000 RawArray* names_; // Array of [length_] variable names. |
| 1001 int32_t length_; // Number of descriptors. |
968 | 1002 |
969 // Variable info with [length_] entries. | 1003 // Variable info with [length_] entries. |
970 VarInfo* data() { OPEN_ARRAY_START(VarInfo, intptr_t); } | 1004 VarInfo* data() { OPEN_ARRAY_START(VarInfo, int32_t); } |
971 }; | 1005 }; |
972 | 1006 |
973 | 1007 |
974 class RawExceptionHandlers : public RawObject { | 1008 class RawExceptionHandlers : public RawObject { |
975 public: | 1009 public: |
976 // The index into the ExceptionHandlers table corresponds to | 1010 // The index into the ExceptionHandlers table corresponds to |
977 // the try_index of the handler. | 1011 // the try_index of the handler. |
978 struct HandlerInfo { | 1012 struct HandlerInfo { |
979 intptr_t handler_pc; // PC value of handler. | 1013 intptr_t handler_pc; // PC value of handler. |
980 int16_t outer_try_index; // Try block index of enclosing try block. | 1014 int16_t outer_try_index; // Try block index of enclosing try block. |
981 int8_t needs_stacktrace; // True if a stacktrace is needed. | 1015 int8_t needs_stacktrace; // True if a stacktrace is needed. |
982 int8_t has_catch_all; // Catches all exceptions. | 1016 int8_t has_catch_all; // Catches all exceptions. |
983 }; | 1017 }; |
984 | 1018 |
985 private: | 1019 private: |
986 RAW_HEAP_OBJECT_IMPLEMENTATION(ExceptionHandlers); | 1020 RAW_HEAP_OBJECT_IMPLEMENTATION(ExceptionHandlers); |
987 | 1021 |
988 // Number of exception handler entries. | 1022 // Number of exception handler entries. |
989 intptr_t length_; | 1023 int32_t length_; |
990 | 1024 |
991 // Array with [length_] entries. Each entry is an array of all handled | 1025 // Array with [length_] entries. Each entry is an array of all handled |
992 // exception types. | 1026 // exception types. |
993 RawArray* handled_types_data_; | 1027 RawArray* handled_types_data_; |
994 | 1028 |
995 // Exception handler info of length [length_]. | 1029 // Exception handler info of length [length_]. |
996 HandlerInfo* data() { OPEN_ARRAY_START(HandlerInfo, intptr_t); } | 1030 HandlerInfo* data() { OPEN_ARRAY_START(HandlerInfo, intptr_t); } |
997 }; | 1031 }; |
998 | 1032 |
999 | 1033 |
1000 // Contains an array of deoptimization commands, e.g., move a specific register | 1034 // Contains an array of deoptimization commands, e.g., move a specific register |
1001 // into a specific slot of unoptimized frame. | 1035 // into a specific slot of unoptimized frame. |
1002 class RawDeoptInfo : public RawObject { | 1036 class RawDeoptInfo : public RawObject { |
1003 RAW_HEAP_OBJECT_IMPLEMENTATION(DeoptInfo); | 1037 RAW_HEAP_OBJECT_IMPLEMENTATION(DeoptInfo); |
1004 | 1038 |
1005 RawSmi* length_; // Number of deoptimization commands | 1039 RawSmi* length_; // Number of deoptimization commands |
1006 | 1040 |
1007 // Variable length data follows here. | 1041 // Variable length data follows here. |
1008 intptr_t* data() { OPEN_ARRAY_START(intptr_t, intptr_t); } | 1042 intptr_t* data() { OPEN_ARRAY_START(intptr_t, intptr_t); } |
1009 }; | 1043 }; |
1010 | 1044 |
1011 | 1045 |
1012 class RawContext : public RawObject { | 1046 class RawContext : public RawObject { |
1013 RAW_HEAP_OBJECT_IMPLEMENTATION(Context); | 1047 RAW_HEAP_OBJECT_IMPLEMENTATION(Context); |
1014 | 1048 |
1015 intptr_t num_variables_; | 1049 int32_t num_variables_; |
1016 Isolate* isolate_; | 1050 Isolate* isolate_; |
1017 | 1051 |
1018 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->parent_); } | 1052 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->parent_); } |
1019 RawContext* parent_; | 1053 RawContext* parent_; |
1020 | 1054 |
1021 // Variable length data follows here. | 1055 // Variable length data follows here. |
1022 RawInstance** data() { OPEN_ARRAY_START(RawInstance*, RawInstance*); } | 1056 RawInstance** data() { OPEN_ARRAY_START(RawInstance*, RawInstance*); } |
1023 RawObject** to(intptr_t num_vars) { | 1057 RawObject** to(intptr_t num_vars) { |
1024 return reinterpret_cast<RawObject**>(&ptr()->data()[num_vars - 1]); | 1058 return reinterpret_cast<RawObject**>(&ptr()->data()[num_vars - 1]); |
1025 } | 1059 } |
1026 | 1060 |
1027 friend class SnapshotReader; | 1061 friend class SnapshotReader; |
1028 }; | 1062 }; |
1029 | 1063 |
1030 | 1064 |
1031 class RawContextScope : public RawObject { | 1065 class RawContextScope : public RawObject { |
1032 RAW_HEAP_OBJECT_IMPLEMENTATION(ContextScope); | 1066 RAW_HEAP_OBJECT_IMPLEMENTATION(ContextScope); |
1033 | 1067 |
1034 // TODO(iposva): Switch to convential enum offset based structure to avoid | 1068 // TODO(iposva): Switch to conventional enum offset based structure to avoid |
1035 // alignment mishaps. | 1069 // alignment mishaps. |
1036 struct VariableDesc { | 1070 struct VariableDesc { |
1037 RawSmi* token_pos; | 1071 RawSmi* token_pos; |
1038 RawString* name; | 1072 RawString* name; |
1039 RawBool* is_final; | 1073 RawBool* is_final; |
1040 RawBool* is_const; | 1074 RawBool* is_const; |
1041 union { | 1075 union { |
1042 RawAbstractType* type; | 1076 RawAbstractType* type; |
1043 RawInstance* value; // iff is_const is true | 1077 RawInstance* value; // iff is_const is true |
1044 }; | 1078 }; |
1045 RawSmi* context_index; | 1079 RawSmi* context_index; |
1046 RawSmi* context_level; | 1080 RawSmi* context_level; |
1047 }; | 1081 }; |
1048 | 1082 |
1049 intptr_t num_variables_; | 1083 int32_t num_variables_; |
1050 | 1084 |
1051 RawObject** from() { | 1085 RawObject** from() { |
1052 return reinterpret_cast<RawObject**>(&ptr()->data()[0]); | 1086 return reinterpret_cast<RawObject**>(&ptr()->data()[0]); |
1053 } | 1087 } |
1054 // Variable length data follows here. | 1088 // Variable length data follows here. |
1055 RawObject** data() { OPEN_ARRAY_START(RawObject*, RawObject*); } | 1089 RawObject** data() { OPEN_ARRAY_START(RawObject*, RawObject*); } |
1056 RawObject** to(intptr_t num_vars) { | 1090 RawObject** to(intptr_t num_vars) { |
1057 const intptr_t data_length = num_vars * (sizeof(VariableDesc)/kWordSize); | 1091 const intptr_t data_length = num_vars * (sizeof(VariableDesc)/kWordSize); |
1058 return reinterpret_cast<RawObject**>(&ptr()->data()[data_length - 1]); | 1092 return reinterpret_cast<RawObject**>(&ptr()->data()[data_length - 1]); |
1059 } | 1093 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 friend class SnapshotReader; | 1342 friend class SnapshotReader; |
1309 }; | 1343 }; |
1310 | 1344 |
1311 | 1345 |
1312 class RawBigint : public RawInteger { | 1346 class RawBigint : public RawInteger { |
1313 RAW_HEAP_OBJECT_IMPLEMENTATION(Bigint); | 1347 RAW_HEAP_OBJECT_IMPLEMENTATION(Bigint); |
1314 | 1348 |
1315 // Actual length in chunks at the time of allocation (later we may | 1349 // Actual length in chunks at the time of allocation (later we may |
1316 // clamp the operational length but we need to maintain a consistent | 1350 // clamp the operational length but we need to maintain a consistent |
1317 // object length so that the object can be traversed during GC). | 1351 // object length so that the object can be traversed during GC). |
1318 intptr_t allocated_length_; | 1352 int32_t allocated_length_; |
1319 | 1353 |
1320 // Operational length in chunks of the bigint object, clamping can | 1354 // Operational length in chunks of the bigint object, clamping can |
1321 // cause this length to be reduced. If the signed_length_ is | 1355 // cause this length to be reduced. If the signed_length_ is |
1322 // negative then the number is negative. | 1356 // negative then the number is negative. |
1323 intptr_t signed_length_; | 1357 int32_t signed_length_; |
1324 | 1358 |
1325 // A sequence of Chunks (typedef in Bignum) representing bignum digits. | 1359 // A sequence of Chunks (typedef in Bignum) representing bignum digits. |
1326 // Bignum::Chunk chunks_[Utils::Abs(signed_length_)]; | 1360 // Bignum::Chunk chunks_[Utils::Abs(signed_length_)]; |
1327 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } | 1361 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } |
1328 | 1362 |
1329 friend class SnapshotReader; | 1363 friend class SnapshotReader; |
1330 }; | 1364 }; |
1331 | 1365 |
1332 | 1366 |
1333 class RawDouble : public RawNumber { | 1367 class RawDouble : public RawNumber { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 RawObject** from() { | 1641 RawObject** from() { |
1608 return reinterpret_cast<RawObject**>(&ptr()->data_length_); | 1642 return reinterpret_cast<RawObject**>(&ptr()->data_length_); |
1609 } | 1643 } |
1610 RawSmi* data_length_; | 1644 RawSmi* data_length_; |
1611 RawSmi* num_bracket_expressions_; | 1645 RawSmi* num_bracket_expressions_; |
1612 RawString* pattern_; // Pattern to be used for matching. | 1646 RawString* pattern_; // Pattern to be used for matching. |
1613 RawObject** to() { | 1647 RawObject** to() { |
1614 return reinterpret_cast<RawObject**>(&ptr()->pattern_); | 1648 return reinterpret_cast<RawObject**>(&ptr()->pattern_); |
1615 } | 1649 } |
1616 | 1650 |
1617 intptr_t type_; // Uninitialized, simple or complex. | 1651 // A bitfield with two fields: |
1618 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 1652 // type: Uninitialized, simple or complex. |
| 1653 // flags: Represents global/local, case insensitive, multiline. |
| 1654 int8_t type_flags_; |
1619 | 1655 |
1620 // Variable length data follows here. | 1656 // Variable length data follows here. |
1621 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } | 1657 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } |
1622 }; | 1658 }; |
1623 | 1659 |
1624 | 1660 |
1625 class RawWeakProperty : public RawInstance { | 1661 class RawWeakProperty : public RawInstance { |
1626 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); | 1662 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); |
1627 | 1663 |
1628 RawObject** from() { | 1664 RawObject** from() { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 COMPILE_ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14); | 1917 COMPILE_ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14); |
1882 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 1918 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
1883 kTypedDataInt8ArrayViewCid + 15); | 1919 kTypedDataInt8ArrayViewCid + 15); |
1884 COMPILE_ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 14); | 1920 COMPILE_ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 14); |
1885 return (kNullCid - kTypedDataInt8ArrayCid); | 1921 return (kNullCid - kTypedDataInt8ArrayCid); |
1886 } | 1922 } |
1887 | 1923 |
1888 } // namespace dart | 1924 } // namespace dart |
1889 | 1925 |
1890 #endif // VM_RAW_OBJECT_H_ | 1926 #endif // VM_RAW_OBJECT_H_ |
OLD | NEW |