Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1211)

Unified Diff: runtime/vm/object.h

Issue 2490363002: Clean up encoding of size and single entry flag in Instructions. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.h
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index e06c9b05e2e5c8342cf3d4de7fa84b557416e3e0..dbf901e958e177f3915d96c4acae84e956c7f900 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -4012,14 +4012,33 @@ class ObjectPool : public Object {
class Instructions : public Object {
public:
+ enum {
+ kSizePos = 0,
+ kSizeSize = 31,
+ kFlagsPos = kSizePos + kSizeSize,
+ kFlagsSize = 1, // Currently, only flag is single entry flag.
+ };
+
+ class SizeBits : public BitField<uint32_t, uint32_t, kSizePos, kSizeSize> {};
+ class FlagsBits : public BitField<uint32_t, bool, kFlagsPos, kFlagsSize> {};
+
// Excludes HeaderSize().
- intptr_t size() const { return abs(raw_ptr()->size_); }
- bool HasSingleEntryPoint() const { return raw_ptr()->size_ >= 0; }
+ intptr_t Size() const { return SizeBits::decode(raw_ptr()->size_and_flags_); }
+ static intptr_t Size(const RawInstructions* instr) {
+ return SizeBits::decode(instr->ptr()->size_and_flags_);
+ }
+
+ bool HasSingleEntryPoint() const {
+ return FlagsBits::decode(raw_ptr()->size_and_flags_);
+ }
+ static bool HasSingleEntryPoint(const RawInstructions* instr) {
+ return FlagsBits::decode(instr->ptr()->size_and_flags_);
+ }
uword PayloadStart() const { return PayloadStart(raw()); }
uword CheckedEntryPoint() const { return CheckedEntryPoint(raw()); }
uword UncheckedEntryPoint() const { return UncheckedEntryPoint(raw()); }
- static uword PayloadStart(RawInstructions* instr) {
+ static uword PayloadStart(const RawInstructions* instr) {
return reinterpret_cast<uword>(instr->ptr()) + HeaderSize();
}
@@ -4045,16 +4064,16 @@ class Instructions : public Object {
#error Missing entry offsets for current architecture
#endif
- static uword CheckedEntryPoint(RawInstructions* instr) {
+ static uword CheckedEntryPoint(const RawInstructions* instr) {
uword entry = PayloadStart(instr);
- if (instr->ptr()->size_ < 0) {
+ if (!HasSingleEntryPoint(instr)) {
entry += kCheckedEntryOffset;
}
return entry;
}
- static uword UncheckedEntryPoint(RawInstructions* instr) {
+ static uword UncheckedEntryPoint(const RawInstructions* instr) {
uword entry = PayloadStart(instr);
- if (instr->ptr()->size_ < 0) {
+ if (!HasSingleEntryPoint(instr)) {
entry += kUncheckedEntryOffset;
}
return entry;
@@ -4089,16 +4108,23 @@ class Instructions : public Object {
}
bool Equals(const Instructions& other) const {
- if (size() != other.size()) {
+ if (Size() != other.Size()) {
return false;
}
NoSafepointScope no_safepoint;
- return memcmp(raw_ptr(), other.raw_ptr(), InstanceSize(size())) == 0;
+ return memcmp(raw_ptr(), other.raw_ptr(), InstanceSize(Size())) == 0;
}
private:
- void set_size(intptr_t size) const {
- StoreNonPointer(&raw_ptr()->size_, size);
+ void SetSize(intptr_t value) const {
+ ASSERT(value >= 0);
+ StoreNonPointer(&raw_ptr()->size_and_flags_,
+ SizeBits::update(value, raw_ptr()->size_and_flags_));
+ }
+
+ void SetHasSingleEntryPoint(bool value) const {
+ StoreNonPointer(&raw_ptr()->size_and_flags_,
+ FlagsBits::update(value, raw_ptr()->size_and_flags_));
}
// New is a private method as RawInstruction and RawCode objects should
@@ -4573,13 +4599,13 @@ class Code : public Object {
}
intptr_t Size() const {
const Instructions& instr = Instructions::Handle(instructions());
- return instr.size();
+ return instr.Size();
}
RawObjectPool* GetObjectPool() const { return object_pool(); }
bool ContainsInstructionAt(uword addr) const {
const Instructions& instr = Instructions::Handle(instructions());
const uword offset = addr - instr.PayloadStart();
- return offset < static_cast<uword>(instr.size());
+ return offset < static_cast<uword>(instr.Size());
}
// Returns true if there is a debugger breakpoint set in this code object.
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698