• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 
17 #ifndef ART_RUNTIME_OFFSETS_H_
18 #define ART_RUNTIME_OFFSETS_H_
19 
20 #include <ostream>
21 
22 #include "globals.h"
23 
24 namespace art {
25 
26 // Allow the meaning of offsets to be strongly typed.
27 class Offset {
28  public:
Offset(size_t val)29   explicit Offset(size_t val) : val_(val) {}
Int32Value()30   int32_t Int32Value() const {
31     return static_cast<int32_t>(val_);
32   }
Uint32Value()33   uint32_t Uint32Value() const {
34     return static_cast<uint32_t>(val_);
35   }
SizeValue()36   size_t SizeValue() const {
37     return val_;
38   }
39 
40  protected:
41   size_t val_;
42 };
43 std::ostream& operator<<(std::ostream& os, const Offset& offs);
44 
45 // Offsets relative to the current frame.
46 class FrameOffset : public Offset {
47  public:
FrameOffset(size_t val)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 
53 // Offsets relative to the current running thread.
54 template<size_t pointer_size>
55 class ThreadOffset : public Offset {
56  public:
ThreadOffset(size_t val)57   explicit ThreadOffset(size_t val) : Offset(val) {}
58 };
59 
60 // Offsets relative to an object.
61 class MemberOffset : public Offset {
62  public:
MemberOffset(size_t val)63   explicit MemberOffset(size_t val) : Offset(val) {}
64 };
65 
66 }  // namespace art
67 
68 #endif  // ART_RUNTIME_OFFSETS_H_
69