Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_RUNTIME_MIRROR_EMULATED_STACK_FRAME_H_ |
| 18 | #define ART_RUNTIME_MIRROR_EMULATED_STACK_FRAME_H_ |
| 19 | |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 20 | #include "base/utils.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 21 | #include "dex/dex_instruction.h" |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 22 | #include "handle.h" |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 23 | #include "object.h" |
| 24 | #include "stack.h" |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | struct EmulatedStackFrameOffsets; |
| 29 | |
| 30 | namespace mirror { |
| 31 | |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 32 | class MethodType; |
| 33 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 34 | // C++ mirror of dalvik.system.EmulatedStackFrame |
| 35 | class MANAGED EmulatedStackFrame : public Object { |
| 36 | public: |
| 37 | // Creates an emulated stack frame whose type is |frame_type| from |
| 38 | // a shadow frame. |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 39 | static ObjPtr<mirror::EmulatedStackFrame> CreateFromShadowFrameAndArgs( |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 40 | Thread* self, |
| 41 | Handle<mirror::MethodType> args_type, |
| 42 | Handle<mirror::MethodType> frame_type, |
| 43 | const ShadowFrame& caller_frame, |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 44 | const InstructionOperands* const operands) REQUIRES_SHARED(Locks::mutator_lock_); |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 45 | |
| 46 | // Writes the contents of this emulated stack frame to the |callee_frame| |
| 47 | // whose type is |callee_type|, starting at |first_dest_reg|. |
| 48 | bool WriteToShadowFrame( |
| 49 | Thread* self, |
| 50 | Handle<mirror::MethodType> callee_type, |
| 51 | const uint32_t first_dest_reg, |
| 52 | ShadowFrame* callee_frame) REQUIRES_SHARED(Locks::mutator_lock_); |
| 53 | |
| 54 | // Sets |value| to the return value written to this emulated stack frame (if any). |
| 55 | void GetReturnValue(Thread* self, JValue* value) REQUIRES_SHARED(Locks::mutator_lock_); |
| 56 | |
| 57 | // Sets the return value slot of this emulated stack frame to |value|. |
| 58 | void SetReturnValue(Thread* self, const JValue& value) REQUIRES_SHARED(Locks::mutator_lock_); |
| 59 | |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 60 | ObjPtr<mirror::MethodType> GetType() REQUIRES_SHARED(Locks::mutator_lock_); |
Orion Hodson | 1c87878 | 2016-11-25 15:46:49 +0000 | [diff] [blame] | 61 | |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 62 | ObjPtr<mirror::Object> GetReceiver() REQUIRES_SHARED(Locks::mutator_lock_); |
Orion Hodson | 8fd364e | 2017-02-17 12:47:28 +0000 | [diff] [blame] | 63 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 64 | private: |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 65 | ObjPtr<mirror::ObjectArray<mirror::Object>> GetReferences() REQUIRES_SHARED(Locks::mutator_lock_); |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 66 | |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 67 | ObjPtr<mirror::ByteArray> GetStackFrame() REQUIRES_SHARED(Locks::mutator_lock_); |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 68 | |
Narayan Kamath | b79bbd8 | 2017-01-16 17:48:28 +0000 | [diff] [blame] | 69 | static MemberOffset CallsiteTypeOffset() { |
| 70 | return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, callsite_type_)); |
| 71 | } |
| 72 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 73 | static MemberOffset TypeOffset() { |
| 74 | return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, type_)); |
| 75 | } |
| 76 | |
| 77 | static MemberOffset ReferencesOffset() { |
| 78 | return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, references_)); |
| 79 | } |
| 80 | |
| 81 | static MemberOffset StackFrameOffset() { |
| 82 | return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, stack_frame_)); |
| 83 | } |
| 84 | |
Narayan Kamath | b79bbd8 | 2017-01-16 17:48:28 +0000 | [diff] [blame] | 85 | HeapReference<mirror::MethodType> callsite_type_; |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 86 | HeapReference<mirror::ObjectArray<mirror::Object>> references_; |
| 87 | HeapReference<mirror::ByteArray> stack_frame_; |
| 88 | HeapReference<mirror::MethodType> type_; |
| 89 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 90 | friend struct art::EmulatedStackFrameOffsets; // for verifying offset information |
| 91 | DISALLOW_IMPLICIT_CONSTRUCTORS(EmulatedStackFrame); |
| 92 | }; |
| 93 | |
| 94 | } // namespace mirror |
| 95 | } // namespace art |
| 96 | |
| 97 | #endif // ART_RUNTIME_MIRROR_EMULATED_STACK_FRAME_H_ |