Home | History | Annotate | Download | only in jni
      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 <android-base/logging.h>
     18 
     19 #include "art_method-inl.h"
     20 #include "entrypoints/entrypoint_utils.h"
     21 #include "java_vm_ext.h"
     22 #include "mirror/object-inl.h"
     23 #include "scoped_thread_state_change-inl.h"
     24 #include "thread.h"
     25 
     26 namespace art {
     27 
     28 // Used by the JNI dlsym stub to find the native method to invoke if none is registered.
     29 #if defined(__arm__) || defined(__aarch64__)
     30 extern "C" const void* artFindNativeMethod() {
     31   Thread* self = Thread::Current();
     32 #else
     33 extern "C" const void* artFindNativeMethod(Thread* self) {
     34   DCHECK_EQ(self, Thread::Current());
     35 #endif
     36   Locks::mutator_lock_->AssertNotHeld(self);  // We come here as Native.
     37   ScopedObjectAccess soa(self);
     38 
     39   ArtMethod* method = self->GetCurrentMethod(nullptr);
     40   DCHECK(method != nullptr);
     41 
     42   // Lookup symbol address for method, on failure we'll return null with an exception set,
     43   // otherwise we return the address of the method we found.
     44   void* native_code = soa.Vm()->FindCodeForNativeMethod(method);
     45   if (native_code == nullptr) {
     46     self->AssertPendingException();
     47     return nullptr;
     48   }
     49   // Register so that future calls don't come here
     50   return method->RegisterNative(native_code);
     51 }
     52 
     53 }  // namespace art
     54