blob: a12abc81d5a320ec627ee3eb0ce561b0e7a68c56 [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
TDYa127ee0d3fb2012-04-01 14:55:33 -070059 Method* GetMethod() const {
60 DCHECK_NE(method_, static_cast<void*>(NULL));
61 return method_;
62 }
63
TDYa12728f1a142012-03-15 21:51:52 -070064 bool Contains(Object** shadow_frame_entry) const {
65 // A ShadowFrame should at least contain a reference. Even if a
66 // native method has no argument, we put jobject or jclass as a
67 // reference. The former is "this", while the latter is for static
68 // method.
69 DCHECK_GT(number_of_references_, 0U);
70 return ((&references_[0] <= shadow_frame_entry)
71 && (shadow_frame_entry <= (&references_[number_of_references_ - 1])));
72 }
73
Logan Chien1b0a1b72012-03-15 06:20:17 +080074 // Offset of link within shadow frame
75 static size_t LinkOffset() {
76 return OFFSETOF_MEMBER(ShadowFrame, link_);
77 }
78
79 // Offset of method within shadow frame
80 static size_t MethodOffset() {
81 return OFFSETOF_MEMBER(ShadowFrame, method_);
82 }
83
84 // Offset of line number within shadow frame
85 static size_t LineNumOffset() {
86 return OFFSETOF_MEMBER(ShadowFrame, line_num_);
87 }
88
89 // Offset of length within shadow frame
90 static size_t NumberOfReferencesOffset() {
91 return OFFSETOF_MEMBER(ShadowFrame, number_of_references_);
92 }
93
94 // Offset of references within shadow frame
95 static size_t ReferencesOffset() {
96 return OFFSETOF_MEMBER(ShadowFrame, references_);
97 }
98
Logan Chienf7ad17e2012-03-15 03:10:03 +080099 private:
100 // ShadowFrame should be allocated by the generated code directly.
101 // We should not create new shadow stack in the runtime support function.
102 ~ShadowFrame() {}
103
104 uint32_t number_of_references_;
105 ShadowFrame* link_;
TDYa127ee0d3fb2012-04-01 14:55:33 -0700106 Method* method_;
Logan Chienf7ad17e2012-03-15 03:10:03 +0800107 uint32_t line_num_;
108 Object* references_[];
109
110 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
111};
112
113} // namespace art
114
115#endif // ART_SRC_SHADOW_FRAME_H_