diff options
author | Calin Juravle <calin@google.com> | 2014-08-12 20:55:20 +0100 |
---|---|---|
committer | Calin Juravle <calin@google.com> | 2014-08-15 10:10:09 +0100 |
commit | c8423521c1d1136c70b153479b7df3bf4fd7fc2a (patch) | |
tree | f7a0d12391f843d1b1eac1b0227c3237e7da3920 /runtime/native_bridge_art_interface.cc | |
parent | 02a6317297b8745637b265ab75abbfa685879882 (diff) | |
download | art-c8423521c1d1136c70b153479b7df3bf4fd7fc2a.tar.gz art-c8423521c1d1136c70b153479b7df3bf4fd7fc2a.tar.bz2 art-c8423521c1d1136c70b153479b7df3bf4fd7fc2a.zip |
[ART] Move to system/core native bridge library
Some cleanups on the way:
- move NativeBridgeRuntimeCallbacks from a global to a field
- rename native_bridge_library_string to the more suggestive
navtive_bridge_library_path
- clean up imports
Bug: 16884833
Change-Id: I73aab8e212860ba5aee9444d801806d3da326a41
Diffstat (limited to 'runtime/native_bridge_art_interface.cc')
-rw-r--r-- | runtime/native_bridge_art_interface.cc | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/runtime/native_bridge_art_interface.cc b/runtime/native_bridge_art_interface.cc new file mode 100644 index 0000000000..453c92f495 --- /dev/null +++ b/runtime/native_bridge_art_interface.cc @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "native_bridge_art_interface.h" + +#include "mirror/art_method-inl.h" +#include "mirror/class-inl.h" +#include "scoped_thread_state_change.h" + +namespace art { + +const char* GetMethodShorty(JNIEnv* env, jmethodID mid) { + ScopedObjectAccess soa(env); + StackHandleScope<1> scope(soa.Self()); + mirror::ArtMethod* m = soa.DecodeMethod(mid); + MethodHelper mh(scope.NewHandle(m)); + return mh.GetShorty(); +} + +uint32_t GetNativeMethodCount(JNIEnv* env, jclass clazz) { + if (clazz == nullptr) + return 0; + + ScopedObjectAccess soa(env); + mirror::Class* c = soa.Decode<mirror::Class*>(clazz); + + uint32_t native_method_count = 0; + for (uint32_t i = 0; i < c->NumDirectMethods(); ++i) { + mirror::ArtMethod* m = c->GetDirectMethod(i); + if (m->IsNative()) { + native_method_count++; + } + } + for (uint32_t i = 0; i < c->NumVirtualMethods(); ++i) { + mirror::ArtMethod* m = c->GetVirtualMethod(i); + if (m->IsNative()) { + native_method_count++; + } + } + return native_method_count; +} + +uint32_t GetNativeMethods(JNIEnv* env, jclass clazz, JNINativeMethod* methods, + uint32_t method_count) { + if ((clazz == nullptr) || (methods == nullptr)) { + return 0; + } + ScopedObjectAccess soa(env); + mirror::Class* c = soa.Decode<mirror::Class*>(clazz); + + uint32_t count = 0; + for (uint32_t i = 0; i < c->NumDirectMethods(); ++i) { + mirror::ArtMethod* m = c->GetDirectMethod(i); + if (m->IsNative()) { + if (count < method_count) { + methods[count].name = m->GetName(); + methods[count].signature = m->GetShorty(); + methods[count].fnPtr = const_cast<void*>(m->GetNativeMethod()); + count++; + } else { + LOG(WARNING) << "Output native method array too small. Skipping " << PrettyMethod(m); + } + } + } + for (uint32_t i = 0; i < c->NumVirtualMethods(); ++i) { + mirror::ArtMethod* m = c->GetVirtualMethod(i); + if (m->IsNative()) { + if (count < method_count) { + methods[count].name = m->GetName(); + methods[count].signature = m->GetShorty(); + methods[count].fnPtr = const_cast<void*>(m->GetNativeMethod()); + count++; + } else { + LOG(WARNING) << "Output native method array too small. Skipping " << PrettyMethod(m); + } + } + } + return count; +} + +}; // namespace art |