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