blob: 9bfa4d6098637c3327b95f140ff855b3243b012b [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 Sehr9e734c72018-01-04 17:56:19 -080020#include "dex/dex_instruction.h"
Narayan Kamath000e1882016-10-24 17:14:25 +010021#include "method_type.h"
22#include "object.h"
23#include "stack.h"
24#include "string.h"
25#include "utils.h"
26
27namespace art {
28
29struct EmulatedStackFrameOffsets;
30
31namespace mirror {
32
33// C++ mirror of dalvik.system.EmulatedStackFrame
34class MANAGED EmulatedStackFrame : public Object {
35 public:
36 // Creates an emulated stack frame whose type is |frame_type| from
37 // a shadow frame.
Narayan Kamath000e1882016-10-24 17:14:25 +010038 static mirror::EmulatedStackFrame* CreateFromShadowFrameAndArgs(
39 Thread* self,
40 Handle<mirror::MethodType> args_type,
41 Handle<mirror::MethodType> frame_type,
42 const ShadowFrame& caller_frame,
Orion Hodson960d4f72017-11-10 15:32:38 +000043 const InstructionOperands* const operands) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamath000e1882016-10-24 17:14:25 +010044
45 // Writes the contents of this emulated stack frame to the |callee_frame|
46 // whose type is |callee_type|, starting at |first_dest_reg|.
47 bool WriteToShadowFrame(
48 Thread* self,
49 Handle<mirror::MethodType> callee_type,
50 const uint32_t first_dest_reg,
51 ShadowFrame* callee_frame) REQUIRES_SHARED(Locks::mutator_lock_);
52
53 // Sets |value| to the return value written to this emulated stack frame (if any).
54 void GetReturnValue(Thread* self, JValue* value) REQUIRES_SHARED(Locks::mutator_lock_);
55
56 // Sets the return value slot of this emulated stack frame to |value|.
57 void SetReturnValue(Thread* self, const JValue& value) REQUIRES_SHARED(Locks::mutator_lock_);
58
Orion Hodson1c878782016-11-25 15:46:49 +000059 mirror::MethodType* GetType() REQUIRES_SHARED(Locks::mutator_lock_) {
60 return GetFieldObject<MethodType>(OFFSET_OF_OBJECT_MEMBER(EmulatedStackFrame, type_));
61 }
62
Orion Hodson8fd364e2017-02-17 12:47:28 +000063 mirror::Object* GetReceiver() REQUIRES_SHARED(Locks::mutator_lock_) {
64 return GetReferences()->Get(0);
65 }
66
Narayan Kamath000e1882016-10-24 17:14:25 +010067 static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
68 static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
69 static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
70
71 private:
72 static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
73 return static_class_.Read();
74 }
75
Narayan Kamath000e1882016-10-24 17:14:25 +010076 mirror::ObjectArray<mirror::Object>* GetReferences() REQUIRES_SHARED(Locks::mutator_lock_) {
77 return GetFieldObject<mirror::ObjectArray<mirror::Object>>(
78 OFFSET_OF_OBJECT_MEMBER(EmulatedStackFrame, references_));
79 }
80
81 mirror::ByteArray* GetStackFrame() REQUIRES_SHARED(Locks::mutator_lock_) {
82 return GetFieldObject<mirror::ByteArray>(
83 OFFSET_OF_OBJECT_MEMBER(EmulatedStackFrame, stack_frame_));
84 }
85
Narayan Kamathb79bbd82017-01-16 17:48:28 +000086 static MemberOffset CallsiteTypeOffset() {
87 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, callsite_type_));
88 }
89
Narayan Kamath000e1882016-10-24 17:14:25 +010090 static MemberOffset TypeOffset() {
91 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, type_));
92 }
93
94 static MemberOffset ReferencesOffset() {
95 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, references_));
96 }
97
98 static MemberOffset StackFrameOffset() {
99 return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, stack_frame_));
100 }
101
Narayan Kamathb79bbd82017-01-16 17:48:28 +0000102 HeapReference<mirror::MethodType> callsite_type_;
Narayan Kamath000e1882016-10-24 17:14:25 +0100103 HeapReference<mirror::ObjectArray<mirror::Object>> references_;
104 HeapReference<mirror::ByteArray> stack_frame_;
105 HeapReference<mirror::MethodType> type_;
106
107 static GcRoot<mirror::Class> static_class_; // dalvik.system.EmulatedStackFrame.class
108
109 friend struct art::EmulatedStackFrameOffsets; // for verifying offset information
110 DISALLOW_IMPLICIT_CONSTRUCTORS(EmulatedStackFrame);
111};
112
113} // namespace mirror
114} // namespace art
115
116#endif // ART_RUNTIME_MIRROR_EMULATED_STACK_FRAME_H_