blob: 9d5063f3ee80da4f749a7912a94f56fa18769990 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Shapiro69759ea2011-07-21 18:13:35 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_OFFSETS_H_
18#define ART_RUNTIME_OFFSETS_H_
Carl Shapiro69759ea2011-07-21 18:13:35 -070019
Ian Rogerscf7f1912014-10-22 22:06:39 -070020#include <ostream>
21
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070022#include "globals.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070023
24namespace art {
25
Ian Rogersef7d42f2014-01-06 12:55:46 -080026// Allow the meaning of offsets to be strongly typed.
Carl Shapiro69759ea2011-07-21 18:13:35 -070027class Offset {
28 public:
29 explicit Offset(size_t val) : val_(val) {}
30 int32_t Int32Value() const {
31 return static_cast<int32_t>(val_);
32 }
33 uint32_t Uint32Value() const {
34 return static_cast<uint32_t>(val_);
35 }
Hiroshi Yamauchiaa866f52014-03-21 16:18:30 -070036 size_t SizeValue() const {
37 return val_;
38 }
39
Carl Shapiro69759ea2011-07-21 18:13:35 -070040 protected:
41 size_t val_;
42};
43std::ostream& operator<<(std::ostream& os, const Offset& offs);
44
Ian Rogersef7d42f2014-01-06 12:55:46 -080045// Offsets relative to the current frame.
Carl Shapiro69759ea2011-07-21 18:13:35 -070046class FrameOffset : public Offset {
47 public:
48 explicit FrameOffset(size_t val) : Offset(val) {}
49 bool operator>(FrameOffset other) const { return val_ > other.val_; }
50 bool operator<(FrameOffset other) const { return val_ < other.val_; }
51};
52
Ian Rogersef7d42f2014-01-06 12:55:46 -080053// Offsets relative to the current running thread.
Ian Rogersdd7624d2014-03-14 17:43:00 -070054template<size_t pointer_size>
Carl Shapiro69759ea2011-07-21 18:13:35 -070055class ThreadOffset : public Offset {
56 public:
57 explicit ThreadOffset(size_t val) : Offset(val) {}
58};
59
Ian Rogersef7d42f2014-01-06 12:55:46 -080060// Offsets relative to an object.
Carl Shapiro69759ea2011-07-21 18:13:35 -070061class MemberOffset : public Offset {
62 public:
63 explicit MemberOffset(size_t val) : Offset(val) {}
64};
65
66} // namespace art
67
Brian Carlstromfc0e3212013-07-17 14:40:12 -070068#endif // ART_RUNTIME_OFFSETS_H_