blob: c4a633f7037add2fa837ca6cc344f9272dcf4b69 [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
TDYa127de479be2012-05-31 08:03:26 -070035 void SetNumberOfReferences(uint32_t number_of_references) {
36 number_of_references_ = number_of_references;
37 }
38
TDYa127c8dc1012012-04-19 07:03:33 -070039 // Caller dex pc
40 uint32_t GetDexPC() const {
41 return dex_pc_;
Shih-wei Liao02f01fe2012-03-26 12:58:11 -070042 }
43
TDYa127de479be2012-05-31 08:03:26 -070044 void SetDexPC(uint32_t dex_pc) {
45 dex_pc_ = dex_pc;
46 }
47
Logan Chienf7ad17e2012-03-15 03:10:03 +080048 // Link to previous shadow frame or NULL
49 ShadowFrame* GetLink() const {
50 return link_;
51 }
52
53 void SetLink(ShadowFrame* frame) {
54 DCHECK_NE(this, frame);
55 link_ = frame;
56 }
57
58 Object* GetReference(size_t i) const {
59 DCHECK_LT(i, number_of_references_);
60 return references_[i];
61 }
62
63 void SetReference(size_t i, Object* object) {
64 DCHECK_LT(i, number_of_references_);
65 references_[i] = object;
66 }
67
TDYa127ee0d3fb2012-04-01 14:55:33 -070068 Method* GetMethod() const {
69 DCHECK_NE(method_, static_cast<void*>(NULL));
70 return method_;
71 }
72
TDYa127de479be2012-05-31 08:03:26 -070073 void SetMethod(Method* method) {
74 DCHECK_NE(method, static_cast<void*>(NULL));
75 method_ = method;
76 }
77
TDYa12728f1a142012-03-15 21:51:52 -070078 bool Contains(Object** shadow_frame_entry) const {
79 // A ShadowFrame should at least contain a reference. Even if a
80 // native method has no argument, we put jobject or jclass as a
81 // reference. The former is "this", while the latter is for static
82 // method.
83 DCHECK_GT(number_of_references_, 0U);
84 return ((&references_[0] <= shadow_frame_entry)
85 && (shadow_frame_entry <= (&references_[number_of_references_ - 1])));
86 }
87
Logan Chien1b0a1b72012-03-15 06:20:17 +080088 // Offset of link within shadow frame
89 static size_t LinkOffset() {
90 return OFFSETOF_MEMBER(ShadowFrame, link_);
91 }
92
93 // Offset of method within shadow frame
94 static size_t MethodOffset() {
95 return OFFSETOF_MEMBER(ShadowFrame, method_);
96 }
97
TDYa127c8dc1012012-04-19 07:03:33 -070098 // Offset of dex pc within shadow frame
99 static size_t DexPCOffset() {
100 return OFFSETOF_MEMBER(ShadowFrame, dex_pc_);
Logan Chien1b0a1b72012-03-15 06:20:17 +0800101 }
102
103 // Offset of length within shadow frame
104 static size_t NumberOfReferencesOffset() {
105 return OFFSETOF_MEMBER(ShadowFrame, number_of_references_);
106 }
107
108 // Offset of references within shadow frame
109 static size_t ReferencesOffset() {
110 return OFFSETOF_MEMBER(ShadowFrame, references_);
111 }
112
Logan Chienf7ad17e2012-03-15 03:10:03 +0800113 private:
114 // ShadowFrame should be allocated by the generated code directly.
115 // We should not create new shadow stack in the runtime support function.
116 ~ShadowFrame() {}
117
118 uint32_t number_of_references_;
119 ShadowFrame* link_;
TDYa127ee0d3fb2012-04-01 14:55:33 -0700120 Method* method_;
TDYa127c8dc1012012-04-19 07:03:33 -0700121 uint32_t dex_pc_;
Logan Chienf7ad17e2012-03-15 03:10:03 +0800122 Object* references_[];
123
124 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
125};
126
127} // namespace art
128
129#endif // ART_SRC_SHADOW_FRAME_H_