• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include "dex_instruction.h"
21 #include "method_type.h"
22 #include "object.h"
23 #include "stack.h"
24 #include "string.h"
25 #include "utils.h"
26 
27 namespace art {
28 
29 struct EmulatedStackFrameOffsets;
30 
31 namespace mirror {
32 
33 // C++ mirror of dalvik.system.EmulatedStackFrame
34 class MANAGED EmulatedStackFrame : public Object {
35  public:
36   // Creates an emulated stack frame whose type is |frame_type| from
37   // a shadow frame.
38   template <bool is_range>
39   static mirror::EmulatedStackFrame* CreateFromShadowFrameAndArgs(
40       Thread* self,
41       Handle<mirror::MethodType> args_type,
42       Handle<mirror::MethodType> frame_type,
43       const ShadowFrame& caller_frame,
44       const uint32_t first_src_reg,
45       const uint32_t (&arg)[Instruction::kMaxVarArgRegs]) REQUIRES_SHARED(Locks::mutator_lock_);
46 
47   // Writes the contents of this emulated stack frame to the |callee_frame|
48   // whose type is |callee_type|, starting at |first_dest_reg|.
49   bool WriteToShadowFrame(
50       Thread* self,
51       Handle<mirror::MethodType> callee_type,
52       const uint32_t first_dest_reg,
53       ShadowFrame* callee_frame) REQUIRES_SHARED(Locks::mutator_lock_);
54 
55   // Sets |value| to the return value written to this emulated stack frame (if any).
56   void GetReturnValue(Thread* self, JValue* value) REQUIRES_SHARED(Locks::mutator_lock_);
57 
58   // Sets the return value slot of this emulated stack frame to |value|.
59   void SetReturnValue(Thread* self, const JValue& value) REQUIRES_SHARED(Locks::mutator_lock_);
60 
GetType()61   mirror::MethodType* GetType() REQUIRES_SHARED(Locks::mutator_lock_) {
62     return GetFieldObject<MethodType>(OFFSET_OF_OBJECT_MEMBER(EmulatedStackFrame, type_));
63   }
64 
GetReceiver()65   mirror::Object* GetReceiver() REQUIRES_SHARED(Locks::mutator_lock_) {
66     return GetReferences()->Get(0);
67   }
68 
69   static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
70   static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
71   static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
72 
73  private:
StaticClass()74   static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
75     return static_class_.Read();
76   }
77 
GetReferences()78   mirror::ObjectArray<mirror::Object>* GetReferences() REQUIRES_SHARED(Locks::mutator_lock_) {
79     return GetFieldObject<mirror::ObjectArray<mirror::Object>>(
80         OFFSET_OF_OBJECT_MEMBER(EmulatedStackFrame, references_));
81   }
82 
GetStackFrame()83   mirror::ByteArray* GetStackFrame() REQUIRES_SHARED(Locks::mutator_lock_) {
84     return GetFieldObject<mirror::ByteArray>(
85         OFFSET_OF_OBJECT_MEMBER(EmulatedStackFrame, stack_frame_));
86   }
87 
CallsiteTypeOffset()88   static MemberOffset CallsiteTypeOffset() {
89     return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, callsite_type_));
90   }
91 
TypeOffset()92   static MemberOffset TypeOffset() {
93     return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, type_));
94   }
95 
ReferencesOffset()96   static MemberOffset ReferencesOffset() {
97     return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, references_));
98   }
99 
StackFrameOffset()100   static MemberOffset StackFrameOffset() {
101     return MemberOffset(OFFSETOF_MEMBER(EmulatedStackFrame, stack_frame_));
102   }
103 
104   HeapReference<mirror::MethodType> callsite_type_;
105   HeapReference<mirror::ObjectArray<mirror::Object>> references_;
106   HeapReference<mirror::ByteArray> stack_frame_;
107   HeapReference<mirror::MethodType> type_;
108 
109   static GcRoot<mirror::Class> static_class_;  // dalvik.system.EmulatedStackFrame.class
110 
111   friend struct art::EmulatedStackFrameOffsets;  // for verifying offset information
112   DISALLOW_IMPLICIT_CONSTRUCTORS(EmulatedStackFrame);
113 };
114 
115 }  // namespace mirror
116 }  // namespace art
117 
118 #endif  // ART_RUNTIME_MIRROR_EMULATED_STACK_FRAME_H_
119