blob: b63ccaabf909c2df3590f02a780e56c385106485 [file] [log] [blame]
Narayan Kamath000e1882016-10-24 17:14:25 +01001/*
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 Sehrc431b9d2018-03-02 12:01:51 -080020#include "base/utils.h"
David Sehr9e734c72018-01-04 17:56:19 -080021#include "dex/dex_instruction.h"
Vladimir Marko423bebb2019-03-26 15:17:21 +000022#include "handle.h"
Narayan Kamath000e1882016-10-24 17:14:25 +010023#include "object.h"
24#include "stack.h"
Narayan Kamath000e1882016-10-24 17:14:25 +010025
26namespace art {
27
28struct EmulatedStackFrameOffsets;
29
30namespace mirror {
31
Vladimir Marko423bebb2019-03-26 15:17:21 +000032class MethodType;
33
Narayan Kamath000e1882016-10-24 17:14:25 +010034// C++ mirror of dalvik.system.EmulatedStackFrame
35class MANAGED EmulatedStackFrame : public Object {
36 public:
Alex Light8f187c32021-04-20 14:29:00 -070037 MIRROR_CLASS("Ldalvik/system/EmulatedStackFrame;");
38
Narayan Kamath000e1882016-10-24 17:14:25 +010039 // Creates an emulated stack frame whose type is |frame_type| from
40 // a shadow frame.
Vladimir Marko423bebb2019-03-26 15:17:21 +000041 static ObjPtr<mirror::EmulatedStackFrame> CreateFromShadowFrameAndArgs(
Narayan Kamath000e1882016-10-24 17:14:25 +010042 Thread* self,
43 Handle<mirror::MethodType> args_type,
44 Handle<mirror::MethodType> frame_type,
45 const ShadowFrame& caller_frame,
Orion Hodson960d4f72017-11-10 15:32:38 +000046 const InstructionOperands* const operands) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamath000e1882016-10-24 17:14:25 +010047
48 // Writes the contents of this emulated stack frame to the |callee_frame|
49 // whose type is |callee_type|, starting at |first_dest_reg|.
50 bool WriteToShadowFrame(
51 Thread* self,
52 Handle<mirror::MethodType> callee_type,
53 const uint32_t first_dest_reg,
54 ShadowFrame* callee_frame) REQUIRES_SHARED(Locks::mutator_lock_);
55
56 // Sets |value| to the return value written to this emulated stack frame (if any).
57 void GetReturnValue(Thread* self, JValue* value) REQUIRES_SHARED(Locks::mutator_lock_);
58
59 // Sets the return value slot of this emulated stack frame to |value|.
60 void SetReturnValue(Thread* self, const JValue& value) REQUIRES_SHARED(Locks::mutator_lock_);
61
Vladimir Marko423bebb2019-03-26 15:17:21 +000062 ObjPtr<mirror::MethodType> GetType() REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson1c878782016-11-25 15:46:49 +000063
Vladimir Marko423bebb2019-03-26 15:17:21 +000064 ObjPtr<mirror::Object> GetReceiver() REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson8fd364e2017-02-17 12:47:28 +000065
Narayan Kamath000e1882016-10-24 17:14:25 +010066 private:
Vladimir Marko423bebb2019-03-26 15:17:21 +000067 ObjPtr<mirror::ObjectArray<mirror::Object>> GetReferences() REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamath000e1882016-10-24 17:14:25 +010068
Vladimir Marko423bebb2019-03-26 15:17:21 +000069 ObjPtr<mirror::ByteArray> GetStackFrame() REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamath000e1882016-10-24 17:14:25 +010070
Narayan Kamathb79bbd82017-01-16 17:48:28 +000071 static MemberOffset CallsiteTypeOffset() {
72 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, callsite_type_));
73 }
74
Narayan Kamath000e1882016-10-24 17:14:25 +010075 static MemberOffset TypeOffset() {
76 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, type_));
77 }
78
79 static MemberOffset ReferencesOffset() {
80 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, references_));
81 }
82
83 static MemberOffset StackFrameOffset() {
84 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, stack_frame_));
85 }
86
Narayan Kamathb79bbd82017-01-16 17:48:28 +000087 HeapReference<mirror::MethodType> callsite_type_;
Narayan Kamath000e1882016-10-24 17:14:25 +010088 HeapReference<mirror::ObjectArray<mirror::Object>> references_;
89 HeapReference<mirror::ByteArray> stack_frame_;
90 HeapReference<mirror::MethodType> type_;
91
Narayan Kamath000e1882016-10-24 17:14:25 +010092 friend struct art::EmulatedStackFrameOffsets; // for verifying offset information
93 DISALLOW_IMPLICIT_CONSTRUCTORS(EmulatedStackFrame);
94};
95
96} // namespace mirror
97} // namespace art
98
99#endif // ART_RUNTIME_MIRROR_EMULATED_STACK_FRAME_H_