Logan Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace art { |
| 24 | |
| 25 | class Object; |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 26 | class Method; |
Logan Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 27 | |
| 28 | class ShadowFrame { |
| 29 | public: |
| 30 | // Number of references contained within this shadow frame |
| 31 | uint32_t NumberOfReferences() const { |
| 32 | return number_of_references_; |
| 33 | } |
| 34 | |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 35 | void SetNumberOfReferences(uint32_t number_of_references) { |
| 36 | number_of_references_ = number_of_references; |
| 37 | } |
| 38 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 39 | // Caller dex pc |
| 40 | uint32_t GetDexPC() const { |
| 41 | return dex_pc_; |
Shih-wei Liao | 02f01fe | 2012-03-26 12:58:11 -0700 | [diff] [blame] | 42 | } |
| 43 | |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 44 | void SetDexPC(uint32_t dex_pc) { |
| 45 | dex_pc_ = dex_pc; |
| 46 | } |
| 47 | |
Logan Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 48 | // 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 | |
TDYa127 | ee0d3fb | 2012-04-01 14:55:33 -0700 | [diff] [blame] | 68 | Method* GetMethod() const { |
| 69 | DCHECK_NE(method_, static_cast<void*>(NULL)); |
| 70 | return method_; |
| 71 | } |
| 72 | |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 73 | void SetMethod(Method* method) { |
| 74 | DCHECK_NE(method, static_cast<void*>(NULL)); |
| 75 | method_ = method; |
| 76 | } |
| 77 | |
TDYa127 | 28f1a14 | 2012-03-15 21:51:52 -0700 | [diff] [blame] | 78 | 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 Chien | 1b0a1b7 | 2012-03-15 06:20:17 +0800 | [diff] [blame] | 88 | // 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 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 98 | // Offset of dex pc within shadow frame |
| 99 | static size_t DexPCOffset() { |
| 100 | return OFFSETOF_MEMBER(ShadowFrame, dex_pc_); |
Logan Chien | 1b0a1b7 | 2012-03-15 06:20:17 +0800 | [diff] [blame] | 101 | } |
| 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 Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 113 | 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_; |
TDYa127 | ee0d3fb | 2012-04-01 14:55:33 -0700 | [diff] [blame] | 120 | Method* method_; |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 121 | uint32_t dex_pc_; |
Logan Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 122 | Object* references_[]; |
| 123 | |
| 124 | DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame); |
| 125 | }; |
| 126 | |
| 127 | } // namespace art |
| 128 | |
| 129 | #endif // ART_SRC_SHADOW_FRAME_H_ |