blob: 98f7b1283c2322caaadb46556716344b82e48bf6 [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"
18#include "mirror/abstract_method.h"
19#include "scoped_thread_state_change.h"
20#include "thread.h"
21
22namespace art {
23
24// Used by the JNI dlsym stub to find the native method to invoke if none is registered.
25extern "C" void* artFindNativeMethod(Thread* self) {
26 Locks::mutator_lock_->AssertNotHeld(self); // We come here as Native.
27 DCHECK(Thread::Current() == self);
28 ScopedObjectAccess soa(self);
29
30 mirror::AbstractMethod* method = self->GetCurrentMethod(NULL);
31 DCHECK(method != NULL);
32
33 // Lookup symbol address for method, on failure we'll return NULL with an
34 // exception set, otherwise we return the address of the method we found.
35 void* native_code = soa.Vm()->FindCodeForNativeMethod(method);
36 if (native_code == NULL) {
37 DCHECK(self->IsExceptionPending());
38 return NULL;
39 } else {
40 // Register so that future calls don't come here
41 method->RegisterNative(self, native_code);
42 return native_code;
43 }
44}
45
46} // namespace art