blob: ed4e49ea6e685a9411596c8be1aa31a6b241dce3 [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
20#include <iostream> // NOLINT
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "globals.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070022
23namespace art {
24
Ian Rogersef7d42f2014-01-06 12:55:46 -080025// Allow the meaning of offsets to be strongly typed.
Carl Shapiro69759ea2011-07-21 18:13:35 -070026class Offset {
27 public:
28 explicit Offset(size_t val) : val_(val) {}
29 int32_t Int32Value() const {
30 return static_cast<int32_t>(val_);
31 }
32 uint32_t Uint32Value() const {
33 return static_cast<uint32_t>(val_);
34 }
Hiroshi Yamauchiaa866f52014-03-21 16:18:30 -070035 size_t SizeValue() const {
36 return val_;
37 }
38
Carl Shapiro69759ea2011-07-21 18:13:35 -070039 protected:
40 size_t val_;
41};
42std::ostream& operator<<(std::ostream& os, const Offset& offs);
43
Ian Rogersef7d42f2014-01-06 12:55:46 -080044// Offsets relative to the current frame.
Carl Shapiro69759ea2011-07-21 18:13:35 -070045class FrameOffset : public Offset {
46 public:
47 explicit FrameOffset(size_t val) : Offset(val) {}
48 bool operator>(FrameOffset other) const { return val_ > other.val_; }
49 bool operator<(FrameOffset other) const { return val_ < other.val_; }
50};
51
Ian Rogersef7d42f2014-01-06 12:55:46 -080052// Offsets relative to the current running thread.
Carl Shapiro69759ea2011-07-21 18:13:35 -070053class ThreadOffset : public Offset {
54 public:
55 explicit ThreadOffset(size_t val) : Offset(val) {}
56};
57
Ian Rogersef7d42f2014-01-06 12:55:46 -080058// Offsets relative to an object.
Carl Shapiro69759ea2011-07-21 18:13:35 -070059class MemberOffset : public Offset {
60 public:
61 explicit MemberOffset(size_t val) : Offset(val) {}
62};
63
64} // namespace art
65
Brian Carlstromfc0e3212013-07-17 14:40:12 -070066#endif // ART_RUNTIME_OFFSETS_H_