Chromium Code Reviews| Index: runtime/vm/raw_object.h |
| =================================================================== |
| --- runtime/vm/raw_object.h (revision 37403) |
| +++ runtime/vm/raw_object.h (working copy) |
| @@ -223,7 +223,6 @@ |
| SNAPSHOT_WRITER_SUPPORT() \ |
| HEAP_PROFILER_SUPPORT() \ |
| - |
| // RawObject is the base class of all raw objects, even though it carries the |
| // class_ field not all raw objects are allocated in the heap and thus cannot |
| // be dereferenced (e.g. RawSmi). |
| @@ -558,9 +557,13 @@ |
| RawSmi* length_; |
| // Variable length data follows here. |
| - RawAbstractType* types_[0]; |
| + RawAbstractType** types() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(RawAbstractType*))); |
| + 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.
|
| + } |
| RawObject** to(intptr_t length) { |
| - return reinterpret_cast<RawObject**>(&ptr()->types_[length - 1]); |
| + return reinterpret_cast<RawObject**>(&ptr()->types()[length - 1]); |
| } |
| friend class SnapshotReader; |
| @@ -855,10 +858,12 @@ |
| intptr_t patch_code_pc_offset_; |
| intptr_t lazy_deopt_pc_offset_; |
| - intptr_t dummy_alignment_; |
| - |
| // Variable length data follows here. |
| - int32_t data_[0]; |
| + int32_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(int32_t))); |
| + return reinterpret_cast<int32_t*>(result); |
| + } |
|
siva
2014/06/17 22:29:50
int32_t* data() { OPEN_ARRAY_START(int32_t); }
zra
2014/06/17 23:17:57
Done.
|
| friend class StackFrame; |
| friend class MarkingVisitor; |
| @@ -880,7 +885,11 @@ |
| intptr_t size_; |
| // Variable length data follows here. |
| - uint8_t data_[0]; |
| + uint8_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); |
| + return reinterpret_cast<uint8_t*>(result); |
| + } |
| // Private helper function used while visiting stack frames. The |
| // code which iterates over dart frames is also called during GC and |
| @@ -901,7 +910,11 @@ |
| intptr_t length_; // Number of descriptors. |
| // Variable length data follows here. |
| - intptr_t data_[0]; |
| + intptr_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); |
| + return reinterpret_cast<intptr_t*>(result); |
| + } |
| friend class Object; |
| }; |
| @@ -925,7 +938,11 @@ |
| uword pc_; // PC corresponding to this stack map representation. |
| // Variable length data follows here (bitmap of the stack layout). |
| - uint8_t data_[0]; |
| + uint8_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); |
| + return reinterpret_cast<uint8_t*>(result); |
| + } |
| }; |
| @@ -952,7 +969,12 @@ |
| intptr_t length_; // Number of descriptors. |
| RawArray* names_; // Array of [length_] variable names. |
| - VarInfo data_[0]; // Variable info with [length_] entries. |
| + // Variable info with [length_] entries. |
| + VarInfo* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); |
| + return reinterpret_cast<VarInfo*>(result); |
| + } |
| }; |
| @@ -966,6 +988,7 @@ |
| int8_t needs_stacktrace; // True if a stacktrace is needed. |
| int8_t has_catch_all; // Catches all exceptions. |
| }; |
| + |
| private: |
| RAW_HEAP_OBJECT_IMPLEMENTATION(ExceptionHandlers); |
| @@ -977,7 +1000,11 @@ |
| RawArray* handled_types_data_; |
| // Exception handler info of length [length_]. |
| - HandlerInfo data_[0]; |
| + HandlerInfo* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); |
| + return reinterpret_cast<HandlerInfo*>(result); |
| + } |
| }; |
| @@ -989,7 +1016,11 @@ |
| RawSmi* length_; // Number of deoptimization commands |
| // Variable length data follows here. |
| - intptr_t data_[0]; |
| + intptr_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(intptr_t))); |
| + return reinterpret_cast<intptr_t*>(result); |
| + } |
| }; |
| @@ -1003,9 +1034,13 @@ |
| RawContext* parent_; |
| // Variable length data follows here. |
| - RawInstance* data_[0]; |
| + RawInstance** data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(RawInstance*))); |
| + return reinterpret_cast<RawInstance**>(result); |
| + } |
| RawObject** to(intptr_t num_vars) { |
| - return reinterpret_cast<RawObject**>(&ptr()->data_[num_vars - 1]); |
| + return reinterpret_cast<RawObject**>(&ptr()->data()[num_vars - 1]); |
| } |
| friend class SnapshotReader; |
| @@ -1033,11 +1068,17 @@ |
| intptr_t num_variables_; |
| // 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.
|
| - RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->data_[0]); } |
| - RawObject* data_[0]; |
| + RawObject** from() { |
| + return reinterpret_cast<RawObject**>(&ptr()->data()[0]); |
| + } |
| + RawObject** data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(RawObject*))); |
| + return reinterpret_cast<RawObject**>(result); |
| + } |
| RawObject** to(intptr_t num_vars) { |
| - intptr_t data_length = num_vars * (sizeof(VariableDesc)/kWordSize); |
| - return reinterpret_cast<RawObject**>(&ptr()->data_[data_length - 1]); |
| + const intptr_t data_length = num_vars * (sizeof(VariableDesc)/kWordSize); |
| + return reinterpret_cast<RawObject**>(&ptr()->data()[data_length - 1]); |
| } |
| }; |
| @@ -1306,7 +1347,11 @@ |
| // A sequence of Chunks (typedef in Bignum) representing bignum digits. |
| // Bignum::Chunk chunks_[Utils::Abs(signed_length_)]; |
| - uint8_t data_[0]; |
| + uint8_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); |
| + return reinterpret_cast<uint8_t*>(result); |
| + } |
| friend class SnapshotReader; |
| }; |
| @@ -1337,7 +1382,11 @@ |
| RAW_HEAP_OBJECT_IMPLEMENTATION(OneByteString); |
| // Variable length data follows here. |
| - uint8_t data_[0]; |
| + uint8_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); |
| + return reinterpret_cast<uint8_t*>(result); |
| + } |
| friend class ApiMessageReader; |
| friend class SnapshotReader; |
| @@ -1348,7 +1397,11 @@ |
| RAW_HEAP_OBJECT_IMPLEMENTATION(TwoByteString); |
| // Variable length data follows here. |
| - uint16_t data_[0]; |
| + uint16_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(uint16_t))); |
| + return reinterpret_cast<uint16_t*>(result); |
| + } |
| friend class SnapshotReader; |
| }; |
| @@ -1411,8 +1464,9 @@ |
| RawSmi* length_; |
| // Variable length data follows here. |
| RawObject** data() { |
| - uword address_of_length = reinterpret_cast<uword>(&length_); |
| - return reinterpret_cast<RawObject**>(address_of_length + kWordSize); |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(RawObject*))); |
| + return reinterpret_cast<RawObject**>(result); |
| } |
| RawObject** to(intptr_t length) { |
| return reinterpret_cast<RawObject**>(&ptr()->data()[length - 1]); |
| @@ -1510,11 +1564,14 @@ |
| protected: |
| RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| RawSmi* length_; |
| + // Variable length data follows here. |
| + uint8_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); |
| + return reinterpret_cast<uint8_t*>(result); |
| + } |
| RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| - // Variable length data follows here. |
| - uint8_t data_[0]; |
| - |
| friend class Api; |
| friend class Object; |
| friend class Instance; |
| @@ -1604,7 +1661,11 @@ |
| intptr_t flags_; // Represents global/local, case insensitive, multiline. |
| // Variable length data follows here. |
| - uint8_t data_[0]; |
| + uint8_t* data() { |
| + const uword result = reinterpret_cast<uword>(this) + sizeof(*this); |
| + ASSERT(Utils::IsAligned(result, sizeof(uint8_t))); |
| + return reinterpret_cast<uint8_t*>(result); |
| + } |
| }; |