blob: 3bdee8e443e188933b5b5d204b60bbb1f6579a04 [file] [log] [blame]
Logan Chienf7ad17e2012-03-15 03:10:03 +08001/*
2 * Copyright (C) 2012 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_SRC_SHADOW_FRAME_H_
18#define ART_SRC_SHADOW_FRAME_H_
19
20#include "logging.h"
21#include "macros.h"
22
23namespace art {
24
25class Object;
26
27class ShadowFrame {
28 public:
29 // Number of references contained within this shadow frame
30 uint32_t NumberOfReferences() const {
31 return number_of_references_;
32 }
33
34 // Link to previous shadow frame or NULL
35 ShadowFrame* GetLink() const {
36 return link_;
37 }
38
39 void SetLink(ShadowFrame* frame) {
40 DCHECK_NE(this, frame);
41 link_ = frame;
42 }
43
44 Object* GetReference(size_t i) const {
45 DCHECK_LT(i, number_of_references_);
46 return references_[i];
47 }
48
49 void SetReference(size_t i, Object* object) {
50 DCHECK_LT(i, number_of_references_);
51 references_[i] = object;
52 }
53
Logan Chien1b0a1b72012-03-15 06:20:17 +080054 // Offset of link within shadow frame
55 static size_t LinkOffset() {
56 return OFFSETOF_MEMBER(ShadowFrame, link_);
57 }
58
59 // Offset of method within shadow frame
60 static size_t MethodOffset() {
61 return OFFSETOF_MEMBER(ShadowFrame, method_);
62 }
63
64 // Offset of line number within shadow frame
65 static size_t LineNumOffset() {
66 return OFFSETOF_MEMBER(ShadowFrame, line_num_);
67 }
68
69 // Offset of length within shadow frame
70 static size_t NumberOfReferencesOffset() {
71 return OFFSETOF_MEMBER(ShadowFrame, number_of_references_);
72 }
73
74 // Offset of references within shadow frame
75 static size_t ReferencesOffset() {
76 return OFFSETOF_MEMBER(ShadowFrame, references_);
77 }
78
Logan Chienf7ad17e2012-03-15 03:10:03 +080079 private:
80 // ShadowFrame should be allocated by the generated code directly.
81 // We should not create new shadow stack in the runtime support function.
82 ~ShadowFrame() {}
83
84 uint32_t number_of_references_;
85 ShadowFrame* link_;
86 Object* method_;
87 uint32_t line_num_;
88 Object* references_[];
89
90 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
91};
92
93} // namespace art
94
95#endif // ART_SRC_SHADOW_FRAME_H_