Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "jni_internal.h" |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 18 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 19 | #include <dlfcn.h> |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 20 | |
| 21 | #include <cstdarg> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 22 | #include <memory> |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 23 | #include <utility> |
| 24 | #include <vector> |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 25 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 26 | #include "atomic.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 27 | #include "base/logging.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 28 | #include "base/mutex.h" |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 29 | #include "base/stl_util.h" |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 30 | #include "class_linker-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 31 | #include "dex_file-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 32 | #include "gc/accounting/card_table-inl.h" |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 33 | #include "indirect_reference_table-inl.h" |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 34 | #include "interpreter/interpreter.h" |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 35 | #include "jni.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 36 | #include "mirror/art_field-inl.h" |
| 37 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | #include "mirror/class-inl.h" |
| 39 | #include "mirror/class_loader.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 40 | #include "mirror/object-inl.h" |
| 41 | #include "mirror/object_array-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 42 | #include "mirror/string-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 43 | #include "mirror/throwable.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 44 | #include "object_utils.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 45 | #include "parsed_options.h" |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 46 | #include "reflection.h" |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 47 | #include "runtime.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 48 | #include "safe_map.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 49 | #include "scoped_thread_state_change.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 50 | #include "ScopedLocalRef.h" |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 51 | #include "thread.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 52 | #include "utf.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 53 | #include "well_known_classes.h" |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 54 | |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 55 | namespace art { |
| 56 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 57 | static const size_t kMonitorsInitial = 32; // Arbitrary. |
| 58 | static const size_t kMonitorsMax = 4096; // Arbitrary sanity check. |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 59 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 60 | static const size_t kLocalsInitial = 64; // Arbitrary. |
| 61 | static const size_t kLocalsMax = 512; // Arbitrary sanity check. |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 62 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 63 | static const size_t kPinTableInitial = 16; // Arbitrary. |
| 64 | static const size_t kPinTableMax = 1024; // Arbitrary sanity check. |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 65 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 66 | static size_t gGlobalsInitial = 512; // Arbitrary. |
| 67 | static size_t gGlobalsMax = 51200; // Arbitrary sanity check. (Must fit in 16 bits.) |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 68 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 69 | static const size_t kWeakGlobalsInitial = 16; // Arbitrary. |
| 70 | static const size_t kWeakGlobalsMax = 51200; // Arbitrary sanity check. (Must fit in 16 bits.) |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 71 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 72 | static jweak AddWeakGlobalReference(ScopedObjectAccess& soa, mirror::Object* obj) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 73 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 74 | return soa.Vm()->AddWeakGlobalReference(soa.Self(), obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Jeff Hao | 19c5d37 | 2013-03-15 14:33:43 -0700 | [diff] [blame] | 77 | static bool IsBadJniVersion(int version) { |
| 78 | // We don't support JNI_VERSION_1_1. These are the only other valid versions. |
| 79 | return version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4 && version != JNI_VERSION_1_6; |
| 80 | } |
| 81 | |
Elliott Hughes | 6b43685 | 2011-08-12 10:16:44 -0700 | [diff] [blame] | 82 | // Section 12.3.2 of the JNI spec describes JNI class descriptors. They're |
| 83 | // separated with slashes but aren't wrapped with "L;" like regular descriptors |
| 84 | // (i.e. "a/b/C" rather than "La/b/C;"). Arrays of reference types are an |
| 85 | // exception; there the "L;" must be present ("[La/b/C;"). Historically we've |
| 86 | // supported names with dots too (such as "a.b.C"). |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 87 | static std::string NormalizeJniClassDescriptor(const char* name) { |
Elliott Hughes | 6b43685 | 2011-08-12 10:16:44 -0700 | [diff] [blame] | 88 | std::string result; |
| 89 | // Add the missing "L;" if necessary. |
| 90 | if (name[0] == '[') { |
| 91 | result = name; |
| 92 | } else { |
| 93 | result += 'L'; |
| 94 | result += name; |
| 95 | result += ';'; |
| 96 | } |
| 97 | // Rewrite '.' as '/' for backwards compatibility. |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 98 | if (result.find('.') != std::string::npos) { |
| 99 | LOG(WARNING) << "Call to JNI FindClass with dots in name: " |
| 100 | << "\"" << name << "\""; |
| 101 | std::replace(result.begin(), result.end(), '.', '/'); |
Elliott Hughes | 6b43685 | 2011-08-12 10:16:44 -0700 | [diff] [blame] | 102 | } |
| 103 | return result; |
| 104 | } |
| 105 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 106 | static void ThrowNoSuchMethodError(ScopedObjectAccess& soa, mirror::Class* c, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 107 | const char* name, const char* sig, const char* kind) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 108 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 109 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 110 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchMethodError;", |
| 111 | "no %s method \"%s.%s%s\"", |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 112 | kind, c->GetDescriptor().c_str(), name, sig); |
Elliott Hughes | 14134a1 | 2011-09-30 16:55:51 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 115 | static mirror::Class* EnsureInitialized(Thread* self, mirror::Class* klass) |
| 116 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 117 | if (LIKELY(klass->IsInitialized())) { |
| 118 | return klass; |
| 119 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 120 | StackHandleScope<1> hs(self); |
| 121 | Handle<mirror::Class> h_klass(hs.NewHandle(klass)); |
| 122 | if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(h_klass, true, true)) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 123 | return nullptr; |
| 124 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 125 | return h_klass.Get(); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 128 | static jmethodID FindMethodID(ScopedObjectAccess& soa, jclass jni_class, |
| 129 | const char* name, const char* sig, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 130 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 131 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(jni_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 132 | if (c == nullptr) { |
| 133 | return nullptr; |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 134 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 135 | mirror::ArtMethod* method = nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 136 | if (is_static) { |
| 137 | method = c->FindDirectMethod(name, sig); |
Brian Carlstrom | 004644f | 2014-06-18 08:34:01 -0700 | [diff] [blame] | 138 | } else if (c->IsInterface()) { |
| 139 | method = c->FindInterfaceMethod(name, sig); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 140 | } else { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 141 | method = c->FindVirtualMethod(name, sig); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 142 | if (method == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 143 | // No virtual method matching the signature. Search declared |
| 144 | // private methods and constructors. |
| 145 | method = c->FindDeclaredDirectMethod(name, sig); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 146 | } |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 147 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 148 | if (method == nullptr || method->IsStatic() != is_static) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 149 | ThrowNoSuchMethodError(soa, c, name, sig, is_static ? "static" : "non-static"); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 150 | return nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 151 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 152 | return soa.EncodeMethod(method); |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 155 | static mirror::ClassLoader* GetClassLoader(const ScopedObjectAccess& soa) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 156 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 157 | mirror::ArtMethod* method = soa.Self()->GetCurrentMethod(nullptr); |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 158 | // If we are running Runtime.nativeLoad, use the overriding ClassLoader it set. |
| 159 | if (method == soa.DecodeMethod(WellKnownClasses::java_lang_Runtime_nativeLoad)) { |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 160 | return soa.Self()->GetClassLoaderOverride(); |
Brian Carlstrom | 00fae58 | 2011-10-28 01:16:28 -0700 | [diff] [blame] | 161 | } |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 162 | // If we have a method, use its ClassLoader for context. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 163 | if (method != nullptr) { |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 164 | return method->GetDeclaringClass()->GetClassLoader(); |
| 165 | } |
| 166 | // We don't have a method, so try to use the system ClassLoader. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 167 | mirror::ClassLoader* class_loader = |
| 168 | soa.Decode<mirror::ClassLoader*>(Runtime::Current()->GetSystemClassLoader()); |
| 169 | if (class_loader != nullptr) { |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 170 | return class_loader; |
| 171 | } |
| 172 | // See if the override ClassLoader is set for gtests. |
| 173 | class_loader = soa.Self()->GetClassLoaderOverride(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 174 | if (class_loader != nullptr) { |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 175 | // If so, CommonCompilerTest should have set UseCompileTimeClassPath. |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 176 | CHECK(Runtime::Current()->UseCompileTimeClassPath()); |
| 177 | return class_loader; |
| 178 | } |
| 179 | // Use the BOOTCLASSPATH. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 180 | return nullptr; |
Brian Carlstrom | 00fae58 | 2011-10-28 01:16:28 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 183 | static jfieldID FindFieldID(const ScopedObjectAccess& soa, jclass jni_class, const char* name, |
| 184 | const char* sig, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 185 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 186 | StackHandleScope<2> hs(soa.Self()); |
| 187 | Handle<mirror::Class> c( |
| 188 | hs.NewHandle(EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(jni_class)))); |
| 189 | if (c.Get() == nullptr) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 190 | return nullptr; |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 191 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 192 | mirror::ArtField* field = nullptr; |
| 193 | mirror::Class* field_type; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 194 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 195 | if (sig[1] != '\0') { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 196 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(c->GetClassLoader())); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 197 | field_type = class_linker->FindClass(soa.Self(), sig, class_loader); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 198 | } else { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 199 | field_type = class_linker->FindPrimitiveClass(*sig); |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 200 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 201 | if (field_type == nullptr) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 202 | // Failed to find type from the signature of the field. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 203 | DCHECK(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 204 | ThrowLocation throw_location; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 205 | StackHandleScope<1> hs(soa.Self()); |
| 206 | Handle<mirror::Throwable> cause(hs.NewHandle(soa.Self()->GetException(&throw_location))); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 207 | soa.Self()->ClearException(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 208 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchFieldError;", |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 209 | "no type \"%s\" found and so no field \"%s\" " |
| 210 | "could be found in class \"%s\" or its superclasses", sig, name, |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 211 | c->GetDescriptor().c_str()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 212 | soa.Self()->GetException(nullptr)->SetCause(cause.Get()); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 213 | return nullptr; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 214 | } |
| 215 | if (is_static) { |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 216 | field = mirror::Class::FindStaticField(soa.Self(), c, name, |
| 217 | field_type->GetDescriptor().c_str()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 218 | } else { |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 219 | field = c->FindInstanceField(name, field_type->GetDescriptor().c_str()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 220 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 221 | if (field == nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 222 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 223 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchFieldError;", |
| 224 | "no \"%s\" field \"%s\" in class \"%s\" or its superclasses", |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 225 | sig, name, c->GetDescriptor().c_str()); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 226 | return nullptr; |
Elliott Hughes | 8a26c5c | 2011-08-15 18:35:43 -0700 | [diff] [blame] | 227 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 228 | return soa.EncodeField(field); |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 231 | static void PinPrimitiveArray(const ScopedObjectAccess& soa, mirror::Array* array) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 232 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 233 | JavaVMExt* vm = soa.Vm(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 234 | MutexLock mu(soa.Self(), vm->pins_lock); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 235 | vm->pin_table.Add(array); |
| 236 | } |
| 237 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 238 | static void UnpinPrimitiveArray(const ScopedObjectAccess& soa, mirror::Array* array) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 239 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 240 | JavaVMExt* vm = soa.Vm(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 241 | MutexLock mu(soa.Self(), vm->pins_lock); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 242 | vm->pin_table.Remove(array); |
| 243 | } |
| 244 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 245 | static void ThrowAIOOBE(ScopedObjectAccess& soa, mirror::Array* array, jsize start, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 246 | jsize length, const char* identifier) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 247 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 248 | std::string type(PrettyTypeOf(array)); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 249 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 250 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/ArrayIndexOutOfBoundsException;", |
| 251 | "%s offset=%d length=%d %s.length=%d", |
| 252 | type.c_str(), start, length, identifier, array->GetLength()); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 253 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 254 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 255 | static void ThrowSIOOBE(ScopedObjectAccess& soa, jsize start, jsize length, |
| 256 | jsize array_length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 257 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 258 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 259 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/StringIndexOutOfBoundsException;", |
| 260 | "offset=%d length=%d string.length()=%d", start, length, |
| 261 | array_length); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 262 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 263 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 264 | int ThrowNewException(JNIEnv* env, jclass exception_class, const char* msg, jobject cause) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 265 | LOCKS_EXCLUDED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 266 | // Turn the const char* into a java.lang.String. |
| 267 | ScopedLocalRef<jstring> s(env, env->NewStringUTF(msg)); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 268 | if (msg != nullptr && s.get() == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 269 | return JNI_ERR; |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 270 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 271 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 272 | // Choose an appropriate constructor and set up the arguments. |
| 273 | jvalue args[2]; |
| 274 | const char* signature; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 275 | if (msg == nullptr && cause == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 276 | signature = "()V"; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 277 | } else if (msg != nullptr && cause == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 278 | signature = "(Ljava/lang/String;)V"; |
| 279 | args[0].l = s.get(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 280 | } else if (msg == nullptr && cause != nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 281 | signature = "(Ljava/lang/Throwable;)V"; |
| 282 | args[0].l = cause; |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 283 | } else { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 284 | signature = "(Ljava/lang/String;Ljava/lang/Throwable;)V"; |
| 285 | args[0].l = s.get(); |
| 286 | args[1].l = cause; |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 287 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 288 | jmethodID mid = env->GetMethodID(exception_class, "<init>", signature); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 289 | if (mid == nullptr) { |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 290 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 291 | LOG(ERROR) << "No <init>" << signature << " in " |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 292 | << PrettyClass(soa.Decode<mirror::Class*>(exception_class)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 293 | return JNI_ERR; |
| 294 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 295 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 296 | ScopedLocalRef<jthrowable> exception( |
| 297 | env, reinterpret_cast<jthrowable>(env->NewObjectA(exception_class, mid, args))); |
| 298 | if (exception.get() == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 299 | return JNI_ERR; |
| 300 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 301 | ScopedObjectAccess soa(env); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 302 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 303 | soa.Self()->SetException(throw_location, soa.Decode<mirror::Throwable*>(exception.get())); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 304 | return JNI_OK; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 307 | static jint JII_AttachCurrentThread(JavaVM* vm, JNIEnv** p_env, void* raw_args, bool as_daemon) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 308 | if (vm == nullptr || p_env == nullptr) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 309 | return JNI_ERR; |
| 310 | } |
| 311 | |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 312 | // Return immediately if we're already attached. |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 313 | Thread* self = Thread::Current(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 314 | if (self != nullptr) { |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 315 | *p_env = self->GetJniEnv(); |
| 316 | return JNI_OK; |
| 317 | } |
| 318 | |
| 319 | Runtime* runtime = reinterpret_cast<JavaVMExt*>(vm)->runtime; |
| 320 | |
| 321 | // No threads allowed in zygote mode. |
| 322 | if (runtime->IsZygote()) { |
| 323 | LOG(ERROR) << "Attempt to attach a thread in the zygote"; |
| 324 | return JNI_ERR; |
| 325 | } |
| 326 | |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 327 | JavaVMAttachArgs* args = static_cast<JavaVMAttachArgs*>(raw_args); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 328 | const char* thread_name = nullptr; |
| 329 | jobject thread_group = nullptr; |
| 330 | if (args != nullptr) { |
Elliott Hughes | 83a2532 | 2013-03-14 11:18:53 -0700 | [diff] [blame] | 331 | if (IsBadJniVersion(args->version)) { |
| 332 | LOG(ERROR) << "Bad JNI version passed to " |
| 333 | << (as_daemon ? "AttachCurrentThreadAsDaemon" : "AttachCurrentThread") << ": " |
| 334 | << args->version; |
| 335 | return JNI_EVERSION; |
Brian Carlstrom | 8692215 | 2013-03-12 00:59:36 -0700 | [diff] [blame] | 336 | } |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 337 | thread_name = args->name; |
Ian Rogers | 365c102 | 2012-06-22 15:05:28 -0700 | [diff] [blame] | 338 | thread_group = args->group; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 339 | } |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 340 | |
Mathieu Chartier | 664bebf | 2012-11-12 16:54:11 -0800 | [diff] [blame] | 341 | if (!runtime->AttachCurrentThread(thread_name, as_daemon, thread_group, !runtime->IsCompiler())) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 342 | *p_env = nullptr; |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 343 | return JNI_ERR; |
| 344 | } else { |
| 345 | *p_env = Thread::Current()->GetJniEnv(); |
| 346 | return JNI_OK; |
| 347 | } |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 350 | class SharedLibrary { |
| 351 | public: |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 352 | SharedLibrary(const std::string& path, void* handle, mirror::Object* class_loader) |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 353 | : path_(path), |
| 354 | handle_(handle), |
Shih-wei Liao | 31384c5 | 2011-09-06 15:27:45 -0700 | [diff] [blame] | 355 | class_loader_(class_loader), |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 356 | jni_on_load_lock_("JNI_OnLoad lock"), |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 357 | jni_on_load_cond_("JNI_OnLoad condition variable", jni_on_load_lock_), |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 358 | jni_on_load_thread_id_(Thread::Current()->GetThreadId()), |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 359 | jni_on_load_result_(kPending) { |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Hiroshi Yamauchi | ea2e1bd | 2014-06-18 13:47:35 -0700 | [diff] [blame] | 362 | mirror::Object* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 363 | mirror::Object** root = &class_loader_; |
| 364 | return ReadBarrier::BarrierForRoot<mirror::Object, kWithReadBarrier>(root); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | std::string GetPath() { |
| 368 | return path_; |
| 369 | } |
| 370 | |
| 371 | /* |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 372 | * Check the result of an earlier call to JNI_OnLoad on this library. |
| 373 | * If the call has not yet finished in another thread, wait for it. |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 374 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 375 | bool CheckOnLoadResult() |
| 376 | LOCKS_EXCLUDED(jni_on_load_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 377 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 378 | Thread* self = Thread::Current(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 379 | self->TransitionFromRunnableToSuspended(kWaitingForJniOnLoad); |
| 380 | bool okay; |
| 381 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 382 | MutexLock mu(self, jni_on_load_lock_); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 383 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 384 | if (jni_on_load_thread_id_ == self->GetThreadId()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 385 | // Check this so we don't end up waiting for ourselves. We need to return "true" so the |
| 386 | // caller can continue. |
| 387 | LOG(INFO) << *self << " recursive attempt to load library " << "\"" << path_ << "\""; |
| 388 | okay = true; |
| 389 | } else { |
| 390 | while (jni_on_load_result_ == kPending) { |
| 391 | VLOG(jni) << "[" << *self << " waiting for \"" << path_ << "\" " << "JNI_OnLoad...]"; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 392 | jni_on_load_cond_.Wait(self); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 393 | } |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 394 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 395 | okay = (jni_on_load_result_ == kOkay); |
| 396 | VLOG(jni) << "[Earlier JNI_OnLoad for \"" << path_ << "\" " |
| 397 | << (okay ? "succeeded" : "failed") << "]"; |
| 398 | } |
| 399 | } |
| 400 | self->TransitionFromSuspendedToRunnable(); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 401 | return okay; |
| 402 | } |
| 403 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 404 | void SetResult(bool result) LOCKS_EXCLUDED(jni_on_load_lock_) { |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 405 | Thread* self = Thread::Current(); |
| 406 | MutexLock mu(self, jni_on_load_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 407 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 408 | jni_on_load_result_ = result ? kOkay : kFailed; |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 409 | jni_on_load_thread_id_ = 0; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 410 | |
| 411 | // Broadcast a wakeup to anybody sleeping on the condition variable. |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 412 | jni_on_load_cond_.Broadcast(self); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void* FindSymbol(const std::string& symbol_name) { |
| 416 | return dlsym(handle_, symbol_name.c_str()); |
| 417 | } |
| 418 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 419 | void VisitRoots(RootCallback* visitor, void* arg) { |
Mathieu Chartier | 8f4be93 | 2014-01-28 15:25:19 -0800 | [diff] [blame] | 420 | if (class_loader_ != nullptr) { |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 421 | visitor(&class_loader_, arg, 0, kRootVMInternal); |
Mathieu Chartier | 8f4be93 | 2014-01-28 15:25:19 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 425 | private: |
| 426 | enum JNI_OnLoadState { |
| 427 | kPending, |
| 428 | kFailed, |
| 429 | kOkay, |
| 430 | }; |
| 431 | |
| 432 | // Path to library "/system/lib/libjni.so". |
| 433 | std::string path_; |
| 434 | |
| 435 | // The void* returned by dlopen(3). |
| 436 | void* handle_; |
| 437 | |
| 438 | // The ClassLoader this library is associated with. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 439 | mirror::Object* class_loader_; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 440 | |
| 441 | // Guards remaining items. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 442 | Mutex jni_on_load_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 443 | // Wait for JNI_OnLoad in other thread. |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 444 | ConditionVariable jni_on_load_cond_ GUARDED_BY(jni_on_load_lock_); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 445 | // Recursive invocation guard. |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 446 | uint32_t jni_on_load_thread_id_ GUARDED_BY(jni_on_load_lock_); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 447 | // Result of earlier JNI_OnLoad call. |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 448 | JNI_OnLoadState jni_on_load_result_ GUARDED_BY(jni_on_load_lock_); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 449 | }; |
| 450 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 451 | // This exists mainly to keep implementation details out of the header file. |
| 452 | class Libraries { |
| 453 | public: |
| 454 | Libraries() { |
| 455 | } |
| 456 | |
| 457 | ~Libraries() { |
Elliott Hughes | c31664f | 2011-09-29 15:58:28 -0700 | [diff] [blame] | 458 | STLDeleteValues(&libraries_); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 461 | void Dump(std::ostream& os) const { |
| 462 | bool first = true; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 463 | for (const auto& library : libraries_) { |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 464 | if (!first) { |
| 465 | os << ' '; |
| 466 | } |
| 467 | first = false; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 468 | os << library.first; |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
| 472 | size_t size() const { |
| 473 | return libraries_.size(); |
| 474 | } |
| 475 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 476 | SharedLibrary* Get(const std::string& path) { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 477 | auto it = libraries_.find(path); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 478 | return (it == libraries_.end()) ? nullptr : it->second; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | void Put(const std::string& path, SharedLibrary* library) { |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 482 | libraries_.Put(path, library); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | // See section 11.3 "Linking Native Methods" of the JNI spec. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 486 | void* FindNativeMethod(mirror::ArtMethod* m, std::string& detail) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 487 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 488 | std::string jni_short_name(JniShortName(m)); |
| 489 | std::string jni_long_name(JniLongName(m)); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 490 | const mirror::ClassLoader* declaring_class_loader = m->GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 491 | for (const auto& lib : libraries_) { |
| 492 | SharedLibrary* library = lib.second; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 493 | if (library->GetClassLoader() != declaring_class_loader) { |
| 494 | // We only search libraries loaded by the appropriate ClassLoader. |
| 495 | continue; |
| 496 | } |
| 497 | // Try the short name then the long name... |
| 498 | void* fn = library->FindSymbol(jni_short_name); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 499 | if (fn == nullptr) { |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 500 | fn = library->FindSymbol(jni_long_name); |
| 501 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 502 | if (fn != nullptr) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 503 | VLOG(jni) << "[Found native code for " << PrettyMethod(m) |
| 504 | << " in \"" << library->GetPath() << "\"]"; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 505 | return fn; |
| 506 | } |
| 507 | } |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 508 | detail += "No implementation found for "; |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 509 | detail += PrettyMethod(m); |
Brian Carlstrom | 92827a5 | 2011-10-10 15:50:01 -0700 | [diff] [blame] | 510 | detail += " (tried " + jni_short_name + " and " + jni_long_name + ")"; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 511 | LOG(ERROR) << detail; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 512 | return nullptr; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 515 | void VisitRoots(RootCallback* callback, void* arg) { |
Mathieu Chartier | 8f4be93 | 2014-01-28 15:25:19 -0800 | [diff] [blame] | 516 | for (auto& lib_pair : libraries_) { |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 517 | lib_pair.second->VisitRoots(callback, arg); |
Mathieu Chartier | 8f4be93 | 2014-01-28 15:25:19 -0800 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 521 | private: |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 522 | SafeMap<std::string, SharedLibrary*> libraries_; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 523 | }; |
| 524 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 525 | #define CHECK_NON_NULL_ARGUMENT(value) \ |
| 526 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, nullptr) |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 527 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 528 | #define CHECK_NON_NULL_ARGUMENT_RETURN_VOID(value) \ |
| 529 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, ) |
| 530 | |
| 531 | #define CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(value) \ |
| 532 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, 0) |
| 533 | |
| 534 | #define CHECK_NON_NULL_ARGUMENT_RETURN(value, return_val) \ |
| 535 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, return_val) |
| 536 | |
| 537 | #define CHECK_NON_NULL_ARGUMENT_FN_NAME(name, value, return_val) \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 538 | if (UNLIKELY(value == nullptr)) { \ |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 539 | JniAbortF(name, #value " == null"); \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 540 | return return_val; \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 543 | #define CHECK_NON_NULL_MEMCPY_ARGUMENT(length, value) \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 544 | if (UNLIKELY(length != 0 && value == nullptr)) { \ |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 545 | JniAbortF(__FUNCTION__, #value " == null"); \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 546 | return; \ |
Ian Rogers | 4ffdc6b | 2013-08-21 16:55:13 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 549 | class JNI { |
| 550 | public: |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 551 | static jint GetVersion(JNIEnv*) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 552 | return JNI_VERSION_1_6; |
| 553 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 554 | |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 555 | static jclass DefineClass(JNIEnv*, const char*, jobject, const jbyte*, jsize) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 556 | LOG(WARNING) << "JNI DefineClass is not supported"; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 557 | return nullptr; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 560 | static jclass FindClass(JNIEnv* env, const char* name) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 561 | CHECK_NON_NULL_ARGUMENT(name); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 562 | Runtime* runtime = Runtime::Current(); |
| 563 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 564 | std::string descriptor(NormalizeJniClassDescriptor(name)); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 565 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 566 | mirror::Class* c = nullptr; |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 567 | if (runtime->IsStarted()) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 568 | StackHandleScope<1> hs(soa.Self()); |
| 569 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(GetClassLoader(soa))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 570 | c = class_linker->FindClass(soa.Self(), descriptor.c_str(), class_loader); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 571 | } else { |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 572 | c = class_linker->FindSystemClass(soa.Self(), descriptor.c_str()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 573 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 574 | return soa.AddLocalReference<jclass>(c); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 575 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 576 | |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 577 | static jmethodID FromReflectedMethod(JNIEnv* env, jobject jlr_method) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 578 | CHECK_NON_NULL_ARGUMENT(jlr_method); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 579 | ScopedObjectAccess soa(env); |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 580 | return soa.EncodeMethod(mirror::ArtMethod::FromReflectedMethod(soa, jlr_method)); |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 581 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 582 | |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 583 | static jfieldID FromReflectedField(JNIEnv* env, jobject jlr_field) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 584 | CHECK_NON_NULL_ARGUMENT(jlr_field); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 585 | ScopedObjectAccess soa(env); |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 586 | return soa.EncodeField(mirror::ArtField::FromReflectedField(soa, jlr_field)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 587 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 588 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 589 | static jobject ToReflectedMethod(JNIEnv* env, jclass, jmethodID mid, jboolean) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 590 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 591 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 592 | mirror::ArtMethod* m = soa.DecodeMethod(mid); |
| 593 | CHECK(!kMovingMethods); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 594 | jobject art_method = soa.AddLocalReference<jobject>(m); |
| 595 | jobject reflect_method = env->AllocObject(WellKnownClasses::java_lang_reflect_Method); |
| 596 | if (env->ExceptionCheck()) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 597 | return nullptr; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 598 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 599 | SetObjectField(env, reflect_method, |
| 600 | WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod, art_method); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 601 | return reflect_method; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 602 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 603 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 604 | static jobject ToReflectedField(JNIEnv* env, jclass, jfieldID fid, jboolean) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 605 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 606 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 607 | mirror::ArtField* f = soa.DecodeField(fid); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 608 | jobject art_field = soa.AddLocalReference<jobject>(f); |
| 609 | jobject reflect_field = env->AllocObject(WellKnownClasses::java_lang_reflect_Field); |
| 610 | if (env->ExceptionCheck()) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 611 | return nullptr; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 612 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 613 | SetObjectField(env, reflect_field, |
| 614 | WellKnownClasses::java_lang_reflect_Field_artField, art_field); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 615 | return reflect_field; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 616 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 617 | |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 618 | static jclass GetObjectClass(JNIEnv* env, jobject java_object) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 619 | CHECK_NON_NULL_ARGUMENT(java_object); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 620 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 621 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 622 | return soa.AddLocalReference<jclass>(o->GetClass()); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 625 | static jclass GetSuperclass(JNIEnv* env, jclass java_class) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 626 | CHECK_NON_NULL_ARGUMENT(java_class); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 627 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 628 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 629 | return soa.AddLocalReference<jclass>(c->GetSuperClass()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 630 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 631 | |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 632 | static jboolean IsAssignableFrom(JNIEnv* env, jclass java_class1, jclass java_class2) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 633 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class1, JNI_FALSE); |
| 634 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class2, JNI_FALSE); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 635 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 636 | mirror::Class* c1 = soa.Decode<mirror::Class*>(java_class1); |
| 637 | mirror::Class* c2 = soa.Decode<mirror::Class*>(java_class2); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 638 | return c1->IsAssignableFrom(c2) ? JNI_TRUE : JNI_FALSE; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 639 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 640 | |
Elliott Hughes | e84278b | 2012-03-22 10:06:53 -0700 | [diff] [blame] | 641 | static jboolean IsInstanceOf(JNIEnv* env, jobject jobj, jclass java_class) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 642 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class, JNI_FALSE); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 643 | if (jobj == nullptr) { |
Brian Carlstrom | 5d40f18 | 2011-09-26 22:29:18 -0700 | [diff] [blame] | 644 | // Note: JNI is different from regular Java instanceof in this respect |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 645 | return JNI_TRUE; |
| 646 | } else { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 647 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 648 | mirror::Object* obj = soa.Decode<mirror::Object*>(jobj); |
| 649 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Elliott Hughes | e84278b | 2012-03-22 10:06:53 -0700 | [diff] [blame] | 650 | return obj->InstanceOf(c) ? JNI_TRUE : JNI_FALSE; |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 651 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 652 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 653 | |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 654 | static jint Throw(JNIEnv* env, jthrowable java_exception) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 655 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 656 | mirror::Throwable* exception = soa.Decode<mirror::Throwable*>(java_exception); |
| 657 | if (exception == nullptr) { |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 658 | return JNI_ERR; |
| 659 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 660 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 661 | soa.Self()->SetException(throw_location, exception); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 662 | return JNI_OK; |
| 663 | } |
| 664 | |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 665 | static jint ThrowNew(JNIEnv* env, jclass c, const char* msg) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 666 | CHECK_NON_NULL_ARGUMENT_RETURN(c, JNI_ERR); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 667 | return ThrowNewException(env, c, msg, nullptr); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static jboolean ExceptionCheck(JNIEnv* env) { |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 671 | return static_cast<JNIEnvExt*>(env)->self->IsExceptionPending() ? JNI_TRUE : JNI_FALSE; |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static void ExceptionClear(JNIEnv* env) { |
Serguei Katkov | a309d76 | 2014-05-26 11:23:39 +0700 | [diff] [blame] | 675 | ScopedObjectAccess soa(env); |
| 676 | soa.Self()->ClearException(); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static void ExceptionDescribe(JNIEnv* env) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 680 | ScopedObjectAccess soa(env); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 681 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 682 | StackHandleScope<3> hs(soa.Self()); |
| 683 | // TODO: Use nullptr instead of null handles? |
| 684 | auto old_throw_this_object(hs.NewHandle<mirror::Object>(nullptr)); |
| 685 | auto old_throw_method(hs.NewHandle<mirror::ArtMethod>(nullptr)); |
| 686 | auto old_exception(hs.NewHandle<mirror::Throwable>(nullptr)); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 687 | uint32_t old_throw_dex_pc; |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 688 | bool old_is_exception_reported; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 689 | { |
| 690 | ThrowLocation old_throw_location; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 691 | mirror::Throwable* old_exception_obj = soa.Self()->GetException(&old_throw_location); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 692 | old_throw_this_object.Assign(old_throw_location.GetThis()); |
| 693 | old_throw_method.Assign(old_throw_location.GetMethod()); |
| 694 | old_exception.Assign(old_exception_obj); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 695 | old_throw_dex_pc = old_throw_location.GetDexPc(); |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 696 | old_is_exception_reported = soa.Self()->IsExceptionReportedToInstrumentation(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 697 | soa.Self()->ClearException(); |
| 698 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 699 | ScopedLocalRef<jthrowable> exception(env, |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 700 | soa.AddLocalReference<jthrowable>(old_exception.Get())); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 701 | ScopedLocalRef<jclass> exception_class(env, env->GetObjectClass(exception.get())); |
| 702 | jmethodID mid = env->GetMethodID(exception_class.get(), "printStackTrace", "()V"); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 703 | if (mid == nullptr) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 704 | LOG(WARNING) << "JNI WARNING: no printStackTrace()V in " |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 705 | << PrettyTypeOf(old_exception.Get()); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 706 | } else { |
| 707 | env->CallVoidMethod(exception.get(), mid); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 708 | if (soa.Self()->IsExceptionPending()) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 709 | LOG(WARNING) << "JNI WARNING: " << PrettyTypeOf(soa.Self()->GetException(nullptr)) |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 710 | << " thrown while calling printStackTrace"; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 711 | soa.Self()->ClearException(); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 712 | } |
| 713 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 714 | ThrowLocation gc_safe_throw_location(old_throw_this_object.Get(), old_throw_method.Get(), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 715 | old_throw_dex_pc); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 716 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 717 | soa.Self()->SetException(gc_safe_throw_location, old_exception.Get()); |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 718 | soa.Self()->SetExceptionReportedToInstrumentation(old_is_exception_reported); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 719 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 720 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 721 | static jthrowable ExceptionOccurred(JNIEnv* env) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 722 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 723 | mirror::Object* exception = soa.Self()->GetException(nullptr); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 724 | return soa.AddLocalReference<jthrowable>(exception); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 727 | static void FatalError(JNIEnv*, const char* msg) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 728 | LOG(FATAL) << "JNI FatalError called: " << msg; |
| 729 | } |
| 730 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 731 | static jint PushLocalFrame(JNIEnv* env, jint capacity) { |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 732 | // TODO: SOA may not be necessary but I do it to please lock annotations. |
| 733 | ScopedObjectAccess soa(env); |
| 734 | if (EnsureLocalCapacity(soa, capacity, "PushLocalFrame") != JNI_OK) { |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 735 | return JNI_ERR; |
| 736 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 737 | static_cast<JNIEnvExt*>(env)->PushFrame(capacity); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 738 | return JNI_OK; |
| 739 | } |
| 740 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 741 | static jobject PopLocalFrame(JNIEnv* env, jobject java_survivor) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 742 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 743 | mirror::Object* survivor = soa.Decode<mirror::Object*>(java_survivor); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 744 | soa.Env()->PopFrame(); |
| 745 | return soa.AddLocalReference<jobject>(survivor); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 748 | static jint EnsureLocalCapacity(JNIEnv* env, jint desired_capacity) { |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 749 | // TODO: SOA may not be necessary but I do it to please lock annotations. |
| 750 | ScopedObjectAccess soa(env); |
| 751 | return EnsureLocalCapacity(soa, desired_capacity, "EnsureLocalCapacity"); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 754 | static jobject NewGlobalRef(JNIEnv* env, jobject obj) { |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 755 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 756 | mirror::Object* decoded_obj = soa.Decode<mirror::Object*>(obj); |
Mathieu Chartier | e8c48db | 2013-12-19 14:59:00 -0800 | [diff] [blame] | 757 | // Check for null after decoding the object to handle cleared weak globals. |
| 758 | if (decoded_obj == nullptr) { |
| 759 | return nullptr; |
| 760 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 761 | JavaVMExt* vm = soa.Vm(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 762 | IndirectReferenceTable& globals = vm->globals; |
Ian Rogers | b8a0b94 | 2013-08-20 18:09:52 -0700 | [diff] [blame] | 763 | WriterMutexLock mu(soa.Self(), vm->globals_lock); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 764 | IndirectRef ref = globals.Add(IRT_FIRST_SEGMENT, decoded_obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 765 | return reinterpret_cast<jobject>(ref); |
| 766 | } |
| 767 | |
| 768 | static void DeleteGlobalRef(JNIEnv* env, jobject obj) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 769 | if (obj == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 770 | return; |
| 771 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 772 | JavaVMExt* vm = reinterpret_cast<JNIEnvExt*>(env)->vm; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 773 | IndirectReferenceTable& globals = vm->globals; |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 774 | Thread* self = reinterpret_cast<JNIEnvExt*>(env)->self; |
Ian Rogers | b8a0b94 | 2013-08-20 18:09:52 -0700 | [diff] [blame] | 775 | WriterMutexLock mu(self, vm->globals_lock); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 776 | |
| 777 | if (!globals.Remove(IRT_FIRST_SEGMENT, obj)) { |
| 778 | LOG(WARNING) << "JNI WARNING: DeleteGlobalRef(" << obj << ") " |
| 779 | << "failed to find entry"; |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | static jweak NewWeakGlobalRef(JNIEnv* env, jobject obj) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 784 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 785 | return AddWeakGlobalReference(soa, soa.Decode<mirror::Object*>(obj)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | static void DeleteWeakGlobalRef(JNIEnv* env, jweak obj) { |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 789 | if (obj != nullptr) { |
| 790 | ScopedObjectAccess soa(env); |
| 791 | soa.Vm()->DeleteWeakGlobalRef(soa.Self(), obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | |
| 795 | static jobject NewLocalRef(JNIEnv* env, jobject obj) { |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 796 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 797 | mirror::Object* decoded_obj = soa.Decode<mirror::Object*>(obj); |
Mathieu Chartier | e8c48db | 2013-12-19 14:59:00 -0800 | [diff] [blame] | 798 | // Check for null after decoding the object to handle cleared weak globals. |
| 799 | if (decoded_obj == nullptr) { |
| 800 | return nullptr; |
| 801 | } |
| 802 | return soa.AddLocalReference<jobject>(decoded_obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static void DeleteLocalRef(JNIEnv* env, jobject obj) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 806 | if (obj == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 807 | return; |
| 808 | } |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 809 | ScopedObjectAccess soa(env); |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 810 | IndirectReferenceTable& locals = reinterpret_cast<JNIEnvExt*>(env)->locals; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 811 | |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 812 | uint32_t cookie = reinterpret_cast<JNIEnvExt*>(env)->local_ref_cookie; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 813 | if (!locals.Remove(cookie, obj)) { |
| 814 | // Attempting to delete a local reference that is not in the |
| 815 | // topmost local reference frame is a no-op. DeleteLocalRef returns |
| 816 | // void and doesn't throw any exceptions, but we should probably |
| 817 | // complain about it so the user will notice that things aren't |
| 818 | // going quite the way they expect. |
| 819 | LOG(WARNING) << "JNI WARNING: DeleteLocalRef(" << obj << ") " |
| 820 | << "failed to find entry"; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | static jboolean IsSameObject(JNIEnv* env, jobject obj1, jobject obj2) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 825 | if (obj1 == obj2) { |
| 826 | return JNI_TRUE; |
| 827 | } else { |
| 828 | ScopedObjectAccess soa(env); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 829 | return (soa.Decode<mirror::Object*>(obj1) == soa.Decode<mirror::Object*>(obj2)) |
| 830 | ? JNI_TRUE : JNI_FALSE; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 831 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 834 | static jobject AllocObject(JNIEnv* env, jclass java_class) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 835 | CHECK_NON_NULL_ARGUMENT(java_class); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 836 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 837 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 838 | if (c == nullptr) { |
| 839 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 840 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 841 | return soa.AddLocalReference<jobject>(c->AllocObject(soa.Self())); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 844 | static jobject NewObject(JNIEnv* env, jclass java_class, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 845 | va_list args; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 846 | va_start(args, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 847 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 848 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 849 | jobject result = NewObjectV(env, java_class, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 850 | va_end(args); |
| 851 | return result; |
| 852 | } |
| 853 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 854 | static jobject NewObjectV(JNIEnv* env, jclass java_class, jmethodID mid, va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 855 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 856 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 857 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 858 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 859 | if (c == nullptr) { |
| 860 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 861 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 862 | mirror::Object* result = c->AllocObject(soa.Self()); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 863 | if (result == nullptr) { |
| 864 | return nullptr; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 865 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 866 | jobject local_result = soa.AddLocalReference<jobject>(result); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 867 | CallNonvirtualVoidMethodV(env, local_result, java_class, mid, args); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 868 | if (soa.Self()->IsExceptionPending()) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 869 | return nullptr; |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 870 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 871 | return local_result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 874 | static jobject NewObjectA(JNIEnv* env, jclass java_class, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 875 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 876 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 877 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 878 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 879 | if (c == nullptr) { |
| 880 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 881 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 882 | mirror::Object* result = c->AllocObject(soa.Self()); |
| 883 | if (result == nullptr) { |
| 884 | return nullptr; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 885 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 886 | jobject local_result = soa.AddLocalReference<jobjectArray>(result); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 887 | CallNonvirtualVoidMethodA(env, local_result, java_class, mid, args); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 888 | if (soa.Self()->IsExceptionPending()) { |
| 889 | return nullptr; |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 890 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 891 | return local_result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 894 | static jmethodID GetMethodID(JNIEnv* env, jclass java_class, const char* name, const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 895 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 896 | CHECK_NON_NULL_ARGUMENT(name); |
| 897 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 898 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 899 | return FindMethodID(soa, java_class, name, sig, false); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 902 | static jmethodID GetStaticMethodID(JNIEnv* env, jclass java_class, const char* name, |
| 903 | const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 904 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 905 | CHECK_NON_NULL_ARGUMENT(name); |
| 906 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 907 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 908 | return FindMethodID(soa, java_class, name, sig, true); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 911 | static jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 912 | va_list ap; |
| 913 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 914 | CHECK_NON_NULL_ARGUMENT(obj); |
| 915 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 916 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 917 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 918 | va_end(ap); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 919 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 922 | static jobject CallObjectMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 923 | CHECK_NON_NULL_ARGUMENT(obj); |
| 924 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 925 | ScopedObjectAccess soa(env); |
| 926 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args)); |
| 927 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 930 | static jobject CallObjectMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 931 | CHECK_NON_NULL_ARGUMENT(obj); |
| 932 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 933 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 934 | JValue result(InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 935 | args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 936 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 939 | static jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 940 | va_list ap; |
| 941 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 942 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 943 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 944 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 945 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 946 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 947 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 950 | static jboolean CallBooleanMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 951 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 952 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 953 | ScopedObjectAccess soa(env); |
| 954 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 957 | static jboolean CallBooleanMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 958 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 959 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 960 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 961 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 962 | args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 965 | static jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 966 | va_list ap; |
| 967 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 968 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 969 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 970 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 971 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 972 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 973 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 976 | static jbyte CallByteMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 977 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 978 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 979 | ScopedObjectAccess soa(env); |
| 980 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 983 | static jbyte CallByteMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 984 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 985 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 986 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 987 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 988 | args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 991 | static jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 992 | va_list ap; |
| 993 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 994 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 995 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 996 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 997 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 998 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 999 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1002 | static jchar CallCharMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1003 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1004 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1005 | ScopedObjectAccess soa(env); |
| 1006 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1009 | static jchar CallCharMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1010 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1011 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1012 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1013 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 1014 | args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1017 | static jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1018 | va_list ap; |
| 1019 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1020 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1021 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1022 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1023 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1024 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1025 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1028 | static jdouble CallDoubleMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1029 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1030 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1031 | ScopedObjectAccess soa(env); |
| 1032 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1035 | static jdouble CallDoubleMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1036 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1037 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1038 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1039 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 1040 | args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1043 | static jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1044 | va_list ap; |
| 1045 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1046 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1047 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1048 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1049 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1050 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1051 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1054 | static jfloat CallFloatMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1055 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1056 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1057 | ScopedObjectAccess soa(env); |
| 1058 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1061 | static jfloat CallFloatMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1062 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1063 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1064 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1065 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 1066 | args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1069 | static jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1070 | va_list ap; |
| 1071 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1072 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1073 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1074 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1075 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1076 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1077 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1080 | static jint CallIntMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1081 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1082 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1083 | ScopedObjectAccess soa(env); |
| 1084 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1087 | static jint CallIntMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1088 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1089 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1090 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1091 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 1092 | args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1095 | static jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1096 | va_list ap; |
| 1097 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1098 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1099 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1100 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1101 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1102 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1103 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1106 | static jlong CallLongMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1107 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1108 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1109 | ScopedObjectAccess soa(env); |
| 1110 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1113 | static jlong CallLongMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1114 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1115 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1116 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1117 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 1118 | args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1121 | static jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1122 | va_list ap; |
| 1123 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1124 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1125 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1126 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1127 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1128 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1129 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1132 | static jshort CallShortMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1133 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1134 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1135 | ScopedObjectAccess soa(env); |
| 1136 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1139 | static jshort CallShortMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1140 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1141 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1142 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1143 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 1144 | args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1147 | static void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1148 | va_list ap; |
| 1149 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1150 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1151 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1152 | ScopedObjectAccess soa(env); |
Ian Rogers | 1b09b09 | 2012-08-20 15:35:52 -0700 | [diff] [blame] | 1153 | InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1154 | va_end(ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1157 | static void CallVoidMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1158 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1159 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1160 | ScopedObjectAccess soa(env); |
| 1161 | InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1164 | static void CallVoidMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1165 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1166 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1167 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1168 | InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1171 | static jobject CallNonvirtualObjectMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1172 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1173 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1174 | CHECK_NON_NULL_ARGUMENT(obj); |
| 1175 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1176 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1177 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
| 1178 | jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1179 | va_end(ap); |
| 1180 | return local_result; |
| 1181 | } |
| 1182 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1183 | static jobject CallNonvirtualObjectMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1184 | va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1185 | CHECK_NON_NULL_ARGUMENT(obj); |
| 1186 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1187 | ScopedObjectAccess soa(env); |
| 1188 | JValue result(InvokeWithVarArgs(soa, obj, mid, args)); |
| 1189 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1192 | static jobject CallNonvirtualObjectMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1193 | jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1194 | CHECK_NON_NULL_ARGUMENT(obj); |
| 1195 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1196 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1197 | JValue result(InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1198 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1201 | static jboolean CallNonvirtualBooleanMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1202 | ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1203 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1204 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1205 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1206 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1207 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1208 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1209 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1210 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1213 | static jboolean CallNonvirtualBooleanMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1214 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1215 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1216 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1217 | ScopedObjectAccess soa(env); |
| 1218 | return InvokeWithVarArgs(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1221 | static jboolean CallNonvirtualBooleanMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1222 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1223 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1224 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1225 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1226 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1229 | static jbyte CallNonvirtualByteMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1230 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1231 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1232 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1233 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1234 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1235 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1236 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1237 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1240 | static jbyte CallNonvirtualByteMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1241 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1242 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1243 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1244 | ScopedObjectAccess soa(env); |
| 1245 | return InvokeWithVarArgs(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1248 | static jbyte CallNonvirtualByteMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1249 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1250 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1251 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1252 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1253 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1256 | static jchar CallNonvirtualCharMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1257 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1258 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1259 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1260 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1261 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1262 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1263 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1264 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1267 | static jchar CallNonvirtualCharMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1268 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1269 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1270 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1271 | ScopedObjectAccess soa(env); |
| 1272 | return InvokeWithVarArgs(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1275 | static jchar CallNonvirtualCharMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1276 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1277 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1278 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1279 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1280 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1283 | static jshort CallNonvirtualShortMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1284 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1285 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1286 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1287 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1288 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1289 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1290 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1291 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1294 | static jshort CallNonvirtualShortMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1295 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1296 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1297 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1298 | ScopedObjectAccess soa(env); |
| 1299 | return InvokeWithVarArgs(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1302 | static jshort CallNonvirtualShortMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1303 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1304 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1305 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1306 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1307 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1310 | static jint CallNonvirtualIntMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1311 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1312 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1313 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1314 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1315 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1316 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1317 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1318 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1321 | static jint CallNonvirtualIntMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1322 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1323 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1324 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1325 | ScopedObjectAccess soa(env); |
| 1326 | return InvokeWithVarArgs(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1329 | static jint CallNonvirtualIntMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1330 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1331 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1332 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1333 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1334 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1337 | static jlong CallNonvirtualLongMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1338 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1339 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1340 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1341 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1342 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1343 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1344 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1345 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1348 | static jlong CallNonvirtualLongMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1349 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1350 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1351 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1352 | ScopedObjectAccess soa(env); |
| 1353 | return InvokeWithVarArgs(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1356 | static jlong CallNonvirtualLongMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1357 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1358 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1359 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1360 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1361 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1364 | static jfloat CallNonvirtualFloatMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1365 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1366 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1367 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1368 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1369 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1370 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1371 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1372 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1375 | static jfloat CallNonvirtualFloatMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1376 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1377 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1378 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1379 | ScopedObjectAccess soa(env); |
| 1380 | return InvokeWithVarArgs(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1383 | static jfloat CallNonvirtualFloatMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1384 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1385 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1386 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1387 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1388 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1391 | static jdouble CallNonvirtualDoubleMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1392 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1393 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1394 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1395 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1396 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1397 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1398 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1399 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1402 | static jdouble CallNonvirtualDoubleMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1403 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1404 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1405 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1406 | ScopedObjectAccess soa(env); |
| 1407 | return InvokeWithVarArgs(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1410 | static jdouble CallNonvirtualDoubleMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1411 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1412 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1413 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1414 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1415 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1418 | static void CallNonvirtualVoidMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1419 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1420 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1421 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1422 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1423 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1424 | InvokeWithVarArgs(soa, obj, mid, ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1425 | va_end(ap); |
| 1426 | } |
| 1427 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1428 | static void CallNonvirtualVoidMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1429 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1430 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1431 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1432 | ScopedObjectAccess soa(env); |
| 1433 | InvokeWithVarArgs(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1436 | static void CallNonvirtualVoidMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1437 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1438 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1439 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1440 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1441 | InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1444 | static jfieldID GetFieldID(JNIEnv* env, jclass java_class, const char* name, const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1445 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 1446 | CHECK_NON_NULL_ARGUMENT(name); |
| 1447 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1448 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1449 | return FindFieldID(soa, java_class, name, sig, false); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1450 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1451 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1452 | static jfieldID GetStaticFieldID(JNIEnv* env, jclass java_class, const char* name, |
| 1453 | const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1454 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 1455 | CHECK_NON_NULL_ARGUMENT(name); |
| 1456 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1457 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1458 | return FindFieldID(soa, java_class, name, sig, true); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1459 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1460 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1461 | static jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fid) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1462 | CHECK_NON_NULL_ARGUMENT(obj); |
| 1463 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1464 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1465 | mirror::Object* o = soa.Decode<mirror::Object*>(obj); |
| 1466 | mirror::ArtField* f = soa.DecodeField(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1467 | return soa.AddLocalReference<jobject>(f->GetObject(o)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1468 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1469 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1470 | static jobject GetStaticObjectField(JNIEnv* env, jclass, jfieldID fid) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1471 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1472 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1473 | mirror::ArtField* f = soa.DecodeField(fid); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1474 | return soa.AddLocalReference<jobject>(f->GetObject(f->GetDeclaringClass())); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1477 | static void SetObjectField(JNIEnv* env, jobject java_object, jfieldID fid, jobject java_value) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1478 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_object); |
| 1479 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1480 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1481 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
| 1482 | mirror::Object* v = soa.Decode<mirror::Object*>(java_value); |
| 1483 | mirror::ArtField* f = soa.DecodeField(fid); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1484 | f->SetObject<false>(o, v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1487 | static void SetStaticObjectField(JNIEnv* env, jclass, jfieldID fid, jobject java_value) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1488 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1489 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1490 | mirror::Object* v = soa.Decode<mirror::Object*>(java_value); |
| 1491 | mirror::ArtField* f = soa.DecodeField(fid); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1492 | f->SetObject<false>(f->GetDeclaringClass(), v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1495 | #define GET_PRIMITIVE_FIELD(fn, instance) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1496 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(instance); \ |
| 1497 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(fid); \ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1498 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1499 | mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ |
| 1500 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1501 | return f->Get ##fn (o) |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1502 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1503 | #define GET_STATIC_PRIMITIVE_FIELD(fn) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1504 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(fid); \ |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1505 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1506 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1507 | return f->Get ##fn (f->GetDeclaringClass()) |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1508 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1509 | #define SET_PRIMITIVE_FIELD(fn, instance, value) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1510 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(instance); \ |
| 1511 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); \ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1512 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1513 | mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ |
| 1514 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1515 | f->Set ##fn <false>(o, value) |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1516 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1517 | #define SET_STATIC_PRIMITIVE_FIELD(fn, value) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1518 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); \ |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1519 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1520 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1521 | f->Set ##fn <false>(f->GetDeclaringClass(), value) |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1522 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1523 | static jboolean GetBooleanField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1524 | GET_PRIMITIVE_FIELD(Boolean, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1527 | static jbyte GetByteField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1528 | GET_PRIMITIVE_FIELD(Byte, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1531 | static jchar GetCharField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1532 | GET_PRIMITIVE_FIELD(Char, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1535 | static jshort GetShortField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1536 | GET_PRIMITIVE_FIELD(Short, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1539 | static jint GetIntField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1540 | GET_PRIMITIVE_FIELD(Int, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1543 | static jlong GetLongField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1544 | GET_PRIMITIVE_FIELD(Long, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1547 | static jfloat GetFloatField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1548 | GET_PRIMITIVE_FIELD(Float, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1551 | static jdouble GetDoubleField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1552 | GET_PRIMITIVE_FIELD(Double, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1555 | static jboolean GetStaticBooleanField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1556 | GET_STATIC_PRIMITIVE_FIELD(Boolean); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1559 | static jbyte GetStaticByteField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1560 | GET_STATIC_PRIMITIVE_FIELD(Byte); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1563 | static jchar GetStaticCharField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1564 | GET_STATIC_PRIMITIVE_FIELD(Char); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1567 | static jshort GetStaticShortField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1568 | GET_STATIC_PRIMITIVE_FIELD(Short); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1571 | static jint GetStaticIntField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1572 | GET_STATIC_PRIMITIVE_FIELD(Int); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1575 | static jlong GetStaticLongField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1576 | GET_STATIC_PRIMITIVE_FIELD(Long); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1579 | static jfloat GetStaticFloatField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1580 | GET_STATIC_PRIMITIVE_FIELD(Float); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1583 | static jdouble GetStaticDoubleField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1584 | GET_STATIC_PRIMITIVE_FIELD(Double); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | static void SetBooleanField(JNIEnv* env, jobject obj, jfieldID fid, jboolean v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1588 | SET_PRIMITIVE_FIELD(Boolean, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | static void SetByteField(JNIEnv* env, jobject obj, jfieldID fid, jbyte v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1592 | SET_PRIMITIVE_FIELD(Byte, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | static void SetCharField(JNIEnv* env, jobject obj, jfieldID fid, jchar v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1596 | SET_PRIMITIVE_FIELD(Char, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | static void SetFloatField(JNIEnv* env, jobject obj, jfieldID fid, jfloat v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1600 | SET_PRIMITIVE_FIELD(Float, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | static void SetDoubleField(JNIEnv* env, jobject obj, jfieldID fid, jdouble v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1604 | SET_PRIMITIVE_FIELD(Double, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | static void SetIntField(JNIEnv* env, jobject obj, jfieldID fid, jint v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1608 | SET_PRIMITIVE_FIELD(Int, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | static void SetLongField(JNIEnv* env, jobject obj, jfieldID fid, jlong v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1612 | SET_PRIMITIVE_FIELD(Long, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | static void SetShortField(JNIEnv* env, jobject obj, jfieldID fid, jshort v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1616 | SET_PRIMITIVE_FIELD(Short, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static void SetStaticBooleanField(JNIEnv* env, jclass, jfieldID fid, jboolean v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1620 | SET_STATIC_PRIMITIVE_FIELD(Boolean, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | static void SetStaticByteField(JNIEnv* env, jclass, jfieldID fid, jbyte v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1624 | SET_STATIC_PRIMITIVE_FIELD(Byte, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | static void SetStaticCharField(JNIEnv* env, jclass, jfieldID fid, jchar v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1628 | SET_STATIC_PRIMITIVE_FIELD(Char, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | static void SetStaticFloatField(JNIEnv* env, jclass, jfieldID fid, jfloat v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1632 | SET_STATIC_PRIMITIVE_FIELD(Float, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | static void SetStaticDoubleField(JNIEnv* env, jclass, jfieldID fid, jdouble v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1636 | SET_STATIC_PRIMITIVE_FIELD(Double, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | static void SetStaticIntField(JNIEnv* env, jclass, jfieldID fid, jint v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1640 | SET_STATIC_PRIMITIVE_FIELD(Int, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | static void SetStaticLongField(JNIEnv* env, jclass, jfieldID fid, jlong v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1644 | SET_STATIC_PRIMITIVE_FIELD(Long, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | static void SetStaticShortField(JNIEnv* env, jclass, jfieldID fid, jshort v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1648 | SET_STATIC_PRIMITIVE_FIELD(Short, v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1651 | static jobject CallStaticObjectMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1652 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1653 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1654 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1655 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1656 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1657 | jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1658 | va_end(ap); |
| 1659 | return local_result; |
| 1660 | } |
| 1661 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1662 | static jobject CallStaticObjectMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1663 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1664 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1665 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1666 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1669 | static jobject CallStaticObjectMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1670 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1671 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1672 | JValue result(InvokeWithJValues(soa, nullptr, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1673 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1676 | static jboolean CallStaticBooleanMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1677 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1678 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1679 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1680 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1681 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1682 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1683 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1686 | static jboolean CallStaticBooleanMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1687 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1688 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1689 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1692 | static jboolean CallStaticBooleanMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1693 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1694 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1695 | return InvokeWithJValues(soa, nullptr, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1698 | static jbyte CallStaticByteMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1699 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1700 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1701 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1702 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1703 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1704 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1705 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1708 | static jbyte CallStaticByteMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1709 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1710 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1711 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1714 | static jbyte CallStaticByteMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1715 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1716 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1717 | return InvokeWithJValues(soa, nullptr, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1720 | static jchar CallStaticCharMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1721 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1722 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1723 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1724 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1725 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1726 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1727 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1730 | static jchar CallStaticCharMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1731 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1732 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1733 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1736 | static jchar CallStaticCharMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1737 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1738 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1739 | return InvokeWithJValues(soa, nullptr, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1742 | static jshort CallStaticShortMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1743 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1744 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1745 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1746 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1747 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1748 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1749 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1752 | static jshort CallStaticShortMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1753 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1754 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1755 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1758 | static jshort CallStaticShortMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1759 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1760 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1761 | return InvokeWithJValues(soa, nullptr, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1764 | static jint CallStaticIntMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1765 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1766 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1767 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1768 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1769 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1770 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1771 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1774 | static jint CallStaticIntMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1775 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1776 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1777 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1780 | static jint CallStaticIntMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1781 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1782 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1783 | return InvokeWithJValues(soa, nullptr, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1786 | static jlong CallStaticLongMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1787 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1788 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1789 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1790 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1791 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1792 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1793 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1796 | static jlong CallStaticLongMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1797 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1798 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1799 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1802 | static jlong CallStaticLongMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1803 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1804 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1805 | return InvokeWithJValues(soa, nullptr, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1808 | static jfloat CallStaticFloatMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1809 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1810 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1811 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1812 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1813 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1814 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1815 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1818 | static jfloat CallStaticFloatMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1819 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1820 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1821 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1824 | static jfloat CallStaticFloatMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1825 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1826 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1827 | return InvokeWithJValues(soa, nullptr, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1830 | static jdouble CallStaticDoubleMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1831 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1832 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1833 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1834 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1835 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1836 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1837 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1840 | static jdouble CallStaticDoubleMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1841 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1842 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1843 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1846 | static jdouble CallStaticDoubleMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1847 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1848 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1849 | return InvokeWithJValues(soa, nullptr, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1852 | static void CallStaticVoidMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1853 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1854 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1855 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1856 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1857 | InvokeWithVarArgs(soa, nullptr, mid, ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1858 | va_end(ap); |
| 1859 | } |
| 1860 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1861 | static void CallStaticVoidMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1862 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1863 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1864 | InvokeWithVarArgs(soa, nullptr, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1867 | static void CallStaticVoidMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1868 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1869 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1870 | InvokeWithJValues(soa, nullptr, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1873 | static jstring NewString(JNIEnv* env, const jchar* chars, jsize char_count) { |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1874 | if (UNLIKELY(char_count < 0)) { |
| 1875 | JniAbortF("NewString", "char_count < 0: %d", char_count); |
| 1876 | return nullptr; |
| 1877 | } |
| 1878 | if (UNLIKELY(chars == nullptr && char_count > 0)) { |
| 1879 | JniAbortF("NewString", "chars == null && char_count > 0"); |
| 1880 | return nullptr; |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1881 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1882 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1883 | mirror::String* result = mirror::String::AllocFromUtf16(soa.Self(), char_count, chars); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1884 | return soa.AddLocalReference<jstring>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | static jstring NewStringUTF(JNIEnv* env, const char* utf) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1888 | if (utf == nullptr) { |
| 1889 | return nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1890 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1891 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1892 | mirror::String* result = mirror::String::AllocFromModifiedUtf8(soa.Self(), utf); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1893 | return soa.AddLocalReference<jstring>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1896 | static jsize GetStringLength(JNIEnv* env, jstring java_string) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1897 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1898 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1899 | return soa.Decode<mirror::String*>(java_string)->GetLength(); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | static jsize GetStringUTFLength(JNIEnv* env, jstring java_string) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1903 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1904 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1905 | return soa.Decode<mirror::String*>(java_string)->GetUtfLength(); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1908 | static void GetStringRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, |
| 1909 | jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1910 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1911 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1912 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1913 | if (start < 0 || length < 0 || start + length > s->GetLength()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1914 | ThrowSIOOBE(soa, start, length, s->GetLength()); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1915 | } else { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1916 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1917 | const jchar* chars = s->GetCharArray()->GetData() + s->GetOffset(); |
| 1918 | memcpy(buf, chars + start, length * sizeof(jchar)); |
| 1919 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1922 | static void GetStringUTFRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, |
| 1923 | char* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1924 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1925 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1926 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1927 | if (start < 0 || length < 0 || start + length > s->GetLength()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1928 | ThrowSIOOBE(soa, start, length, s->GetLength()); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1929 | } else { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1930 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1931 | const jchar* chars = s->GetCharArray()->GetData() + s->GetOffset(); |
| 1932 | ConvertUtf16ToModifiedUtf8(buf, chars + start, length); |
| 1933 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1936 | static const jchar* GetStringChars(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1937 | CHECK_NON_NULL_ARGUMENT(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1938 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1939 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1940 | mirror::CharArray* chars = s->GetCharArray(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1941 | PinPrimitiveArray(soa, chars); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1942 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1943 | if (heap->IsMovableObject(chars)) { |
| 1944 | if (is_copy != nullptr) { |
| 1945 | *is_copy = JNI_TRUE; |
| 1946 | } |
| 1947 | int32_t char_count = s->GetLength(); |
| 1948 | int32_t offset = s->GetOffset(); |
| 1949 | jchar* bytes = new jchar[char_count]; |
| 1950 | for (int32_t i = 0; i < char_count; i++) { |
| 1951 | bytes[i] = chars->Get(i + offset); |
| 1952 | } |
| 1953 | return bytes; |
| 1954 | } else { |
| 1955 | if (is_copy != nullptr) { |
| 1956 | *is_copy = JNI_FALSE; |
| 1957 | } |
| 1958 | return static_cast<jchar*>(chars->GetData() + s->GetOffset()); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1959 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1962 | static void ReleaseStringChars(JNIEnv* env, jstring java_string, const jchar* chars) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1963 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1964 | ScopedObjectAccess soa(env); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1965 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1966 | mirror::CharArray* s_chars = s->GetCharArray(); |
| 1967 | if (chars != (s_chars->GetData() + s->GetOffset())) { |
| 1968 | delete[] chars; |
| 1969 | } |
| 1970 | UnpinPrimitiveArray(soa, s->GetCharArray()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1973 | static const jchar* GetStringCritical(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1974 | CHECK_NON_NULL_ARGUMENT(java_string); |
| 1975 | ScopedObjectAccess soa(env); |
| 1976 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1977 | mirror::CharArray* chars = s->GetCharArray(); |
| 1978 | int32_t offset = s->GetOffset(); |
| 1979 | PinPrimitiveArray(soa, chars); |
| 1980 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1981 | if (heap->IsMovableObject(chars)) { |
| 1982 | StackHandleScope<1> hs(soa.Self()); |
| 1983 | HandleWrapper<mirror::CharArray> h(hs.NewHandleWrapper(&chars)); |
| 1984 | heap->IncrementDisableMovingGC(soa.Self()); |
| 1985 | } |
| 1986 | if (is_copy != nullptr) { |
| 1987 | *is_copy = JNI_FALSE; |
| 1988 | } |
| 1989 | return static_cast<jchar*>(chars->GetData() + offset); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1992 | static void ReleaseStringCritical(JNIEnv* env, jstring java_string, const jchar* chars) { |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1993 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
| 1994 | ScopedObjectAccess soa(env); |
| 1995 | UnpinPrimitiveArray(soa, soa.Decode<mirror::String*>(java_string)->GetCharArray()); |
| 1996 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1997 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1998 | mirror::CharArray* s_chars = s->GetCharArray(); |
| 1999 | if (heap->IsMovableObject(s_chars)) { |
| 2000 | heap->DecrementDisableMovingGC(soa.Self()); |
| 2001 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2004 | static const char* GetStringUTFChars(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2005 | if (java_string == nullptr) { |
| 2006 | return nullptr; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2007 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2008 | if (is_copy != nullptr) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2009 | *is_copy = JNI_TRUE; |
| 2010 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 2011 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2012 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2013 | size_t byte_count = s->GetUtfLength(); |
| 2014 | char* bytes = new char[byte_count + 1]; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2015 | CHECK(bytes != nullptr); // bionic aborts anyway. |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2016 | const uint16_t* chars = s->GetCharArray()->GetData() + s->GetOffset(); |
| 2017 | ConvertUtf16ToModifiedUtf8(bytes, chars, s->GetLength()); |
| 2018 | bytes[byte_count] = '\0'; |
| 2019 | return bytes; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2022 | static void ReleaseStringUTFChars(JNIEnv* env, jstring, const char* chars) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2023 | delete[] chars; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Elliott Hughes | bd93599 | 2011-08-22 11:59:34 -0700 | [diff] [blame] | 2026 | static jsize GetArrayLength(JNIEnv* env, jarray java_array) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2027 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2028 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2029 | mirror::Object* obj = soa.Decode<mirror::Object*>(java_array); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 2030 | if (UNLIKELY(!obj->IsArrayInstance())) { |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2031 | JniAbortF("GetArrayLength", "not an array: %s", PrettyTypeOf(obj).c_str()); |
| 2032 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2033 | mirror::Array* array = obj->AsArray(); |
Elliott Hughes | bd93599 | 2011-08-22 11:59:34 -0700 | [diff] [blame] | 2034 | return array->GetLength(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 2037 | static jobject GetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 2038 | CHECK_NON_NULL_ARGUMENT(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2039 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2040 | mirror::ObjectArray<mirror::Object>* array = |
| 2041 | soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2042 | return soa.AddLocalReference<jobject>(array->Get(index)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2045 | static void SetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index, |
| 2046 | jobject java_value) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2047 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2048 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2049 | mirror::ObjectArray<mirror::Object>* array = |
| 2050 | soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); |
| 2051 | mirror::Object* value = soa.Decode<mirror::Object*>(java_value); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 2052 | array->Set<false>(index, value); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | static jbooleanArray NewBooleanArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2056 | return NewPrimitiveArray<jbooleanArray, mirror::BooleanArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | static jbyteArray NewByteArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2060 | return NewPrimitiveArray<jbyteArray, mirror::ByteArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | static jcharArray NewCharArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2064 | return NewPrimitiveArray<jcharArray, mirror::CharArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | static jdoubleArray NewDoubleArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2068 | return NewPrimitiveArray<jdoubleArray, mirror::DoubleArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | static jfloatArray NewFloatArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2072 | return NewPrimitiveArray<jfloatArray, mirror::FloatArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | static jintArray NewIntArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2076 | return NewPrimitiveArray<jintArray, mirror::IntArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | static jlongArray NewLongArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2080 | return NewPrimitiveArray<jlongArray, mirror::LongArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2083 | static jobjectArray NewObjectArray(JNIEnv* env, jsize length, jclass element_jclass, |
| 2084 | jobject initial_element) { |
| 2085 | if (UNLIKELY(length < 0)) { |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2086 | JniAbortF("NewObjectArray", "negative array length: %d", length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2087 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2088 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2089 | CHECK_NON_NULL_ARGUMENT(element_jclass); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2090 | |
| 2091 | // Compute the array class corresponding to the given element class. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 2092 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2093 | mirror::Class* array_class; |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2094 | { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2095 | mirror::Class* element_class = soa.Decode<mirror::Class*>(element_jclass); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2096 | if (UNLIKELY(element_class->IsPrimitive())) { |
| 2097 | JniAbortF("NewObjectArray", "not an object type: %s", |
| 2098 | PrettyDescriptor(element_class).c_str()); |
| 2099 | return nullptr; |
| 2100 | } |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2101 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | b74cd29 | 2014-05-29 14:31:33 -0700 | [diff] [blame] | 2102 | array_class = class_linker->FindArrayClass(soa.Self(), &element_class); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2103 | if (UNLIKELY(array_class == nullptr)) { |
| 2104 | return nullptr; |
| 2105 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2108 | // Allocate and initialize if necessary. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2109 | mirror::ObjectArray<mirror::Object>* result = |
| 2110 | mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), array_class, length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2111 | if (result != nullptr && initial_element != nullptr) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2112 | mirror::Object* initial_object = soa.Decode<mirror::Object*>(initial_element); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2113 | if (initial_object != nullptr) { |
| 2114 | mirror::Class* element_class = result->GetClass()->GetComponentType(); |
| 2115 | if (UNLIKELY(!element_class->IsAssignableFrom(initial_object->GetClass()))) { |
| 2116 | JniAbortF("NewObjectArray", "cannot assign object of type '%s' to array with element " |
| 2117 | "type of '%s'", PrettyDescriptor(initial_object->GetClass()).c_str(), |
| 2118 | PrettyDescriptor(element_class).c_str()); |
| 2119 | |
| 2120 | } else { |
| 2121 | for (jsize i = 0; i < length; ++i) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 2122 | result->SetWithoutChecks<false>(i, initial_object); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2123 | } |
| 2124 | } |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2125 | } |
| 2126 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2127 | return soa.AddLocalReference<jobjectArray>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | static jshortArray NewShortArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2131 | return NewPrimitiveArray<jshortArray, mirror::ShortArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 2134 | static void* GetPrimitiveArrayCritical(JNIEnv* env, jarray java_array, jboolean* is_copy) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 2135 | CHECK_NON_NULL_ARGUMENT(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2136 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2137 | mirror::Array* array = soa.Decode<mirror::Array*>(java_array); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2138 | if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) { |
| 2139 | JniAbortF("GetPrimitiveArrayCritical", "expected primitive array, given %s", |
| 2140 | PrettyDescriptor(array->GetClass()).c_str()); |
| 2141 | return nullptr; |
| 2142 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2143 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 2144 | if (heap->IsMovableObject(array)) { |
Mathieu Chartier | 1d27b34 | 2014-01-28 12:51:09 -0800 | [diff] [blame] | 2145 | heap->IncrementDisableMovingGC(soa.Self()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2146 | // Re-decode in case the object moved since IncrementDisableGC waits for GC to complete. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2147 | array = soa.Decode<mirror::Array*>(java_array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2148 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2149 | PinPrimitiveArray(soa, array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2150 | if (is_copy != nullptr) { |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 2151 | *is_copy = JNI_FALSE; |
| 2152 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2153 | return array->GetRawData(array->GetClass()->GetComponentSize(), 0); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2156 | static void ReleasePrimitiveArrayCritical(JNIEnv* env, jarray java_array, void* elements, |
| 2157 | jint mode) { |
| 2158 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 2159 | ScopedObjectAccess soa(env); |
| 2160 | mirror::Array* array = soa.Decode<mirror::Array*>(java_array); |
| 2161 | if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) { |
| 2162 | JniAbortF("ReleasePrimitiveArrayCritical", "expected primitive array, given %s", |
| 2163 | PrettyDescriptor(array->GetClass()).c_str()); |
| 2164 | return; |
| 2165 | } |
| 2166 | const size_t component_size = array->GetClass()->GetComponentSize(); |
| 2167 | ReleasePrimitiveArray(soa, array, component_size, elements, mode); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2170 | static jboolean* GetBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2171 | return GetPrimitiveArray<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2174 | static jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2175 | return GetPrimitiveArray<jbyteArray, jbyte, mirror::ByteArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2178 | static jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2179 | return GetPrimitiveArray<jcharArray, jchar, mirror::CharArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2182 | static jdouble* GetDoubleArrayElements(JNIEnv* env, jdoubleArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2183 | return GetPrimitiveArray<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2186 | static jfloat* GetFloatArrayElements(JNIEnv* env, jfloatArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2187 | return GetPrimitiveArray<jfloatArray, jfloat, mirror::FloatArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2190 | static jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2191 | return GetPrimitiveArray<jintArray, jint, mirror::IntArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2194 | static jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2195 | return GetPrimitiveArray<jlongArray, jlong, mirror::LongArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2198 | static jshort* GetShortArrayElements(JNIEnv* env, jshortArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2199 | return GetPrimitiveArray<jshortArray, jshort, mirror::ShortArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2202 | static void ReleaseBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* elements, |
| 2203 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2204 | ReleasePrimitiveArray<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, elements, |
| 2205 | mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2208 | static void ReleaseByteArrayElements(JNIEnv* env, jbyteArray array, jbyte* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2209 | ReleasePrimitiveArray<jbyteArray, jbyte, mirror::ByteArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2212 | static void ReleaseCharArrayElements(JNIEnv* env, jcharArray array, jchar* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2213 | ReleasePrimitiveArray<jcharArray, jchar, mirror::CharArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2216 | static void ReleaseDoubleArrayElements(JNIEnv* env, jdoubleArray array, jdouble* elements, |
| 2217 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2218 | ReleasePrimitiveArray<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2221 | static void ReleaseFloatArrayElements(JNIEnv* env, jfloatArray array, jfloat* elements, |
| 2222 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2223 | ReleasePrimitiveArray<jfloatArray, jfloat, mirror::FloatArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2226 | static void ReleaseIntArrayElements(JNIEnv* env, jintArray array, jint* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2227 | ReleasePrimitiveArray<jintArray, jint, mirror::IntArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2230 | static void ReleaseLongArrayElements(JNIEnv* env, jlongArray array, jlong* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2231 | ReleasePrimitiveArray<jlongArray, jlong, mirror::LongArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2232 | } |
| 2233 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2234 | static void ReleaseShortArrayElements(JNIEnv* env, jshortArray array, jshort* elements, |
| 2235 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2236 | ReleasePrimitiveArray<jshortArray, jshort, mirror::ShortArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2239 | static void GetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize length, |
| 2240 | jboolean* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2241 | GetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, start, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2242 | length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2245 | static void GetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize length, |
| 2246 | jbyte* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2247 | GetPrimitiveArrayRegion<jbyteArray, jbyte, mirror::ByteArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2250 | static void GetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize length, |
| 2251 | jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2252 | GetPrimitiveArrayRegion<jcharArray, jchar, mirror::CharArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2255 | static void GetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize length, |
| 2256 | jdouble* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2257 | GetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2258 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2261 | static void GetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize length, |
| 2262 | jfloat* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2263 | GetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2264 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2267 | static void GetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize length, |
| 2268 | jint* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2269 | GetPrimitiveArrayRegion<jintArray, jint, mirror::IntArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2272 | static void GetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize length, |
| 2273 | jlong* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2274 | GetPrimitiveArrayRegion<jlongArray, jlong, mirror::LongArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2277 | static void GetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize length, |
| 2278 | jshort* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2279 | GetPrimitiveArrayRegion<jshortArray, jshort, mirror::ShortArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2280 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2283 | static void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize length, |
| 2284 | const jboolean* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2285 | SetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, start, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2286 | length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2289 | static void SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize length, |
| 2290 | const jbyte* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2291 | SetPrimitiveArrayRegion<jbyteArray, jbyte, mirror::ByteArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2294 | static void SetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize length, |
| 2295 | const jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2296 | SetPrimitiveArrayRegion<jcharArray, jchar, mirror::CharArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2299 | static void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize length, |
| 2300 | const jdouble* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2301 | SetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, start, length, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2302 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2305 | static void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize length, |
| 2306 | const jfloat* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2307 | SetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(env, array, start, length, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2308 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2311 | static void SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize length, |
| 2312 | const jint* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2313 | SetPrimitiveArrayRegion<jintArray, jint, mirror::IntArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2316 | static void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize length, |
| 2317 | const jlong* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2318 | SetPrimitiveArrayRegion<jlongArray, jlong, mirror::LongArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2321 | static void SetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize length, |
| 2322 | const jshort* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2323 | SetPrimitiveArrayRegion<jshortArray, jshort, mirror::ShortArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2324 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2327 | static jint RegisterNatives(JNIEnv* env, jclass java_class, const JNINativeMethod* methods, |
| 2328 | jint method_count) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2329 | return RegisterNativeMethods(env, java_class, methods, method_count, true); |
| 2330 | } |
| 2331 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2332 | static jint RegisterNativeMethods(JNIEnv* env, jclass java_class, const JNINativeMethod* methods, |
| 2333 | jint method_count, bool return_errors) { |
| 2334 | if (UNLIKELY(method_count < 0)) { |
Elliott Hughes | aa836f7 | 2013-08-20 16:57:23 -0700 | [diff] [blame] | 2335 | JniAbortF("RegisterNatives", "negative method count: %d", method_count); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2336 | return JNI_ERR; // Not reached. |
| 2337 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2338 | CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", java_class, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2339 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2340 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2341 | if (UNLIKELY(method_count == 0)) { |
| 2342 | LOG(WARNING) << "JNI RegisterNativeMethods: attempt to register 0 native methods for " |
| 2343 | << PrettyDescriptor(c); |
| 2344 | return JNI_OK; |
| 2345 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2346 | CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", methods, JNI_ERR); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2347 | for (jint i = 0; i < method_count; ++i) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2348 | const char* name = methods[i].name; |
| 2349 | const char* sig = methods[i].signature; |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 2350 | bool is_fast = false; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2351 | if (*sig == '!') { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 2352 | is_fast = true; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2353 | ++sig; |
| 2354 | } |
| 2355 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2356 | mirror::ArtMethod* m = c->FindDirectMethod(name, sig); |
| 2357 | if (m == nullptr) { |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2358 | m = c->FindVirtualMethod(name, sig); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2359 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2360 | if (m == nullptr) { |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 2361 | c->DumpClass(LOG(ERROR), mirror::Class::kDumpClassFullDetail); |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2362 | LOG(return_errors ? ERROR : FATAL) << "Failed to register native method " |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 2363 | << PrettyDescriptor(c) << "." << name << sig << " in " |
| 2364 | << c->GetDexCache()->GetLocation()->ToModifiedUtf8(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2365 | ThrowNoSuchMethodError(soa, c, name, sig, "static or non-static"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2366 | return JNI_ERR; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2367 | } else if (!m->IsNative()) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2368 | LOG(return_errors ? ERROR : FATAL) << "Failed to register non-native method " |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2369 | << PrettyDescriptor(c) << "." << name << sig |
| 2370 | << " as native"; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2371 | ThrowNoSuchMethodError(soa, c, name, sig, "native"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2372 | return JNI_ERR; |
| 2373 | } |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2374 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 2375 | VLOG(jni) << "[Registering JNI native method " << PrettyMethod(m) << "]"; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2376 | |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 2377 | m->RegisterNative(soa.Self(), methods[i].fnPtr, is_fast); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2378 | } |
| 2379 | return JNI_OK; |
| 2380 | } |
| 2381 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2382 | static jint UnregisterNatives(JNIEnv* env, jclass java_class) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2383 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2384 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2385 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2386 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 2387 | VLOG(jni) << "[Unregistering JNI native methods for " << PrettyClass(c) << "]"; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2388 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2389 | size_t unregistered_count = 0; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2390 | for (size_t i = 0; i < c->NumDirectMethods(); ++i) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2391 | mirror::ArtMethod* m = c->GetDirectMethod(i); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2392 | if (m->IsNative()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2393 | m->UnregisterNative(soa.Self()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2394 | unregistered_count++; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2395 | } |
| 2396 | } |
| 2397 | for (size_t i = 0; i < c->NumVirtualMethods(); ++i) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2398 | mirror::ArtMethod* m = c->GetVirtualMethod(i); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2399 | if (m->IsNative()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2400 | m->UnregisterNative(soa.Self()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2401 | unregistered_count++; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2402 | } |
| 2403 | } |
| 2404 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2405 | if (unregistered_count == 0) { |
| 2406 | LOG(WARNING) << "JNI UnregisterNatives: attempt to unregister native methods of class '" |
| 2407 | << PrettyDescriptor(c) << "' that contains no native methods"; |
| 2408 | } |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2409 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 2412 | static jint MonitorEnter(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2413 | CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2414 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2415 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
| 2416 | o = o->MonitorEnter(soa.Self()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2417 | if (soa.Self()->IsExceptionPending()) { |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2418 | return JNI_ERR; |
| 2419 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2420 | soa.Env()->monitors.Add(o); |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2421 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 2424 | static jint MonitorExit(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2425 | CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2426 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2427 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2428 | o->MonitorExit(soa.Self()); |
| 2429 | if (soa.Self()->IsExceptionPending()) { |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2430 | return JNI_ERR; |
| 2431 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2432 | soa.Env()->monitors.Remove(o); |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2433 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | static jint GetJavaVM(JNIEnv* env, JavaVM** vm) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2437 | CHECK_NON_NULL_ARGUMENT_RETURN(vm, JNI_ERR); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2438 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2439 | if (runtime != nullptr) { |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 2440 | *vm = runtime->GetJavaVM(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2441 | } else { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2442 | *vm = nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2443 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2444 | return (*vm != nullptr) ? JNI_OK : JNI_ERR; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2447 | static jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) { |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2448 | if (capacity < 0) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2449 | JniAbortF("NewDirectByteBuffer", "negative buffer capacity: %" PRId64, capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame^] | 2450 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2451 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2452 | if (address == nullptr && capacity != 0) { |
| 2453 | JniAbortF("NewDirectByteBuffer", "non-zero capacity for nullptr pointer: %" PRId64, capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame^] | 2454 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2455 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2456 | |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame^] | 2457 | // At the moment, the capacity is limited to a jint (31 bits). |
| 2458 | if (capacity > INT_MAX) { |
| 2459 | JniAbortF("NewDirectByteBuffer", "buffer capacity greater than maximum jint: %" PRId64, capacity); |
| 2460 | return nullptr; |
| 2461 | } |
Elliott Hughes | b568121 | 2013-03-29 17:29:22 -0700 | [diff] [blame] | 2462 | jlong address_arg = reinterpret_cast<jlong>(address); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2463 | jint capacity_arg = static_cast<jint>(capacity); |
| 2464 | |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 2465 | jobject result = env->NewObject(WellKnownClasses::java_nio_DirectByteBuffer, |
| 2466 | WellKnownClasses::java_nio_DirectByteBuffer_init, |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 2467 | address_arg, capacity_arg); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2468 | return static_cast<JNIEnvExt*>(env)->self->IsExceptionPending() ? nullptr : result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2471 | static void* GetDirectBufferAddress(JNIEnv* env, jobject java_buffer) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2472 | return reinterpret_cast<void*>(env->GetLongField( |
| 2473 | java_buffer, WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2476 | static jlong GetDirectBufferCapacity(JNIEnv* env, jobject java_buffer) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2477 | return static_cast<jlong>(env->GetIntField( |
| 2478 | java_buffer, WellKnownClasses::java_nio_DirectByteBuffer_capacity)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2481 | static jobjectRefType GetObjectRefType(JNIEnv* env, jobject java_object) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2482 | CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNIInvalidRefType); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2483 | |
| 2484 | // Do we definitely know what kind of reference this is? |
| 2485 | IndirectRef ref = reinterpret_cast<IndirectRef>(java_object); |
| 2486 | IndirectRefKind kind = GetIndirectRefKind(ref); |
| 2487 | switch (kind) { |
Mathieu Chartier | c645f1d | 2014-03-06 18:11:53 -0800 | [diff] [blame] | 2488 | case kLocal: { |
| 2489 | ScopedObjectAccess soa(env); |
Hiroshi Yamauchi | 196851b | 2014-05-29 12:16:04 -0700 | [diff] [blame] | 2490 | // The local refs don't need a read barrier. |
| 2491 | if (static_cast<JNIEnvExt*>(env)->locals.Get<kWithoutReadBarrier>(ref) != |
| 2492 | kInvalidIndirectRefObject) { |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 2493 | return JNILocalRefType; |
| 2494 | } |
| 2495 | return JNIInvalidRefType; |
Mathieu Chartier | c645f1d | 2014-03-06 18:11:53 -0800 | [diff] [blame] | 2496 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2497 | case kGlobal: |
| 2498 | return JNIGlobalRefType; |
| 2499 | case kWeakGlobal: |
| 2500 | return JNIWeakGlobalRefType; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2501 | case kHandleScopeOrInvalid: |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2502 | // Is it in a stack IRT? |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2503 | if (static_cast<JNIEnvExt*>(env)->self->HandleScopeContains(java_object)) { |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2504 | return JNILocalRefType; |
| 2505 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2506 | return JNIInvalidRefType; |
| 2507 | } |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 2508 | LOG(FATAL) << "IndirectRefKind[" << kind << "]"; |
| 2509 | return JNIInvalidRefType; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2510 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2511 | |
| 2512 | private: |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 2513 | static jint EnsureLocalCapacity(ScopedObjectAccess& soa, jint desired_capacity, |
| 2514 | const char* caller) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2515 | // TODO: we should try to expand the table if necessary. |
Elliott Hughes | aa836f7 | 2013-08-20 16:57:23 -0700 | [diff] [blame] | 2516 | if (desired_capacity < 0 || desired_capacity > static_cast<jint>(kLocalsMax)) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2517 | LOG(ERROR) << "Invalid capacity given to " << caller << ": " << desired_capacity; |
| 2518 | return JNI_ERR; |
| 2519 | } |
| 2520 | // TODO: this isn't quite right, since "capacity" includes holes. |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 2521 | const size_t capacity = soa.Env()->locals.Capacity(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2522 | bool okay = (static_cast<jint>(kLocalsMax - capacity) >= desired_capacity); |
| 2523 | if (!okay) { |
| 2524 | soa.Self()->ThrowOutOfMemoryError(caller); |
| 2525 | } |
| 2526 | return okay ? JNI_OK : JNI_ERR; |
| 2527 | } |
| 2528 | |
| 2529 | template<typename JniT, typename ArtT> |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2530 | static JniT NewPrimitiveArray(JNIEnv* env, jsize length) { |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2531 | if (UNLIKELY(length < 0)) { |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2532 | JniAbortF("NewPrimitiveArray", "negative array length: %d", length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2533 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2534 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2535 | ScopedObjectAccess soa(env); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 2536 | ArtT* result = ArtT::Alloc(soa.Self(), length); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2537 | return soa.AddLocalReference<JniT>(result); |
| 2538 | } |
| 2539 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2540 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2541 | static ArtArrayT* DecodeAndCheckArrayType(ScopedObjectAccess& soa, JArrayT java_array, |
| 2542 | const char* fn_name, const char* operation) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 2543 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2544 | ArtArrayT* array = soa.Decode<ArtArrayT*>(java_array); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2545 | if (UNLIKELY(ArtArrayT::GetArrayClass() != array->GetClass())) { |
| 2546 | JniAbortF(fn_name, "attempt to %s %s primitive array elements with an object of type %s", |
| 2547 | operation, PrettyDescriptor(ArtArrayT::GetArrayClass()->GetComponentType()).c_str(), |
| 2548 | PrettyDescriptor(array->GetClass()).c_str()); |
| 2549 | return nullptr; |
| 2550 | } |
| 2551 | DCHECK_EQ(sizeof(ElementT), array->GetClass()->GetComponentSize()); |
| 2552 | return array; |
| 2553 | } |
| 2554 | |
| 2555 | template <typename ArrayT, typename ElementT, typename ArtArrayT> |
| 2556 | static ElementT* GetPrimitiveArray(JNIEnv* env, ArrayT java_array, jboolean* is_copy) { |
| 2557 | CHECK_NON_NULL_ARGUMENT(java_array); |
| 2558 | ScopedObjectAccess soa(env); |
| 2559 | ArtArrayT* array = DecodeAndCheckArrayType<ArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2560 | "GetArrayElements", |
| 2561 | "get"); |
| 2562 | if (UNLIKELY(array == nullptr)) { |
| 2563 | return nullptr; |
| 2564 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2565 | PinPrimitiveArray(soa, array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2566 | // Only make a copy if necessary. |
| 2567 | if (Runtime::Current()->GetHeap()->IsMovableObject(array)) { |
| 2568 | if (is_copy != nullptr) { |
| 2569 | *is_copy = JNI_TRUE; |
| 2570 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2571 | const size_t component_size = sizeof(ElementT); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2572 | size_t size = array->GetLength() * component_size; |
| 2573 | void* data = new uint64_t[RoundUp(size, 8) / 8]; |
| 2574 | memcpy(data, array->GetData(), size); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2575 | return reinterpret_cast<ElementT*>(data); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2576 | } else { |
| 2577 | if (is_copy != nullptr) { |
| 2578 | *is_copy = JNI_FALSE; |
| 2579 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2580 | return reinterpret_cast<ElementT*>(array->GetData()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2581 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2584 | template <typename ArrayT, typename ElementT, typename ArtArrayT> |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2585 | static void ReleasePrimitiveArray(JNIEnv* env, ArrayT java_array, ElementT* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2586 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2587 | ScopedObjectAccess soa(env); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2588 | ArtArrayT* array = DecodeAndCheckArrayType<ArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2589 | "ReleaseArrayElements", |
| 2590 | "release"); |
| 2591 | if (array == nullptr) { |
| 2592 | return; |
| 2593 | } |
| 2594 | ReleasePrimitiveArray(soa, array, sizeof(ElementT), elements, mode); |
| 2595 | } |
| 2596 | |
| 2597 | static void ReleasePrimitiveArray(ScopedObjectAccess& soa, mirror::Array* array, |
| 2598 | size_t component_size, void* elements, jint mode) |
| 2599 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2600 | void* array_data = array->GetRawData(component_size, 0); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2601 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2602 | bool is_copy = array_data != elements; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2603 | size_t bytes = array->GetLength() * component_size; |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2604 | VLOG(heap) << "Release primitive array " << soa.Env() << " array_data " << array_data |
| 2605 | << " elements " << elements; |
Mathieu Chartier | d68ac70 | 2014-02-11 14:50:51 -0800 | [diff] [blame] | 2606 | if (is_copy) { |
| 2607 | // Sanity check: If elements is not the same as the java array's data, it better not be a |
| 2608 | // heap address. TODO: This might be slow to check, may be worth keeping track of which |
| 2609 | // copies we make? |
| 2610 | if (heap->IsNonDiscontinuousSpaceHeapAddress(reinterpret_cast<mirror::Object*>(elements))) { |
| 2611 | JniAbortF("ReleaseArrayElements", "invalid element pointer %p, array elements are %p", |
| 2612 | reinterpret_cast<void*>(elements), array_data); |
| 2613 | return; |
| 2614 | } |
| 2615 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2616 | // Don't need to copy if we had a direct pointer. |
| 2617 | if (mode != JNI_ABORT && is_copy) { |
| 2618 | memcpy(array_data, elements, bytes); |
| 2619 | } |
| 2620 | if (mode != JNI_COMMIT) { |
| 2621 | if (is_copy) { |
| 2622 | delete[] reinterpret_cast<uint64_t*>(elements); |
Mathieu Chartier | 3e8b2e1 | 2014-01-19 17:17:26 -0800 | [diff] [blame] | 2623 | } else if (heap->IsMovableObject(array)) { |
Mathieu Chartier | 1d27b34 | 2014-01-28 12:51:09 -0800 | [diff] [blame] | 2624 | // Non copy to a movable object must means that we had disabled the moving GC. |
| 2625 | heap->DecrementDisableMovingGC(soa.Self()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2626 | } |
Mathieu Chartier | 3e8b2e1 | 2014-01-19 17:17:26 -0800 | [diff] [blame] | 2627 | UnpinPrimitiveArray(soa, array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2628 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2629 | } |
| 2630 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2631 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2632 | static void GetPrimitiveArrayRegion(JNIEnv* env, JArrayT java_array, |
| 2633 | jsize start, jsize length, ElementT* buf) { |
| 2634 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 2635 | ScopedObjectAccess soa(env); |
| 2636 | ArtArrayT* array = |
| 2637 | DecodeAndCheckArrayType<JArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2638 | "GetPrimitiveArrayRegion", |
| 2639 | "get region of"); |
| 2640 | if (array != nullptr) { |
| 2641 | if (start < 0 || length < 0 || start + length > array->GetLength()) { |
| 2642 | ThrowAIOOBE(soa, array, start, length, "src"); |
| 2643 | } else { |
| 2644 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
| 2645 | ElementT* data = array->GetData(); |
| 2646 | memcpy(buf, data + start, length * sizeof(ElementT)); |
| 2647 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2651 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2652 | static void SetPrimitiveArrayRegion(JNIEnv* env, JArrayT java_array, |
| 2653 | jsize start, jsize length, const ElementT* buf) { |
| 2654 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 2655 | ScopedObjectAccess soa(env); |
| 2656 | ArtArrayT* array = |
| 2657 | DecodeAndCheckArrayType<JArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2658 | "SetPrimitiveArrayRegion", |
| 2659 | "set region of"); |
| 2660 | if (array != nullptr) { |
| 2661 | if (start < 0 || length < 0 || start + length > array->GetLength()) { |
| 2662 | ThrowAIOOBE(soa, array, start, length, "dst"); |
| 2663 | } else { |
| 2664 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
| 2665 | ElementT* data = array->GetData(); |
| 2666 | memcpy(data + start, buf, length * sizeof(ElementT)); |
| 2667 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2668 | } |
| 2669 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2670 | }; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 2671 | |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 2672 | const JNINativeInterface gJniNativeInterface = { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2673 | nullptr, // reserved0. |
| 2674 | nullptr, // reserved1. |
| 2675 | nullptr, // reserved2. |
| 2676 | nullptr, // reserved3. |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2677 | JNI::GetVersion, |
| 2678 | JNI::DefineClass, |
| 2679 | JNI::FindClass, |
| 2680 | JNI::FromReflectedMethod, |
| 2681 | JNI::FromReflectedField, |
| 2682 | JNI::ToReflectedMethod, |
| 2683 | JNI::GetSuperclass, |
| 2684 | JNI::IsAssignableFrom, |
| 2685 | JNI::ToReflectedField, |
| 2686 | JNI::Throw, |
| 2687 | JNI::ThrowNew, |
| 2688 | JNI::ExceptionOccurred, |
| 2689 | JNI::ExceptionDescribe, |
| 2690 | JNI::ExceptionClear, |
| 2691 | JNI::FatalError, |
| 2692 | JNI::PushLocalFrame, |
| 2693 | JNI::PopLocalFrame, |
| 2694 | JNI::NewGlobalRef, |
| 2695 | JNI::DeleteGlobalRef, |
| 2696 | JNI::DeleteLocalRef, |
| 2697 | JNI::IsSameObject, |
| 2698 | JNI::NewLocalRef, |
| 2699 | JNI::EnsureLocalCapacity, |
| 2700 | JNI::AllocObject, |
| 2701 | JNI::NewObject, |
| 2702 | JNI::NewObjectV, |
| 2703 | JNI::NewObjectA, |
| 2704 | JNI::GetObjectClass, |
| 2705 | JNI::IsInstanceOf, |
| 2706 | JNI::GetMethodID, |
| 2707 | JNI::CallObjectMethod, |
| 2708 | JNI::CallObjectMethodV, |
| 2709 | JNI::CallObjectMethodA, |
| 2710 | JNI::CallBooleanMethod, |
| 2711 | JNI::CallBooleanMethodV, |
| 2712 | JNI::CallBooleanMethodA, |
| 2713 | JNI::CallByteMethod, |
| 2714 | JNI::CallByteMethodV, |
| 2715 | JNI::CallByteMethodA, |
| 2716 | JNI::CallCharMethod, |
| 2717 | JNI::CallCharMethodV, |
| 2718 | JNI::CallCharMethodA, |
| 2719 | JNI::CallShortMethod, |
| 2720 | JNI::CallShortMethodV, |
| 2721 | JNI::CallShortMethodA, |
| 2722 | JNI::CallIntMethod, |
| 2723 | JNI::CallIntMethodV, |
| 2724 | JNI::CallIntMethodA, |
| 2725 | JNI::CallLongMethod, |
| 2726 | JNI::CallLongMethodV, |
| 2727 | JNI::CallLongMethodA, |
| 2728 | JNI::CallFloatMethod, |
| 2729 | JNI::CallFloatMethodV, |
| 2730 | JNI::CallFloatMethodA, |
| 2731 | JNI::CallDoubleMethod, |
| 2732 | JNI::CallDoubleMethodV, |
| 2733 | JNI::CallDoubleMethodA, |
| 2734 | JNI::CallVoidMethod, |
| 2735 | JNI::CallVoidMethodV, |
| 2736 | JNI::CallVoidMethodA, |
| 2737 | JNI::CallNonvirtualObjectMethod, |
| 2738 | JNI::CallNonvirtualObjectMethodV, |
| 2739 | JNI::CallNonvirtualObjectMethodA, |
| 2740 | JNI::CallNonvirtualBooleanMethod, |
| 2741 | JNI::CallNonvirtualBooleanMethodV, |
| 2742 | JNI::CallNonvirtualBooleanMethodA, |
| 2743 | JNI::CallNonvirtualByteMethod, |
| 2744 | JNI::CallNonvirtualByteMethodV, |
| 2745 | JNI::CallNonvirtualByteMethodA, |
| 2746 | JNI::CallNonvirtualCharMethod, |
| 2747 | JNI::CallNonvirtualCharMethodV, |
| 2748 | JNI::CallNonvirtualCharMethodA, |
| 2749 | JNI::CallNonvirtualShortMethod, |
| 2750 | JNI::CallNonvirtualShortMethodV, |
| 2751 | JNI::CallNonvirtualShortMethodA, |
| 2752 | JNI::CallNonvirtualIntMethod, |
| 2753 | JNI::CallNonvirtualIntMethodV, |
| 2754 | JNI::CallNonvirtualIntMethodA, |
| 2755 | JNI::CallNonvirtualLongMethod, |
| 2756 | JNI::CallNonvirtualLongMethodV, |
| 2757 | JNI::CallNonvirtualLongMethodA, |
| 2758 | JNI::CallNonvirtualFloatMethod, |
| 2759 | JNI::CallNonvirtualFloatMethodV, |
| 2760 | JNI::CallNonvirtualFloatMethodA, |
| 2761 | JNI::CallNonvirtualDoubleMethod, |
| 2762 | JNI::CallNonvirtualDoubleMethodV, |
| 2763 | JNI::CallNonvirtualDoubleMethodA, |
| 2764 | JNI::CallNonvirtualVoidMethod, |
| 2765 | JNI::CallNonvirtualVoidMethodV, |
| 2766 | JNI::CallNonvirtualVoidMethodA, |
| 2767 | JNI::GetFieldID, |
| 2768 | JNI::GetObjectField, |
| 2769 | JNI::GetBooleanField, |
| 2770 | JNI::GetByteField, |
| 2771 | JNI::GetCharField, |
| 2772 | JNI::GetShortField, |
| 2773 | JNI::GetIntField, |
| 2774 | JNI::GetLongField, |
| 2775 | JNI::GetFloatField, |
| 2776 | JNI::GetDoubleField, |
| 2777 | JNI::SetObjectField, |
| 2778 | JNI::SetBooleanField, |
| 2779 | JNI::SetByteField, |
| 2780 | JNI::SetCharField, |
| 2781 | JNI::SetShortField, |
| 2782 | JNI::SetIntField, |
| 2783 | JNI::SetLongField, |
| 2784 | JNI::SetFloatField, |
| 2785 | JNI::SetDoubleField, |
| 2786 | JNI::GetStaticMethodID, |
| 2787 | JNI::CallStaticObjectMethod, |
| 2788 | JNI::CallStaticObjectMethodV, |
| 2789 | JNI::CallStaticObjectMethodA, |
| 2790 | JNI::CallStaticBooleanMethod, |
| 2791 | JNI::CallStaticBooleanMethodV, |
| 2792 | JNI::CallStaticBooleanMethodA, |
| 2793 | JNI::CallStaticByteMethod, |
| 2794 | JNI::CallStaticByteMethodV, |
| 2795 | JNI::CallStaticByteMethodA, |
| 2796 | JNI::CallStaticCharMethod, |
| 2797 | JNI::CallStaticCharMethodV, |
| 2798 | JNI::CallStaticCharMethodA, |
| 2799 | JNI::CallStaticShortMethod, |
| 2800 | JNI::CallStaticShortMethodV, |
| 2801 | JNI::CallStaticShortMethodA, |
| 2802 | JNI::CallStaticIntMethod, |
| 2803 | JNI::CallStaticIntMethodV, |
| 2804 | JNI::CallStaticIntMethodA, |
| 2805 | JNI::CallStaticLongMethod, |
| 2806 | JNI::CallStaticLongMethodV, |
| 2807 | JNI::CallStaticLongMethodA, |
| 2808 | JNI::CallStaticFloatMethod, |
| 2809 | JNI::CallStaticFloatMethodV, |
| 2810 | JNI::CallStaticFloatMethodA, |
| 2811 | JNI::CallStaticDoubleMethod, |
| 2812 | JNI::CallStaticDoubleMethodV, |
| 2813 | JNI::CallStaticDoubleMethodA, |
| 2814 | JNI::CallStaticVoidMethod, |
| 2815 | JNI::CallStaticVoidMethodV, |
| 2816 | JNI::CallStaticVoidMethodA, |
| 2817 | JNI::GetStaticFieldID, |
| 2818 | JNI::GetStaticObjectField, |
| 2819 | JNI::GetStaticBooleanField, |
| 2820 | JNI::GetStaticByteField, |
| 2821 | JNI::GetStaticCharField, |
| 2822 | JNI::GetStaticShortField, |
| 2823 | JNI::GetStaticIntField, |
| 2824 | JNI::GetStaticLongField, |
| 2825 | JNI::GetStaticFloatField, |
| 2826 | JNI::GetStaticDoubleField, |
| 2827 | JNI::SetStaticObjectField, |
| 2828 | JNI::SetStaticBooleanField, |
| 2829 | JNI::SetStaticByteField, |
| 2830 | JNI::SetStaticCharField, |
| 2831 | JNI::SetStaticShortField, |
| 2832 | JNI::SetStaticIntField, |
| 2833 | JNI::SetStaticLongField, |
| 2834 | JNI::SetStaticFloatField, |
| 2835 | JNI::SetStaticDoubleField, |
| 2836 | JNI::NewString, |
| 2837 | JNI::GetStringLength, |
| 2838 | JNI::GetStringChars, |
| 2839 | JNI::ReleaseStringChars, |
| 2840 | JNI::NewStringUTF, |
| 2841 | JNI::GetStringUTFLength, |
| 2842 | JNI::GetStringUTFChars, |
| 2843 | JNI::ReleaseStringUTFChars, |
| 2844 | JNI::GetArrayLength, |
| 2845 | JNI::NewObjectArray, |
| 2846 | JNI::GetObjectArrayElement, |
| 2847 | JNI::SetObjectArrayElement, |
| 2848 | JNI::NewBooleanArray, |
| 2849 | JNI::NewByteArray, |
| 2850 | JNI::NewCharArray, |
| 2851 | JNI::NewShortArray, |
| 2852 | JNI::NewIntArray, |
| 2853 | JNI::NewLongArray, |
| 2854 | JNI::NewFloatArray, |
| 2855 | JNI::NewDoubleArray, |
| 2856 | JNI::GetBooleanArrayElements, |
| 2857 | JNI::GetByteArrayElements, |
| 2858 | JNI::GetCharArrayElements, |
| 2859 | JNI::GetShortArrayElements, |
| 2860 | JNI::GetIntArrayElements, |
| 2861 | JNI::GetLongArrayElements, |
| 2862 | JNI::GetFloatArrayElements, |
| 2863 | JNI::GetDoubleArrayElements, |
| 2864 | JNI::ReleaseBooleanArrayElements, |
| 2865 | JNI::ReleaseByteArrayElements, |
| 2866 | JNI::ReleaseCharArrayElements, |
| 2867 | JNI::ReleaseShortArrayElements, |
| 2868 | JNI::ReleaseIntArrayElements, |
| 2869 | JNI::ReleaseLongArrayElements, |
| 2870 | JNI::ReleaseFloatArrayElements, |
| 2871 | JNI::ReleaseDoubleArrayElements, |
| 2872 | JNI::GetBooleanArrayRegion, |
| 2873 | JNI::GetByteArrayRegion, |
| 2874 | JNI::GetCharArrayRegion, |
| 2875 | JNI::GetShortArrayRegion, |
| 2876 | JNI::GetIntArrayRegion, |
| 2877 | JNI::GetLongArrayRegion, |
| 2878 | JNI::GetFloatArrayRegion, |
| 2879 | JNI::GetDoubleArrayRegion, |
| 2880 | JNI::SetBooleanArrayRegion, |
| 2881 | JNI::SetByteArrayRegion, |
| 2882 | JNI::SetCharArrayRegion, |
| 2883 | JNI::SetShortArrayRegion, |
| 2884 | JNI::SetIntArrayRegion, |
| 2885 | JNI::SetLongArrayRegion, |
| 2886 | JNI::SetFloatArrayRegion, |
| 2887 | JNI::SetDoubleArrayRegion, |
| 2888 | JNI::RegisterNatives, |
| 2889 | JNI::UnregisterNatives, |
| 2890 | JNI::MonitorEnter, |
| 2891 | JNI::MonitorExit, |
| 2892 | JNI::GetJavaVM, |
| 2893 | JNI::GetStringRegion, |
| 2894 | JNI::GetStringUTFRegion, |
| 2895 | JNI::GetPrimitiveArrayCritical, |
| 2896 | JNI::ReleasePrimitiveArrayCritical, |
| 2897 | JNI::GetStringCritical, |
| 2898 | JNI::ReleaseStringCritical, |
| 2899 | JNI::NewWeakGlobalRef, |
| 2900 | JNI::DeleteWeakGlobalRef, |
| 2901 | JNI::ExceptionCheck, |
| 2902 | JNI::NewDirectByteBuffer, |
| 2903 | JNI::GetDirectBufferAddress, |
| 2904 | JNI::GetDirectBufferCapacity, |
| 2905 | JNI::GetObjectRefType, |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 2906 | }; |
| 2907 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2908 | JNIEnvExt::JNIEnvExt(Thread* self, JavaVMExt* vm) |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 2909 | : self(self), |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2910 | vm(vm), |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 2911 | local_ref_cookie(IRT_FIRST_SEGMENT), |
| 2912 | locals(kLocalsInitial, kLocalsMax, kLocal), |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 2913 | check_jni(false), |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 2914 | critical(0), |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 2915 | monitors("monitors", kMonitorsInitial, kMonitorsMax) { |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 2916 | functions = unchecked_functions = &gJniNativeInterface; |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 2917 | if (vm->check_jni) { |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 2918 | SetCheckJniEnabled(true); |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 2919 | } |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 2922 | JNIEnvExt::~JNIEnvExt() { |
| 2923 | } |
| 2924 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2925 | jobject JNIEnvExt::NewLocalRef(mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 2926 | if (obj == nullptr) { |
| 2927 | return nullptr; |
| 2928 | } |
| 2929 | return reinterpret_cast<jobject>(locals.Add(local_ref_cookie, obj)); |
| 2930 | } |
| 2931 | |
| 2932 | void JNIEnvExt::DeleteLocalRef(jobject obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 2933 | if (obj != nullptr) { |
| 2934 | locals.Remove(local_ref_cookie, reinterpret_cast<IndirectRef>(obj)); |
| 2935 | } |
| 2936 | } |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 2937 | void JNIEnvExt::SetCheckJniEnabled(bool enabled) { |
| 2938 | check_jni = enabled; |
| 2939 | functions = enabled ? GetCheckJniNativeInterface() : &gJniNativeInterface; |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 2942 | void JNIEnvExt::DumpReferenceTables(std::ostream& os) { |
| 2943 | locals.Dump(os); |
| 2944 | monitors.Dump(os); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 2947 | void JNIEnvExt::PushFrame(int capacity) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 2948 | UNUSED(capacity); // cpplint gets confused with (int) and thinks its a cast. |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 2949 | // TODO: take 'capacity' into account. |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 2950 | stacked_local_ref_cookies.push_back(local_ref_cookie); |
| 2951 | local_ref_cookie = locals.GetSegmentState(); |
| 2952 | } |
| 2953 | |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 2954 | void JNIEnvExt::PopFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 2955 | locals.SetSegmentState(local_ref_cookie); |
| 2956 | local_ref_cookie = stacked_local_ref_cookies.back(); |
| 2957 | stacked_local_ref_cookies.pop_back(); |
| 2958 | } |
| 2959 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 2960 | Offset JNIEnvExt::SegmentStateOffset() { |
| 2961 | return Offset(OFFSETOF_MEMBER(JNIEnvExt, locals) + |
| 2962 | IndirectReferenceTable::SegmentStateOffset().Int32Value()); |
| 2963 | } |
| 2964 | |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 2965 | // JNI Invocation interface. |
| 2966 | |
Brian Carlstrom | bddf976 | 2013-05-14 11:35:37 -0700 | [diff] [blame] | 2967 | extern "C" jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args) { |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2968 | const JavaVMInitArgs* args = static_cast<JavaVMInitArgs*>(vm_args); |
Elliott Hughes | 83a2532 | 2013-03-14 11:18:53 -0700 | [diff] [blame] | 2969 | if (IsBadJniVersion(args->version)) { |
| 2970 | LOG(ERROR) << "Bad JNI version passed to CreateJavaVM: " << args->version; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2971 | return JNI_EVERSION; |
| 2972 | } |
| 2973 | Runtime::Options options; |
| 2974 | for (int i = 0; i < args->nOptions; ++i) { |
| 2975 | JavaVMOption* option = &args->options[i]; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 2976 | options.push_back(std::make_pair(std::string(option->optionString), option->extraInfo)); |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2977 | } |
| 2978 | bool ignore_unrecognized = args->ignoreUnrecognized; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2979 | if (!Runtime::Create(options, ignore_unrecognized)) { |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2980 | return JNI_ERR; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2981 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2982 | Runtime* runtime = Runtime::Current(); |
Brian Carlstrom | bd86bcc | 2013-03-10 20:26:16 -0700 | [diff] [blame] | 2983 | bool started = runtime->Start(); |
| 2984 | if (!started) { |
| 2985 | delete Thread::Current()->GetJniEnv(); |
| 2986 | delete runtime->GetJavaVM(); |
| 2987 | LOG(WARNING) << "CreateJavaVM failed"; |
| 2988 | return JNI_ERR; |
| 2989 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 2990 | *p_env = Thread::Current()->GetJniEnv(); |
| 2991 | *p_vm = runtime->GetJavaVM(); |
| 2992 | return JNI_OK; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 2995 | extern "C" jint JNI_GetCreatedJavaVMs(JavaVM** vms, jsize, jsize* vm_count) { |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2996 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2997 | if (runtime == nullptr) { |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 2998 | *vm_count = 0; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 2999 | } else { |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 3000 | *vm_count = 1; |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 3001 | vms[0] = runtime->GetJavaVM(); |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 3002 | } |
| 3003 | return JNI_OK; |
| 3004 | } |
| 3005 | |
| 3006 | // Historically unsupported. |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 3007 | extern "C" jint JNI_GetDefaultJavaVMInitArgs(void* /*vm_args*/) { |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 3008 | return JNI_ERR; |
| 3009 | } |
| 3010 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3011 | class JII { |
| 3012 | public: |
| 3013 | static jint DestroyJavaVM(JavaVM* vm) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3014 | if (vm == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3015 | return JNI_ERR; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3016 | } |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 3017 | JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm); |
| 3018 | delete raw_vm->runtime; |
| 3019 | return JNI_OK; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 3020 | } |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 3021 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3022 | static jint AttachCurrentThread(JavaVM* vm, JNIEnv** p_env, void* thr_args) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 3023 | return JII_AttachCurrentThread(vm, p_env, thr_args, false); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | static jint AttachCurrentThreadAsDaemon(JavaVM* vm, JNIEnv** p_env, void* thr_args) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 3027 | return JII_AttachCurrentThread(vm, p_env, thr_args, true); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | static jint DetachCurrentThread(JavaVM* vm) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3031 | if (vm == nullptr || Thread::Current() == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3032 | return JNI_ERR; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3033 | } |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 3034 | JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm); |
| 3035 | Runtime* runtime = raw_vm->runtime; |
| 3036 | runtime->DetachCurrentThread(); |
| 3037 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | static jint GetEnv(JavaVM* vm, void** env, jint version) { |
Elliott Hughes | 3b7ffa1 | 2013-09-06 15:57:08 -0700 | [diff] [blame] | 3041 | // GetEnv always returns a JNIEnv* for the most current supported JNI version, |
| 3042 | // and unlike other calls that take a JNI version doesn't care if you supply |
| 3043 | // JNI_VERSION_1_1, which we don't otherwise support. |
| 3044 | if (IsBadJniVersion(version) && version != JNI_VERSION_1_1) { |
Elliott Hughes | 83a2532 | 2013-03-14 11:18:53 -0700 | [diff] [blame] | 3045 | LOG(ERROR) << "Bad JNI version passed to GetEnv: " << version; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3046 | return JNI_EVERSION; |
| 3047 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3048 | if (vm == nullptr || env == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3049 | return JNI_ERR; |
| 3050 | } |
| 3051 | Thread* thread = Thread::Current(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3052 | if (thread == nullptr) { |
| 3053 | *env = nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3054 | return JNI_EDETACHED; |
| 3055 | } |
| 3056 | *env = thread->GetJniEnv(); |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 3057 | return JNI_OK; |
| 3058 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3059 | }; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 3060 | |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 3061 | const JNIInvokeInterface gJniInvokeInterface = { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3062 | nullptr, // reserved0 |
| 3063 | nullptr, // reserved1 |
| 3064 | nullptr, // reserved2 |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3065 | JII::DestroyJavaVM, |
| 3066 | JII::AttachCurrentThread, |
| 3067 | JII::DetachCurrentThread, |
| 3068 | JII::GetEnv, |
| 3069 | JII::AttachCurrentThreadAsDaemon |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 3070 | }; |
| 3071 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 3072 | JavaVMExt::JavaVMExt(Runtime* runtime, ParsedOptions* options) |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 3073 | : runtime(runtime), |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3074 | check_jni_abort_hook(nullptr), |
| 3075 | check_jni_abort_hook_data(nullptr), |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 3076 | check_jni(false), |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 3077 | force_copy(false), // TODO: add a way to enable this |
Elliott Hughes | a095764 | 2011-09-02 14:27:33 -0700 | [diff] [blame] | 3078 | trace(options->jni_trace_), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 3079 | pins_lock("JNI pin table lock", kPinTableLock), |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 3080 | pin_table("pin table", kPinTableInitial, kPinTableMax), |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 3081 | globals_lock("JNI global reference table lock"), |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 3082 | globals(gGlobalsInitial, gGlobalsMax, kGlobal), |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3083 | libraries_lock("JNI shared libraries map lock", kLoadLibraryLock), |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 3084 | libraries(new Libraries), |
| 3085 | weak_globals_lock_("JNI weak global reference table lock"), |
| 3086 | weak_globals_(kWeakGlobalsInitial, kWeakGlobalsMax, kWeakGlobal), |
| 3087 | allow_new_weak_globals_(true), |
| 3088 | weak_globals_add_condition_("weak globals add condition", weak_globals_lock_) { |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 3089 | functions = unchecked_functions = &gJniInvokeInterface; |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 3090 | if (options->check_jni_) { |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 3091 | SetCheckJniEnabled(true); |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 3092 | } |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
Elliott Hughes | de69d7f | 2011-08-18 16:49:37 -0700 | [diff] [blame] | 3095 | JavaVMExt::~JavaVMExt() { |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3096 | delete libraries; |
Elliott Hughes | de69d7f | 2011-08-18 16:49:37 -0700 | [diff] [blame] | 3097 | } |
| 3098 | |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 3099 | jweak JavaVMExt::AddWeakGlobalReference(Thread* self, mirror::Object* obj) { |
| 3100 | if (obj == nullptr) { |
| 3101 | return nullptr; |
| 3102 | } |
| 3103 | MutexLock mu(self, weak_globals_lock_); |
| 3104 | while (UNLIKELY(!allow_new_weak_globals_)) { |
| 3105 | weak_globals_add_condition_.WaitHoldingLocks(self); |
| 3106 | } |
| 3107 | IndirectRef ref = weak_globals_.Add(IRT_FIRST_SEGMENT, obj); |
| 3108 | return reinterpret_cast<jweak>(ref); |
| 3109 | } |
| 3110 | |
| 3111 | void JavaVMExt::DeleteWeakGlobalRef(Thread* self, jweak obj) { |
| 3112 | MutexLock mu(self, weak_globals_lock_); |
| 3113 | if (!weak_globals_.Remove(IRT_FIRST_SEGMENT, obj)) { |
| 3114 | LOG(WARNING) << "JNI WARNING: DeleteWeakGlobalRef(" << obj << ") " |
| 3115 | << "failed to find entry"; |
| 3116 | } |
| 3117 | } |
| 3118 | |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 3119 | void JavaVMExt::SetCheckJniEnabled(bool enabled) { |
| 3120 | check_jni = enabled; |
| 3121 | functions = enabled ? GetCheckJniInvokeInterface() : &gJniInvokeInterface; |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 3124 | void JavaVMExt::DumpForSigQuit(std::ostream& os) { |
| 3125 | os << "JNI: CheckJNI is " << (check_jni ? "on" : "off"); |
| 3126 | if (force_copy) { |
| 3127 | os << " (with forcecopy)"; |
| 3128 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3129 | Thread* self = Thread::Current(); |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 3130 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3131 | MutexLock mu(self, pins_lock); |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 3132 | os << "; pins=" << pin_table.Size(); |
| 3133 | } |
| 3134 | { |
Ian Rogers | b8a0b94 | 2013-08-20 18:09:52 -0700 | [diff] [blame] | 3135 | ReaderMutexLock mu(self, globals_lock); |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 3136 | os << "; globals=" << globals.Capacity(); |
| 3137 | } |
| 3138 | { |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 3139 | MutexLock mu(self, weak_globals_lock_); |
| 3140 | if (weak_globals_.Capacity() > 0) { |
| 3141 | os << " (plus " << weak_globals_.Capacity() << " weak)"; |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | os << '\n'; |
| 3145 | |
| 3146 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3147 | MutexLock mu(self, libraries_lock); |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 3148 | os << "Libraries: " << Dumpable<Libraries>(*libraries) << " (" << libraries->size() << ")\n"; |
| 3149 | } |
| 3150 | } |
| 3151 | |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 3152 | void JavaVMExt::DisallowNewWeakGlobals() { |
| 3153 | MutexLock mu(Thread::Current(), weak_globals_lock_); |
| 3154 | allow_new_weak_globals_ = false; |
| 3155 | } |
| 3156 | |
| 3157 | void JavaVMExt::AllowNewWeakGlobals() { |
| 3158 | Thread* self = Thread::Current(); |
| 3159 | MutexLock mu(self, weak_globals_lock_); |
| 3160 | allow_new_weak_globals_ = true; |
| 3161 | weak_globals_add_condition_.Broadcast(self); |
| 3162 | } |
| 3163 | |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 3164 | mirror::Object* JavaVMExt::DecodeWeakGlobal(Thread* self, IndirectRef ref) { |
| 3165 | MutexLock mu(self, weak_globals_lock_); |
| 3166 | while (UNLIKELY(!allow_new_weak_globals_)) { |
| 3167 | weak_globals_add_condition_.WaitHoldingLocks(self); |
| 3168 | } |
Hiroshi Yamauchi | ea2e1bd | 2014-06-18 13:47:35 -0700 | [diff] [blame] | 3169 | return weak_globals_.Get(ref); |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 3170 | } |
| 3171 | |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 3172 | void JavaVMExt::DumpReferenceTables(std::ostream& os) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3173 | Thread* self = Thread::Current(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 3174 | { |
Ian Rogers | b8a0b94 | 2013-08-20 18:09:52 -0700 | [diff] [blame] | 3175 | ReaderMutexLock mu(self, globals_lock); |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 3176 | globals.Dump(os); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 3177 | } |
| 3178 | { |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 3179 | MutexLock mu(self, weak_globals_lock_); |
| 3180 | weak_globals_.Dump(os); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 3181 | } |
| 3182 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3183 | MutexLock mu(self, pins_lock); |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 3184 | pin_table.Dump(os); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 3185 | } |
| 3186 | } |
| 3187 | |
Mathieu Chartier | 055d46c | 2014-02-06 11:22:17 -0800 | [diff] [blame] | 3188 | bool JavaVMExt::LoadNativeLibrary(const std::string& path, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 3189 | Handle<mirror::ClassLoader> class_loader, |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 3190 | std::string* detail) { |
| 3191 | detail->clear(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3192 | |
| 3193 | // See if we've already loaded this library. If we have, and the class loader |
| 3194 | // matches, return successfully without doing anything. |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 3195 | // TODO: for better results we should canonicalize the pathname (or even compare |
| 3196 | // inodes). This implementation is fine if everybody is using System.loadLibrary. |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3197 | SharedLibrary* library; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3198 | Thread* self = Thread::Current(); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3199 | { |
| 3200 | // TODO: move the locking (and more of this logic) into Libraries. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3201 | MutexLock mu(self, libraries_lock); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3202 | library = libraries->Get(path); |
| 3203 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3204 | if (library != nullptr) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3205 | if (library->GetClassLoader() != class_loader.Get()) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 3206 | // The library will be associated with class_loader. The JNI |
| 3207 | // spec says we can't load the same library into more than one |
| 3208 | // class loader. |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 3209 | StringAppendF(detail, "Shared library \"%s\" already opened by " |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 3210 | "ClassLoader %p; can't open in ClassLoader %p", |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3211 | path.c_str(), library->GetClassLoader(), class_loader.Get()); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 3212 | LOG(WARNING) << detail; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3213 | return false; |
| 3214 | } |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 3215 | VLOG(jni) << "[Shared library \"" << path << "\" already loaded in " |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3216 | << "ClassLoader " << class_loader.Get() << "]"; |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 3217 | if (!library->CheckOnLoadResult()) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 3218 | StringAppendF(detail, "JNI_OnLoad failed on a previous attempt " |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 3219 | "to load \"%s\"", path.c_str()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3220 | return false; |
| 3221 | } |
| 3222 | return true; |
| 3223 | } |
| 3224 | |
| 3225 | // Open the shared library. Because we're using a full path, the system |
| 3226 | // doesn't have to search through LD_LIBRARY_PATH. (It may do so to |
| 3227 | // resolve this library's dependencies though.) |
| 3228 | |
| 3229 | // Failures here are expected when java.library.path has several entries |
| 3230 | // and we have to hunt for the lib. |
| 3231 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3232 | // Below we dlopen but there is no paired dlclose, this would be necessary if we supported |
| 3233 | // class unloading. Libraries will only be unloaded when the reference count (incremented by |
| 3234 | // dlopen) becomes zero from dlclose. |
| 3235 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3236 | // This can execute slowly for a large library on a busy system, so we |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3237 | // want to switch from kRunnable while it executes. This allows the GC to ignore us. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3238 | self->TransitionFromRunnableToSuspended(kWaitingForJniOnLoad); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3239 | void* handle = dlopen(path.empty() ? nullptr : path.c_str(), RTLD_LAZY); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3240 | self->TransitionFromSuspendedToRunnable(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3241 | |
Elliott Hughes | 84b2f14 | 2012-09-27 09:16:28 -0700 | [diff] [blame] | 3242 | VLOG(jni) << "[Call to dlopen(\"" << path << "\", RTLD_LAZY) returned " << handle << "]"; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3243 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3244 | if (handle == nullptr) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 3245 | *detail = dlerror(); |
Colin Cross | 35d5c3b | 2014-04-23 14:56:31 -0700 | [diff] [blame] | 3246 | LOG(ERROR) << "dlopen(\"" << path << "\", RTLD_LAZY) failed: " << *detail; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3247 | return false; |
| 3248 | } |
| 3249 | |
| 3250 | // Create a new entry. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3251 | // TODO: move the locking (and more of this logic) into Libraries. |
| 3252 | bool created_library = false; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3253 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3254 | MutexLock mu(self, libraries_lock); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3255 | library = libraries->Get(path); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3256 | if (library == nullptr) { // We won race to get libraries_lock |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3257 | library = new SharedLibrary(path, handle, class_loader.Get()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3258 | libraries->Put(path, library); |
| 3259 | created_library = true; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3260 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3261 | } |
| 3262 | if (!created_library) { |
| 3263 | LOG(INFO) << "WOW: we lost a race to add shared library: " |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3264 | << "\"" << path << "\" ClassLoader=" << class_loader.Get(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 3265 | return library->CheckOnLoadResult(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3266 | } |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3267 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3268 | VLOG(jni) << "[Added shared library \"" << path << "\" for ClassLoader " << class_loader.Get() |
Mathieu Chartier | 055d46c | 2014-02-06 11:22:17 -0800 | [diff] [blame] | 3269 | << "]"; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3270 | |
Elliott Hughes | 7935372 | 2013-08-02 16:52:18 -0700 | [diff] [blame] | 3271 | bool was_successful = false; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3272 | void* sym = dlsym(handle, "JNI_OnLoad"); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3273 | if (sym == nullptr) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 3274 | VLOG(jni) << "[No JNI_OnLoad found in \"" << path << "\"]"; |
Elliott Hughes | 85affca | 2013-08-02 17:48:52 -0700 | [diff] [blame] | 3275 | was_successful = true; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3276 | } else { |
| 3277 | // Call JNI_OnLoad. We have to override the current class |
| 3278 | // loader, which will always be "null" since the stuff at the |
| 3279 | // top of the stack is around Runtime.loadLibrary(). (See |
| 3280 | // the comments in the JNI FindClass function.) |
| 3281 | typedef int (*JNI_OnLoadFn)(JavaVM*, void*); |
| 3282 | JNI_OnLoadFn jni_on_load = reinterpret_cast<JNI_OnLoadFn>(sym); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3283 | StackHandleScope<1> hs(self); |
| 3284 | Handle<mirror::ClassLoader> old_class_loader(hs.NewHandle(self->GetClassLoaderOverride())); |
| 3285 | self->SetClassLoaderOverride(class_loader.Get()); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3286 | |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 3287 | int version = 0; |
| 3288 | { |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 3289 | ScopedThreadStateChange tsc(self, kNative); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 3290 | VLOG(jni) << "[Calling JNI_OnLoad in \"" << path << "\"]"; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3291 | version = (*jni_on_load)(this, nullptr); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3292 | } |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3293 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 3294 | self->SetClassLoaderOverride(old_class_loader.Get()); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3295 | |
Elliott Hughes | 7935372 | 2013-08-02 16:52:18 -0700 | [diff] [blame] | 3296 | if (version == JNI_ERR) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 3297 | StringAppendF(detail, "JNI_ERR returned from JNI_OnLoad in \"%s\"", path.c_str()); |
Elliott Hughes | 7935372 | 2013-08-02 16:52:18 -0700 | [diff] [blame] | 3298 | } else if (IsBadJniVersion(version)) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 3299 | StringAppendF(detail, "Bad JNI version returned from JNI_OnLoad in \"%s\": %d", |
Brian Carlstrom | 75fe90c | 2013-06-26 22:26:16 -0700 | [diff] [blame] | 3300 | path.c_str(), version); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3301 | // It's unwise to call dlclose() here, but we can mark it |
| 3302 | // as bad and ensure that future load attempts will fail. |
| 3303 | // We don't know how far JNI_OnLoad got, so there could |
| 3304 | // be some partially-initialized stuff accessible through |
| 3305 | // newly-registered native method calls. We could try to |
| 3306 | // unregister them, but that doesn't seem worthwhile. |
Elliott Hughes | 7935372 | 2013-08-02 16:52:18 -0700 | [diff] [blame] | 3307 | } else { |
| 3308 | was_successful = true; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3309 | } |
Elliott Hughes | 7935372 | 2013-08-02 16:52:18 -0700 | [diff] [blame] | 3310 | VLOG(jni) << "[Returned " << (was_successful ? "successfully" : "failure") |
Brian Carlstrom | 75fe90c | 2013-06-26 22:26:16 -0700 | [diff] [blame] | 3311 | << " from JNI_OnLoad in \"" << path << "\"]"; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
Elliott Hughes | 7935372 | 2013-08-02 16:52:18 -0700 | [diff] [blame] | 3314 | library->SetResult(was_successful); |
| 3315 | return was_successful; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3318 | void* JavaVMExt::FindCodeForNativeMethod(mirror::ArtMethod* m) { |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3319 | CHECK(m->IsNative()); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3320 | mirror::Class* c = m->GetDeclaringClass(); |
Ian Rogers | 6c5cb21 | 2014-06-18 16:07:20 -0700 | [diff] [blame] | 3321 | // If this is a static method, it could be called before the class has been initialized. |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3322 | if (m->IsStatic()) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 3323 | c = EnsureInitialized(Thread::Current(), c); |
| 3324 | if (c == nullptr) { |
| 3325 | return nullptr; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3326 | } |
| 3327 | } else { |
Ian Rogers | b8a0b94 | 2013-08-20 18:09:52 -0700 | [diff] [blame] | 3328 | CHECK(c->IsInitializing()) << c->GetStatus() << " " << PrettyMethod(m); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 3329 | } |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 3330 | std::string detail; |
| 3331 | void* native_method; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3332 | Thread* self = Thread::Current(); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 3333 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3334 | MutexLock mu(self, libraries_lock); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 3335 | native_method = libraries->FindNativeMethod(m, detail); |
| 3336 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 3337 | // Throwing can cause libraries_lock to be reacquired. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3338 | if (native_method == nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 3339 | ThrowLocation throw_location = self->GetCurrentLocationForThrow(); |
| 3340 | self->ThrowNewException(throw_location, "Ljava/lang/UnsatisfiedLinkError;", detail.c_str()); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 3341 | } |
| 3342 | return native_method; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 3345 | void JavaVMExt::SweepJniWeakGlobals(IsMarkedCallback* callback, void* arg) { |
Mathieu Chartier | 810b1d7 | 2013-09-20 14:02:02 -0700 | [diff] [blame] | 3346 | MutexLock mu(Thread::Current(), weak_globals_lock_); |
| 3347 | for (mirror::Object** entry : weak_globals_) { |
Hiroshi Yamauchi | 196851b | 2014-05-29 12:16:04 -0700 | [diff] [blame] | 3348 | // Since this is called by the GC, we don't need a read barrier. |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 3349 | mirror::Object* obj = *entry; |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 3350 | mirror::Object* new_obj = callback(obj, arg); |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 3351 | if (new_obj == nullptr) { |
| 3352 | new_obj = kClearedJniWeakGlobal; |
| 3353 | } |
| 3354 | *entry = new_obj; |
| 3355 | } |
| 3356 | } |
| 3357 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 3358 | void JavaVMExt::VisitRoots(RootCallback* callback, void* arg) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3359 | Thread* self = Thread::Current(); |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 3360 | { |
Ian Rogers | b8a0b94 | 2013-08-20 18:09:52 -0700 | [diff] [blame] | 3361 | ReaderMutexLock mu(self, globals_lock); |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 3362 | globals.VisitRoots(callback, arg, 0, kRootJNIGlobal); |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 3363 | } |
| 3364 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 3365 | MutexLock mu(self, pins_lock); |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 3366 | pin_table.VisitRoots(callback, arg, 0, kRootVMInternal); |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 3367 | } |
Mathieu Chartier | 8f4be93 | 2014-01-28 15:25:19 -0800 | [diff] [blame] | 3368 | { |
| 3369 | MutexLock mu(self, libraries_lock); |
| 3370 | // Libraries contains shared libraries which hold a pointer to a class loader. |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 3371 | libraries->VisitRoots(callback, arg); |
Mathieu Chartier | 8f4be93 | 2014-01-28 15:25:19 -0800 | [diff] [blame] | 3372 | } |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 3373 | // The weak_globals table is visited by the GC itself (because it mutates the table). |
| 3374 | } |
| 3375 | |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 3376 | void RegisterNativeMethods(JNIEnv* env, const char* jni_class_name, const JNINativeMethod* methods, |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 3377 | jint method_count) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 3378 | ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name)); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3379 | if (c.get() == nullptr) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 3380 | LOG(FATAL) << "Couldn't find class: " << jni_class_name; |
| 3381 | } |
| 3382 | JNI::RegisterNativeMethods(env, c.get(), methods, method_count, false); |
| 3383 | } |
| 3384 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 3385 | } // namespace art |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 3386 | |
| 3387 | std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs) { |
| 3388 | switch (rhs) { |
| 3389 | case JNIInvalidRefType: |
| 3390 | os << "JNIInvalidRefType"; |
| 3391 | return os; |
| 3392 | case JNILocalRefType: |
| 3393 | os << "JNILocalRefType"; |
| 3394 | return os; |
| 3395 | case JNIGlobalRefType: |
| 3396 | os << "JNIGlobalRefType"; |
| 3397 | return os; |
| 3398 | case JNIWeakGlobalRefType: |
| 3399 | os << "JNIWeakGlobalRefType"; |
| 3400 | return os; |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 3401 | default: |
Shih-wei Liao | 24782c6 | 2012-01-08 12:46:11 -0800 | [diff] [blame] | 3402 | LOG(FATAL) << "jobjectRefType[" << static_cast<int>(rhs) << "]"; |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 3403 | return os; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 3404 | } |
| 3405 | } |