1 /*
2  * Copyright (C) 2019 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_NTERP_HELPERS_H_
18 #define ART_RUNTIME_NTERP_HELPERS_H_
19 
20 #include "base/macros.h"
21 #include "quick/quick_method_frame_info.h"
22 
23 namespace art HIDDEN {
24 
25 class ArtMethod;
26 
27 /**
28  * Returns the QuickMethodFrameInfo of the given frame corresponding to the
29  * given method.
30  */
31 QuickMethodFrameInfo NterpFrameInfo(ArtMethod** frame)
32     REQUIRES_SHARED(Locks::mutator_lock_);
33 
34 /**
35  * Returns the dex PC at which the given nterp frame is executing.
36  */
37 uint32_t NterpGetDexPC(ArtMethod** frame)
38     REQUIRES_SHARED(Locks::mutator_lock_);
39 
40 /**
41  * Returns the reference array to be used by the GC to visit references in an
42  * nterp frame.
43  */
44 uintptr_t NterpGetReferenceArray(ArtMethod** frame)
45       REQUIRES_SHARED(Locks::mutator_lock_);
46 
47 /**
48  * Returns the dex register array to be used by the GC to update references in
49  * an nterp frame.
50  */
51 uintptr_t NterpGetRegistersArray(ArtMethod** frame)
52       REQUIRES_SHARED(Locks::mutator_lock_);
53 
54 /**
55  * Returns the nterp landing pad for catching an exception.
56  */
57 uintptr_t NterpGetCatchHandler();
58 
59 /**
60  * Returns the value of dex register number `vreg` in the given frame.
61  */
62 uint32_t NterpGetVReg(ArtMethod** frame, uint16_t vreg)
63     REQUIRES_SHARED(Locks::mutator_lock_);
64 
65 /**
66  * Returns the value of dex register number `vreg` in the given frame if it is a
67  * reference. Return 0 otehrwise.
68  */
69 uint32_t NterpGetVRegReference(ArtMethod** frame, uint16_t vreg)
70     REQUIRES_SHARED(Locks::mutator_lock_);
71 
72 /**
73  * Returns whether the given method can run with nterp. The instruction set can
74  * be passed for cross-compilation.
75  */
76 EXPORT bool CanMethodUseNterp(ArtMethod* method, InstructionSet isa = kRuntimeISA)
77     REQUIRES_SHARED(Locks::mutator_lock_);
78 
79 /**
80  * Returns kAccNterpInvokeFastPathFlag and/or kAccNterpEntryPointFastPathFlag, if appropriate.
81  */
82 uint32_t GetNterpFastPathFlags(std::string_view shorty, uint32_t access_flags, InstructionSet isa);
83 
84 }  // namespace art
85 
86 #endif  // ART_RUNTIME_NTERP_HELPERS_H_
87