1 /*
2  * Copyright (C) 2012 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_ENTRYPOINTS_QUICK_QUICK_ENTRYPOINTS_H_
18 #define ART_RUNTIME_ENTRYPOINTS_QUICK_QUICK_ENTRYPOINTS_H_
19 
20 #include <jni.h>
21 
22 #include "base/macros.h"
23 #include "base/mutex.h"
24 #include "offsets.h"
25 
26 #define QUICK_ENTRYPOINT_OFFSET(ptr_size, x) \
27     Thread::QuickEntryPointOffset<ptr_size>(OFFSETOF_MEMBER(QuickEntryPoints, x))
28 
29 namespace art {
30 
31 namespace mirror {
32 class Array;
33 class Class;
34 template<class MirrorType> class CompressedReference;
35 class Object;
36 }  // namespace mirror
37 
38 class ArtMethod;
39 template<class MirrorType> class GcRoot;
40 class Thread;
41 
42 // Pointers to functions that are called by quick compiler generated code via thread-local storage.
43 struct PACKED(4) QuickEntryPoints {
44 #define ENTRYPOINT_ENUM(name, rettype, ...) rettype ( * p ## name )( __VA_ARGS__ );
45 #include "quick_entrypoints_list.h"
46   QUICK_ENTRYPOINT_LIST(ENTRYPOINT_ENUM)
47 #undef QUICK_ENTRYPOINT_LIST
48 #undef ENTRYPOINT_ENUM
49 };
50 
51 
52 // JNI entrypoints.
53 // TODO: NO_THREAD_SAFETY_ANALYSIS due to different control paths depending on fast JNI.
54 extern uint32_t JniMethodStart(Thread* self) NO_THREAD_SAFETY_ANALYSIS HOT_ATTR;
55 extern uint32_t JniMethodStartSynchronized(jobject to_lock, Thread* self)
56     NO_THREAD_SAFETY_ANALYSIS HOT_ATTR;
57 extern void JniMethodEnd(uint32_t saved_local_ref_cookie, Thread* self)
58     NO_THREAD_SAFETY_ANALYSIS HOT_ATTR;
59 extern void JniMethodEndSynchronized(uint32_t saved_local_ref_cookie, jobject locked,
60                                      Thread* self)
61     NO_THREAD_SAFETY_ANALYSIS HOT_ATTR;
62 extern mirror::Object* JniMethodEndWithReference(jobject result, uint32_t saved_local_ref_cookie,
63                                                  Thread* self)
64     NO_THREAD_SAFETY_ANALYSIS HOT_ATTR;
65 
66 extern mirror::Object* JniMethodEndWithReferenceSynchronized(jobject result,
67                                                              uint32_t saved_local_ref_cookie,
68                                                              jobject locked, Thread* self)
69     NO_THREAD_SAFETY_ANALYSIS HOT_ATTR;
70 
71 extern void ReadBarrierJni(mirror::CompressedReference<mirror::Object>* handle_on_stack,
72                            Thread* self)
73     NO_THREAD_SAFETY_ANALYSIS HOT_ATTR;
74 
75 
76 // Read barrier entrypoints.
77 //
78 // Compilers for ARM, ARM64, MIPS, MIPS64 can insert a call to these
79 // functions directly.  For x86 and x86-64, compilers need a wrapper
80 // assembly function, to handle mismatch in ABI.
81 
82 // Mark the heap reference `obj`. This entry point is used by read
83 // barrier fast path implementations generated by the compiler to mark
84 // an object that is referenced by a field of a gray object.
85 extern "C" mirror::Object* artReadBarrierMark(mirror::Object* obj)
86     SHARED_REQUIRES(Locks::mutator_lock_) HOT_ATTR;
87 
88 // Read barrier entrypoint for heap references.
89 // This is the read barrier slow path for instance and static fields
90 // and reference type arrays.
91 extern "C" mirror::Object* artReadBarrierSlow(mirror::Object* ref,
92                                               mirror::Object* obj,
93                                               uint32_t offset)
94     SHARED_REQUIRES(Locks::mutator_lock_) HOT_ATTR;
95 
96 // Read barrier entrypoint for GC roots.
97 extern "C" mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root)
98     SHARED_REQUIRES(Locks::mutator_lock_) HOT_ATTR;
99 
100 }  // namespace art
101 
102 #endif  // ART_RUNTIME_ENTRYPOINTS_QUICK_QUICK_ENTRYPOINTS_H_
103