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