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 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 35 | // Caller dex pc |
| 36 | uint32_t GetDexPC() const { |
| 37 | return dex_pc_; |
Shih-wei Liao | 02f01fe | 2012-03-26 12:58:11 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Logan Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 40 | // 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 | |
TDYa127 | ee0d3fb | 2012-04-01 14:55:33 -0700 | [diff] [blame] | 60 | Method* GetMethod() const { |
| 61 | DCHECK_NE(method_, static_cast<void*>(NULL)); |
| 62 | return method_; |
| 63 | } |
| 64 | |
TDYa127 | 28f1a14 | 2012-03-15 21:51:52 -0700 | [diff] [blame] | 65 | 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 Chien | 1b0a1b7 | 2012-03-15 06:20:17 +0800 | [diff] [blame] | 75 | // 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 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 85 | // Offset of dex pc within shadow frame |
| 86 | static size_t DexPCOffset() { |
| 87 | return OFFSETOF_MEMBER(ShadowFrame, dex_pc_); |
Logan Chien | 1b0a1b7 | 2012-03-15 06:20:17 +0800 | [diff] [blame] | 88 | } |
| 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 Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 100 | 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_; |
TDYa127 | ee0d3fb | 2012-04-01 14:55:33 -0700 | [diff] [blame] | 107 | Method* method_; |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 108 | uint32_t dex_pc_; |
Logan Chien | f7ad17e | 2012-03-15 03:10:03 +0800 | [diff] [blame] | 109 | Object* references_[]; |
| 110 | |
| 111 | DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame); |
| 112 | }; |
| 113 | |
| 114 | } // namespace art |
| 115 | |
| 116 | #endif // ART_SRC_SHADOW_FRAME_H_ |