Home | History | Annotate | Download | only in portable
      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 #include "entrypoints/entrypoint_utils-inl.h"
     18 #include "mirror/art_method-inl.h"
     19 #include "mirror/dex_cache-inl.h"
     20 #include "mirror/object-inl.h"
     21 
     22 namespace art {
     23 
     24 template<InvokeType type, bool access_check>
     25 mirror::ArtMethod* FindMethodHelper(uint32_t method_idx, mirror::Object* this_object,
     26                                     mirror::ArtMethod* caller_method, Thread* self) {
     27   mirror::ArtMethod* method = FindMethodFast(method_idx, this_object, caller_method,
     28                                              access_check, type);
     29   if (UNLIKELY(method == NULL)) {
     30     // Note: This can cause thread suspension.
     31     self->AssertThreadSuspensionIsAllowable();
     32     method = FindMethodFromCode<type, access_check>(method_idx, &this_object, &caller_method,
     33                                                     self);
     34     if (UNLIKELY(method == NULL)) {
     35       CHECK(self->IsExceptionPending());
     36       return 0;  // failure
     37     }
     38   }
     39   DCHECK(!self->IsExceptionPending());
     40 #if defined(ART_USE_PORTABLE_COMPILER)
     41   const void* code = method->GetEntryPointFromPortableCompiledCode();
     42 #else
     43   const void* code = nullptr;
     44 #endif
     45 
     46   // When we return, the caller will branch to this address, so it had better not be 0!
     47   if (UNLIKELY(code == NULL)) {
     48       LOG(FATAL) << "Code was NULL in method: " << PrettyMethod(method)
     49                  << " location: " << method->GetDexFile()->GetLocation();
     50   }
     51   return method;
     52 }
     53 
     54 // Explicit template declarations of FindMethodHelper for all invoke types.
     55 #define EXPLICIT_FIND_METHOD_HELPER_TEMPLATE_DECL(_type, _access_check)                        \
     56   template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)                                         \
     57   mirror::ArtMethod* FindMethodHelper<_type, _access_check>(uint32_t method_idx,               \
     58                                                             mirror::Object* this_object,       \
     59                                                             mirror::ArtMethod* caller_method,  \
     60                                                             Thread* thread)
     61 #define EXPLICIT_FIND_METHOD_HELPER_TYPED_TEMPLATE_DECL(_type) \
     62     EXPLICIT_FIND_METHOD_HELPER_TEMPLATE_DECL(_type, false);   \
     63     EXPLICIT_FIND_METHOD_HELPER_TEMPLATE_DECL(_type, true)
     64 
     65 EXPLICIT_FIND_METHOD_HELPER_TYPED_TEMPLATE_DECL(kStatic);
     66 EXPLICIT_FIND_METHOD_HELPER_TYPED_TEMPLATE_DECL(kDirect);
     67 EXPLICIT_FIND_METHOD_HELPER_TYPED_TEMPLATE_DECL(kVirtual);
     68 EXPLICIT_FIND_METHOD_HELPER_TYPED_TEMPLATE_DECL(kSuper);
     69 EXPLICIT_FIND_METHOD_HELPER_TYPED_TEMPLATE_DECL(kInterface);
     70 
     71 #undef EXPLICIT_FIND_METHOD_HELPER_TYPED_TEMPLATE_DECL
     72 #undef EXPLICIT_FIND_METHOD_HELPER_TEMPLATE_DECL
     73 
     74 extern "C" mirror::Object* art_portable_find_static_method_from_code_with_access_check(uint32_t method_idx,
     75                                                                                        mirror::Object* this_object,
     76                                                                                        mirror::ArtMethod* referrer,
     77                                                                                        Thread* thread)
     78     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     79   return FindMethodHelper<kStatic, true>(method_idx, this_object, referrer, thread);
     80 }
     81 
     82 extern "C" mirror::Object* art_portable_find_direct_method_from_code_with_access_check(uint32_t method_idx,
     83                                                                                        mirror::Object* this_object,
     84                                                                                        mirror::ArtMethod* referrer,
     85                                                                                        Thread* thread)
     86     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     87   return FindMethodHelper<kDirect, true>(method_idx, this_object, referrer, thread);
     88 }
     89 
     90 extern "C" mirror::Object* art_portable_find_virtual_method_from_code_with_access_check(uint32_t method_idx,
     91                                                                                         mirror::Object* this_object,
     92                                                                                         mirror::ArtMethod* referrer,
     93                                                                                         Thread* thread)
     94     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     95   return FindMethodHelper<kVirtual, true>(method_idx, this_object, referrer, thread);
     96 }
     97 
     98 extern "C" mirror::Object* art_portable_find_super_method_from_code_with_access_check(uint32_t method_idx,
     99                                                                                       mirror::Object* this_object,
    100                                                                                       mirror::ArtMethod* referrer,
    101                                                                                       Thread* thread)
    102     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
    103   return FindMethodHelper<kSuper, true>(method_idx, this_object, referrer, thread);
    104 }
    105 
    106 extern "C" mirror::Object* art_portable_find_interface_method_from_code_with_access_check(uint32_t method_idx,
    107                                                                                           mirror::Object* this_object,
    108                                                                                           mirror::ArtMethod* referrer,
    109                                                                                           Thread* thread)
    110     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
    111   return FindMethodHelper<kInterface, true>(method_idx, this_object, referrer, thread);
    112 }
    113 
    114 extern "C" mirror::Object* art_portable_find_interface_method_from_code(uint32_t method_idx,
    115                                                                         mirror::Object* this_object,
    116                                                                         mirror::ArtMethod* referrer,
    117                                                                         Thread* thread)
    118     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
    119   return FindMethodHelper<kInterface, false>(method_idx, this_object, referrer, thread);
    120 }
    121 
    122 }  // namespace art
    123