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" |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 public: | 1025 public: |
1026 enum Kind { | 1026 enum Kind { |
1027 kDeopt = 1, // Deoptimization continuation point. | 1027 kDeopt = 1, // Deoptimization continuation point. |
1028 kIcCall = kDeopt << 1, // IC call. | 1028 kIcCall = kDeopt << 1, // IC call. |
1029 kOptStaticCall = kIcCall << 1, // Call directly to known target. | 1029 kOptStaticCall = kIcCall << 1, // Call directly to known target. |
1030 kUnoptStaticCall = kOptStaticCall << 1, // Call to a known target via stub. | 1030 kUnoptStaticCall = kOptStaticCall << 1, // Call to a known target via stub. |
1031 kClosureCall = kUnoptStaticCall << 1, // Closure call. | 1031 kClosureCall = kUnoptStaticCall << 1, // Closure call. |
1032 kRuntimeCall = kClosureCall << 1, // Runtime call. | 1032 kRuntimeCall = kClosureCall << 1, // Runtime call. |
1033 kOsrEntry = kRuntimeCall << 1, // OSR entry point in unopt. code. | 1033 kOsrEntry = kRuntimeCall << 1, // OSR entry point in unopt. code. |
1034 kOther = kOsrEntry << 1, | 1034 kOther = kOsrEntry << 1, |
1035 kAnyKind = 0xFF | 1035 kLastKind = kOther, |
| 1036 kAnyKind = -1 |
1036 }; | 1037 }; |
1037 | 1038 |
1038 // Compressed version assumes try_index is always -1 and does not store it. | 1039 class MergedKindTry { |
1039 struct PcDescriptorRec { | 1040 public: |
1040 uword pc_offset() const { return pc_offset_; } | 1041 // Most of the time try_index will be small and merged field will fit into |
1041 void set_pc_offset(uword value) { | 1042 // one byte. |
1042 // Some C compilers warn about the comparison always being true when using | 1043 static intptr_t Encode(intptr_t kind, intptr_t try_index) { |
1043 // <= due to limited range of data type. | 1044 intptr_t kind_shift = Utils::ShiftForPowerOfTwo(kind); |
1044 ASSERT((value == static_cast<uword>(kMaxUint32)) || | 1045 ASSERT(Utils::IsUint(kKindShiftSize, kind_shift)); |
1045 (value < static_cast<uword>(kMaxUint32))); | 1046 ASSERT(Utils::IsInt(kTryIndexSize, try_index)); |
1046 pc_offset_ = value; | 1047 return (try_index << kTryIndexPos) | (kind_shift << kKindShiftPos); |
1047 } | 1048 } |
1048 | 1049 |
1049 Kind kind() const { | 1050 static intptr_t DecodeKind(intptr_t merged_kind_try) { |
1050 return static_cast<Kind>(deopt_id_and_kind_ & kAnyKind); | 1051 const intptr_t kKindShiftMask = (1 << kKindShiftSize) - 1; |
1051 } | 1052 return 1 << (merged_kind_try & kKindShiftMask); |
1052 void set_kind(Kind kind) { | |
1053 deopt_id_and_kind_ = (deopt_id_and_kind_ & 0xFFFFFF00) | kind; | |
1054 } | 1053 } |
1055 | 1054 |
1056 int16_t try_index() const { return is_compressed() ? -1 : try_index_; } | 1055 static intptr_t DecodeTryIndex(intptr_t merged_kind_try) { |
1057 void set_try_index(int16_t value) { | 1056 // Arithmetic shift. |
1058 if (is_compressed()) { | 1057 return merged_kind_try >> kTryIndexPos; |
1059 ASSERT(value == -1); | |
1060 return; | |
1061 } | |
1062 try_index_ = value; | |
1063 } | |
1064 | |
1065 intptr_t token_pos() const { return token_pos_ >> 1; } | |
1066 void set_token_pos(int32_t value, bool compressed) { | |
1067 int32_t bit = compressed ? 0x1 : 0x0; | |
1068 token_pos_ = (value << 1) | bit; | |
1069 } | |
1070 | |
1071 intptr_t deopt_id() const { return deopt_id_and_kind_ >> 8; } | |
1072 void set_deopt_id(int32_t value) { | |
1073 ASSERT(Utils::IsInt(24, value)); | |
1074 deopt_id_and_kind_ = (deopt_id_and_kind_ & 0xFF) | (value << 8); | |
1075 } | 1058 } |
1076 | 1059 |
1077 private: | 1060 private: |
1078 bool is_compressed() const { | 1061 static const intptr_t kKindShiftPos = 0; |
1079 return (token_pos_ & 0x1) == 1; | 1062 static const intptr_t kKindShiftSize = 3; |
1080 } | 1063 // Is kKindShiftSize enough bits? |
| 1064 COMPILE_ASSERT(kLastKind <= 1 << ((1 << kKindShiftSize) - 1)); |
1081 | 1065 |
1082 uint32_t pc_offset_; | 1066 static const intptr_t kTryIndexPos = kKindShiftSize; |
1083 int32_t deopt_id_and_kind_; // Bits 31..8 -> deopt_id, bits 7..0 kind. | 1067 static const intptr_t kTryIndexSize = kBitsPerWord - kKindShiftSize; |
1084 int32_t token_pos_; // Bits 31..1 -> token_pos, bit 1 -> compressed flag; | |
1085 int16_t try_index_; | |
1086 }; | 1068 }; |
1087 | 1069 |
1088 // This structure is only used to compute what the size of PcDescriptorRec | |
1089 // should be when the try_index_ field is omitted. | |
1090 struct CompressedPcDescriptorRec { | |
1091 uint32_t pc_offset_; | |
1092 int32_t deopt_id_and_kind_; | |
1093 int32_t token_pos_; | |
1094 }; | |
1095 | |
1096 static intptr_t RecordSize(bool has_try_index); | |
1097 | |
1098 private: | 1070 private: |
1099 RAW_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors); | 1071 RAW_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors); |
1100 | 1072 |
1101 static const intptr_t kFullRecSize; | |
1102 static const intptr_t kCompressedRecSize; | |
1103 | |
1104 int32_t record_size_in_bytes_; | |
1105 int32_t length_; // Number of descriptors. | 1073 int32_t length_; // Number of descriptors. |
1106 | 1074 |
1107 // Variable length data follows here. | 1075 // Variable length data follows here. |
1108 uint8_t* data() { OPEN_ARRAY_START(uint8_t, intptr_t); } | 1076 uint8_t* data() { OPEN_ARRAY_START(uint8_t, intptr_t); } |
1109 const uint8_t* data() const { OPEN_ARRAY_START(uint8_t, intptr_t); } | 1077 const uint8_t* data() const { OPEN_ARRAY_START(uint8_t, intptr_t); } |
1110 | 1078 |
1111 friend class Object; | 1079 friend class Object; |
1112 }; | 1080 }; |
1113 | 1081 |
1114 | 1082 |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 2123 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
2156 kTypedDataInt8ArrayViewCid + 15); | 2124 kTypedDataInt8ArrayViewCid + 15); |
2157 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); | 2125 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); |
2158 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); | 2126 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); |
2159 return (kNullCid - kTypedDataInt8ArrayCid); | 2127 return (kNullCid - kTypedDataInt8ArrayCid); |
2160 } | 2128 } |
2161 | 2129 |
2162 } // namespace dart | 2130 } // namespace dart |
2163 | 2131 |
2164 #endif // VM_RAW_OBJECT_H_ | 2132 #endif // VM_RAW_OBJECT_H_ |
OLD | NEW |