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 3994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4005 | 4005 |
4006 FINAL_HEAP_OBJECT_IMPLEMENTATION(ObjectPool, Object); | 4006 FINAL_HEAP_OBJECT_IMPLEMENTATION(ObjectPool, Object); |
4007 friend class Class; | 4007 friend class Class; |
4008 friend class Object; | 4008 friend class Object; |
4009 friend class RawObjectPool; | 4009 friend class RawObjectPool; |
4010 }; | 4010 }; |
4011 | 4011 |
4012 | 4012 |
4013 class Instructions : public Object { | 4013 class Instructions : public Object { |
4014 public: | 4014 public: |
| 4015 enum { |
| 4016 kSizePos = 0, |
| 4017 kSizeSize = 31, |
| 4018 kFlagsPos = kSizePos + kSizeSize, |
| 4019 kFlagsSize = 1, // Currently, only flag is single entry flag. |
| 4020 }; |
| 4021 |
| 4022 class SizeBits : public BitField<uint32_t, uint32_t, kSizePos, kSizeSize> {}; |
| 4023 class FlagsBits : public BitField<uint32_t, bool, kFlagsPos, kFlagsSize> {}; |
| 4024 |
4015 // Excludes HeaderSize(). | 4025 // Excludes HeaderSize(). |
4016 intptr_t size() const { return abs(raw_ptr()->size_); } | 4026 intptr_t Size() const { return SizeBits::decode(raw_ptr()->size_and_flags_); } |
4017 bool HasSingleEntryPoint() const { return raw_ptr()->size_ >= 0; } | 4027 static intptr_t Size(const RawInstructions* instr) { |
| 4028 return SizeBits::decode(instr->ptr()->size_and_flags_); |
| 4029 } |
| 4030 |
| 4031 bool HasSingleEntryPoint() const { |
| 4032 return FlagsBits::decode(raw_ptr()->size_and_flags_); |
| 4033 } |
| 4034 static bool HasSingleEntryPoint(const RawInstructions* instr) { |
| 4035 return FlagsBits::decode(instr->ptr()->size_and_flags_); |
| 4036 } |
4018 | 4037 |
4019 uword PayloadStart() const { return PayloadStart(raw()); } | 4038 uword PayloadStart() const { return PayloadStart(raw()); } |
4020 uword CheckedEntryPoint() const { return CheckedEntryPoint(raw()); } | 4039 uword CheckedEntryPoint() const { return CheckedEntryPoint(raw()); } |
4021 uword UncheckedEntryPoint() const { return UncheckedEntryPoint(raw()); } | 4040 uword UncheckedEntryPoint() const { return UncheckedEntryPoint(raw()); } |
4022 static uword PayloadStart(RawInstructions* instr) { | 4041 static uword PayloadStart(const RawInstructions* instr) { |
4023 return reinterpret_cast<uword>(instr->ptr()) + HeaderSize(); | 4042 return reinterpret_cast<uword>(instr->ptr()) + HeaderSize(); |
4024 } | 4043 } |
4025 | 4044 |
4026 #if defined(TARGET_ARCH_IA32) | 4045 #if defined(TARGET_ARCH_IA32) |
4027 static const intptr_t kCheckedEntryOffset = 0; | 4046 static const intptr_t kCheckedEntryOffset = 0; |
4028 static const intptr_t kUncheckedEntryOffset = 0; | 4047 static const intptr_t kUncheckedEntryOffset = 0; |
4029 #elif defined(TARGET_ARCH_X64) | 4048 #elif defined(TARGET_ARCH_X64) |
4030 static const intptr_t kCheckedEntryOffset = 16; | 4049 static const intptr_t kCheckedEntryOffset = 16; |
4031 static const intptr_t kUncheckedEntryOffset = 38; | 4050 static const intptr_t kUncheckedEntryOffset = 38; |
4032 #elif defined(TARGET_ARCH_ARM) | 4051 #elif defined(TARGET_ARCH_ARM) |
4033 static const intptr_t kCheckedEntryOffset = 8; | 4052 static const intptr_t kCheckedEntryOffset = 8; |
4034 static const intptr_t kUncheckedEntryOffset = 32; | 4053 static const intptr_t kUncheckedEntryOffset = 32; |
4035 #elif defined(TARGET_ARCH_ARM64) | 4054 #elif defined(TARGET_ARCH_ARM64) |
4036 static const intptr_t kCheckedEntryOffset = 16; | 4055 static const intptr_t kCheckedEntryOffset = 16; |
4037 static const intptr_t kUncheckedEntryOffset = 40; | 4056 static const intptr_t kUncheckedEntryOffset = 40; |
4038 #elif defined(TARGET_ARCH_MIPS) | 4057 #elif defined(TARGET_ARCH_MIPS) |
4039 static const intptr_t kCheckedEntryOffset = 12; | 4058 static const intptr_t kCheckedEntryOffset = 12; |
4040 static const intptr_t kUncheckedEntryOffset = 52; | 4059 static const intptr_t kUncheckedEntryOffset = 52; |
4041 #elif defined(TARGET_ARCH_DBC) | 4060 #elif defined(TARGET_ARCH_DBC) |
4042 static const intptr_t kCheckedEntryOffset = 0; | 4061 static const intptr_t kCheckedEntryOffset = 0; |
4043 static const intptr_t kUncheckedEntryOffset = 0; | 4062 static const intptr_t kUncheckedEntryOffset = 0; |
4044 #else | 4063 #else |
4045 #error Missing entry offsets for current architecture | 4064 #error Missing entry offsets for current architecture |
4046 #endif | 4065 #endif |
4047 | 4066 |
4048 static uword CheckedEntryPoint(RawInstructions* instr) { | 4067 static uword CheckedEntryPoint(const RawInstructions* instr) { |
4049 uword entry = PayloadStart(instr); | 4068 uword entry = PayloadStart(instr); |
4050 if (instr->ptr()->size_ < 0) { | 4069 if (!HasSingleEntryPoint(instr)) { |
4051 entry += kCheckedEntryOffset; | 4070 entry += kCheckedEntryOffset; |
4052 } | 4071 } |
4053 return entry; | 4072 return entry; |
4054 } | 4073 } |
4055 static uword UncheckedEntryPoint(RawInstructions* instr) { | 4074 static uword UncheckedEntryPoint(const RawInstructions* instr) { |
4056 uword entry = PayloadStart(instr); | 4075 uword entry = PayloadStart(instr); |
4057 if (instr->ptr()->size_ < 0) { | 4076 if (!HasSingleEntryPoint(instr)) { |
4058 entry += kUncheckedEntryOffset; | 4077 entry += kUncheckedEntryOffset; |
4059 } | 4078 } |
4060 return entry; | 4079 return entry; |
4061 } | 4080 } |
4062 | 4081 |
4063 static const intptr_t kMaxElements = | 4082 static const intptr_t kMaxElements = |
4064 (kMaxInt32 - (sizeof(RawInstructions) + sizeof(RawObject) + | 4083 (kMaxInt32 - (sizeof(RawInstructions) + sizeof(RawObject) + |
4065 (2 * OS::kMaxPreferredCodeAlignment))); | 4084 (2 * OS::kMaxPreferredCodeAlignment))); |
4066 | 4085 |
4067 static intptr_t InstanceSize() { | 4086 static intptr_t InstanceSize() { |
(...skipping 14 matching lines...) Expand all Loading... |
4082 intptr_t alignment = OS::PreferredCodeAlignment(); | 4101 intptr_t alignment = OS::PreferredCodeAlignment(); |
4083 return Utils::RoundUp(sizeof(RawInstructions), alignment); | 4102 return Utils::RoundUp(sizeof(RawInstructions), alignment); |
4084 } | 4103 } |
4085 | 4104 |
4086 static RawInstructions* FromPayloadStart(uword payload_start) { | 4105 static RawInstructions* FromPayloadStart(uword payload_start) { |
4087 return reinterpret_cast<RawInstructions*>(payload_start - HeaderSize() + | 4106 return reinterpret_cast<RawInstructions*>(payload_start - HeaderSize() + |
4088 kHeapObjectTag); | 4107 kHeapObjectTag); |
4089 } | 4108 } |
4090 | 4109 |
4091 bool Equals(const Instructions& other) const { | 4110 bool Equals(const Instructions& other) const { |
4092 if (size() != other.size()) { | 4111 if (Size() != other.Size()) { |
4093 return false; | 4112 return false; |
4094 } | 4113 } |
4095 NoSafepointScope no_safepoint; | 4114 NoSafepointScope no_safepoint; |
4096 return memcmp(raw_ptr(), other.raw_ptr(), InstanceSize(size())) == 0; | 4115 return memcmp(raw_ptr(), other.raw_ptr(), InstanceSize(Size())) == 0; |
4097 } | 4116 } |
4098 | 4117 |
4099 private: | 4118 private: |
4100 void set_size(intptr_t size) const { | 4119 void SetSize(intptr_t value) const { |
4101 StoreNonPointer(&raw_ptr()->size_, size); | 4120 ASSERT(value >= 0); |
| 4121 StoreNonPointer(&raw_ptr()->size_and_flags_, |
| 4122 SizeBits::update(value, raw_ptr()->size_and_flags_)); |
| 4123 } |
| 4124 |
| 4125 void SetHasSingleEntryPoint(bool value) const { |
| 4126 StoreNonPointer(&raw_ptr()->size_and_flags_, |
| 4127 FlagsBits::update(value, raw_ptr()->size_and_flags_)); |
4102 } | 4128 } |
4103 | 4129 |
4104 // New is a private method as RawInstruction and RawCode objects should | 4130 // New is a private method as RawInstruction and RawCode objects should |
4105 // only be created using the Code::FinalizeCode method. This method creates | 4131 // only be created using the Code::FinalizeCode method. This method creates |
4106 // the RawInstruction and RawCode objects, sets up the pointer offsets | 4132 // the RawInstruction and RawCode objects, sets up the pointer offsets |
4107 // and links the two in a GC safe manner. | 4133 // and links the two in a GC safe manner. |
4108 static RawInstructions* New(intptr_t size, bool has_single_entry_point); | 4134 static RawInstructions* New(intptr_t size, bool has_single_entry_point); |
4109 | 4135 |
4110 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); | 4136 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); |
4111 friend class Class; | 4137 friend class Class; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4566 uword UncheckedEntryPoint() const { | 4592 uword UncheckedEntryPoint() const { |
4567 const Instructions& instr = Instructions::Handle(instructions()); | 4593 const Instructions& instr = Instructions::Handle(instructions()); |
4568 return instr.UncheckedEntryPoint(); | 4594 return instr.UncheckedEntryPoint(); |
4569 } | 4595 } |
4570 uword CheckedEntryPoint() const { | 4596 uword CheckedEntryPoint() const { |
4571 const Instructions& instr = Instructions::Handle(instructions()); | 4597 const Instructions& instr = Instructions::Handle(instructions()); |
4572 return instr.CheckedEntryPoint(); | 4598 return instr.CheckedEntryPoint(); |
4573 } | 4599 } |
4574 intptr_t Size() const { | 4600 intptr_t Size() const { |
4575 const Instructions& instr = Instructions::Handle(instructions()); | 4601 const Instructions& instr = Instructions::Handle(instructions()); |
4576 return instr.size(); | 4602 return instr.Size(); |
4577 } | 4603 } |
4578 RawObjectPool* GetObjectPool() const { return object_pool(); } | 4604 RawObjectPool* GetObjectPool() const { return object_pool(); } |
4579 bool ContainsInstructionAt(uword addr) const { | 4605 bool ContainsInstructionAt(uword addr) const { |
4580 const Instructions& instr = Instructions::Handle(instructions()); | 4606 const Instructions& instr = Instructions::Handle(instructions()); |
4581 const uword offset = addr - instr.PayloadStart(); | 4607 const uword offset = addr - instr.PayloadStart(); |
4582 return offset < static_cast<uword>(instr.size()); | 4608 return offset < static_cast<uword>(instr.Size()); |
4583 } | 4609 } |
4584 | 4610 |
4585 // Returns true if there is a debugger breakpoint set in this code object. | 4611 // Returns true if there is a debugger breakpoint set in this code object. |
4586 bool HasBreakpoint() const; | 4612 bool HasBreakpoint() const; |
4587 | 4613 |
4588 RawPcDescriptors* pc_descriptors() const { | 4614 RawPcDescriptors* pc_descriptors() const { |
4589 return raw_ptr()->pc_descriptors_; | 4615 return raw_ptr()->pc_descriptors_; |
4590 } | 4616 } |
4591 void set_pc_descriptors(const PcDescriptors& descriptors) const { | 4617 void set_pc_descriptors(const PcDescriptors& descriptors) const { |
4592 ASSERT(descriptors.IsOld()); | 4618 ASSERT(descriptors.IsOld()); |
(...skipping 4196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8789 | 8815 |
8790 inline void TypeArguments::SetHash(intptr_t value) const { | 8816 inline void TypeArguments::SetHash(intptr_t value) const { |
8791 // This is only safe because we create a new Smi, which does not cause | 8817 // This is only safe because we create a new Smi, which does not cause |
8792 // heap allocation. | 8818 // heap allocation. |
8793 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 8819 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
8794 } | 8820 } |
8795 | 8821 |
8796 } // namespace dart | 8822 } // namespace dart |
8797 | 8823 |
8798 #endif // RUNTIME_VM_OBJECT_H_ | 8824 #endif // RUNTIME_VM_OBJECT_H_ |
OLD | NEW |