blob: 9a02a583e73c5a956ffb6281acdee5b05e3784e1 [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
Shih-wei Liao02f01fe2012-03-26 12:58:11 -070034 // Caller line number
35 uint32_t GetLineNumber() const {
36 return line_num_;
37 }
38
Logan Chienf7ad17e2012-03-15 03:10:03 +080039 // Link to previous shadow frame or NULL
40 ShadowFrame* GetLink() const {
41 return link_;
42 }
43
44 void SetLink(ShadowFrame* frame) {
45 DCHECK_NE(this, frame);
46 link_ = frame;
47 }
48
49 Object* GetReference(size_t i) const {
50 DCHECK_LT(i, number_of_references_);
51 return references_[i];
52 }
53
54 void SetReference(size_t i, Object* object) {
55 DCHECK_LT(i, number_of_references_);
56 references_[i] = object;
57 }
58
TDYa12728f1a142012-03-15 21:51:52 -070059 bool Contains(Object** shadow_frame_entry) const {
60 // A ShadowFrame should at least contain a reference. Even if a
61 // native method has no argument, we put jobject or jclass as a
62 // reference. The former is "this", while the latter is for static
63 // method.
64 DCHECK_GT(number_of_references_, 0U);
65 return ((&references_[0] <= shadow_frame_entry)
66 && (shadow_frame_entry <= (&references_[number_of_references_ - 1])));
67 }
68
Logan Chien1b0a1b72012-03-15 06:20:17 +080069 // Offset of link within shadow frame
70 static size_t LinkOffset() {
71 return OFFSETOF_MEMBER(ShadowFrame, link_);
72 }
73
74 // Offset of method within shadow frame
75 static size_t MethodOffset() {
76 return OFFSETOF_MEMBER(ShadowFrame, method_);
77 }
78
79 // Offset of line number within shadow frame
80 static size_t LineNumOffset() {
81 return OFFSETOF_MEMBER(ShadowFrame, line_num_);
82 }
83
84 // Offset of length within shadow frame
85 static size_t NumberOfReferencesOffset() {
86 return OFFSETOF_MEMBER(ShadowFrame, number_of_references_);
87 }
88
89 // Offset of references within shadow frame
90 static size_t ReferencesOffset() {
91 return OFFSETOF_MEMBER(ShadowFrame, references_);
92 }
93
Logan Chienf7ad17e2012-03-15 03:10:03 +080094 private:
95 // ShadowFrame should be allocated by the generated code directly.
96 // We should not create new shadow stack in the runtime support function.
97 ~ShadowFrame() {}
98
99 uint32_t number_of_references_;
100 ShadowFrame* link_;
101 Object* method_;
102 uint32_t line_num_;
103 Object* references_[];
104
105 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
106};
107
108} // namespace art
109
110#endif // ART_SRC_SHADOW_FRAME_H_