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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 private: \ | 216 private: \ |
217 RAW_OBJECT_IMPLEMENTATION(object); \ | 217 RAW_OBJECT_IMPLEMENTATION(object); \ |
218 Raw##object* ptr() const { \ | 218 Raw##object* ptr() const { \ |
219 ASSERT(IsHeapObject()); \ | 219 ASSERT(IsHeapObject()); \ |
220 return reinterpret_cast<Raw##object*>( \ | 220 return reinterpret_cast<Raw##object*>( \ |
221 reinterpret_cast<uword>(this) - kHeapObjectTag); \ | 221 reinterpret_cast<uword>(this) - kHeapObjectTag); \ |
222 } \ | 222 } \ |
223 SNAPSHOT_WRITER_SUPPORT() \ | 223 SNAPSHOT_WRITER_SUPPORT() \ |
224 HEAP_PROFILER_SUPPORT() \ | 224 HEAP_PROFILER_SUPPORT() \ |
225 | 225 |
226 | |
227 // RawObject is the base class of all raw objects, even though it carries the | 226 // RawObject is the base class of all raw objects, even though it carries the |
228 // class_ field not all raw objects are allocated in the heap and thus cannot | 227 // class_ field not all raw objects are allocated in the heap and thus cannot |
229 // be dereferenced (e.g. RawSmi). | 228 // be dereferenced (e.g. RawSmi). |
230 class RawObject { | 229 class RawObject { |
231 public: | 230 public: |
232 // The tags field which is a part of the object header uses the following | 231 // The tags field which is a part of the object header uses the following |
233 // bit fields for storing tags. | 232 // bit fields for storing tags. |
234 enum TagBits { | 233 enum TagBits { |
235 kWatchedBit = 0, | 234 kWatchedBit = 0, |
236 kMarkBit = 1, | 235 kMarkBit = 1, |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 return reinterpret_cast<RawObject**>(&ptr()->instantiations_); | 550 return reinterpret_cast<RawObject**>(&ptr()->instantiations_); |
552 } | 551 } |
553 // The instantiations_ array remains empty for instantiated type arguments. | 552 // The instantiations_ array remains empty for instantiated type arguments. |
554 RawArray* instantiations_; // Array of paired canonical vectors: | 553 RawArray* instantiations_; // Array of paired canonical vectors: |
555 // Even index: instantiator. | 554 // Even index: instantiator. |
556 // Odd index: instantiated (without bound error). | 555 // Odd index: instantiated (without bound error). |
557 // Instantiations leading to bound errors do not get cached. | 556 // Instantiations leading to bound errors do not get cached. |
558 RawSmi* length_; | 557 RawSmi* length_; |
559 | 558 |
560 // Variable length data follows here. | 559 // Variable length data follows here. |
561 RawAbstractType* types_[0]; | 560 RawAbstractType** types() { |
561 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
562 ASSERT(Utils::IsAligned(result, sizeof(RawAbstractType*))); | |
563 return reinterpret_cast<RawAbstractType**>(result); | |
siva
2014/06/17 22:29:50
why not make a macro and use that everywhere?
e.g
zra
2014/06/17 23:17:58
Done.
| |
564 } | |
562 RawObject** to(intptr_t length) { | 565 RawObject** to(intptr_t length) { |
563 return reinterpret_cast<RawObject**>(&ptr()->types_[length - 1]); | 566 return reinterpret_cast<RawObject**>(&ptr()->types()[length - 1]); |
564 } | 567 } |
565 | 568 |
566 friend class SnapshotReader; | 569 friend class SnapshotReader; |
567 }; | 570 }; |
568 | 571 |
569 | 572 |
570 class RawPatchClass : public RawObject { | 573 class RawPatchClass : public RawObject { |
571 private: | 574 private: |
572 RAW_HEAP_OBJECT_IMPLEMENTATION(PatchClass); | 575 RAW_HEAP_OBJECT_IMPLEMENTATION(PatchClass); |
573 | 576 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 // Alive: If true, the embedded object pointers will be visited during GC. | 851 // Alive: If true, the embedded object pointers will be visited during GC. |
849 // This field cannot be shorter because of alignment issues on x64 | 852 // This field cannot be shorter because of alignment issues on x64 |
850 // architectures. | 853 // architectures. |
851 intptr_t state_bits_; // state, is_optimized, is_alive. | 854 intptr_t state_bits_; // state, is_optimized, is_alive. |
852 | 855 |
853 // PC offsets for code patching. | 856 // PC offsets for code patching. |
854 intptr_t entry_patch_pc_offset_; | 857 intptr_t entry_patch_pc_offset_; |
855 intptr_t patch_code_pc_offset_; | 858 intptr_t patch_code_pc_offset_; |
856 intptr_t lazy_deopt_pc_offset_; | 859 intptr_t lazy_deopt_pc_offset_; |
857 | 860 |
858 intptr_t dummy_alignment_; | |
859 | |
860 // Variable length data follows here. | 861 // Variable length data follows here. |
861 int32_t data_[0]; | 862 int32_t* data() { |
863 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
864 ASSERT(Utils::IsAligned(result, sizeof(int32_t))); | |
865 return reinterpret_cast<int32_t*>(result); | |
866 } | |
siva
2014/06/17 22:29:50
int32_t* data() { OPEN_ARRAY_START(int32_t); }
zra
2014/06/17 23:17:57
Done.
| |
862 | 867 |
863 friend class StackFrame; | 868 friend class StackFrame; |
864 friend class MarkingVisitor; | 869 friend class MarkingVisitor; |
865 friend class Function; | 870 friend class Function; |
866 }; | 871 }; |
867 | 872 |
868 | 873 |
869 class RawInstructions : public RawObject { | 874 class RawInstructions : public RawObject { |
870 RAW_HEAP_OBJECT_IMPLEMENTATION(Instructions); | 875 RAW_HEAP_OBJECT_IMPLEMENTATION(Instructions); |
871 | 876 |
872 RawObject** from() { | 877 RawObject** from() { |
873 return reinterpret_cast<RawObject**>(&ptr()->code_); | 878 return reinterpret_cast<RawObject**>(&ptr()->code_); |
874 } | 879 } |
875 RawCode* code_; | 880 RawCode* code_; |
876 RawArray* object_pool_; | 881 RawArray* object_pool_; |
877 RawObject** to() { | 882 RawObject** to() { |
878 return reinterpret_cast<RawObject**>(&ptr()->object_pool_); | 883 return reinterpret_cast<RawObject**>(&ptr()->object_pool_); |
879 } | 884 } |
880 intptr_t size_; | 885 intptr_t size_; |
881 | 886 |
882 // Variable length data follows here. | 887 // Variable length data follows here. |
883 uint8_t data_[0]; | 888 uint8_t* data() { |
889 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
890 ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); | |
891 return reinterpret_cast<uint8_t*>(result); | |
892 } | |
884 | 893 |
885 // Private helper function used while visiting stack frames. The | 894 // Private helper function used while visiting stack frames. The |
886 // code which iterates over dart frames is also called during GC and | 895 // code which iterates over dart frames is also called during GC and |
887 // is not allowed to create handles. | 896 // is not allowed to create handles. |
888 static bool ContainsPC(RawObject* raw_obj, uword pc); | 897 static bool ContainsPC(RawObject* raw_obj, uword pc); |
889 | 898 |
890 friend class RawCode; | 899 friend class RawCode; |
891 friend class Code; | 900 friend class Code; |
892 friend class StackFrame; | 901 friend class StackFrame; |
893 friend class MarkingVisitor; | 902 friend class MarkingVisitor; |
894 friend class Function; | 903 friend class Function; |
895 }; | 904 }; |
896 | 905 |
897 | 906 |
898 class RawPcDescriptors : public RawObject { | 907 class RawPcDescriptors : public RawObject { |
899 RAW_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors); | 908 RAW_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors); |
900 | 909 |
901 intptr_t length_; // Number of descriptors. | 910 intptr_t length_; // Number of descriptors. |
902 | 911 |
903 // Variable length data follows here. | 912 // Variable length data follows here. |
904 intptr_t data_[0]; | 913 intptr_t* data() { |
914 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
915 ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); | |
916 return reinterpret_cast<intptr_t*>(result); | |
917 } | |
905 | 918 |
906 friend class Object; | 919 friend class Object; |
907 }; | 920 }; |
908 | 921 |
909 | 922 |
910 // Stackmap is an immutable representation of the layout of the stack at a | 923 // Stackmap is an immutable representation of the layout of the stack at a |
911 // PC. The stack map representation consists of a bit map which marks each | 924 // PC. The stack map representation consists of a bit map which marks each |
912 // live object index starting from the base of the frame. | 925 // live object index starting from the base of the frame. |
913 // | 926 // |
914 // The Stackmap also consists of a link to the code object corresponding to | 927 // The Stackmap also consists of a link to the code object corresponding to |
915 // the frame which the stack map is describing. The bit map representation | 928 // the frame which the stack map is describing. The bit map representation |
916 // is optimized for dense and small bit maps, without any upper bound. | 929 // is optimized for dense and small bit maps, without any upper bound. |
917 class RawStackmap : public RawObject { | 930 class RawStackmap : public RawObject { |
918 RAW_HEAP_OBJECT_IMPLEMENTATION(Stackmap); | 931 RAW_HEAP_OBJECT_IMPLEMENTATION(Stackmap); |
919 | 932 |
920 // TODO(kmillikin): We need a small number of bits to encode the register | 933 // TODO(kmillikin): We need a small number of bits to encode the register |
921 // count. Consider packing them in with the length. | 934 // count. Consider packing them in with the length. |
922 intptr_t length_; // Length of payload, in bits. | 935 intptr_t length_; // Length of payload, in bits. |
923 intptr_t register_bit_count_; // Live register bits, included in length_. | 936 intptr_t register_bit_count_; // Live register bits, included in length_. |
924 | 937 |
925 uword pc_; // PC corresponding to this stack map representation. | 938 uword pc_; // PC corresponding to this stack map representation. |
926 | 939 |
927 // Variable length data follows here (bitmap of the stack layout). | 940 // Variable length data follows here (bitmap of the stack layout). |
928 uint8_t data_[0]; | 941 uint8_t* data() { |
942 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
943 ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); | |
944 return reinterpret_cast<uint8_t*>(result); | |
945 } | |
929 }; | 946 }; |
930 | 947 |
931 | 948 |
932 class RawLocalVarDescriptors : public RawObject { | 949 class RawLocalVarDescriptors : public RawObject { |
933 public: | 950 public: |
934 enum VarInfoKind { | 951 enum VarInfoKind { |
935 kStackVar = 1, | 952 kStackVar = 1, |
936 kContextVar, | 953 kContextVar, |
937 kContextLevel, | 954 kContextLevel, |
938 kSavedEntryContext, | 955 kSavedEntryContext, |
939 kSavedCurrentContext | 956 kSavedCurrentContext |
940 }; | 957 }; |
941 | 958 |
942 struct VarInfo { | 959 struct VarInfo { |
943 intptr_t index; // Slot index on stack or in context. | 960 intptr_t index; // Slot index on stack or in context. |
944 int8_t kind; // Entry kind of type VarInfoKind. | 961 int8_t kind; // Entry kind of type VarInfoKind. |
945 int16_t scope_id; // Scope to which the variable belongs. | 962 int16_t scope_id; // Scope to which the variable belongs. |
946 intptr_t begin_pos; // Token position of scope start. | 963 intptr_t begin_pos; // Token position of scope start. |
947 intptr_t end_pos; // Token position of scope end. | 964 intptr_t end_pos; // Token position of scope end. |
948 }; | 965 }; |
949 | 966 |
950 private: | 967 private: |
951 RAW_HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors); | 968 RAW_HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors); |
952 intptr_t length_; // Number of descriptors. | 969 intptr_t length_; // Number of descriptors. |
953 RawArray* names_; // Array of [length_] variable names. | 970 RawArray* names_; // Array of [length_] variable names. |
954 | 971 |
955 VarInfo data_[0]; // Variable info with [length_] entries. | 972 // Variable info with [length_] entries. |
973 VarInfo* data() { | |
974 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
975 ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); | |
976 return reinterpret_cast<VarInfo*>(result); | |
977 } | |
956 }; | 978 }; |
957 | 979 |
958 | 980 |
959 class RawExceptionHandlers : public RawObject { | 981 class RawExceptionHandlers : public RawObject { |
960 public: | 982 public: |
961 // The index into the ExceptionHandlers table corresponds to | 983 // The index into the ExceptionHandlers table corresponds to |
962 // the try_index of the handler. | 984 // the try_index of the handler. |
963 struct HandlerInfo { | 985 struct HandlerInfo { |
964 intptr_t handler_pc; // PC value of handler. | 986 intptr_t handler_pc; // PC value of handler. |
965 int16_t outer_try_index; // Try block index of enclosing try block. | 987 int16_t outer_try_index; // Try block index of enclosing try block. |
966 int8_t needs_stacktrace; // True if a stacktrace is needed. | 988 int8_t needs_stacktrace; // True if a stacktrace is needed. |
967 int8_t has_catch_all; // Catches all exceptions. | 989 int8_t has_catch_all; // Catches all exceptions. |
968 }; | 990 }; |
991 | |
969 private: | 992 private: |
970 RAW_HEAP_OBJECT_IMPLEMENTATION(ExceptionHandlers); | 993 RAW_HEAP_OBJECT_IMPLEMENTATION(ExceptionHandlers); |
971 | 994 |
972 // Number of exception handler entries. | 995 // Number of exception handler entries. |
973 intptr_t length_; | 996 intptr_t length_; |
974 | 997 |
975 // Array with [length_] entries. Each entry is an array of all handled | 998 // Array with [length_] entries. Each entry is an array of all handled |
976 // exception types. | 999 // exception types. |
977 RawArray* handled_types_data_; | 1000 RawArray* handled_types_data_; |
978 | 1001 |
979 // Exception handler info of length [length_]. | 1002 // Exception handler info of length [length_]. |
980 HandlerInfo data_[0]; | 1003 HandlerInfo* data() { |
1004 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1005 ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); | |
1006 return reinterpret_cast<HandlerInfo*>(result); | |
1007 } | |
981 }; | 1008 }; |
982 | 1009 |
983 | 1010 |
984 // Contains an array of deoptimization commands, e.g., move a specific register | 1011 // Contains an array of deoptimization commands, e.g., move a specific register |
985 // into a specific slot of unoptimized frame. | 1012 // into a specific slot of unoptimized frame. |
986 class RawDeoptInfo : public RawObject { | 1013 class RawDeoptInfo : public RawObject { |
987 RAW_HEAP_OBJECT_IMPLEMENTATION(DeoptInfo); | 1014 RAW_HEAP_OBJECT_IMPLEMENTATION(DeoptInfo); |
988 | 1015 |
989 RawSmi* length_; // Number of deoptimization commands | 1016 RawSmi* length_; // Number of deoptimization commands |
990 | 1017 |
991 // Variable length data follows here. | 1018 // Variable length data follows here. |
992 intptr_t data_[0]; | 1019 intptr_t* data() { |
1020 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1021 ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); | |
1022 return reinterpret_cast<intptr_t*>(result); | |
1023 } | |
993 }; | 1024 }; |
994 | 1025 |
995 | 1026 |
996 class RawContext : public RawObject { | 1027 class RawContext : public RawObject { |
997 RAW_HEAP_OBJECT_IMPLEMENTATION(Context); | 1028 RAW_HEAP_OBJECT_IMPLEMENTATION(Context); |
998 | 1029 |
999 intptr_t num_variables_; | 1030 intptr_t num_variables_; |
1000 Isolate* isolate_; | 1031 Isolate* isolate_; |
1001 | 1032 |
1002 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->parent_); } | 1033 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->parent_); } |
1003 RawContext* parent_; | 1034 RawContext* parent_; |
1004 | 1035 |
1005 // Variable length data follows here. | 1036 // Variable length data follows here. |
1006 RawInstance* data_[0]; | 1037 RawInstance** data() { |
1038 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1039 ASSERT(Utils::IsAligned(result, sizeof(RawInstance*))); | |
1040 return reinterpret_cast<RawInstance**>(result); | |
1041 } | |
1007 RawObject** to(intptr_t num_vars) { | 1042 RawObject** to(intptr_t num_vars) { |
1008 return reinterpret_cast<RawObject**>(&ptr()->data_[num_vars - 1]); | 1043 return reinterpret_cast<RawObject**>(&ptr()->data()[num_vars - 1]); |
1009 } | 1044 } |
1010 | 1045 |
1011 friend class SnapshotReader; | 1046 friend class SnapshotReader; |
1012 }; | 1047 }; |
1013 | 1048 |
1014 | 1049 |
1015 class RawContextScope : public RawObject { | 1050 class RawContextScope : public RawObject { |
1016 RAW_HEAP_OBJECT_IMPLEMENTATION(ContextScope); | 1051 RAW_HEAP_OBJECT_IMPLEMENTATION(ContextScope); |
1017 | 1052 |
1018 // TODO(iposva): Switch to convential enum offset based structure to avoid | 1053 // TODO(iposva): Switch to convential enum offset based structure to avoid |
1019 // alignment mishaps. | 1054 // alignment mishaps. |
1020 struct VariableDesc { | 1055 struct VariableDesc { |
1021 RawSmi* token_pos; | 1056 RawSmi* token_pos; |
1022 RawString* name; | 1057 RawString* name; |
1023 RawBool* is_final; | 1058 RawBool* is_final; |
1024 RawBool* is_const; | 1059 RawBool* is_const; |
1025 union { | 1060 union { |
1026 RawAbstractType* type; | 1061 RawAbstractType* type; |
1027 RawInstance* value; // iff is_const is true | 1062 RawInstance* value; // iff is_const is true |
1028 }; | 1063 }; |
1029 RawSmi* context_index; | 1064 RawSmi* context_index; |
1030 RawSmi* context_level; | 1065 RawSmi* context_level; |
1031 }; | 1066 }; |
1032 | 1067 |
1033 intptr_t num_variables_; | 1068 intptr_t num_variables_; |
1034 | 1069 |
1035 // Variable length data follows here. | 1070 // Variable length data follows here. |
siva
2014/06/17 22:29:50
This comment should be above data() for consistenc
zra
2014/06/17 23:17:58
Done.
| |
1036 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->data_[0]); } | 1071 RawObject** from() { |
1037 RawObject* data_[0]; | 1072 return reinterpret_cast<RawObject**>(&ptr()->data()[0]); |
1073 } | |
1074 RawObject** data() { | |
1075 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1076 ASSERT(Utils::IsAligned(result, sizeof(RawObject*))); | |
1077 return reinterpret_cast<RawObject**>(result); | |
1078 } | |
1038 RawObject** to(intptr_t num_vars) { | 1079 RawObject** to(intptr_t num_vars) { |
1039 intptr_t data_length = num_vars * (sizeof(VariableDesc)/kWordSize); | 1080 const intptr_t data_length = num_vars * (sizeof(VariableDesc)/kWordSize); |
1040 return reinterpret_cast<RawObject**>(&ptr()->data_[data_length - 1]); | 1081 return reinterpret_cast<RawObject**>(&ptr()->data()[data_length - 1]); |
1041 } | 1082 } |
1042 }; | 1083 }; |
1043 | 1084 |
1044 | 1085 |
1045 class RawICData : public RawObject { | 1086 class RawICData : public RawObject { |
1046 RAW_HEAP_OBJECT_IMPLEMENTATION(ICData); | 1087 RAW_HEAP_OBJECT_IMPLEMENTATION(ICData); |
1047 | 1088 |
1048 RawObject** from() { | 1089 RawObject** from() { |
1049 return reinterpret_cast<RawObject**>(&ptr()->owner_); | 1090 return reinterpret_cast<RawObject**>(&ptr()->owner_); |
1050 } | 1091 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 // object length so that the object can be traversed during GC). | 1340 // object length so that the object can be traversed during GC). |
1300 intptr_t allocated_length_; | 1341 intptr_t allocated_length_; |
1301 | 1342 |
1302 // Operational length in chunks of the bigint object, clamping can | 1343 // Operational length in chunks of the bigint object, clamping can |
1303 // cause this length to be reduced. If the signed_length_ is | 1344 // cause this length to be reduced. If the signed_length_ is |
1304 // negative then the number is negative. | 1345 // negative then the number is negative. |
1305 intptr_t signed_length_; | 1346 intptr_t signed_length_; |
1306 | 1347 |
1307 // A sequence of Chunks (typedef in Bignum) representing bignum digits. | 1348 // A sequence of Chunks (typedef in Bignum) representing bignum digits. |
1308 // Bignum::Chunk chunks_[Utils::Abs(signed_length_)]; | 1349 // Bignum::Chunk chunks_[Utils::Abs(signed_length_)]; |
1309 uint8_t data_[0]; | 1350 uint8_t* data() { |
1351 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1352 ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); | |
1353 return reinterpret_cast<uint8_t*>(result); | |
1354 } | |
1310 | 1355 |
1311 friend class SnapshotReader; | 1356 friend class SnapshotReader; |
1312 }; | 1357 }; |
1313 | 1358 |
1314 | 1359 |
1315 class RawDouble : public RawNumber { | 1360 class RawDouble : public RawNumber { |
1316 RAW_HEAP_OBJECT_IMPLEMENTATION(Double); | 1361 RAW_HEAP_OBJECT_IMPLEMENTATION(Double); |
1317 | 1362 |
1318 double value_; | 1363 double value_; |
1319 | 1364 |
(...skipping 10 matching lines...) Expand all Loading... | |
1330 RawSmi* length_; | 1375 RawSmi* length_; |
1331 RawSmi* hash_; | 1376 RawSmi* hash_; |
1332 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->hash_); } | 1377 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->hash_); } |
1333 }; | 1378 }; |
1334 | 1379 |
1335 | 1380 |
1336 class RawOneByteString : public RawString { | 1381 class RawOneByteString : public RawString { |
1337 RAW_HEAP_OBJECT_IMPLEMENTATION(OneByteString); | 1382 RAW_HEAP_OBJECT_IMPLEMENTATION(OneByteString); |
1338 | 1383 |
1339 // Variable length data follows here. | 1384 // Variable length data follows here. |
1340 uint8_t data_[0]; | 1385 uint8_t* data() { |
1386 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1387 ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); | |
1388 return reinterpret_cast<uint8_t*>(result); | |
1389 } | |
1341 | 1390 |
1342 friend class ApiMessageReader; | 1391 friend class ApiMessageReader; |
1343 friend class SnapshotReader; | 1392 friend class SnapshotReader; |
1344 }; | 1393 }; |
1345 | 1394 |
1346 | 1395 |
1347 class RawTwoByteString : public RawString { | 1396 class RawTwoByteString : public RawString { |
1348 RAW_HEAP_OBJECT_IMPLEMENTATION(TwoByteString); | 1397 RAW_HEAP_OBJECT_IMPLEMENTATION(TwoByteString); |
1349 | 1398 |
1350 // Variable length data follows here. | 1399 // Variable length data follows here. |
1351 uint16_t data_[0]; | 1400 uint16_t* data() { |
1401 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1402 ASSERT(Utils::IsAligned(result, sizeof(uint16_t))); | |
1403 return reinterpret_cast<uint16_t*>(result); | |
1404 } | |
1352 | 1405 |
1353 friend class SnapshotReader; | 1406 friend class SnapshotReader; |
1354 }; | 1407 }; |
1355 | 1408 |
1356 | 1409 |
1357 template<typename T> | 1410 template<typename T> |
1358 class ExternalStringData { | 1411 class ExternalStringData { |
1359 public: | 1412 public: |
1360 ExternalStringData(const T* data, void* peer, Dart_PeerFinalizer callback) : | 1413 ExternalStringData(const T* data, void* peer, Dart_PeerFinalizer callback) : |
1361 data_(data), peer_(peer), callback_(callback) { | 1414 data_(data), peer_(peer), callback_(callback) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1404 class RawArray : public RawInstance { | 1457 class RawArray : public RawInstance { |
1405 RAW_HEAP_OBJECT_IMPLEMENTATION(Array); | 1458 RAW_HEAP_OBJECT_IMPLEMENTATION(Array); |
1406 | 1459 |
1407 RawObject** from() { | 1460 RawObject** from() { |
1408 return reinterpret_cast<RawObject**>(&ptr()->type_arguments_); | 1461 return reinterpret_cast<RawObject**>(&ptr()->type_arguments_); |
1409 } | 1462 } |
1410 RawTypeArguments* type_arguments_; | 1463 RawTypeArguments* type_arguments_; |
1411 RawSmi* length_; | 1464 RawSmi* length_; |
1412 // Variable length data follows here. | 1465 // Variable length data follows here. |
1413 RawObject** data() { | 1466 RawObject** data() { |
1414 uword address_of_length = reinterpret_cast<uword>(&length_); | 1467 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
1415 return reinterpret_cast<RawObject**>(address_of_length + kWordSize); | 1468 ASSERT(Utils::IsAligned(result, sizeof(RawObject*))); |
1469 return reinterpret_cast<RawObject**>(result); | |
1416 } | 1470 } |
1417 RawObject** to(intptr_t length) { | 1471 RawObject** to(intptr_t length) { |
1418 return reinterpret_cast<RawObject**>(&ptr()->data()[length - 1]); | 1472 return reinterpret_cast<RawObject**>(&ptr()->data()[length - 1]); |
1419 } | 1473 } |
1420 | 1474 |
1421 friend class RawCode; | 1475 friend class RawCode; |
1422 friend class RawImmutableArray; | 1476 friend class RawImmutableArray; |
1423 friend class SnapshotReader; | 1477 friend class SnapshotReader; |
1424 friend class GrowableObjectArray; | 1478 friend class GrowableObjectArray; |
1425 friend class Object; | 1479 friend class Object; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1503 #error Architecture is not 32-bit or 64-bit. | 1557 #error Architecture is not 32-bit or 64-bit. |
1504 #endif // ARCH_IS_32_BIT | 1558 #endif // ARCH_IS_32_BIT |
1505 | 1559 |
1506 | 1560 |
1507 class RawTypedData : public RawInstance { | 1561 class RawTypedData : public RawInstance { |
1508 RAW_HEAP_OBJECT_IMPLEMENTATION(TypedData); | 1562 RAW_HEAP_OBJECT_IMPLEMENTATION(TypedData); |
1509 | 1563 |
1510 protected: | 1564 protected: |
1511 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } | 1565 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
1512 RawSmi* length_; | 1566 RawSmi* length_; |
1567 // Variable length data follows here. | |
1568 uint8_t* data() { | |
1569 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1570 ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); | |
1571 return reinterpret_cast<uint8_t*>(result); | |
1572 } | |
1513 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } | 1573 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
1514 | 1574 |
1515 // Variable length data follows here. | |
1516 uint8_t data_[0]; | |
1517 | |
1518 friend class Api; | 1575 friend class Api; |
1519 friend class Object; | 1576 friend class Object; |
1520 friend class Instance; | 1577 friend class Instance; |
1521 }; | 1578 }; |
1522 | 1579 |
1523 | 1580 |
1524 class RawExternalTypedData : public RawInstance { | 1581 class RawExternalTypedData : public RawInstance { |
1525 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData); | 1582 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData); |
1526 | 1583 |
1527 protected: | 1584 protected: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1597 RawSmi* num_bracket_expressions_; | 1654 RawSmi* num_bracket_expressions_; |
1598 RawString* pattern_; // Pattern to be used for matching. | 1655 RawString* pattern_; // Pattern to be used for matching. |
1599 RawObject** to() { | 1656 RawObject** to() { |
1600 return reinterpret_cast<RawObject**>(&ptr()->pattern_); | 1657 return reinterpret_cast<RawObject**>(&ptr()->pattern_); |
1601 } | 1658 } |
1602 | 1659 |
1603 intptr_t type_; // Uninitialized, simple or complex. | 1660 intptr_t type_; // Uninitialized, simple or complex. |
1604 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 1661 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
1605 | 1662 |
1606 // Variable length data follows here. | 1663 // Variable length data follows here. |
1607 uint8_t data_[0]; | 1664 uint8_t* data() { |
1665 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); | |
1666 ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); | |
1667 return reinterpret_cast<uint8_t*>(result); | |
1668 } | |
1608 }; | 1669 }; |
1609 | 1670 |
1610 | 1671 |
1611 class RawWeakProperty : public RawInstance { | 1672 class RawWeakProperty : public RawInstance { |
1612 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); | 1673 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); |
1613 | 1674 |
1614 RawObject** from() { | 1675 RawObject** from() { |
1615 return reinterpret_cast<RawObject**>(&ptr()->key_); | 1676 return reinterpret_cast<RawObject**>(&ptr()->key_); |
1616 } | 1677 } |
1617 RawObject* key_; | 1678 RawObject* key_; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1867 COMPILE_ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14); | 1928 COMPILE_ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14); |
1868 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 1929 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
1869 kTypedDataInt8ArrayViewCid + 15); | 1930 kTypedDataInt8ArrayViewCid + 15); |
1870 COMPILE_ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 14); | 1931 COMPILE_ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 14); |
1871 return (kNullCid - kTypedDataInt8ArrayCid); | 1932 return (kNullCid - kTypedDataInt8ArrayCid); |
1872 } | 1933 } |
1873 | 1934 |
1874 } // namespace dart | 1935 } // namespace dart |
1875 | 1936 |
1876 #endif // VM_RAW_OBJECT_H_ | 1937 #endif // VM_RAW_OBJECT_H_ |
OLD | NEW |