blob: b1ec81f8839fcebde93590297414ad1d0d90267b [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;
TDYa127d668a062012-04-13 12:36:57 -070026class Method;
Logan Chienf7ad17e2012-03-15 03:10:03 +080027
28class ShadowFrame {
29 public:
30 // Number of references contained within this shadow frame
31 uint32_t NumberOfReferences() const {
32 return number_of_references_;
33 }
34
TDYa127c8dc1012012-04-19 07:03:33 -070035 // Caller dex pc
36 uint32_t GetDexPC() const {
37 return dex_pc_;
Shih-wei Liao02f01fe2012-03-26 12:58:11 -070038 }
39
Logan Chienf7ad17e2012-03-15 03:10:03 +080040 // Link to previous shadow frame or NULL
41 ShadowFrame* GetLink() const {
42 return link_;
43 }
44
45 void SetLink(ShadowFrame* frame) {
46 DCHECK_NE(this, frame);
47 link_ = frame;
48 }
49
50 Object* GetReference(size_t i) const {
51 DCHECK_LT(i, number_of_references_);
52 return references_[i];
53 }
54
55 void SetReference(size_t i, Object* object) {
56 DCHECK_LT(i, number_of_references_);
57 references_[i] = object;
58 }
59
TDYa127ee0d3fb2012-04-01 14:55:33 -070060 Method* GetMethod() const {
61 DCHECK_NE(method_, static_cast<void*>(NULL));
62 return method_;
63 }
64
TDYa12728f1a142012-03-15 21:51:52 -070065 bool Contains(Object** shadow_frame_entry) const {
66 // A ShadowFrame should at least contain a reference. Even if a
67 // native method has no argument, we put jobject or jclass as a
68 // reference. The former is "this", while the latter is for static
69 // method.
70 DCHECK_GT(number_of_references_, 0U);
71 return ((&references_[0] <= shadow_frame_entry)
72 && (shadow_frame_entry <= (&references_[number_of_references_ - 1])));
73 }
74
Logan Chien1b0a1b72012-03-15 06:20:17 +080075 // Offset of link within shadow frame
76 static size_t LinkOffset() {
77 return OFFSETOF_MEMBER(ShadowFrame, link_);
78 }
79
80 // Offset of method within shadow frame
81 static size_t MethodOffset() {
82 return OFFSETOF_MEMBER(ShadowFrame, method_);
83 }
84
TDYa127c8dc1012012-04-19 07:03:33 -070085 // Offset of dex pc within shadow frame
86 static size_t DexPCOffset() {
87 return OFFSETOF_MEMBER(ShadowFrame, dex_pc_);
Logan Chien1b0a1b72012-03-15 06:20:17 +080088 }
89
90 // Offset of length within shadow frame
91 static size_t NumberOfReferencesOffset() {
92 return OFFSETOF_MEMBER(ShadowFrame, number_of_references_);
93 }
94
95 // Offset of references within shadow frame
96 static size_t ReferencesOffset() {
97 return OFFSETOF_MEMBER(ShadowFrame, references_);
98 }
99
Logan Chienf7ad17e2012-03-15 03:10:03 +0800100 private:
101 // ShadowFrame should be allocated by the generated code directly.
102 // We should not create new shadow stack in the runtime support function.
103 ~ShadowFrame() {}
104
105 uint32_t number_of_references_;
106 ShadowFrame* link_;
TDYa127ee0d3fb2012-04-01 14:55:33 -0700107 Method* method_;
TDYa127c8dc1012012-04-19 07:03:33 -0700108 uint32_t dex_pc_;
Logan Chienf7ad17e2012-03-15 03:10:03 +0800109 Object* references_[];
110
111 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
112};
113
114} // namespace art
115
116#endif // ART_SRC_SHADOW_FRAME_H_