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