• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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_INTERPRETER_UNSTARTED_RUNTIME_H_
18 #define ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_
19 
20 #include "interpreter.h"
21 
22 #include "base/macros.h"
23 #include "dex/dex_file.h"
24 #include "jvalue.h"
25 #include "unstarted_runtime_list.h"
26 
27 namespace art HIDDEN {
28 
29 class ArtMethod;
30 class CodeItemDataAccessor;
31 class Thread;
32 class ShadowFrame;
33 
34 namespace mirror {
35 class Object;
36 }  // namespace mirror
37 
38 namespace interpreter {
39 
40 // Support for an unstarted runtime. These are special handwritten implementations for select
41 // libcore native and non-native methods so we can compile-time initialize classes in the boot
42 // image.
43 //
44 // While it would technically be OK to only expose the public functions, a class was chosen to
45 // wrap this so the actual implementations are exposed for testing. This is also why the private
46 // methods are not documented here - they are not intended to be used directly except in
47 // testing.
48 
49 class UnstartedRuntime {
50  public:
51   EXPORT static void Initialize();
52 
53   // For testing. When we destroy the Runtime and create a new one,
54   // we need to reinitialize maps with new `ArtMethod*` keys.
55   static void Reinitialize();
56 
57   static void Invoke(Thread* self,
58                      const CodeItemDataAccessor& accessor,
59                      ShadowFrame* shadow_frame,
60                      JValue* result,
61                      size_t arg_offset)
62       REQUIRES_SHARED(Locks::mutator_lock_);
63 
64   static void Jni(Thread* self,
65                   ArtMethod* method,
66                   mirror::Object* receiver,
67                   uint32_t* args,
68                   JValue* result)
69       REQUIRES_SHARED(Locks::mutator_lock_);
70 
71  private:
72   // Methods that intercept available libcore implementations.
73 #define UNSTARTED_DIRECT(ShortName, DescriptorIgnored, NameIgnored, SignatureIgnored) \
74   static void Unstarted ## ShortName(Thread* self,                                    \
75                                      ShadowFrame* shadow_frame,                       \
76                                      JValue* result,                                  \
77                                      size_t arg_offset)                               \
78       REQUIRES_SHARED(Locks::mutator_lock_);
79   UNSTARTED_RUNTIME_DIRECT_LIST(UNSTARTED_DIRECT)
80 #undef UNSTARTED_DIRECT
81 
82   // Methods that are native.
83 #define UNSTARTED_JNI(ShortName, DescriptorIgnored, NameIgnored, SignatureIgnored) \
84   static void UnstartedJNI ## ShortName(Thread* self,                              \
85                                         ArtMethod* method,                         \
86                                         mirror::Object* receiver,                  \
87                                         uint32_t* args,                            \
88                                         JValue* result)                            \
89       REQUIRES_SHARED(Locks::mutator_lock_);
90   UNSTARTED_RUNTIME_JNI_LIST(UNSTARTED_JNI)
91 #undef UNSTARTED_JNI
92 
93   static void UnstartedClassForNameCommon(Thread* self,
94                                           ShadowFrame* shadow_frame,
95                                           JValue* result,
96                                           size_t arg_offset,
97                                           bool long_form) REQUIRES_SHARED(Locks::mutator_lock_);
98 
99   static void InitializeInvokeHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
100   static void InitializeJNIHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
101 
102   friend class UnstartedRuntimeTestBase;
103 
104   DISALLOW_ALLOCATION();
105   DISALLOW_COPY_AND_ASSIGN(UnstartedRuntime);
106 };
107 
108 }  // namespace interpreter
109 }  // namespace art
110 
111 #endif  // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_
112