blob: bae4023c1dfc98093abe8f76c3e59b2bb4eb0dc4 [file] [log] [blame]
Ian Rogers7655f292013-07-29 11:07:13 -07001/*
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 "base/logging.h"
Ian Rogers848871b2013-08-05 10:56:33 -070018#include "entrypoints/entrypoint_utils.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070019#include "mirror/art_method-inl.h"
Ian Rogers848871b2013-08-05 10:56:33 -070020#include "mirror/object-inl.h"
21#include "object_utils.h"
Ian Rogers7655f292013-07-29 11:07:13 -070022#include "scoped_thread_state_change.h"
23#include "thread.h"
24
25namespace art {
26
27// Used by the JNI dlsym stub to find the native method to invoke if none is registered.
Ian Rogers04c31d22014-07-07 21:44:06 -070028#if defined(__arm__) || defined(__aarch64__)
Ian Rogers848871b2013-08-05 10:56:33 -070029extern "C" void* artFindNativeMethod() {
30 Thread* self = Thread::Current();
Ian Rogers04c31d22014-07-07 21:44:06 -070031#else
32extern "C" void* artFindNativeMethod(Thread* self) {
33 DCHECK_EQ(self, Thread::Current());
34#endif
Ian Rogers7655f292013-07-29 11:07:13 -070035 Locks::mutator_lock_->AssertNotHeld(self); // We come here as Native.
Ian Rogers7655f292013-07-29 11:07:13 -070036 ScopedObjectAccess soa(self);
37
Brian Carlstromea46f952013-07-30 01:26:50 -070038 mirror::ArtMethod* method = self->GetCurrentMethod(NULL);
Ian Rogers7655f292013-07-29 11:07:13 -070039 DCHECK(method != NULL);
40
Ian Rogers848871b2013-08-05 10:56:33 -070041 // 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.
Ian Rogers7655f292013-07-29 11:07:13 -070043 void* native_code = soa.Vm()->FindCodeForNativeMethod(method);
44 if (native_code == NULL) {
45 DCHECK(self->IsExceptionPending());
46 return NULL;
47 } else {
48 // Register so that future calls don't come here
Ian Rogers1eb512d2013-10-18 15:42:20 -070049 method->RegisterNative(self, native_code, false);
Ian Rogers7655f292013-07-29 11:07:13 -070050 return native_code;
51 }
52}
53
Ian Rogers7655f292013-07-29 11:07:13 -070054} // namespace art