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" |
Mathieu Chartier | bad0267 | 2014-08-25 13:08:22 -0700 | [diff] [blame] | 27 | #include "base/allocator.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 28 | #include "base/logging.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 29 | #include "base/mutex.h" |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 30 | #include "base/stl_util.h" |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 31 | #include "class_linker-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 32 | #include "dex_file-inl.h" |
Mathieu Chartier | d000480 | 2014-10-15 16:59:47 -0700 | [diff] [blame] | 33 | #include "fault_handler.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 34 | #include "gc_root.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 35 | #include "gc/accounting/card_table-inl.h" |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 36 | #include "indirect_reference_table-inl.h" |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 37 | #include "interpreter/interpreter.h" |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 38 | #include "jni_env_ext.h" |
| 39 | #include "java_vm_ext.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 40 | #include "mirror/art_field-inl.h" |
| 41 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | #include "mirror/class-inl.h" |
| 43 | #include "mirror/class_loader.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | #include "mirror/object-inl.h" |
| 45 | #include "mirror/object_array-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 46 | #include "mirror/string-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | #include "mirror/throwable.h" |
jgu21 | 6d03104 | 2014-09-10 06:57:17 -0400 | [diff] [blame] | 48 | #include "nativebridge/native_bridge.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 49 | #include "parsed_options.h" |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 50 | #include "reflection.h" |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 51 | #include "runtime.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 52 | #include "safe_map.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 53 | #include "scoped_thread_state_change.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 54 | #include "ScopedLocalRef.h" |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 55 | #include "thread.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 56 | #include "utf.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 57 | #include "well_known_classes.h" |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 58 | |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 59 | namespace art { |
| 60 | |
Mathieu Chartier | 24555ad | 2014-10-06 13:41:33 -0700 | [diff] [blame] | 61 | // Consider turning this on when there is errors which could be related to JNI array copies such as |
| 62 | // things not rendering correctly. E.g. b/16858794 |
| 63 | static constexpr bool kWarnJniAbort = false; |
| 64 | |
Elliott Hughes | 6b43685 | 2011-08-12 10:16:44 -0700 | [diff] [blame] | 65 | // Section 12.3.2 of the JNI spec describes JNI class descriptors. They're |
| 66 | // separated with slashes but aren't wrapped with "L;" like regular descriptors |
| 67 | // (i.e. "a/b/C" rather than "La/b/C;"). Arrays of reference types are an |
| 68 | // exception; there the "L;" must be present ("[La/b/C;"). Historically we've |
| 69 | // supported names with dots too (such as "a.b.C"). |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 70 | static std::string NormalizeJniClassDescriptor(const char* name) { |
Elliott Hughes | 6b43685 | 2011-08-12 10:16:44 -0700 | [diff] [blame] | 71 | std::string result; |
| 72 | // Add the missing "L;" if necessary. |
| 73 | if (name[0] == '[') { |
| 74 | result = name; |
| 75 | } else { |
| 76 | result += 'L'; |
| 77 | result += name; |
| 78 | result += ';'; |
| 79 | } |
| 80 | // Rewrite '.' as '/' for backwards compatibility. |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 81 | if (result.find('.') != std::string::npos) { |
| 82 | LOG(WARNING) << "Call to JNI FindClass with dots in name: " |
| 83 | << "\"" << name << "\""; |
| 84 | std::replace(result.begin(), result.end(), '.', '/'); |
Elliott Hughes | 6b43685 | 2011-08-12 10:16:44 -0700 | [diff] [blame] | 85 | } |
| 86 | return result; |
| 87 | } |
| 88 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 89 | static void ThrowNoSuchMethodError(ScopedObjectAccess& soa, mirror::Class* c, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 90 | const char* name, const char* sig, const char* kind) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 91 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 92 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 93 | std::string temp; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 94 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchMethodError;", |
| 95 | "no %s method \"%s.%s%s\"", |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 96 | kind, c->GetDescriptor(&temp), name, sig); |
Elliott Hughes | 14134a1 | 2011-09-30 16:55:51 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Sebastien Hertz | fa65e84 | 2014-07-03 09:39:53 +0200 | [diff] [blame] | 99 | static void ReportInvalidJNINativeMethod(const ScopedObjectAccess& soa, mirror::Class* c, |
| 100 | const char* kind, jint idx, bool return_errors) |
| 101 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 102 | LOG(return_errors ? ERROR : FATAL) << "Failed to register native method in " |
| 103 | << PrettyDescriptor(c) << " in " << c->GetDexCache()->GetLocation()->ToModifiedUtf8() |
| 104 | << ": " << kind << " is null at index " << idx; |
| 105 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 106 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchMethodError;", |
| 107 | "%s is null at index %d", kind, idx); |
| 108 | } |
| 109 | |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 110 | static mirror::Class* EnsureInitialized(Thread* self, mirror::Class* klass) |
| 111 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 112 | if (LIKELY(klass->IsInitialized())) { |
| 113 | return klass; |
| 114 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 115 | StackHandleScope<1> hs(self); |
| 116 | Handle<mirror::Class> h_klass(hs.NewHandle(klass)); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 117 | if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_klass, true, true)) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 118 | return nullptr; |
| 119 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 120 | return h_klass.Get(); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 123 | static jmethodID FindMethodID(ScopedObjectAccess& soa, jclass jni_class, |
| 124 | const char* name, const char* sig, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 125 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 126 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(jni_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 127 | if (c == nullptr) { |
| 128 | return nullptr; |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 129 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 130 | mirror::ArtMethod* method = nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 131 | if (is_static) { |
| 132 | method = c->FindDirectMethod(name, sig); |
Brian Carlstrom | 004644f | 2014-06-18 08:34:01 -0700 | [diff] [blame] | 133 | } else if (c->IsInterface()) { |
| 134 | method = c->FindInterfaceMethod(name, sig); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 135 | } else { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 136 | method = c->FindVirtualMethod(name, sig); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 137 | if (method == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 138 | // No virtual method matching the signature. Search declared |
| 139 | // private methods and constructors. |
| 140 | method = c->FindDeclaredDirectMethod(name, sig); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 141 | } |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 142 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 143 | if (method == nullptr || method->IsStatic() != is_static) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 144 | ThrowNoSuchMethodError(soa, c, name, sig, is_static ? "static" : "non-static"); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 145 | return nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 146 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 147 | return soa.EncodeMethod(method); |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 150 | static mirror::ClassLoader* GetClassLoader(const ScopedObjectAccess& soa) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 151 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 152 | mirror::ArtMethod* method = soa.Self()->GetCurrentMethod(nullptr); |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 153 | // If we are running Runtime.nativeLoad, use the overriding ClassLoader it set. |
| 154 | if (method == soa.DecodeMethod(WellKnownClasses::java_lang_Runtime_nativeLoad)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 155 | return soa.Decode<mirror::ClassLoader*>(soa.Self()->GetClassLoaderOverride()); |
Brian Carlstrom | 00fae58 | 2011-10-28 01:16:28 -0700 | [diff] [blame] | 156 | } |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 157 | // If we have a method, use its ClassLoader for context. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 158 | if (method != nullptr) { |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 159 | return method->GetDeclaringClass()->GetClassLoader(); |
| 160 | } |
| 161 | // 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] | 162 | mirror::ClassLoader* class_loader = |
| 163 | soa.Decode<mirror::ClassLoader*>(Runtime::Current()->GetSystemClassLoader()); |
| 164 | if (class_loader != nullptr) { |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 165 | return class_loader; |
| 166 | } |
| 167 | // See if the override ClassLoader is set for gtests. |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 168 | class_loader = soa.Decode<mirror::ClassLoader*>(soa.Self()->GetClassLoaderOverride()); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 169 | if (class_loader != nullptr) { |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 170 | // If so, CommonCompilerTest should have set UseCompileTimeClassPath. |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 171 | CHECK(Runtime::Current()->UseCompileTimeClassPath()); |
| 172 | return class_loader; |
| 173 | } |
| 174 | // Use the BOOTCLASSPATH. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 175 | return nullptr; |
Brian Carlstrom | 00fae58 | 2011-10-28 01:16:28 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 178 | static jfieldID FindFieldID(const ScopedObjectAccess& soa, jclass jni_class, const char* name, |
| 179 | const char* sig, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 180 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 181 | StackHandleScope<2> hs(soa.Self()); |
| 182 | Handle<mirror::Class> c( |
| 183 | hs.NewHandle(EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(jni_class)))); |
| 184 | if (c.Get() == nullptr) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 185 | return nullptr; |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 186 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 187 | mirror::ArtField* field = nullptr; |
| 188 | mirror::Class* field_type; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 189 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 190 | if (sig[1] != '\0') { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 191 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(c->GetClassLoader())); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 192 | field_type = class_linker->FindClass(soa.Self(), sig, class_loader); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 193 | } else { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 194 | field_type = class_linker->FindPrimitiveClass(*sig); |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 195 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 196 | if (field_type == nullptr) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 197 | // Failed to find type from the signature of the field. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 198 | DCHECK(soa.Self()->IsExceptionPending()); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 199 | StackHandleScope<1> hs2(soa.Self()); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 200 | Handle<mirror::Throwable> cause(hs2.NewHandle(soa.Self()->GetException())); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 201 | soa.Self()->ClearException(); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 202 | std::string temp; |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 203 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 204 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchFieldError;", |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 205 | "no type \"%s\" found and so no field \"%s\" " |
| 206 | "could be found in class \"%s\" or its superclasses", sig, name, |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 207 | c->GetDescriptor(&temp)); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 208 | soa.Self()->GetException()->SetCause(cause.Get()); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 209 | return nullptr; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 210 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 211 | std::string temp; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 212 | if (is_static) { |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 213 | field = mirror::Class::FindStaticField(soa.Self(), c, name, |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 214 | field_type->GetDescriptor(&temp)); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 215 | } else { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 216 | field = c->FindInstanceField(name, field_type->GetDescriptor(&temp)); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 217 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 218 | if (field == nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 219 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 220 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchFieldError;", |
| 221 | "no \"%s\" field \"%s\" in class \"%s\" or its superclasses", |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 222 | sig, name, c->GetDescriptor(&temp)); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 223 | return nullptr; |
Elliott Hughes | 8a26c5c | 2011-08-15 18:35:43 -0700 | [diff] [blame] | 224 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 225 | return soa.EncodeField(field); |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 228 | static void ThrowAIOOBE(ScopedObjectAccess& soa, mirror::Array* array, jsize start, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 229 | jsize length, const char* identifier) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 230 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 231 | std::string type(PrettyTypeOf(array)); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 232 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 233 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/ArrayIndexOutOfBoundsException;", |
| 234 | "%s offset=%d length=%d %s.length=%d", |
| 235 | type.c_str(), start, length, identifier, array->GetLength()); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 236 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 237 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 238 | static void ThrowSIOOBE(ScopedObjectAccess& soa, jsize start, jsize length, |
| 239 | jsize array_length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 240 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 241 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 242 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/StringIndexOutOfBoundsException;", |
| 243 | "offset=%d length=%d string.length()=%d", start, length, |
| 244 | array_length); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 245 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 246 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 247 | int ThrowNewException(JNIEnv* env, jclass exception_class, const char* msg, jobject cause) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 248 | LOCKS_EXCLUDED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 249 | // Turn the const char* into a java.lang.String. |
| 250 | ScopedLocalRef<jstring> s(env, env->NewStringUTF(msg)); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 251 | if (msg != nullptr && s.get() == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 252 | return JNI_ERR; |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 253 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 254 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 255 | // Choose an appropriate constructor and set up the arguments. |
| 256 | jvalue args[2]; |
| 257 | const char* signature; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 258 | if (msg == nullptr && cause == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 259 | signature = "()V"; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 260 | } else if (msg != nullptr && cause == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 261 | signature = "(Ljava/lang/String;)V"; |
| 262 | args[0].l = s.get(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 263 | } else if (msg == nullptr && cause != nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 264 | signature = "(Ljava/lang/Throwable;)V"; |
| 265 | args[0].l = cause; |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 266 | } else { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 267 | signature = "(Ljava/lang/String;Ljava/lang/Throwable;)V"; |
| 268 | args[0].l = s.get(); |
| 269 | args[1].l = cause; |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 270 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 271 | jmethodID mid = env->GetMethodID(exception_class, "<init>", signature); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 272 | if (mid == nullptr) { |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 273 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 274 | LOG(ERROR) << "No <init>" << signature << " in " |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 275 | << PrettyClass(soa.Decode<mirror::Class*>(exception_class)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 276 | return JNI_ERR; |
| 277 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 278 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 279 | ScopedLocalRef<jthrowable> exception( |
| 280 | env, reinterpret_cast<jthrowable>(env->NewObjectA(exception_class, mid, args))); |
| 281 | if (exception.get() == nullptr) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 282 | return JNI_ERR; |
| 283 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 284 | ScopedObjectAccess soa(env); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 285 | soa.Self()->SetException(soa.Decode<mirror::Throwable*>(exception.get())); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 286 | return JNI_OK; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 289 | static JavaVMExt* JavaVmExtFromEnv(JNIEnv* env) { |
| 290 | return reinterpret_cast<JNIEnvExt*>(env)->vm; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 293 | #define CHECK_NON_NULL_ARGUMENT(value) \ |
| 294 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, nullptr) |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 295 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 296 | #define CHECK_NON_NULL_ARGUMENT_RETURN_VOID(value) \ |
| 297 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, ) |
| 298 | |
| 299 | #define CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(value) \ |
| 300 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, 0) |
| 301 | |
| 302 | #define CHECK_NON_NULL_ARGUMENT_RETURN(value, return_val) \ |
| 303 | CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value, return_val) |
| 304 | |
| 305 | #define CHECK_NON_NULL_ARGUMENT_FN_NAME(name, value, return_val) \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 306 | if (UNLIKELY(value == nullptr)) { \ |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 307 | JavaVmExtFromEnv(env)->JniAbortF(name, #value " == null"); \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 308 | return return_val; \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 311 | #define CHECK_NON_NULL_MEMCPY_ARGUMENT(length, value) \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 312 | if (UNLIKELY(length != 0 && value == nullptr)) { \ |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 313 | JavaVmExtFromEnv(env)->JniAbortF(__FUNCTION__, #value " == null"); \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 314 | return; \ |
Ian Rogers | 4ffdc6b | 2013-08-21 16:55:13 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 317 | class JNI { |
| 318 | public: |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 319 | static jint GetVersion(JNIEnv*) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 320 | return JNI_VERSION_1_6; |
| 321 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 322 | |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 323 | static jclass DefineClass(JNIEnv*, const char*, jobject, const jbyte*, jsize) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 324 | LOG(WARNING) << "JNI DefineClass is not supported"; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 325 | return nullptr; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 328 | static jclass FindClass(JNIEnv* env, const char* name) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 329 | CHECK_NON_NULL_ARGUMENT(name); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 330 | Runtime* runtime = Runtime::Current(); |
| 331 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 332 | std::string descriptor(NormalizeJniClassDescriptor(name)); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 333 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 334 | mirror::Class* c = nullptr; |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 335 | if (runtime->IsStarted()) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 336 | StackHandleScope<1> hs(soa.Self()); |
| 337 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(GetClassLoader(soa))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 338 | c = class_linker->FindClass(soa.Self(), descriptor.c_str(), class_loader); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 339 | } else { |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 340 | c = class_linker->FindSystemClass(soa.Self(), descriptor.c_str()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 341 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 342 | return soa.AddLocalReference<jclass>(c); |
Ian Rogers | 4dd71f1 | 2011-08-16 14:16:02 -0700 | [diff] [blame] | 343 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 344 | |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 345 | static jmethodID FromReflectedMethod(JNIEnv* env, jobject jlr_method) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 346 | CHECK_NON_NULL_ARGUMENT(jlr_method); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 347 | ScopedObjectAccess soa(env); |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 348 | return soa.EncodeMethod(mirror::ArtMethod::FromReflectedMethod(soa, jlr_method)); |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 349 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 350 | |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 351 | static jfieldID FromReflectedField(JNIEnv* env, jobject jlr_field) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 352 | CHECK_NON_NULL_ARGUMENT(jlr_field); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 353 | ScopedObjectAccess soa(env); |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 354 | return soa.EncodeField(mirror::ArtField::FromReflectedField(soa, jlr_field)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 355 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 356 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 357 | static jobject ToReflectedMethod(JNIEnv* env, jclass, jmethodID mid, jboolean) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 358 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 359 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 360 | mirror::ArtMethod* m = soa.DecodeMethod(mid); |
| 361 | CHECK(!kMovingMethods); |
Mathieu Chartier | 41da596 | 2014-11-15 13:07:39 -0800 | [diff] [blame] | 362 | ScopedLocalRef<jobject> art_method(env, soa.AddLocalReference<jobject>(m)); |
Sebastien Hertz | d333376 | 2014-06-26 14:45:07 +0200 | [diff] [blame] | 363 | jobject reflect_method; |
| 364 | if (m->IsConstructor()) { |
| 365 | reflect_method = env->AllocObject(WellKnownClasses::java_lang_reflect_Constructor); |
| 366 | } else { |
| 367 | reflect_method = env->AllocObject(WellKnownClasses::java_lang_reflect_Method); |
| 368 | } |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 369 | if (env->ExceptionCheck()) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 370 | return nullptr; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 371 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 372 | SetObjectField(env, reflect_method, |
Mathieu Chartier | 41da596 | 2014-11-15 13:07:39 -0800 | [diff] [blame] | 373 | WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod, art_method.get()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 374 | return reflect_method; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 375 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 376 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 377 | static jobject ToReflectedField(JNIEnv* env, jclass, jfieldID fid, jboolean) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 378 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 379 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 380 | mirror::ArtField* f = soa.DecodeField(fid); |
Mathieu Chartier | 41da596 | 2014-11-15 13:07:39 -0800 | [diff] [blame] | 381 | ScopedLocalRef<jobject> art_field(env, soa.AddLocalReference<jobject>(f)); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 382 | jobject reflect_field = env->AllocObject(WellKnownClasses::java_lang_reflect_Field); |
| 383 | if (env->ExceptionCheck()) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 384 | return nullptr; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 385 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 386 | SetObjectField(env, reflect_field, |
Mathieu Chartier | 41da596 | 2014-11-15 13:07:39 -0800 | [diff] [blame] | 387 | WellKnownClasses::java_lang_reflect_Field_artField, art_field.get()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 388 | return reflect_field; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 389 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 390 | |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 391 | static jclass GetObjectClass(JNIEnv* env, jobject java_object) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 392 | CHECK_NON_NULL_ARGUMENT(java_object); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 393 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 394 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 395 | return soa.AddLocalReference<jclass>(o->GetClass()); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 398 | static jclass GetSuperclass(JNIEnv* env, jclass java_class) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 399 | CHECK_NON_NULL_ARGUMENT(java_class); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 400 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 401 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 402 | return soa.AddLocalReference<jclass>(c->GetSuperClass()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 403 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 404 | |
Narayan Kamath | 1268b74 | 2014-07-11 19:15:11 +0100 | [diff] [blame] | 405 | // Note: java_class1 should be safely castable to java_class2, and |
| 406 | // not the other way around. |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 407 | static jboolean IsAssignableFrom(JNIEnv* env, jclass java_class1, jclass java_class2) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 408 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class1, JNI_FALSE); |
| 409 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class2, JNI_FALSE); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 410 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 411 | mirror::Class* c1 = soa.Decode<mirror::Class*>(java_class1); |
| 412 | mirror::Class* c2 = soa.Decode<mirror::Class*>(java_class2); |
Narayan Kamath | 1268b74 | 2014-07-11 19:15:11 +0100 | [diff] [blame] | 413 | return c2->IsAssignableFrom(c1) ? JNI_TRUE : JNI_FALSE; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 414 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 415 | |
Elliott Hughes | e84278b | 2012-03-22 10:06:53 -0700 | [diff] [blame] | 416 | static jboolean IsInstanceOf(JNIEnv* env, jobject jobj, jclass java_class) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 417 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class, JNI_FALSE); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 418 | if (jobj == nullptr) { |
Brian Carlstrom | 5d40f18 | 2011-09-26 22:29:18 -0700 | [diff] [blame] | 419 | // Note: JNI is different from regular Java instanceof in this respect |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 420 | return JNI_TRUE; |
| 421 | } else { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 422 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 423 | mirror::Object* obj = soa.Decode<mirror::Object*>(jobj); |
| 424 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Elliott Hughes | e84278b | 2012-03-22 10:06:53 -0700 | [diff] [blame] | 425 | return obj->InstanceOf(c) ? JNI_TRUE : JNI_FALSE; |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 426 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 427 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 428 | |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 429 | static jint Throw(JNIEnv* env, jthrowable java_exception) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 430 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 431 | mirror::Throwable* exception = soa.Decode<mirror::Throwable*>(java_exception); |
| 432 | if (exception == nullptr) { |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 433 | return JNI_ERR; |
| 434 | } |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 435 | soa.Self()->SetException(exception); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 436 | return JNI_OK; |
| 437 | } |
| 438 | |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 439 | static jint ThrowNew(JNIEnv* env, jclass c, const char* msg) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 440 | CHECK_NON_NULL_ARGUMENT_RETURN(c, JNI_ERR); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 441 | return ThrowNewException(env, c, msg, nullptr); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static jboolean ExceptionCheck(JNIEnv* env) { |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 445 | return static_cast<JNIEnvExt*>(env)->self->IsExceptionPending() ? JNI_TRUE : JNI_FALSE; |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static void ExceptionClear(JNIEnv* env) { |
Serguei Katkov | a309d76 | 2014-05-26 11:23:39 +0700 | [diff] [blame] | 449 | ScopedObjectAccess soa(env); |
| 450 | soa.Self()->ClearException(); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static void ExceptionDescribe(JNIEnv* env) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 454 | ScopedObjectAccess soa(env); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 455 | |
Alexei Zavjalov | 3a1444c | 2014-06-25 16:04:55 +0700 | [diff] [blame] | 456 | // If we have no exception to describe, pass through. |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 457 | if (!soa.Self()->GetException()) { |
Alexei Zavjalov | 3a1444c | 2014-06-25 16:04:55 +0700 | [diff] [blame] | 458 | return; |
| 459 | } |
| 460 | |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 461 | StackHandleScope<1> hs(soa.Self()); |
| 462 | Handle<mirror::Throwable> old_exception( |
| 463 | hs.NewHandle<mirror::Throwable>(soa.Self()->GetException())); |
| 464 | soa.Self()->ClearException(); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 465 | ScopedLocalRef<jthrowable> exception(env, |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 466 | soa.AddLocalReference<jthrowable>(old_exception.Get())); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 467 | ScopedLocalRef<jclass> exception_class(env, env->GetObjectClass(exception.get())); |
| 468 | jmethodID mid = env->GetMethodID(exception_class.get(), "printStackTrace", "()V"); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 469 | if (mid == nullptr) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 470 | LOG(WARNING) << "JNI WARNING: no printStackTrace()V in " |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 471 | << PrettyTypeOf(old_exception.Get()); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 472 | } else { |
| 473 | env->CallVoidMethod(exception.get(), mid); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 474 | if (soa.Self()->IsExceptionPending()) { |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 475 | LOG(WARNING) << "JNI WARNING: " << PrettyTypeOf(soa.Self()->GetException()) |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 476 | << " thrown while calling printStackTrace"; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 477 | soa.Self()->ClearException(); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 478 | } |
| 479 | } |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 480 | soa.Self()->SetException(old_exception.Get()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 481 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 482 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 483 | static jthrowable ExceptionOccurred(JNIEnv* env) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 484 | ScopedObjectAccess soa(env); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame^] | 485 | mirror::Object* exception = soa.Self()->GetException(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 486 | return soa.AddLocalReference<jthrowable>(exception); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 489 | static void FatalError(JNIEnv*, const char* msg) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 490 | LOG(FATAL) << "JNI FatalError called: " << msg; |
| 491 | } |
| 492 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 493 | static jint PushLocalFrame(JNIEnv* env, jint capacity) { |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 494 | // TODO: SOA may not be necessary but I do it to please lock annotations. |
| 495 | ScopedObjectAccess soa(env); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 496 | if (EnsureLocalCapacityInternal(soa, capacity, "PushLocalFrame") != JNI_OK) { |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 497 | return JNI_ERR; |
| 498 | } |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 499 | down_cast<JNIEnvExt*>(env)->PushFrame(capacity); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 500 | return JNI_OK; |
| 501 | } |
| 502 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 503 | static jobject PopLocalFrame(JNIEnv* env, jobject java_survivor) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 504 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 505 | mirror::Object* survivor = soa.Decode<mirror::Object*>(java_survivor); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 506 | soa.Env()->PopFrame(); |
| 507 | return soa.AddLocalReference<jobject>(survivor); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 510 | static jint EnsureLocalCapacity(JNIEnv* env, jint desired_capacity) { |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 511 | // TODO: SOA may not be necessary but I do it to please lock annotations. |
| 512 | ScopedObjectAccess soa(env); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 513 | return EnsureLocalCapacityInternal(soa, desired_capacity, "EnsureLocalCapacity"); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 516 | static jobject NewGlobalRef(JNIEnv* env, jobject obj) { |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 517 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 518 | mirror::Object* decoded_obj = soa.Decode<mirror::Object*>(obj); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 519 | return soa.Vm()->AddGlobalRef(soa.Self(), decoded_obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static void DeleteGlobalRef(JNIEnv* env, jobject obj) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 523 | JavaVMExt* vm = down_cast<JNIEnvExt*>(env)->vm; |
| 524 | Thread* self = down_cast<JNIEnvExt*>(env)->self; |
| 525 | vm->DeleteGlobalRef(self, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | static jweak NewWeakGlobalRef(JNIEnv* env, jobject obj) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 529 | ScopedObjectAccess soa(env); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 530 | mirror::Object* decoded_obj = soa.Decode<mirror::Object*>(obj); |
| 531 | return soa.Vm()->AddWeakGlobalRef(soa.Self(), decoded_obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static void DeleteWeakGlobalRef(JNIEnv* env, jweak obj) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 535 | JavaVMExt* vm = down_cast<JNIEnvExt*>(env)->vm; |
| 536 | Thread* self = down_cast<JNIEnvExt*>(env)->self; |
| 537 | vm->DeleteWeakGlobalRef(self, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static jobject NewLocalRef(JNIEnv* env, jobject obj) { |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 541 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 542 | mirror::Object* decoded_obj = soa.Decode<mirror::Object*>(obj); |
Mathieu Chartier | e8c48db | 2013-12-19 14:59:00 -0800 | [diff] [blame] | 543 | // Check for null after decoding the object to handle cleared weak globals. |
| 544 | if (decoded_obj == nullptr) { |
| 545 | return nullptr; |
| 546 | } |
| 547 | return soa.AddLocalReference<jobject>(decoded_obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Stephen Hines | 95c51b3 | 2014-11-26 01:24:13 -0800 | [diff] [blame] | 550 | static void DeleteLocalRef(JNIEnv* env, jobject obj) |
| 551 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 552 | if (obj == nullptr) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 553 | return; |
| 554 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 555 | IndirectReferenceTable& locals = reinterpret_cast<JNIEnvExt*>(env)->locals; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 556 | |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 557 | uint32_t cookie = reinterpret_cast<JNIEnvExt*>(env)->local_ref_cookie; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 558 | if (!locals.Remove(cookie, obj)) { |
| 559 | // Attempting to delete a local reference that is not in the |
| 560 | // topmost local reference frame is a no-op. DeleteLocalRef returns |
| 561 | // void and doesn't throw any exceptions, but we should probably |
| 562 | // complain about it so the user will notice that things aren't |
| 563 | // going quite the way they expect. |
| 564 | LOG(WARNING) << "JNI WARNING: DeleteLocalRef(" << obj << ") " |
| 565 | << "failed to find entry"; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | static jboolean IsSameObject(JNIEnv* env, jobject obj1, jobject obj2) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 570 | if (obj1 == obj2) { |
| 571 | return JNI_TRUE; |
| 572 | } else { |
| 573 | ScopedObjectAccess soa(env); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 574 | return (soa.Decode<mirror::Object*>(obj1) == soa.Decode<mirror::Object*>(obj2)) |
| 575 | ? JNI_TRUE : JNI_FALSE; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 576 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 579 | static jobject AllocObject(JNIEnv* env, jclass java_class) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 580 | CHECK_NON_NULL_ARGUMENT(java_class); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 581 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 582 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 583 | if (c == nullptr) { |
| 584 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 585 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 586 | return soa.AddLocalReference<jobject>(c->AllocObject(soa.Self())); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 589 | static jobject NewObject(JNIEnv* env, jclass java_class, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 590 | va_list args; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 591 | va_start(args, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 592 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 593 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 594 | jobject result = NewObjectV(env, java_class, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 595 | va_end(args); |
| 596 | return result; |
| 597 | } |
| 598 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 599 | 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] | 600 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 601 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 602 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 603 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 604 | if (c == nullptr) { |
| 605 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 606 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 607 | mirror::Object* result = c->AllocObject(soa.Self()); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 608 | if (result == nullptr) { |
| 609 | return nullptr; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 610 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 611 | jobject local_result = soa.AddLocalReference<jobject>(result); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 612 | CallNonvirtualVoidMethodV(env, local_result, java_class, mid, args); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 613 | if (soa.Self()->IsExceptionPending()) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 614 | return nullptr; |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 615 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 616 | return local_result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 619 | static jobject NewObjectA(JNIEnv* env, jclass java_class, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 620 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 621 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 622 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 623 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 624 | if (c == nullptr) { |
| 625 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 626 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 627 | mirror::Object* result = c->AllocObject(soa.Self()); |
| 628 | if (result == nullptr) { |
| 629 | return nullptr; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 630 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 631 | jobject local_result = soa.AddLocalReference<jobjectArray>(result); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 632 | CallNonvirtualVoidMethodA(env, local_result, java_class, mid, args); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 633 | if (soa.Self()->IsExceptionPending()) { |
| 634 | return nullptr; |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 635 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 636 | return local_result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 639 | 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] | 640 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 641 | CHECK_NON_NULL_ARGUMENT(name); |
| 642 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 643 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 644 | return FindMethodID(soa, java_class, name, sig, false); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 647 | static jmethodID GetStaticMethodID(JNIEnv* env, jclass java_class, const char* name, |
| 648 | const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 649 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 650 | CHECK_NON_NULL_ARGUMENT(name); |
| 651 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 652 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 653 | return FindMethodID(soa, java_class, name, sig, true); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 656 | static jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 657 | va_list ap; |
| 658 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 659 | CHECK_NON_NULL_ARGUMENT(obj); |
| 660 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 661 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 662 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 663 | va_end(ap); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 664 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 667 | static jobject CallObjectMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 668 | CHECK_NON_NULL_ARGUMENT(obj); |
| 669 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 670 | ScopedObjectAccess soa(env); |
| 671 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args)); |
| 672 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 675 | static jobject CallObjectMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 676 | CHECK_NON_NULL_ARGUMENT(obj); |
| 677 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 678 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 679 | JValue result(InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 680 | args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 681 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 684 | static jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 685 | va_list ap; |
| 686 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 687 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 688 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 689 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 690 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 691 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 692 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 695 | static jboolean CallBooleanMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 696 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 697 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 698 | ScopedObjectAccess soa(env); |
| 699 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 702 | static jboolean CallBooleanMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 703 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 704 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 705 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 706 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 707 | args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 710 | static jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 711 | va_list ap; |
| 712 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 713 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 714 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 715 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 716 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 717 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 718 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 721 | static jbyte CallByteMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 722 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 723 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 724 | ScopedObjectAccess soa(env); |
| 725 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 728 | static jbyte CallByteMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 729 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 730 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 731 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 732 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 733 | args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 736 | static jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 737 | va_list ap; |
| 738 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 739 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 740 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 741 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 742 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 743 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 744 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 747 | static jchar CallCharMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 748 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 749 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 750 | ScopedObjectAccess soa(env); |
| 751 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 754 | static jchar CallCharMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 755 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 756 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 757 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 758 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 759 | args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 762 | static jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 763 | va_list ap; |
| 764 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 765 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 766 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 767 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 768 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 769 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 770 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 773 | static jdouble CallDoubleMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 774 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 775 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 776 | ScopedObjectAccess soa(env); |
| 777 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 780 | static jdouble CallDoubleMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 781 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 782 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 783 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 784 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 785 | args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 788 | static jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 789 | va_list ap; |
| 790 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 791 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 792 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 793 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 794 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 795 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 796 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 799 | static jfloat CallFloatMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 800 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 801 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 802 | ScopedObjectAccess soa(env); |
| 803 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 806 | static jfloat CallFloatMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 807 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 808 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 809 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 810 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 811 | args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 814 | static jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 815 | va_list ap; |
| 816 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 817 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 818 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 819 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 820 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 821 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 822 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 825 | static jint CallIntMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 826 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 827 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 828 | ScopedObjectAccess soa(env); |
| 829 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 832 | static jint CallIntMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 833 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 834 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 835 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 836 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 837 | args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 840 | static jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 841 | va_list ap; |
| 842 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 843 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 844 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 845 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 846 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 847 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 848 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 851 | static jlong CallLongMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 852 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 853 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 854 | ScopedObjectAccess soa(env); |
| 855 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 858 | static jlong CallLongMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 859 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 860 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 861 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 862 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 863 | args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 866 | static jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 867 | va_list ap; |
| 868 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 869 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 870 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 871 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 872 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 873 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 874 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 877 | static jshort CallShortMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 878 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 879 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 880 | ScopedObjectAccess soa(env); |
| 881 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 884 | static jshort CallShortMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 885 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 886 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 887 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 888 | return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, |
| 889 | args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 892 | static void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 893 | va_list ap; |
| 894 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 895 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 896 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 897 | ScopedObjectAccess soa(env); |
Ian Rogers | 1b09b09 | 2012-08-20 15:35:52 -0700 | [diff] [blame] | 898 | InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 899 | va_end(ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 902 | static void CallVoidMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 903 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 904 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 905 | ScopedObjectAccess soa(env); |
| 906 | InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 909 | static void CallVoidMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 910 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 911 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 912 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 913 | InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 916 | static jobject CallNonvirtualObjectMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 917 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 918 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 919 | CHECK_NON_NULL_ARGUMENT(obj); |
| 920 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 921 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 922 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
| 923 | jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 924 | va_end(ap); |
| 925 | return local_result; |
| 926 | } |
| 927 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 928 | static jobject CallNonvirtualObjectMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 929 | va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 930 | CHECK_NON_NULL_ARGUMENT(obj); |
| 931 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 932 | ScopedObjectAccess soa(env); |
| 933 | JValue result(InvokeWithVarArgs(soa, obj, mid, args)); |
| 934 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 937 | static jobject CallNonvirtualObjectMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 938 | jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 939 | CHECK_NON_NULL_ARGUMENT(obj); |
| 940 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 941 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 942 | JValue result(InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 943 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 946 | static jboolean CallNonvirtualBooleanMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 947 | ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 948 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 949 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 950 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 951 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 952 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 953 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 954 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 955 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 958 | static jboolean CallNonvirtualBooleanMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 959 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 960 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 961 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 962 | ScopedObjectAccess soa(env); |
| 963 | return InvokeWithVarArgs(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 966 | static jboolean CallNonvirtualBooleanMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 967 | jvalue* args) { |
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 | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 970 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 971 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 974 | static jbyte CallNonvirtualByteMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 975 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 976 | va_start(ap, mid); |
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 | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 979 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 980 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 981 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 982 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 985 | static jbyte CallNonvirtualByteMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 986 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 987 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 988 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 989 | ScopedObjectAccess soa(env); |
| 990 | return InvokeWithVarArgs(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 993 | static jbyte CallNonvirtualByteMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 994 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 995 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 996 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 997 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 998 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1001 | static jchar CallNonvirtualCharMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1002 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1003 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1004 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1005 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1006 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1007 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1008 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1009 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1012 | static jchar CallNonvirtualCharMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1013 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1014 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1015 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1016 | ScopedObjectAccess soa(env); |
| 1017 | return InvokeWithVarArgs(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1020 | static jchar CallNonvirtualCharMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1021 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1022 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1023 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1024 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1025 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1028 | static jshort CallNonvirtualShortMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1029 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1030 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1031 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1032 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1033 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1034 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1035 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1036 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1039 | static jshort CallNonvirtualShortMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1040 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1041 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1042 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1043 | ScopedObjectAccess soa(env); |
| 1044 | return InvokeWithVarArgs(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1047 | static jshort CallNonvirtualShortMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1048 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1049 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1050 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1051 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1052 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1055 | static jint CallNonvirtualIntMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1056 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1057 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1058 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1059 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1060 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1061 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1062 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1063 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1066 | static jint CallNonvirtualIntMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1067 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1068 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1069 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1070 | ScopedObjectAccess soa(env); |
| 1071 | return InvokeWithVarArgs(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1074 | static jint CallNonvirtualIntMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1075 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1076 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1077 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1078 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1079 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1082 | static jlong CallNonvirtualLongMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1083 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1084 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1085 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1086 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1087 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1088 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1089 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1090 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1093 | static jlong CallNonvirtualLongMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1094 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1095 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1096 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1097 | ScopedObjectAccess soa(env); |
| 1098 | return InvokeWithVarArgs(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1101 | static jlong CallNonvirtualLongMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1102 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1103 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1104 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1105 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1106 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1109 | static jfloat CallNonvirtualFloatMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1110 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1111 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1112 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1113 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1114 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1115 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1116 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1117 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1120 | static jfloat CallNonvirtualFloatMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1121 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1122 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1123 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1124 | ScopedObjectAccess soa(env); |
| 1125 | return InvokeWithVarArgs(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1128 | static jfloat CallNonvirtualFloatMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1129 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1130 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1131 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1132 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1133 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1136 | static jdouble CallNonvirtualDoubleMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1137 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1138 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1139 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1140 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1141 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1142 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1143 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1144 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1147 | static jdouble CallNonvirtualDoubleMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1148 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1149 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1150 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1151 | ScopedObjectAccess soa(env); |
| 1152 | return InvokeWithVarArgs(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1155 | static jdouble CallNonvirtualDoubleMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1156 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1157 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1158 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1159 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1160 | return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1163 | static void CallNonvirtualVoidMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1164 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1165 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1166 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1167 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1168 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1169 | InvokeWithVarArgs(soa, obj, mid, ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1170 | va_end(ap); |
| 1171 | } |
| 1172 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1173 | static void CallNonvirtualVoidMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1174 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1175 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1176 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1177 | ScopedObjectAccess soa(env); |
| 1178 | InvokeWithVarArgs(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1181 | static void CallNonvirtualVoidMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1182 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1183 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1184 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1185 | ScopedObjectAccess soa(env); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1186 | InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1189 | 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] | 1190 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 1191 | CHECK_NON_NULL_ARGUMENT(name); |
| 1192 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1193 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1194 | return FindFieldID(soa, java_class, name, sig, false); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1195 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1196 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1197 | static jfieldID GetStaticFieldID(JNIEnv* env, jclass java_class, const char* name, |
| 1198 | const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1199 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 1200 | CHECK_NON_NULL_ARGUMENT(name); |
| 1201 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1202 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1203 | return FindFieldID(soa, java_class, name, sig, true); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1204 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1205 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1206 | static jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fid) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1207 | CHECK_NON_NULL_ARGUMENT(obj); |
| 1208 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1209 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1210 | mirror::Object* o = soa.Decode<mirror::Object*>(obj); |
| 1211 | mirror::ArtField* f = soa.DecodeField(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1212 | return soa.AddLocalReference<jobject>(f->GetObject(o)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1213 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1214 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1215 | static jobject GetStaticObjectField(JNIEnv* env, jclass, jfieldID fid) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1216 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1217 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1218 | mirror::ArtField* f = soa.DecodeField(fid); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1219 | return soa.AddLocalReference<jobject>(f->GetObject(f->GetDeclaringClass())); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1222 | 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] | 1223 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_object); |
| 1224 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1225 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1226 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
| 1227 | mirror::Object* v = soa.Decode<mirror::Object*>(java_value); |
| 1228 | mirror::ArtField* f = soa.DecodeField(fid); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1229 | f->SetObject<false>(o, v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1232 | static void SetStaticObjectField(JNIEnv* env, jclass, jfieldID fid, jobject java_value) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1233 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1234 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1235 | mirror::Object* v = soa.Decode<mirror::Object*>(java_value); |
| 1236 | mirror::ArtField* f = soa.DecodeField(fid); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1237 | f->SetObject<false>(f->GetDeclaringClass(), v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1240 | #define GET_PRIMITIVE_FIELD(fn, instance) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1241 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(instance); \ |
| 1242 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(fid); \ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1243 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1244 | mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ |
| 1245 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1246 | return f->Get ##fn (o) |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1247 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1248 | #define GET_STATIC_PRIMITIVE_FIELD(fn) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1249 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(fid); \ |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1250 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1251 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1252 | return f->Get ##fn (f->GetDeclaringClass()) |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1253 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1254 | #define SET_PRIMITIVE_FIELD(fn, instance, value) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1255 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(instance); \ |
| 1256 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); \ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1257 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1258 | mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ |
| 1259 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1260 | f->Set ##fn <false>(o, value) |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1261 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1262 | #define SET_STATIC_PRIMITIVE_FIELD(fn, value) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1263 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); \ |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1264 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1265 | mirror::ArtField* f = soa.DecodeField(fid); \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1266 | f->Set ##fn <false>(f->GetDeclaringClass(), value) |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1267 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1268 | static jboolean GetBooleanField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1269 | GET_PRIMITIVE_FIELD(Boolean, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1272 | static jbyte GetByteField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1273 | GET_PRIMITIVE_FIELD(Byte, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1276 | static jchar GetCharField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1277 | GET_PRIMITIVE_FIELD(Char, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1280 | static jshort GetShortField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1281 | GET_PRIMITIVE_FIELD(Short, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1284 | static jint GetIntField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1285 | GET_PRIMITIVE_FIELD(Int, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1288 | static jlong GetLongField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1289 | GET_PRIMITIVE_FIELD(Long, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1292 | static jfloat GetFloatField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1293 | GET_PRIMITIVE_FIELD(Float, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1296 | static jdouble GetDoubleField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1297 | GET_PRIMITIVE_FIELD(Double, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1300 | static jboolean GetStaticBooleanField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1301 | GET_STATIC_PRIMITIVE_FIELD(Boolean); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1304 | static jbyte GetStaticByteField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1305 | GET_STATIC_PRIMITIVE_FIELD(Byte); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1308 | static jchar GetStaticCharField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1309 | GET_STATIC_PRIMITIVE_FIELD(Char); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1312 | static jshort GetStaticShortField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1313 | GET_STATIC_PRIMITIVE_FIELD(Short); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1316 | static jint GetStaticIntField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1317 | GET_STATIC_PRIMITIVE_FIELD(Int); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1320 | static jlong GetStaticLongField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1321 | GET_STATIC_PRIMITIVE_FIELD(Long); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1324 | static jfloat GetStaticFloatField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1325 | GET_STATIC_PRIMITIVE_FIELD(Float); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1328 | static jdouble GetStaticDoubleField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1329 | GET_STATIC_PRIMITIVE_FIELD(Double); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | static void SetBooleanField(JNIEnv* env, jobject obj, jfieldID fid, jboolean v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1333 | SET_PRIMITIVE_FIELD(Boolean, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | static void SetByteField(JNIEnv* env, jobject obj, jfieldID fid, jbyte v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1337 | SET_PRIMITIVE_FIELD(Byte, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | static void SetCharField(JNIEnv* env, jobject obj, jfieldID fid, jchar v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1341 | SET_PRIMITIVE_FIELD(Char, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | static void SetFloatField(JNIEnv* env, jobject obj, jfieldID fid, jfloat v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1345 | SET_PRIMITIVE_FIELD(Float, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void SetDoubleField(JNIEnv* env, jobject obj, jfieldID fid, jdouble v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1349 | SET_PRIMITIVE_FIELD(Double, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | static void SetIntField(JNIEnv* env, jobject obj, jfieldID fid, jint v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1353 | SET_PRIMITIVE_FIELD(Int, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | static void SetLongField(JNIEnv* env, jobject obj, jfieldID fid, jlong v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1357 | SET_PRIMITIVE_FIELD(Long, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static void SetShortField(JNIEnv* env, jobject obj, jfieldID fid, jshort v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1361 | SET_PRIMITIVE_FIELD(Short, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | static void SetStaticBooleanField(JNIEnv* env, jclass, jfieldID fid, jboolean v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1365 | SET_STATIC_PRIMITIVE_FIELD(Boolean, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | static void SetStaticByteField(JNIEnv* env, jclass, jfieldID fid, jbyte v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1369 | SET_STATIC_PRIMITIVE_FIELD(Byte, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | static void SetStaticCharField(JNIEnv* env, jclass, jfieldID fid, jchar v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1373 | SET_STATIC_PRIMITIVE_FIELD(Char, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | static void SetStaticFloatField(JNIEnv* env, jclass, jfieldID fid, jfloat v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1377 | SET_STATIC_PRIMITIVE_FIELD(Float, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | static void SetStaticDoubleField(JNIEnv* env, jclass, jfieldID fid, jdouble v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1381 | SET_STATIC_PRIMITIVE_FIELD(Double, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | static void SetStaticIntField(JNIEnv* env, jclass, jfieldID fid, jint v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1385 | SET_STATIC_PRIMITIVE_FIELD(Int, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | static void SetStaticLongField(JNIEnv* env, jclass, jfieldID fid, jlong v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1389 | SET_STATIC_PRIMITIVE_FIELD(Long, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static void SetStaticShortField(JNIEnv* env, jclass, jfieldID fid, jshort v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1393 | SET_STATIC_PRIMITIVE_FIELD(Short, v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1396 | static jobject CallStaticObjectMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1397 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1398 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1399 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1400 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1401 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1402 | jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1403 | va_end(ap); |
| 1404 | return local_result; |
| 1405 | } |
| 1406 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1407 | static jobject CallStaticObjectMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1408 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1409 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1410 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1411 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1414 | static jobject CallStaticObjectMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1415 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1416 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1417 | JValue result(InvokeWithJValues(soa, nullptr, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1418 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1421 | static jboolean CallStaticBooleanMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1422 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1423 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1424 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1425 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1426 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1427 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1428 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1431 | static jboolean CallStaticBooleanMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1432 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1433 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1434 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1437 | static jboolean CallStaticBooleanMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1438 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1439 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1440 | return InvokeWithJValues(soa, nullptr, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1443 | static jbyte CallStaticByteMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1444 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1445 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1446 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1447 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1448 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1449 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1450 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1453 | static jbyte CallStaticByteMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1454 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1455 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1456 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1459 | static jbyte CallStaticByteMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1460 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1461 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1462 | return InvokeWithJValues(soa, nullptr, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1465 | static jchar CallStaticCharMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1466 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1467 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1468 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1469 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1470 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1471 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1472 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1475 | static jchar CallStaticCharMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1476 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1477 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1478 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1481 | static jchar CallStaticCharMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1482 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1483 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1484 | return InvokeWithJValues(soa, nullptr, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1487 | static jshort CallStaticShortMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1488 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1489 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1490 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1491 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1492 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1493 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1494 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1497 | static jshort CallStaticShortMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1498 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1499 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1500 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1503 | static jshort CallStaticShortMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1504 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1505 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1506 | return InvokeWithJValues(soa, nullptr, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1509 | static jint CallStaticIntMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1510 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1511 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1512 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1513 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1514 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1515 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1516 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1519 | static jint CallStaticIntMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1520 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1521 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1522 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1525 | static jint CallStaticIntMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1526 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1527 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1528 | return InvokeWithJValues(soa, nullptr, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1531 | static jlong CallStaticLongMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1532 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1533 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1534 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1535 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1536 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1537 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1538 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1541 | static jlong CallStaticLongMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1542 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1543 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1544 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1547 | static jlong CallStaticLongMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1548 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1549 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1550 | return InvokeWithJValues(soa, nullptr, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1553 | static jfloat CallStaticFloatMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1554 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1555 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1556 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1557 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1558 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1559 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1560 | return result.GetF(); |
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 jfloat CallStaticFloatMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1564 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1565 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1566 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1569 | static jfloat CallStaticFloatMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1570 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1571 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1572 | return InvokeWithJValues(soa, nullptr, mid, args).GetF(); |
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 jdouble CallStaticDoubleMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1576 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1577 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1578 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1579 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1580 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1581 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1582 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1585 | static jdouble CallStaticDoubleMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1586 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1587 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1588 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1591 | static jdouble CallStaticDoubleMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1592 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1593 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1594 | return InvokeWithJValues(soa, nullptr, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1597 | static void CallStaticVoidMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1598 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1599 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1600 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1601 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1602 | InvokeWithVarArgs(soa, nullptr, mid, ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1603 | va_end(ap); |
| 1604 | } |
| 1605 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1606 | static void CallStaticVoidMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1607 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1608 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1609 | InvokeWithVarArgs(soa, nullptr, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1612 | static void CallStaticVoidMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1613 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1614 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1615 | InvokeWithJValues(soa, nullptr, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1618 | static jstring NewString(JNIEnv* env, const jchar* chars, jsize char_count) { |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1619 | if (UNLIKELY(char_count < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1620 | JavaVmExtFromEnv(env)->JniAbortF("NewString", "char_count < 0: %d", char_count); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1621 | return nullptr; |
| 1622 | } |
| 1623 | if (UNLIKELY(chars == nullptr && char_count > 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1624 | JavaVmExtFromEnv(env)->JniAbortF("NewString", "chars == null && char_count > 0"); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1625 | return nullptr; |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1626 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1627 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1628 | mirror::String* result = mirror::String::AllocFromUtf16(soa.Self(), char_count, chars); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1629 | return soa.AddLocalReference<jstring>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | static jstring NewStringUTF(JNIEnv* env, const char* utf) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1633 | if (utf == nullptr) { |
| 1634 | return nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1635 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1636 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1637 | mirror::String* result = mirror::String::AllocFromModifiedUtf8(soa.Self(), utf); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1638 | return soa.AddLocalReference<jstring>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1641 | static jsize GetStringLength(JNIEnv* env, jstring java_string) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1642 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1643 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1644 | return soa.Decode<mirror::String*>(java_string)->GetLength(); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | static jsize GetStringUTFLength(JNIEnv* env, jstring java_string) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1648 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1649 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1650 | return soa.Decode<mirror::String*>(java_string)->GetUtfLength(); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1653 | static void GetStringRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, |
| 1654 | jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1655 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1656 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1657 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1658 | if (start < 0 || length < 0 || start + length > s->GetLength()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1659 | ThrowSIOOBE(soa, start, length, s->GetLength()); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1660 | } else { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1661 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1662 | const jchar* chars = s->GetCharArray()->GetData() + s->GetOffset(); |
| 1663 | memcpy(buf, chars + start, length * sizeof(jchar)); |
| 1664 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1667 | static void GetStringUTFRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, |
| 1668 | char* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1669 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1670 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1671 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1672 | if (start < 0 || length < 0 || start + length > s->GetLength()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1673 | ThrowSIOOBE(soa, start, length, s->GetLength()); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1674 | } else { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1675 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1676 | const jchar* chars = s->GetCharArray()->GetData() + s->GetOffset(); |
| 1677 | ConvertUtf16ToModifiedUtf8(buf, chars + start, length); |
| 1678 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1681 | static const jchar* GetStringChars(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1682 | CHECK_NON_NULL_ARGUMENT(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1683 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1684 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1685 | mirror::CharArray* chars = s->GetCharArray(); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1686 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1687 | if (heap->IsMovableObject(chars)) { |
| 1688 | if (is_copy != nullptr) { |
| 1689 | *is_copy = JNI_TRUE; |
| 1690 | } |
| 1691 | int32_t char_count = s->GetLength(); |
| 1692 | int32_t offset = s->GetOffset(); |
| 1693 | jchar* bytes = new jchar[char_count]; |
| 1694 | for (int32_t i = 0; i < char_count; i++) { |
| 1695 | bytes[i] = chars->Get(i + offset); |
| 1696 | } |
| 1697 | return bytes; |
| 1698 | } else { |
| 1699 | if (is_copy != nullptr) { |
| 1700 | *is_copy = JNI_FALSE; |
| 1701 | } |
| 1702 | return static_cast<jchar*>(chars->GetData() + s->GetOffset()); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1703 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1706 | static void ReleaseStringChars(JNIEnv* env, jstring java_string, const jchar* chars) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1707 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1708 | ScopedObjectAccess soa(env); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1709 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1710 | mirror::CharArray* s_chars = s->GetCharArray(); |
| 1711 | if (chars != (s_chars->GetData() + s->GetOffset())) { |
| 1712 | delete[] chars; |
| 1713 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1716 | static const jchar* GetStringCritical(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1717 | CHECK_NON_NULL_ARGUMENT(java_string); |
| 1718 | ScopedObjectAccess soa(env); |
| 1719 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1720 | mirror::CharArray* chars = s->GetCharArray(); |
| 1721 | int32_t offset = s->GetOffset(); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1722 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1723 | if (heap->IsMovableObject(chars)) { |
| 1724 | StackHandleScope<1> hs(soa.Self()); |
| 1725 | HandleWrapper<mirror::CharArray> h(hs.NewHandleWrapper(&chars)); |
| 1726 | heap->IncrementDisableMovingGC(soa.Self()); |
| 1727 | } |
| 1728 | if (is_copy != nullptr) { |
| 1729 | *is_copy = JNI_FALSE; |
| 1730 | } |
| 1731 | return static_cast<jchar*>(chars->GetData() + offset); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1734 | static void ReleaseStringCritical(JNIEnv* env, jstring java_string, const jchar* chars) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1735 | UNUSED(chars); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1736 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
| 1737 | ScopedObjectAccess soa(env); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1738 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1739 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
| 1740 | mirror::CharArray* s_chars = s->GetCharArray(); |
| 1741 | if (heap->IsMovableObject(s_chars)) { |
| 1742 | heap->DecrementDisableMovingGC(soa.Self()); |
| 1743 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1746 | static const char* GetStringUTFChars(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1747 | if (java_string == nullptr) { |
| 1748 | return nullptr; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1749 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1750 | if (is_copy != nullptr) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1751 | *is_copy = JNI_TRUE; |
| 1752 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 1753 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1754 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1755 | size_t byte_count = s->GetUtfLength(); |
| 1756 | char* bytes = new char[byte_count + 1]; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1757 | CHECK(bytes != nullptr); // bionic aborts anyway. |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1758 | const uint16_t* chars = s->GetCharArray()->GetData() + s->GetOffset(); |
| 1759 | ConvertUtf16ToModifiedUtf8(bytes, chars, s->GetLength()); |
| 1760 | bytes[byte_count] = '\0'; |
| 1761 | return bytes; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1764 | static void ReleaseStringUTFChars(JNIEnv*, jstring, const char* chars) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1765 | delete[] chars; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Elliott Hughes | bd93599 | 2011-08-22 11:59:34 -0700 | [diff] [blame] | 1768 | static jsize GetArrayLength(JNIEnv* env, jarray java_array) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1769 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1770 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1771 | mirror::Object* obj = soa.Decode<mirror::Object*>(java_array); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1772 | if (UNLIKELY(!obj->IsArrayInstance())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1773 | soa.Vm()->JniAbortF("GetArrayLength", "not an array: %s", PrettyTypeOf(obj).c_str()); |
| 1774 | return 0; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 1775 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1776 | mirror::Array* array = obj->AsArray(); |
Elliott Hughes | bd93599 | 2011-08-22 11:59:34 -0700 | [diff] [blame] | 1777 | return array->GetLength(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1780 | static jobject GetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1781 | CHECK_NON_NULL_ARGUMENT(java_array); |
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 | mirror::ObjectArray<mirror::Object>* array = |
| 1784 | soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1785 | return soa.AddLocalReference<jobject>(array->Get(index)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1788 | static void SetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index, |
| 1789 | jobject java_value) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1790 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1791 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1792 | mirror::ObjectArray<mirror::Object>* array = |
| 1793 | soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); |
| 1794 | mirror::Object* value = soa.Decode<mirror::Object*>(java_value); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1795 | array->Set<false>(index, value); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | static jbooleanArray NewBooleanArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1799 | return NewPrimitiveArray<jbooleanArray, mirror::BooleanArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static jbyteArray NewByteArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1803 | return NewPrimitiveArray<jbyteArray, mirror::ByteArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | static jcharArray NewCharArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1807 | return NewPrimitiveArray<jcharArray, mirror::CharArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | static jdoubleArray NewDoubleArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1811 | return NewPrimitiveArray<jdoubleArray, mirror::DoubleArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | static jfloatArray NewFloatArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1815 | return NewPrimitiveArray<jfloatArray, mirror::FloatArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | static jintArray NewIntArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1819 | return NewPrimitiveArray<jintArray, mirror::IntArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | static jlongArray NewLongArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1823 | return NewPrimitiveArray<jlongArray, mirror::LongArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1826 | static jobjectArray NewObjectArray(JNIEnv* env, jsize length, jclass element_jclass, |
| 1827 | jobject initial_element) { |
| 1828 | if (UNLIKELY(length < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1829 | JavaVmExtFromEnv(env)->JniAbortF("NewObjectArray", "negative array length: %d", length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1830 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 1831 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1832 | CHECK_NON_NULL_ARGUMENT(element_jclass); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1833 | |
| 1834 | // Compute the array class corresponding to the given element class. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1835 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1836 | mirror::Class* array_class; |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1837 | { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1838 | mirror::Class* element_class = soa.Decode<mirror::Class*>(element_jclass); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1839 | if (UNLIKELY(element_class->IsPrimitive())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1840 | soa.Vm()->JniAbortF("NewObjectArray", "not an object type: %s", |
| 1841 | PrettyDescriptor(element_class).c_str()); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1842 | return nullptr; |
| 1843 | } |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1844 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | b74cd29 | 2014-05-29 14:31:33 -0700 | [diff] [blame] | 1845 | array_class = class_linker->FindArrayClass(soa.Self(), &element_class); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1846 | if (UNLIKELY(array_class == nullptr)) { |
| 1847 | return nullptr; |
| 1848 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1851 | // Allocate and initialize if necessary. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1852 | mirror::ObjectArray<mirror::Object>* result = |
| 1853 | mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), array_class, length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1854 | if (result != nullptr && initial_element != nullptr) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1855 | mirror::Object* initial_object = soa.Decode<mirror::Object*>(initial_element); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1856 | if (initial_object != nullptr) { |
| 1857 | mirror::Class* element_class = result->GetClass()->GetComponentType(); |
| 1858 | if (UNLIKELY(!element_class->IsAssignableFrom(initial_object->GetClass()))) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1859 | soa.Vm()->JniAbortF("NewObjectArray", "cannot assign object of type '%s' to array with " |
| 1860 | "element type of '%s'", |
| 1861 | PrettyDescriptor(initial_object->GetClass()).c_str(), |
| 1862 | PrettyDescriptor(element_class).c_str()); |
| 1863 | return nullptr; |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1864 | } else { |
| 1865 | for (jsize i = 0; i < length; ++i) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1866 | result->SetWithoutChecks<false>(i, initial_object); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1867 | } |
| 1868 | } |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1869 | } |
| 1870 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1871 | return soa.AddLocalReference<jobjectArray>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | static jshortArray NewShortArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1875 | return NewPrimitiveArray<jshortArray, mirror::ShortArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 1878 | static void* GetPrimitiveArrayCritical(JNIEnv* env, jarray java_array, jboolean* is_copy) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1879 | CHECK_NON_NULL_ARGUMENT(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1880 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1881 | mirror::Array* array = soa.Decode<mirror::Array*>(java_array); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1882 | if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1883 | soa.Vm()->JniAbortF("GetPrimitiveArrayCritical", "expected primitive array, given %s", |
| 1884 | PrettyDescriptor(array->GetClass()).c_str()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1885 | return nullptr; |
| 1886 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1887 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1888 | if (heap->IsMovableObject(array)) { |
Mathieu Chartier | 1d27b34 | 2014-01-28 12:51:09 -0800 | [diff] [blame] | 1889 | heap->IncrementDisableMovingGC(soa.Self()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1890 | // 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] | 1891 | array = soa.Decode<mirror::Array*>(java_array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1892 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1893 | if (is_copy != nullptr) { |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 1894 | *is_copy = JNI_FALSE; |
| 1895 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1896 | return array->GetRawData(array->GetClass()->GetComponentSize(), 0); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1899 | static void ReleasePrimitiveArrayCritical(JNIEnv* env, jarray java_array, void* elements, |
| 1900 | jint mode) { |
| 1901 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 1902 | ScopedObjectAccess soa(env); |
| 1903 | mirror::Array* array = soa.Decode<mirror::Array*>(java_array); |
| 1904 | if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1905 | soa.Vm()->JniAbortF("ReleasePrimitiveArrayCritical", "expected primitive array, given %s", |
| 1906 | PrettyDescriptor(array->GetClass()).c_str()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1907 | return; |
| 1908 | } |
| 1909 | const size_t component_size = array->GetClass()->GetComponentSize(); |
| 1910 | ReleasePrimitiveArray(soa, array, component_size, elements, mode); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1913 | static jboolean* GetBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1914 | return GetPrimitiveArray<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1917 | static jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1918 | return GetPrimitiveArray<jbyteArray, jbyte, mirror::ByteArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1921 | static jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1922 | return GetPrimitiveArray<jcharArray, jchar, mirror::CharArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1925 | static jdouble* GetDoubleArrayElements(JNIEnv* env, jdoubleArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1926 | return GetPrimitiveArray<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1929 | static jfloat* GetFloatArrayElements(JNIEnv* env, jfloatArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1930 | return GetPrimitiveArray<jfloatArray, jfloat, mirror::FloatArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1933 | static jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1934 | return GetPrimitiveArray<jintArray, jint, mirror::IntArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1937 | static jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1938 | return GetPrimitiveArray<jlongArray, jlong, mirror::LongArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1941 | static jshort* GetShortArrayElements(JNIEnv* env, jshortArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1942 | return GetPrimitiveArray<jshortArray, jshort, mirror::ShortArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1945 | static void ReleaseBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* elements, |
| 1946 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1947 | ReleasePrimitiveArray<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, elements, |
| 1948 | mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1951 | static void ReleaseByteArrayElements(JNIEnv* env, jbyteArray array, jbyte* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1952 | ReleasePrimitiveArray<jbyteArray, jbyte, mirror::ByteArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1955 | static void ReleaseCharArrayElements(JNIEnv* env, jcharArray array, jchar* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1956 | ReleasePrimitiveArray<jcharArray, jchar, mirror::CharArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1959 | static void ReleaseDoubleArrayElements(JNIEnv* env, jdoubleArray array, jdouble* elements, |
| 1960 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1961 | ReleasePrimitiveArray<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1964 | static void ReleaseFloatArrayElements(JNIEnv* env, jfloatArray array, jfloat* elements, |
| 1965 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1966 | ReleasePrimitiveArray<jfloatArray, jfloat, mirror::FloatArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1969 | static void ReleaseIntArrayElements(JNIEnv* env, jintArray array, jint* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1970 | ReleasePrimitiveArray<jintArray, jint, mirror::IntArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1973 | static void ReleaseLongArrayElements(JNIEnv* env, jlongArray array, jlong* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1974 | ReleasePrimitiveArray<jlongArray, jlong, mirror::LongArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1977 | static void ReleaseShortArrayElements(JNIEnv* env, jshortArray array, jshort* elements, |
| 1978 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1979 | ReleasePrimitiveArray<jshortArray, jshort, mirror::ShortArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1982 | static void GetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize length, |
| 1983 | jboolean* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1984 | GetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, start, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1985 | length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1988 | static void GetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize length, |
| 1989 | jbyte* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1990 | GetPrimitiveArrayRegion<jbyteArray, jbyte, mirror::ByteArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1993 | static void GetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize length, |
| 1994 | jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1995 | GetPrimitiveArrayRegion<jcharArray, jchar, mirror::CharArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1998 | static void GetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize length, |
| 1999 | jdouble* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2000 | GetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2001 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2004 | static void GetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize length, |
| 2005 | jfloat* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2006 | GetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2007 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2010 | static void GetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize length, |
| 2011 | jint* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2012 | GetPrimitiveArrayRegion<jintArray, jint, mirror::IntArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2015 | static void GetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize length, |
| 2016 | jlong* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2017 | GetPrimitiveArrayRegion<jlongArray, jlong, mirror::LongArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2020 | static void GetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize length, |
| 2021 | jshort* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2022 | GetPrimitiveArrayRegion<jshortArray, jshort, mirror::ShortArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2023 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2026 | static void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize length, |
| 2027 | const jboolean* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2028 | SetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, start, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2029 | length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2032 | static void SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize length, |
| 2033 | const jbyte* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2034 | SetPrimitiveArrayRegion<jbyteArray, jbyte, mirror::ByteArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2037 | static void SetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize length, |
| 2038 | const jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2039 | SetPrimitiveArrayRegion<jcharArray, jchar, mirror::CharArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2042 | static void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize length, |
| 2043 | const jdouble* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2044 | SetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, start, length, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2045 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2048 | static void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize length, |
| 2049 | const jfloat* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2050 | SetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(env, array, start, length, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2051 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2054 | static void SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize length, |
| 2055 | const jint* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2056 | SetPrimitiveArrayRegion<jintArray, jint, mirror::IntArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2059 | static void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize length, |
| 2060 | const jlong* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2061 | SetPrimitiveArrayRegion<jlongArray, jlong, mirror::LongArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2064 | static void SetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize length, |
| 2065 | const jshort* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2066 | SetPrimitiveArrayRegion<jshortArray, jshort, mirror::ShortArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2067 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2070 | static jint RegisterNatives(JNIEnv* env, jclass java_class, const JNINativeMethod* methods, |
| 2071 | jint method_count) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2072 | return RegisterNativeMethods(env, java_class, methods, method_count, true); |
| 2073 | } |
| 2074 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2075 | static jint RegisterNativeMethods(JNIEnv* env, jclass java_class, const JNINativeMethod* methods, |
| 2076 | jint method_count, bool return_errors) { |
| 2077 | if (UNLIKELY(method_count < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2078 | JavaVmExtFromEnv(env)->JniAbortF("RegisterNatives", "negative method count: %d", |
| 2079 | method_count); |
| 2080 | return JNI_ERR; // Not reached except in unit tests. |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2081 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2082 | CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", java_class, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2083 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2084 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2085 | if (UNLIKELY(method_count == 0)) { |
| 2086 | LOG(WARNING) << "JNI RegisterNativeMethods: attempt to register 0 native methods for " |
| 2087 | << PrettyDescriptor(c); |
| 2088 | return JNI_OK; |
| 2089 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2090 | CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", methods, JNI_ERR); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2091 | for (jint i = 0; i < method_count; ++i) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2092 | const char* name = methods[i].name; |
| 2093 | const char* sig = methods[i].signature; |
Sebastien Hertz | fa65e84 | 2014-07-03 09:39:53 +0200 | [diff] [blame] | 2094 | const void* fnPtr = methods[i].fnPtr; |
| 2095 | if (UNLIKELY(name == nullptr)) { |
| 2096 | ReportInvalidJNINativeMethod(soa, c, "method name", i, return_errors); |
| 2097 | return JNI_ERR; |
| 2098 | } else if (UNLIKELY(sig == nullptr)) { |
| 2099 | ReportInvalidJNINativeMethod(soa, c, "method signature", i, return_errors); |
| 2100 | return JNI_ERR; |
| 2101 | } else if (UNLIKELY(fnPtr == nullptr)) { |
| 2102 | ReportInvalidJNINativeMethod(soa, c, "native function", i, return_errors); |
| 2103 | return JNI_ERR; |
| 2104 | } |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 2105 | bool is_fast = false; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2106 | if (*sig == '!') { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 2107 | is_fast = true; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2108 | ++sig; |
| 2109 | } |
| 2110 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2111 | mirror::ArtMethod* m = c->FindDirectMethod(name, sig); |
| 2112 | if (m == nullptr) { |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2113 | m = c->FindVirtualMethod(name, sig); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2114 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2115 | if (m == nullptr) { |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 2116 | c->DumpClass(LOG(ERROR), mirror::Class::kDumpClassFullDetail); |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2117 | LOG(return_errors ? ERROR : FATAL) << "Failed to register native method " |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 2118 | << PrettyDescriptor(c) << "." << name << sig << " in " |
| 2119 | << c->GetDexCache()->GetLocation()->ToModifiedUtf8(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2120 | ThrowNoSuchMethodError(soa, c, name, sig, "static or non-static"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2121 | return JNI_ERR; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2122 | } else if (!m->IsNative()) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2123 | LOG(return_errors ? ERROR : FATAL) << "Failed to register non-native method " |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2124 | << PrettyDescriptor(c) << "." << name << sig |
| 2125 | << " as native"; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2126 | ThrowNoSuchMethodError(soa, c, name, sig, "native"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2127 | return JNI_ERR; |
| 2128 | } |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2129 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 2130 | VLOG(jni) << "[Registering JNI native method " << PrettyMethod(m) << "]"; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2131 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 2132 | m->RegisterNative(fnPtr, is_fast); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2133 | } |
| 2134 | return JNI_OK; |
| 2135 | } |
| 2136 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2137 | static jint UnregisterNatives(JNIEnv* env, jclass java_class) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2138 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2139 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2140 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2141 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 2142 | VLOG(jni) << "[Unregistering JNI native methods for " << PrettyClass(c) << "]"; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2143 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2144 | size_t unregistered_count = 0; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2145 | for (size_t i = 0; i < c->NumDirectMethods(); ++i) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2146 | mirror::ArtMethod* m = c->GetDirectMethod(i); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2147 | if (m->IsNative()) { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 2148 | m->UnregisterNative(); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2149 | unregistered_count++; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2150 | } |
| 2151 | } |
| 2152 | for (size_t i = 0; i < c->NumVirtualMethods(); ++i) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2153 | mirror::ArtMethod* m = c->GetVirtualMethod(i); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2154 | if (m->IsNative()) { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 2155 | m->UnregisterNative(); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2156 | unregistered_count++; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2160 | if (unregistered_count == 0) { |
| 2161 | LOG(WARNING) << "JNI UnregisterNatives: attempt to unregister native methods of class '" |
| 2162 | << PrettyDescriptor(c) << "' that contains no native methods"; |
| 2163 | } |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2164 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 2167 | static jint MonitorEnter(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2168 | CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2169 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2170 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
| 2171 | o = o->MonitorEnter(soa.Self()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2172 | if (soa.Self()->IsExceptionPending()) { |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2173 | return JNI_ERR; |
| 2174 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2175 | soa.Env()->monitors.Add(o); |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2176 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 2179 | static jint MonitorExit(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2180 | CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2181 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2182 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2183 | o->MonitorExit(soa.Self()); |
| 2184 | if (soa.Self()->IsExceptionPending()) { |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2185 | return JNI_ERR; |
| 2186 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2187 | soa.Env()->monitors.Remove(o); |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2188 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | static jint GetJavaVM(JNIEnv* env, JavaVM** vm) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2192 | CHECK_NON_NULL_ARGUMENT_RETURN(vm, JNI_ERR); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2193 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2194 | if (runtime != nullptr) { |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 2195 | *vm = runtime->GetJavaVM(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2196 | } else { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2197 | *vm = nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2198 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2199 | return (*vm != nullptr) ? JNI_OK : JNI_ERR; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2202 | static jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) { |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2203 | if (capacity < 0) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2204 | JavaVmExtFromEnv(env)->JniAbortF("NewDirectByteBuffer", "negative buffer capacity: %" PRId64, |
| 2205 | capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame] | 2206 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2207 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2208 | if (address == nullptr && capacity != 0) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2209 | JavaVmExtFromEnv(env)->JniAbortF("NewDirectByteBuffer", |
| 2210 | "non-zero capacity for nullptr pointer: %" PRId64, capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame] | 2211 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2212 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2213 | |
Brian Carlstrom | 85a9336 | 2014-06-25 09:30:52 -0700 | [diff] [blame] | 2214 | // At the moment, the capacity of DirectByteBuffer is limited to a signed int. |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame] | 2215 | if (capacity > INT_MAX) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2216 | JavaVmExtFromEnv(env)->JniAbortF("NewDirectByteBuffer", |
| 2217 | "buffer capacity greater than maximum jint: %" PRId64, |
| 2218 | capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame] | 2219 | return nullptr; |
| 2220 | } |
Elliott Hughes | b568121 | 2013-03-29 17:29:22 -0700 | [diff] [blame] | 2221 | jlong address_arg = reinterpret_cast<jlong>(address); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2222 | jint capacity_arg = static_cast<jint>(capacity); |
| 2223 | |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 2224 | jobject result = env->NewObject(WellKnownClasses::java_nio_DirectByteBuffer, |
| 2225 | WellKnownClasses::java_nio_DirectByteBuffer_init, |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 2226 | address_arg, capacity_arg); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2227 | return static_cast<JNIEnvExt*>(env)->self->IsExceptionPending() ? nullptr : result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2230 | static void* GetDirectBufferAddress(JNIEnv* env, jobject java_buffer) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2231 | return reinterpret_cast<void*>(env->GetLongField( |
| 2232 | java_buffer, WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2235 | static jlong GetDirectBufferCapacity(JNIEnv* env, jobject java_buffer) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2236 | return static_cast<jlong>(env->GetIntField( |
| 2237 | java_buffer, WellKnownClasses::java_nio_DirectByteBuffer_capacity)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
Andreas Gampe | a876307 | 2014-12-20 00:08:35 -0800 | [diff] [blame] | 2240 | static jobjectRefType GetObjectRefType(JNIEnv* env ATTRIBUTE_UNUSED, jobject java_object) { |
| 2241 | if (java_object == nullptr) { |
| 2242 | return JNIInvalidRefType; |
| 2243 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2244 | |
| 2245 | // Do we definitely know what kind of reference this is? |
| 2246 | IndirectRef ref = reinterpret_cast<IndirectRef>(java_object); |
| 2247 | IndirectRefKind kind = GetIndirectRefKind(ref); |
| 2248 | switch (kind) { |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 2249 | case kLocal: |
| 2250 | return JNILocalRefType; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2251 | case kGlobal: |
| 2252 | return JNIGlobalRefType; |
| 2253 | case kWeakGlobal: |
| 2254 | return JNIWeakGlobalRefType; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2255 | case kHandleScopeOrInvalid: |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 2256 | // Assume value is in a handle scope. |
| 2257 | return JNILocalRefType; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2258 | } |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 2259 | LOG(FATAL) << "IndirectRefKind[" << kind << "]"; |
Andreas Gampe | a876307 | 2014-12-20 00:08:35 -0800 | [diff] [blame] | 2260 | UNREACHABLE(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2261 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2262 | |
| 2263 | private: |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2264 | static jint EnsureLocalCapacityInternal(ScopedObjectAccess& soa, jint desired_capacity, |
| 2265 | const char* caller) |
| 2266 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2267 | // TODO: we should try to expand the table if necessary. |
Elliott Hughes | aa836f7 | 2013-08-20 16:57:23 -0700 | [diff] [blame] | 2268 | if (desired_capacity < 0 || desired_capacity > static_cast<jint>(kLocalsMax)) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2269 | LOG(ERROR) << "Invalid capacity given to " << caller << ": " << desired_capacity; |
| 2270 | return JNI_ERR; |
| 2271 | } |
| 2272 | // TODO: this isn't quite right, since "capacity" includes holes. |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 2273 | const size_t capacity = soa.Env()->locals.Capacity(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2274 | bool okay = (static_cast<jint>(kLocalsMax - capacity) >= desired_capacity); |
| 2275 | if (!okay) { |
| 2276 | soa.Self()->ThrowOutOfMemoryError(caller); |
| 2277 | } |
| 2278 | return okay ? JNI_OK : JNI_ERR; |
| 2279 | } |
| 2280 | |
| 2281 | template<typename JniT, typename ArtT> |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2282 | static JniT NewPrimitiveArray(JNIEnv* env, jsize length) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2283 | ScopedObjectAccess soa(env); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2284 | if (UNLIKELY(length < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2285 | soa.Vm()->JniAbortF("NewPrimitiveArray", "negative array length: %d", length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2286 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2287 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 2288 | ArtT* result = ArtT::Alloc(soa.Self(), length); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2289 | return soa.AddLocalReference<JniT>(result); |
| 2290 | } |
| 2291 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2292 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2293 | static ArtArrayT* DecodeAndCheckArrayType(ScopedObjectAccess& soa, JArrayT java_array, |
| 2294 | const char* fn_name, const char* operation) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 2295 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2296 | ArtArrayT* array = soa.Decode<ArtArrayT*>(java_array); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2297 | if (UNLIKELY(ArtArrayT::GetArrayClass() != array->GetClass())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2298 | soa.Vm()->JniAbortF(fn_name, |
| 2299 | "attempt to %s %s primitive array elements with an object of type %s", |
| 2300 | operation, |
| 2301 | PrettyDescriptor(ArtArrayT::GetArrayClass()->GetComponentType()).c_str(), |
| 2302 | PrettyDescriptor(array->GetClass()).c_str()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2303 | return nullptr; |
| 2304 | } |
| 2305 | DCHECK_EQ(sizeof(ElementT), array->GetClass()->GetComponentSize()); |
| 2306 | return array; |
| 2307 | } |
| 2308 | |
| 2309 | template <typename ArrayT, typename ElementT, typename ArtArrayT> |
| 2310 | static ElementT* GetPrimitiveArray(JNIEnv* env, ArrayT java_array, jboolean* is_copy) { |
| 2311 | CHECK_NON_NULL_ARGUMENT(java_array); |
| 2312 | ScopedObjectAccess soa(env); |
| 2313 | ArtArrayT* array = DecodeAndCheckArrayType<ArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2314 | "GetArrayElements", |
| 2315 | "get"); |
| 2316 | if (UNLIKELY(array == nullptr)) { |
| 2317 | return nullptr; |
| 2318 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2319 | // Only make a copy if necessary. |
| 2320 | if (Runtime::Current()->GetHeap()->IsMovableObject(array)) { |
| 2321 | if (is_copy != nullptr) { |
| 2322 | *is_copy = JNI_TRUE; |
| 2323 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2324 | const size_t component_size = sizeof(ElementT); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2325 | size_t size = array->GetLength() * component_size; |
| 2326 | void* data = new uint64_t[RoundUp(size, 8) / 8]; |
| 2327 | memcpy(data, array->GetData(), size); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2328 | return reinterpret_cast<ElementT*>(data); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2329 | } else { |
| 2330 | if (is_copy != nullptr) { |
| 2331 | *is_copy = JNI_FALSE; |
| 2332 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2333 | return reinterpret_cast<ElementT*>(array->GetData()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2334 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2337 | template <typename ArrayT, typename ElementT, typename ArtArrayT> |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2338 | static void ReleasePrimitiveArray(JNIEnv* env, ArrayT java_array, ElementT* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2339 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2340 | ScopedObjectAccess soa(env); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2341 | ArtArrayT* array = DecodeAndCheckArrayType<ArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2342 | "ReleaseArrayElements", |
| 2343 | "release"); |
| 2344 | if (array == nullptr) { |
| 2345 | return; |
| 2346 | } |
| 2347 | ReleasePrimitiveArray(soa, array, sizeof(ElementT), elements, mode); |
| 2348 | } |
| 2349 | |
| 2350 | static void ReleasePrimitiveArray(ScopedObjectAccess& soa, mirror::Array* array, |
| 2351 | size_t component_size, void* elements, jint mode) |
| 2352 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2353 | void* array_data = array->GetRawData(component_size, 0); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2354 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2355 | bool is_copy = array_data != elements; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2356 | size_t bytes = array->GetLength() * component_size; |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2357 | VLOG(heap) << "Release primitive array " << soa.Env() << " array_data " << array_data |
| 2358 | << " elements " << elements; |
Mathieu Chartier | d68ac70 | 2014-02-11 14:50:51 -0800 | [diff] [blame] | 2359 | if (is_copy) { |
| 2360 | // Sanity check: If elements is not the same as the java array's data, it better not be a |
| 2361 | // heap address. TODO: This might be slow to check, may be worth keeping track of which |
| 2362 | // copies we make? |
| 2363 | if (heap->IsNonDiscontinuousSpaceHeapAddress(reinterpret_cast<mirror::Object*>(elements))) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2364 | soa.Vm()->JniAbortF("ReleaseArrayElements", |
| 2365 | "invalid element pointer %p, array elements are %p", |
| 2366 | reinterpret_cast<void*>(elements), array_data); |
Mathieu Chartier | d68ac70 | 2014-02-11 14:50:51 -0800 | [diff] [blame] | 2367 | return; |
| 2368 | } |
Mathieu Chartier | 24555ad | 2014-10-06 13:41:33 -0700 | [diff] [blame] | 2369 | if (mode != JNI_ABORT) { |
| 2370 | memcpy(array_data, elements, bytes); |
| 2371 | } else if (kWarnJniAbort && memcmp(array_data, elements, bytes) != 0) { |
| 2372 | // Warn if we have JNI_ABORT and the arrays don't match since this is usually an error. |
| 2373 | LOG(WARNING) << "Possible incorrect JNI_ABORT in Release*ArrayElements"; |
| 2374 | soa.Self()->DumpJavaStack(LOG(WARNING)); |
| 2375 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2376 | } |
| 2377 | if (mode != JNI_COMMIT) { |
| 2378 | if (is_copy) { |
| 2379 | delete[] reinterpret_cast<uint64_t*>(elements); |
Mathieu Chartier | 3e8b2e1 | 2014-01-19 17:17:26 -0800 | [diff] [blame] | 2380 | } else if (heap->IsMovableObject(array)) { |
Mathieu Chartier | 1d27b34 | 2014-01-28 12:51:09 -0800 | [diff] [blame] | 2381 | // Non copy to a movable object must means that we had disabled the moving GC. |
| 2382 | heap->DecrementDisableMovingGC(soa.Self()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2383 | } |
| 2384 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2387 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2388 | static void GetPrimitiveArrayRegion(JNIEnv* env, JArrayT java_array, |
| 2389 | jsize start, jsize length, ElementT* buf) { |
| 2390 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 2391 | ScopedObjectAccess soa(env); |
| 2392 | ArtArrayT* array = |
| 2393 | DecodeAndCheckArrayType<JArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2394 | "GetPrimitiveArrayRegion", |
| 2395 | "get region of"); |
| 2396 | if (array != nullptr) { |
| 2397 | if (start < 0 || length < 0 || start + length > array->GetLength()) { |
| 2398 | ThrowAIOOBE(soa, array, start, length, "src"); |
| 2399 | } else { |
| 2400 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
| 2401 | ElementT* data = array->GetData(); |
| 2402 | memcpy(buf, data + start, length * sizeof(ElementT)); |
| 2403 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2404 | } |
| 2405 | } |
| 2406 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2407 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2408 | static void SetPrimitiveArrayRegion(JNIEnv* env, JArrayT java_array, |
| 2409 | jsize start, jsize length, const ElementT* buf) { |
| 2410 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 2411 | ScopedObjectAccess soa(env); |
| 2412 | ArtArrayT* array = |
| 2413 | DecodeAndCheckArrayType<JArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2414 | "SetPrimitiveArrayRegion", |
| 2415 | "set region of"); |
| 2416 | if (array != nullptr) { |
| 2417 | if (start < 0 || length < 0 || start + length > array->GetLength()) { |
| 2418 | ThrowAIOOBE(soa, array, start, length, "dst"); |
| 2419 | } else { |
| 2420 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
| 2421 | ElementT* data = array->GetData(); |
| 2422 | memcpy(data + start, buf, length * sizeof(ElementT)); |
| 2423 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2424 | } |
| 2425 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2426 | }; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 2427 | |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 2428 | const JNINativeInterface gJniNativeInterface = { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2429 | nullptr, // reserved0. |
| 2430 | nullptr, // reserved1. |
| 2431 | nullptr, // reserved2. |
| 2432 | nullptr, // reserved3. |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2433 | JNI::GetVersion, |
| 2434 | JNI::DefineClass, |
| 2435 | JNI::FindClass, |
| 2436 | JNI::FromReflectedMethod, |
| 2437 | JNI::FromReflectedField, |
| 2438 | JNI::ToReflectedMethod, |
| 2439 | JNI::GetSuperclass, |
| 2440 | JNI::IsAssignableFrom, |
| 2441 | JNI::ToReflectedField, |
| 2442 | JNI::Throw, |
| 2443 | JNI::ThrowNew, |
| 2444 | JNI::ExceptionOccurred, |
| 2445 | JNI::ExceptionDescribe, |
| 2446 | JNI::ExceptionClear, |
| 2447 | JNI::FatalError, |
| 2448 | JNI::PushLocalFrame, |
| 2449 | JNI::PopLocalFrame, |
| 2450 | JNI::NewGlobalRef, |
| 2451 | JNI::DeleteGlobalRef, |
| 2452 | JNI::DeleteLocalRef, |
| 2453 | JNI::IsSameObject, |
| 2454 | JNI::NewLocalRef, |
| 2455 | JNI::EnsureLocalCapacity, |
| 2456 | JNI::AllocObject, |
| 2457 | JNI::NewObject, |
| 2458 | JNI::NewObjectV, |
| 2459 | JNI::NewObjectA, |
| 2460 | JNI::GetObjectClass, |
| 2461 | JNI::IsInstanceOf, |
| 2462 | JNI::GetMethodID, |
| 2463 | JNI::CallObjectMethod, |
| 2464 | JNI::CallObjectMethodV, |
| 2465 | JNI::CallObjectMethodA, |
| 2466 | JNI::CallBooleanMethod, |
| 2467 | JNI::CallBooleanMethodV, |
| 2468 | JNI::CallBooleanMethodA, |
| 2469 | JNI::CallByteMethod, |
| 2470 | JNI::CallByteMethodV, |
| 2471 | JNI::CallByteMethodA, |
| 2472 | JNI::CallCharMethod, |
| 2473 | JNI::CallCharMethodV, |
| 2474 | JNI::CallCharMethodA, |
| 2475 | JNI::CallShortMethod, |
| 2476 | JNI::CallShortMethodV, |
| 2477 | JNI::CallShortMethodA, |
| 2478 | JNI::CallIntMethod, |
| 2479 | JNI::CallIntMethodV, |
| 2480 | JNI::CallIntMethodA, |
| 2481 | JNI::CallLongMethod, |
| 2482 | JNI::CallLongMethodV, |
| 2483 | JNI::CallLongMethodA, |
| 2484 | JNI::CallFloatMethod, |
| 2485 | JNI::CallFloatMethodV, |
| 2486 | JNI::CallFloatMethodA, |
| 2487 | JNI::CallDoubleMethod, |
| 2488 | JNI::CallDoubleMethodV, |
| 2489 | JNI::CallDoubleMethodA, |
| 2490 | JNI::CallVoidMethod, |
| 2491 | JNI::CallVoidMethodV, |
| 2492 | JNI::CallVoidMethodA, |
| 2493 | JNI::CallNonvirtualObjectMethod, |
| 2494 | JNI::CallNonvirtualObjectMethodV, |
| 2495 | JNI::CallNonvirtualObjectMethodA, |
| 2496 | JNI::CallNonvirtualBooleanMethod, |
| 2497 | JNI::CallNonvirtualBooleanMethodV, |
| 2498 | JNI::CallNonvirtualBooleanMethodA, |
| 2499 | JNI::CallNonvirtualByteMethod, |
| 2500 | JNI::CallNonvirtualByteMethodV, |
| 2501 | JNI::CallNonvirtualByteMethodA, |
| 2502 | JNI::CallNonvirtualCharMethod, |
| 2503 | JNI::CallNonvirtualCharMethodV, |
| 2504 | JNI::CallNonvirtualCharMethodA, |
| 2505 | JNI::CallNonvirtualShortMethod, |
| 2506 | JNI::CallNonvirtualShortMethodV, |
| 2507 | JNI::CallNonvirtualShortMethodA, |
| 2508 | JNI::CallNonvirtualIntMethod, |
| 2509 | JNI::CallNonvirtualIntMethodV, |
| 2510 | JNI::CallNonvirtualIntMethodA, |
| 2511 | JNI::CallNonvirtualLongMethod, |
| 2512 | JNI::CallNonvirtualLongMethodV, |
| 2513 | JNI::CallNonvirtualLongMethodA, |
| 2514 | JNI::CallNonvirtualFloatMethod, |
| 2515 | JNI::CallNonvirtualFloatMethodV, |
| 2516 | JNI::CallNonvirtualFloatMethodA, |
| 2517 | JNI::CallNonvirtualDoubleMethod, |
| 2518 | JNI::CallNonvirtualDoubleMethodV, |
| 2519 | JNI::CallNonvirtualDoubleMethodA, |
| 2520 | JNI::CallNonvirtualVoidMethod, |
| 2521 | JNI::CallNonvirtualVoidMethodV, |
| 2522 | JNI::CallNonvirtualVoidMethodA, |
| 2523 | JNI::GetFieldID, |
| 2524 | JNI::GetObjectField, |
| 2525 | JNI::GetBooleanField, |
| 2526 | JNI::GetByteField, |
| 2527 | JNI::GetCharField, |
| 2528 | JNI::GetShortField, |
| 2529 | JNI::GetIntField, |
| 2530 | JNI::GetLongField, |
| 2531 | JNI::GetFloatField, |
| 2532 | JNI::GetDoubleField, |
| 2533 | JNI::SetObjectField, |
| 2534 | JNI::SetBooleanField, |
| 2535 | JNI::SetByteField, |
| 2536 | JNI::SetCharField, |
| 2537 | JNI::SetShortField, |
| 2538 | JNI::SetIntField, |
| 2539 | JNI::SetLongField, |
| 2540 | JNI::SetFloatField, |
| 2541 | JNI::SetDoubleField, |
| 2542 | JNI::GetStaticMethodID, |
| 2543 | JNI::CallStaticObjectMethod, |
| 2544 | JNI::CallStaticObjectMethodV, |
| 2545 | JNI::CallStaticObjectMethodA, |
| 2546 | JNI::CallStaticBooleanMethod, |
| 2547 | JNI::CallStaticBooleanMethodV, |
| 2548 | JNI::CallStaticBooleanMethodA, |
| 2549 | JNI::CallStaticByteMethod, |
| 2550 | JNI::CallStaticByteMethodV, |
| 2551 | JNI::CallStaticByteMethodA, |
| 2552 | JNI::CallStaticCharMethod, |
| 2553 | JNI::CallStaticCharMethodV, |
| 2554 | JNI::CallStaticCharMethodA, |
| 2555 | JNI::CallStaticShortMethod, |
| 2556 | JNI::CallStaticShortMethodV, |
| 2557 | JNI::CallStaticShortMethodA, |
| 2558 | JNI::CallStaticIntMethod, |
| 2559 | JNI::CallStaticIntMethodV, |
| 2560 | JNI::CallStaticIntMethodA, |
| 2561 | JNI::CallStaticLongMethod, |
| 2562 | JNI::CallStaticLongMethodV, |
| 2563 | JNI::CallStaticLongMethodA, |
| 2564 | JNI::CallStaticFloatMethod, |
| 2565 | JNI::CallStaticFloatMethodV, |
| 2566 | JNI::CallStaticFloatMethodA, |
| 2567 | JNI::CallStaticDoubleMethod, |
| 2568 | JNI::CallStaticDoubleMethodV, |
| 2569 | JNI::CallStaticDoubleMethodA, |
| 2570 | JNI::CallStaticVoidMethod, |
| 2571 | JNI::CallStaticVoidMethodV, |
| 2572 | JNI::CallStaticVoidMethodA, |
| 2573 | JNI::GetStaticFieldID, |
| 2574 | JNI::GetStaticObjectField, |
| 2575 | JNI::GetStaticBooleanField, |
| 2576 | JNI::GetStaticByteField, |
| 2577 | JNI::GetStaticCharField, |
| 2578 | JNI::GetStaticShortField, |
| 2579 | JNI::GetStaticIntField, |
| 2580 | JNI::GetStaticLongField, |
| 2581 | JNI::GetStaticFloatField, |
| 2582 | JNI::GetStaticDoubleField, |
| 2583 | JNI::SetStaticObjectField, |
| 2584 | JNI::SetStaticBooleanField, |
| 2585 | JNI::SetStaticByteField, |
| 2586 | JNI::SetStaticCharField, |
| 2587 | JNI::SetStaticShortField, |
| 2588 | JNI::SetStaticIntField, |
| 2589 | JNI::SetStaticLongField, |
| 2590 | JNI::SetStaticFloatField, |
| 2591 | JNI::SetStaticDoubleField, |
| 2592 | JNI::NewString, |
| 2593 | JNI::GetStringLength, |
| 2594 | JNI::GetStringChars, |
| 2595 | JNI::ReleaseStringChars, |
| 2596 | JNI::NewStringUTF, |
| 2597 | JNI::GetStringUTFLength, |
| 2598 | JNI::GetStringUTFChars, |
| 2599 | JNI::ReleaseStringUTFChars, |
| 2600 | JNI::GetArrayLength, |
| 2601 | JNI::NewObjectArray, |
| 2602 | JNI::GetObjectArrayElement, |
| 2603 | JNI::SetObjectArrayElement, |
| 2604 | JNI::NewBooleanArray, |
| 2605 | JNI::NewByteArray, |
| 2606 | JNI::NewCharArray, |
| 2607 | JNI::NewShortArray, |
| 2608 | JNI::NewIntArray, |
| 2609 | JNI::NewLongArray, |
| 2610 | JNI::NewFloatArray, |
| 2611 | JNI::NewDoubleArray, |
| 2612 | JNI::GetBooleanArrayElements, |
| 2613 | JNI::GetByteArrayElements, |
| 2614 | JNI::GetCharArrayElements, |
| 2615 | JNI::GetShortArrayElements, |
| 2616 | JNI::GetIntArrayElements, |
| 2617 | JNI::GetLongArrayElements, |
| 2618 | JNI::GetFloatArrayElements, |
| 2619 | JNI::GetDoubleArrayElements, |
| 2620 | JNI::ReleaseBooleanArrayElements, |
| 2621 | JNI::ReleaseByteArrayElements, |
| 2622 | JNI::ReleaseCharArrayElements, |
| 2623 | JNI::ReleaseShortArrayElements, |
| 2624 | JNI::ReleaseIntArrayElements, |
| 2625 | JNI::ReleaseLongArrayElements, |
| 2626 | JNI::ReleaseFloatArrayElements, |
| 2627 | JNI::ReleaseDoubleArrayElements, |
| 2628 | JNI::GetBooleanArrayRegion, |
| 2629 | JNI::GetByteArrayRegion, |
| 2630 | JNI::GetCharArrayRegion, |
| 2631 | JNI::GetShortArrayRegion, |
| 2632 | JNI::GetIntArrayRegion, |
| 2633 | JNI::GetLongArrayRegion, |
| 2634 | JNI::GetFloatArrayRegion, |
| 2635 | JNI::GetDoubleArrayRegion, |
| 2636 | JNI::SetBooleanArrayRegion, |
| 2637 | JNI::SetByteArrayRegion, |
| 2638 | JNI::SetCharArrayRegion, |
| 2639 | JNI::SetShortArrayRegion, |
| 2640 | JNI::SetIntArrayRegion, |
| 2641 | JNI::SetLongArrayRegion, |
| 2642 | JNI::SetFloatArrayRegion, |
| 2643 | JNI::SetDoubleArrayRegion, |
| 2644 | JNI::RegisterNatives, |
| 2645 | JNI::UnregisterNatives, |
| 2646 | JNI::MonitorEnter, |
| 2647 | JNI::MonitorExit, |
| 2648 | JNI::GetJavaVM, |
| 2649 | JNI::GetStringRegion, |
| 2650 | JNI::GetStringUTFRegion, |
| 2651 | JNI::GetPrimitiveArrayCritical, |
| 2652 | JNI::ReleasePrimitiveArrayCritical, |
| 2653 | JNI::GetStringCritical, |
| 2654 | JNI::ReleaseStringCritical, |
| 2655 | JNI::NewWeakGlobalRef, |
| 2656 | JNI::DeleteWeakGlobalRef, |
| 2657 | JNI::ExceptionCheck, |
| 2658 | JNI::NewDirectByteBuffer, |
| 2659 | JNI::GetDirectBufferAddress, |
| 2660 | JNI::GetDirectBufferCapacity, |
| 2661 | JNI::GetObjectRefType, |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 2662 | }; |
| 2663 | |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2664 | const JNINativeInterface* GetJniNativeInterface() { |
| 2665 | return &gJniNativeInterface; |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2668 | void RegisterNativeMethods(JNIEnv* env, const char* jni_class_name, const JNINativeMethod* methods, |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2669 | jint method_count) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2670 | ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name)); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2671 | if (c.get() == nullptr) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2672 | LOG(FATAL) << "Couldn't find class: " << jni_class_name; |
| 2673 | } |
| 2674 | JNI::RegisterNativeMethods(env, c.get(), methods, method_count, false); |
| 2675 | } |
| 2676 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 2677 | } // namespace art |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2678 | |
| 2679 | std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs) { |
| 2680 | switch (rhs) { |
| 2681 | case JNIInvalidRefType: |
| 2682 | os << "JNIInvalidRefType"; |
| 2683 | return os; |
| 2684 | case JNILocalRefType: |
| 2685 | os << "JNILocalRefType"; |
| 2686 | return os; |
| 2687 | case JNIGlobalRefType: |
| 2688 | os << "JNIGlobalRefType"; |
| 2689 | return os; |
| 2690 | case JNIWeakGlobalRefType: |
| 2691 | os << "JNIWeakGlobalRefType"; |
| 2692 | return os; |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 2693 | default: |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 2694 | LOG(::art::FATAL) << "jobjectRefType[" << static_cast<int>(rhs) << "]"; |
| 2695 | UNREACHABLE(); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2696 | } |
| 2697 | } |