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 RUNTIME_VM_OBJECT_H_ | 5 #ifndef RUNTIME_VM_OBJECT_H_ |
6 #define RUNTIME_VM_OBJECT_H_ | 6 #define RUNTIME_VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 4121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4132 | 4132 |
4133 FINAL_HEAP_OBJECT_IMPLEMENTATION(ObjectPool, Object); | 4133 FINAL_HEAP_OBJECT_IMPLEMENTATION(ObjectPool, Object); |
4134 friend class Class; | 4134 friend class Class; |
4135 friend class Object; | 4135 friend class Object; |
4136 friend class RawObjectPool; | 4136 friend class RawObjectPool; |
4137 }; | 4137 }; |
4138 | 4138 |
4139 | 4139 |
4140 class Instructions : public Object { | 4140 class Instructions : public Object { |
4141 public: | 4141 public: |
4142 intptr_t size() const { return raw_ptr()->size_; } // Excludes HeaderSize(). | 4142 // Excludes HeaderSize(). |
4143 intptr_t size() const { return abs(raw_ptr()->size_); } | |
Vyacheslav Egorov (Google)
2016/11/10 13:30:49
Please add a comment to RawInstructions::size_ tha
| |
4144 bool HasSingleEntryPoint() const { return raw_ptr()->size_ >= 0; } | |
4143 | 4145 |
4144 uword PayloadStart() const { | 4146 uword PayloadStart() const { |
4145 return PayloadStart(raw()); | 4147 return PayloadStart(raw()); |
4146 } | 4148 } |
4149 uword CheckedEntryPoint() const { | |
4150 return CheckedEntryPoint(raw()); | |
4151 } | |
4147 uword UncheckedEntryPoint() const { | 4152 uword UncheckedEntryPoint() const { |
4148 return UncheckedEntryPoint(raw()); | 4153 return UncheckedEntryPoint(raw()); |
4149 } | 4154 } |
4150 uword CheckedEntryPoint() const { | |
4151 return CheckedEntryPoint(raw()); | |
4152 } | |
4153 static uword PayloadStart(RawInstructions* instr) { | 4155 static uword PayloadStart(RawInstructions* instr) { |
4154 return reinterpret_cast<uword>(instr->ptr()) + HeaderSize(); | 4156 return reinterpret_cast<uword>(instr->ptr()) + HeaderSize(); |
4155 } | 4157 } |
4156 | 4158 |
4157 #if defined(TARGET_ARCH_IA32) | 4159 #if defined(TARGET_ARCH_IA32) |
4158 static const intptr_t kCheckedEntryOffset = 0; | 4160 static const intptr_t kCheckedEntryOffset = 0; |
4159 static const intptr_t kUncheckedEntryOffset = 0; | 4161 static const intptr_t kUncheckedEntryOffset = 0; |
4160 #elif defined(TARGET_ARCH_X64) | 4162 #elif defined(TARGET_ARCH_X64) |
4161 static const intptr_t kCheckedEntryOffset = 16; | 4163 static const intptr_t kCheckedEntryOffset = 16; |
4162 static const intptr_t kUncheckedEntryOffset = 38; | 4164 static const intptr_t kUncheckedEntryOffset = 38; |
4163 #elif defined(TARGET_ARCH_ARM) | 4165 #elif defined(TARGET_ARCH_ARM) |
4164 static const intptr_t kCheckedEntryOffset = 8; | 4166 static const intptr_t kCheckedEntryOffset = 8; |
4165 static const intptr_t kUncheckedEntryOffset = 32; | 4167 static const intptr_t kUncheckedEntryOffset = 32; |
4166 #elif defined(TARGET_ARCH_ARM64) | 4168 #elif defined(TARGET_ARCH_ARM64) |
4167 static const intptr_t kCheckedEntryOffset = 16; | 4169 static const intptr_t kCheckedEntryOffset = 16; |
4168 static const intptr_t kUncheckedEntryOffset = 40; | 4170 static const intptr_t kUncheckedEntryOffset = 40; |
4169 #elif defined(TARGET_ARCH_MIPS) | 4171 #elif defined(TARGET_ARCH_MIPS) |
4170 static const intptr_t kCheckedEntryOffset = 12; | 4172 static const intptr_t kCheckedEntryOffset = 12; |
4171 static const intptr_t kUncheckedEntryOffset = 52; | 4173 static const intptr_t kUncheckedEntryOffset = 52; |
4172 #elif defined(TARGET_ARCH_DBC) | 4174 #elif defined(TARGET_ARCH_DBC) |
4173 static const intptr_t kCheckedEntryOffset = 0; | 4175 static const intptr_t kCheckedEntryOffset = 0; |
4174 static const intptr_t kUncheckedEntryOffset = 0; | 4176 static const intptr_t kUncheckedEntryOffset = 0; |
4175 #else | 4177 #else |
4176 #error Missing entry offsets for current architecture | 4178 #error Missing entry offsets for current architecture |
4177 #endif | 4179 #endif |
4178 | 4180 |
4181 static uword CheckedEntryPoint(RawInstructions* instr) { | |
4182 uword entry = PayloadStart(instr); | |
4183 if (instr->ptr()->size_ < 0) { | |
Vyacheslav Egorov (Google)
2016/11/10 13:30:49
I suggest having helper:
static bool HasSingleEnt
| |
4184 entry += kCheckedEntryOffset; | |
4185 } | |
4186 return entry; | |
4187 } | |
4179 static uword UncheckedEntryPoint(RawInstructions* instr) { | 4188 static uword UncheckedEntryPoint(RawInstructions* instr) { |
4180 return PayloadStart(instr) + kUncheckedEntryOffset; | 4189 uword entry = PayloadStart(instr); |
4181 } | 4190 if (instr->ptr()->size_ < 0) { |
4182 static uword CheckedEntryPoint(RawInstructions* instr) { | 4191 entry += kUncheckedEntryOffset; |
4183 return PayloadStart(instr) + kCheckedEntryOffset; | 4192 } |
4193 return entry; | |
4184 } | 4194 } |
4185 | 4195 |
4186 static const intptr_t kMaxElements = (kMaxInt32 - | 4196 static const intptr_t kMaxElements = (kMaxInt32 - |
4187 (sizeof(RawInstructions) + | 4197 (sizeof(RawInstructions) + |
4188 sizeof(RawObject) + | 4198 sizeof(RawObject) + |
4189 (2 * OS::kMaxPreferredCodeAlignment))); | 4199 (2 * OS::kMaxPreferredCodeAlignment))); |
4190 | 4200 |
4191 static intptr_t InstanceSize() { | 4201 static intptr_t InstanceSize() { |
4192 ASSERT(sizeof(RawInstructions) == | 4202 ASSERT(sizeof(RawInstructions) == |
4193 OFFSET_OF_RETURNED_VALUE(RawInstructions, data)); | 4203 OFFSET_OF_RETURNED_VALUE(RawInstructions, data)); |
4194 return 0; | 4204 return 0; |
4195 } | 4205 } |
4196 | 4206 |
4197 static intptr_t InstanceSize(intptr_t size) { | 4207 static intptr_t InstanceSize(intptr_t size) { |
4198 intptr_t instructions_size = Utils::RoundUp(size, | 4208 intptr_t instructions_size = Utils::RoundUp(size, |
4199 OS::PreferredCodeAlignment()); | 4209 OS::PreferredCodeAlignment()); |
4200 intptr_t result = instructions_size + HeaderSize(); | 4210 intptr_t result = instructions_size + HeaderSize(); |
4201 ASSERT(result % OS::PreferredCodeAlignment() == 0); | 4211 ASSERT(result % OS::PreferredCodeAlignment() == 0); |
4202 return result; | 4212 return result; |
4203 } | 4213 } |
4204 | 4214 |
4205 static intptr_t HeaderSize() { | 4215 static intptr_t HeaderSize() { |
4206 intptr_t alignment = OS::PreferredCodeAlignment(); | 4216 intptr_t alignment = OS::PreferredCodeAlignment(); |
4207 return Utils::RoundUp(sizeof(RawInstructions), alignment); | 4217 return Utils::RoundUp(sizeof(RawInstructions), alignment); |
4208 } | 4218 } |
4209 | 4219 |
4210 static RawInstructions* FromUncheckedEntryPoint(uword entry_point) { | 4220 static RawInstructions* FromPayloadStart(uword payload_start) { |
4211 return reinterpret_cast<RawInstructions*>( | 4221 return reinterpret_cast<RawInstructions*>( |
4212 entry_point - HeaderSize() - kUncheckedEntryOffset + kHeapObjectTag); | 4222 payload_start - HeaderSize() + kHeapObjectTag); |
4213 } | 4223 } |
4214 | 4224 |
4215 bool Equals(const Instructions& other) const { | 4225 bool Equals(const Instructions& other) const { |
4216 if (size() != other.size()) { | 4226 if (size() != other.size()) { |
4217 return false; | 4227 return false; |
4218 } | 4228 } |
4219 NoSafepointScope no_safepoint; | 4229 NoSafepointScope no_safepoint; |
4220 return memcmp(raw_ptr(), other.raw_ptr(), InstanceSize(size())) == 0; | 4230 return memcmp(raw_ptr(), other.raw_ptr(), InstanceSize(size())) == 0; |
4221 } | 4231 } |
4222 | 4232 |
4223 private: | 4233 private: |
4224 void set_size(intptr_t size) const { | 4234 void set_size(intptr_t size) const { |
4225 StoreNonPointer(&raw_ptr()->size_, size); | 4235 StoreNonPointer(&raw_ptr()->size_, size); |
4226 } | 4236 } |
4227 | 4237 |
4228 // New is a private method as RawInstruction and RawCode objects should | 4238 // New is a private method as RawInstruction and RawCode objects should |
4229 // only be created using the Code::FinalizeCode method. This method creates | 4239 // only be created using the Code::FinalizeCode method. This method creates |
4230 // the RawInstruction and RawCode objects, sets up the pointer offsets | 4240 // the RawInstruction and RawCode objects, sets up the pointer offsets |
4231 // and links the two in a GC safe manner. | 4241 // and links the two in a GC safe manner. |
4232 static RawInstructions* New(intptr_t size); | 4242 static RawInstructions* New(intptr_t size, bool has_single_entry_point); |
4233 | 4243 |
4234 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); | 4244 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); |
4235 friend class Class; | 4245 friend class Class; |
4236 friend class Code; | 4246 friend class Code; |
4237 friend class AssemblyInstructionsWriter; | 4247 friend class AssemblyInstructionsWriter; |
4238 friend class BlobInstructionsWriter; | 4248 friend class BlobInstructionsWriter; |
4239 }; | 4249 }; |
4240 | 4250 |
4241 | 4251 |
4242 class LocalVarDescriptors : public Object { | 4252 class LocalVarDescriptors : public Object { |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4682 bool is_optimized() const { | 4692 bool is_optimized() const { |
4683 return OptimizedBit::decode(raw_ptr()->state_bits_); | 4693 return OptimizedBit::decode(raw_ptr()->state_bits_); |
4684 } | 4694 } |
4685 void set_is_optimized(bool value) const; | 4695 void set_is_optimized(bool value) const; |
4686 bool is_alive() const { | 4696 bool is_alive() const { |
4687 return AliveBit::decode(raw_ptr()->state_bits_); | 4697 return AliveBit::decode(raw_ptr()->state_bits_); |
4688 } | 4698 } |
4689 void set_is_alive(bool value) const; | 4699 void set_is_alive(bool value) const; |
4690 | 4700 |
4691 uword PayloadStart() const { | 4701 uword PayloadStart() const { |
4692 return Instructions::PayloadStart(instructions()); | 4702 const Instructions& instr = Instructions::Handle(instructions()); |
4703 return instr.PayloadStart(); | |
4693 } | 4704 } |
4694 uword UncheckedEntryPoint() const { | 4705 uword UncheckedEntryPoint() const { |
4695 return Instructions::UncheckedEntryPoint(instructions()); | 4706 const Instructions& instr = Instructions::Handle(instructions()); |
4707 return instr.UncheckedEntryPoint(); | |
4696 } | 4708 } |
4697 uword CheckedEntryPoint() const { | 4709 uword CheckedEntryPoint() const { |
4698 return Instructions::CheckedEntryPoint(instructions()); | 4710 const Instructions& instr = Instructions::Handle(instructions()); |
4711 return instr.CheckedEntryPoint(); | |
4699 } | 4712 } |
4700 intptr_t Size() const { | 4713 intptr_t Size() const { |
4701 const Instructions& instr = Instructions::Handle(instructions()); | 4714 const Instructions& instr = Instructions::Handle(instructions()); |
4702 return instr.size(); | 4715 return instr.size(); |
4703 } | 4716 } |
4704 RawObjectPool* GetObjectPool() const { | 4717 RawObjectPool* GetObjectPool() const { |
4705 return object_pool(); | 4718 return object_pool(); |
4706 } | 4719 } |
4707 bool ContainsInstructionAt(uword addr) const { | 4720 bool ContainsInstructionAt(uword addr) const { |
4708 const Instructions& instr = Instructions::Handle(instructions()); | 4721 const Instructions& instr = Instructions::Handle(instructions()); |
(...skipping 4302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9011 | 9024 |
9012 inline void TypeArguments::SetHash(intptr_t value) const { | 9025 inline void TypeArguments::SetHash(intptr_t value) const { |
9013 // This is only safe because we create a new Smi, which does not cause | 9026 // This is only safe because we create a new Smi, which does not cause |
9014 // heap allocation. | 9027 // heap allocation. |
9015 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 9028 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
9016 } | 9029 } |
9017 | 9030 |
9018 } // namespace dart | 9031 } // namespace dart |
9019 | 9032 |
9020 #endif // RUNTIME_VM_OBJECT_H_ | 9033 #endif // RUNTIME_VM_OBJECT_H_ |
OLD | NEW |