Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_OFFSETS_H_ |
| 18 | #define ART_RUNTIME_OFFSETS_H_ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 19 | |
Andreas Gampe | 8764dc3 | 2019-01-07 15:20:12 -0800 | [diff] [blame] | 20 | #include <iosfwd> |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 21 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 22 | #include "base/enums.h" |
Andreas Gampe | 5a0430d | 2019-01-04 14:33:57 -0800 | [diff] [blame] | 23 | #include "runtime_globals.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 27 | // Allow the meaning of offsets to be strongly typed. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 28 | class Offset { |
| 29 | public: |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 30 | constexpr explicit Offset(size_t val) : val_(val) {} |
| 31 | constexpr int32_t Int32Value() const { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 32 | return static_cast<int32_t>(val_); |
| 33 | } |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 34 | constexpr uint32_t Uint32Value() const { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 35 | return static_cast<uint32_t>(val_); |
| 36 | } |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 37 | constexpr size_t SizeValue() const { |
Hiroshi Yamauchi | aa866f5 | 2014-03-21 16:18:30 -0700 | [diff] [blame] | 38 | return val_; |
| 39 | } |
Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 40 | constexpr bool operator==(Offset o) const { |
| 41 | return SizeValue() == o.SizeValue(); |
| 42 | } |
Hiroshi Yamauchi | aa866f5 | 2014-03-21 16:18:30 -0700 | [diff] [blame] | 43 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 44 | protected: |
| 45 | size_t val_; |
| 46 | }; |
| 47 | std::ostream& operator<<(std::ostream& os, const Offset& offs); |
| 48 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 49 | // Offsets relative to the current frame. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 50 | class FrameOffset : public Offset { |
| 51 | public: |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 52 | constexpr explicit FrameOffset(size_t val) : Offset(val) {} |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 53 | bool operator>(FrameOffset other) const { return val_ > other.val_; } |
| 54 | bool operator<(FrameOffset other) const { return val_ < other.val_; } |
| 55 | }; |
| 56 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 57 | // Offsets relative to the current running thread. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 58 | template<PointerSize pointer_size> |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 59 | class ThreadOffset : public Offset { |
| 60 | public: |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 61 | constexpr explicit ThreadOffset(size_t val) : Offset(val) {} |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 64 | using ThreadOffset32 = ThreadOffset<PointerSize::k32>; |
| 65 | using ThreadOffset64 = ThreadOffset<PointerSize::k64>; |
| 66 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 67 | // Offsets relative to an object. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 68 | class MemberOffset : public Offset { |
| 69 | public: |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 70 | constexpr explicit MemberOffset(size_t val) : Offset(val) {} |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace art |
| 74 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 75 | #endif // ART_RUNTIME_OFFSETS_H_ |