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