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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 93 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 102 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 111 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 125 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 152 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 183 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 231 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | REQUIRES_SHARED(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) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 318 | REQUIRES_SHARED(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(); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 595 | return soa.AddLocalReference<jobject>(mirror::String::AllocEmptyString<true>(soa.Self(), |
| 596 | allocator_type)); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 597 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 598 | return soa.AddLocalReference<jobject>(c->AllocObject(soa.Self())); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 601 | static jobject NewObject(JNIEnv* env, jclass java_class, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 602 | va_list args; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 603 | va_start(args, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 604 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 605 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 606 | jobject result = NewObjectV(env, java_class, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 607 | va_end(args); |
| 608 | return result; |
| 609 | } |
| 610 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 611 | 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] | 612 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 613 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 614 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 615 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 616 | if (c == nullptr) { |
| 617 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 618 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 619 | if (c->IsStringClass()) { |
| 620 | // Replace calls to String.<init> with equivalent StringFactory call. |
| 621 | jmethodID sf_mid = WellKnownClasses::StringInitToStringFactoryMethodID(mid); |
| 622 | return CallStaticObjectMethodV(env, WellKnownClasses::java_lang_StringFactory, sf_mid, args); |
| 623 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 624 | mirror::Object* result = c->AllocObject(soa.Self()); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 625 | if (result == nullptr) { |
| 626 | return nullptr; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 627 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 628 | jobject local_result = soa.AddLocalReference<jobject>(result); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 629 | CallNonvirtualVoidMethodV(env, local_result, java_class, mid, args); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 630 | if (soa.Self()->IsExceptionPending()) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 631 | return nullptr; |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 632 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 633 | return local_result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 636 | static jobject NewObjectA(JNIEnv* env, jclass java_class, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 637 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 638 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 639 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 640 | mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 641 | if (c == nullptr) { |
| 642 | return nullptr; |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 643 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 644 | if (c->IsStringClass()) { |
| 645 | // Replace calls to String.<init> with equivalent StringFactory call. |
| 646 | jmethodID sf_mid = WellKnownClasses::StringInitToStringFactoryMethodID(mid); |
| 647 | return CallStaticObjectMethodA(env, WellKnownClasses::java_lang_StringFactory, sf_mid, args); |
| 648 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 649 | mirror::Object* result = c->AllocObject(soa.Self()); |
| 650 | if (result == nullptr) { |
| 651 | return nullptr; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 652 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 653 | jobject local_result = soa.AddLocalReference<jobjectArray>(result); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 654 | CallNonvirtualVoidMethodA(env, local_result, java_class, mid, args); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 655 | if (soa.Self()->IsExceptionPending()) { |
| 656 | return nullptr; |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 657 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 658 | return local_result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 661 | 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] | 662 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 663 | CHECK_NON_NULL_ARGUMENT(name); |
| 664 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 665 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 666 | return FindMethodID(soa, java_class, name, sig, false); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 669 | static jmethodID GetStaticMethodID(JNIEnv* env, jclass java_class, const char* name, |
| 670 | const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 671 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 672 | CHECK_NON_NULL_ARGUMENT(name); |
| 673 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 674 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 675 | return FindMethodID(soa, java_class, name, sig, true); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 678 | static jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 679 | va_list ap; |
| 680 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 681 | CHECK_NON_NULL_ARGUMENT(obj); |
| 682 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 683 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 684 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 685 | va_end(ap); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 686 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 689 | static jobject CallObjectMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 690 | CHECK_NON_NULL_ARGUMENT(obj); |
| 691 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 692 | ScopedObjectAccess soa(env); |
| 693 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args)); |
| 694 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 697 | static jobject CallObjectMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 698 | CHECK_NON_NULL_ARGUMENT(obj); |
| 699 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 700 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 701 | JValue result(InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 702 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 705 | static jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 706 | va_list ap; |
| 707 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 708 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 709 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 710 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 711 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 712 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 713 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 716 | static jboolean CallBooleanMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 717 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 718 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 719 | ScopedObjectAccess soa(env); |
| 720 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 723 | static jboolean CallBooleanMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 724 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 725 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 726 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 727 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 730 | static jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 731 | va_list ap; |
| 732 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 733 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 734 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 735 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 736 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 737 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 738 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 741 | static jbyte CallByteMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 742 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 743 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 744 | ScopedObjectAccess soa(env); |
| 745 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 748 | static jbyte CallByteMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 749 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 750 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 751 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 752 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 755 | static jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 756 | va_list ap; |
| 757 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 758 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 759 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 760 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 761 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 762 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 763 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 766 | static jchar CallCharMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 767 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 768 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 769 | ScopedObjectAccess soa(env); |
| 770 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 773 | static jchar CallCharMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 774 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 775 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 776 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 777 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 780 | static jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 781 | va_list ap; |
| 782 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 783 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 784 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 785 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 786 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 787 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 788 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 791 | static jdouble CallDoubleMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 792 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 793 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 794 | ScopedObjectAccess soa(env); |
| 795 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 798 | static jdouble CallDoubleMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 799 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 800 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 801 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 802 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 805 | static jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 806 | va_list ap; |
| 807 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 808 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 809 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 810 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 811 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 812 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 813 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 816 | static jfloat CallFloatMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 817 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 818 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 819 | ScopedObjectAccess soa(env); |
| 820 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 823 | static jfloat CallFloatMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 824 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 825 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 826 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 827 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 830 | static jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 831 | va_list ap; |
| 832 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 833 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 834 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 835 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 836 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 837 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 838 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 841 | static jint CallIntMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 842 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 843 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 844 | ScopedObjectAccess soa(env); |
| 845 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 848 | static jint CallIntMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 849 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 850 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 851 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 852 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 855 | static jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 856 | va_list ap; |
| 857 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 858 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 859 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 860 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 861 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 862 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 863 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 866 | static jlong CallLongMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 867 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 868 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 869 | ScopedObjectAccess soa(env); |
| 870 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 873 | static jlong CallLongMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 874 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 875 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 876 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 877 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 880 | static jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 881 | va_list ap; |
| 882 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 883 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 884 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 885 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 886 | JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 887 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 888 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 891 | static jshort CallShortMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 892 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 893 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 894 | ScopedObjectAccess soa(env); |
| 895 | return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 898 | static jshort CallShortMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 899 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 900 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 901 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 902 | return InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 905 | static void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 906 | va_list ap; |
| 907 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 908 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 909 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 910 | ScopedObjectAccess soa(env); |
Ian Rogers | 1b09b09 | 2012-08-20 15:35:52 -0700 | [diff] [blame] | 911 | InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 912 | va_end(ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 915 | static void CallVoidMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 916 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 917 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 918 | ScopedObjectAccess soa(env); |
| 919 | InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 922 | static void CallVoidMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 923 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 924 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 925 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 926 | InvokeVirtualOrInterfaceWithJValues(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 929 | static jobject CallNonvirtualObjectMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 930 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 931 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 932 | CHECK_NON_NULL_ARGUMENT(obj); |
| 933 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 934 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 935 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
| 936 | jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 937 | va_end(ap); |
| 938 | return local_result; |
| 939 | } |
| 940 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 941 | static jobject CallNonvirtualObjectMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 942 | va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 943 | CHECK_NON_NULL_ARGUMENT(obj); |
| 944 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 945 | ScopedObjectAccess soa(env); |
| 946 | JValue result(InvokeWithVarArgs(soa, obj, mid, args)); |
| 947 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 950 | static jobject CallNonvirtualObjectMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 951 | jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 952 | CHECK_NON_NULL_ARGUMENT(obj); |
| 953 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 954 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 955 | JValue result(InvokeWithJValues(soa, obj, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 956 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 959 | static jboolean CallNonvirtualBooleanMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 960 | ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 961 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 962 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 963 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 964 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 965 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 966 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 967 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 968 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 971 | static jboolean CallNonvirtualBooleanMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 972 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 973 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 974 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 975 | ScopedObjectAccess soa(env); |
| 976 | return InvokeWithVarArgs(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 979 | static jboolean CallNonvirtualBooleanMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 980 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 981 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 982 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 983 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 984 | return InvokeWithJValues(soa, obj, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 987 | static jbyte CallNonvirtualByteMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 988 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 989 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 990 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 991 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 992 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 993 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 994 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 995 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 998 | static jbyte CallNonvirtualByteMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 999 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1000 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1001 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1002 | ScopedObjectAccess soa(env); |
| 1003 | return InvokeWithVarArgs(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1006 | static jbyte CallNonvirtualByteMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1007 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1008 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1009 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1010 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1011 | return InvokeWithJValues(soa, obj, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1014 | static jchar CallNonvirtualCharMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1015 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1016 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1017 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1018 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1019 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1020 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1021 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1022 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1025 | static jchar CallNonvirtualCharMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1026 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1027 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1028 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1029 | ScopedObjectAccess soa(env); |
| 1030 | return InvokeWithVarArgs(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1033 | static jchar CallNonvirtualCharMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1034 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1035 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1036 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1037 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1038 | return InvokeWithJValues(soa, obj, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1041 | static jshort CallNonvirtualShortMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1042 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1043 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1044 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1045 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1046 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1047 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1048 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1049 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1052 | static jshort CallNonvirtualShortMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1053 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1054 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1055 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1056 | ScopedObjectAccess soa(env); |
| 1057 | return InvokeWithVarArgs(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1060 | static jshort CallNonvirtualShortMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1061 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1062 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1063 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1064 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1065 | return InvokeWithJValues(soa, obj, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1068 | static jint CallNonvirtualIntMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1069 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1070 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1071 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1072 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1073 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1074 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1075 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1076 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1079 | static jint CallNonvirtualIntMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1080 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1081 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1082 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1083 | ScopedObjectAccess soa(env); |
| 1084 | return InvokeWithVarArgs(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1087 | static jint CallNonvirtualIntMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1088 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1089 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1090 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1091 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1092 | return InvokeWithJValues(soa, obj, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1095 | static jlong CallNonvirtualLongMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1096 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1097 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1098 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1099 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1100 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1101 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1102 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1103 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1106 | static jlong CallNonvirtualLongMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1107 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1108 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1109 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1110 | ScopedObjectAccess soa(env); |
| 1111 | return InvokeWithVarArgs(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1114 | static jlong CallNonvirtualLongMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1115 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1116 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1117 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1118 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1119 | return InvokeWithJValues(soa, obj, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1122 | static jfloat CallNonvirtualFloatMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1123 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1124 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1125 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1126 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1127 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1128 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1129 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1130 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1133 | static jfloat CallNonvirtualFloatMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1134 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1135 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1136 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1137 | ScopedObjectAccess soa(env); |
| 1138 | return InvokeWithVarArgs(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1141 | static jfloat CallNonvirtualFloatMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1142 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1143 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1144 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1145 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1146 | return InvokeWithJValues(soa, obj, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1149 | static jdouble CallNonvirtualDoubleMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1150 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1151 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1152 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1153 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1154 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1155 | JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1156 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1157 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1160 | static jdouble CallNonvirtualDoubleMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1161 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1162 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1163 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1164 | ScopedObjectAccess soa(env); |
| 1165 | return InvokeWithVarArgs(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1168 | static jdouble CallNonvirtualDoubleMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1169 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1170 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(obj); |
| 1171 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1172 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1173 | return InvokeWithJValues(soa, obj, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1176 | static void CallNonvirtualVoidMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1177 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1178 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1179 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1180 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1181 | ScopedObjectAccess soa(env); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1182 | InvokeWithVarArgs(soa, obj, mid, ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1183 | va_end(ap); |
| 1184 | } |
| 1185 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1186 | static void CallNonvirtualVoidMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1187 | va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1188 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1189 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1190 | ScopedObjectAccess soa(env); |
| 1191 | InvokeWithVarArgs(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1194 | static void CallNonvirtualVoidMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, |
| 1195 | jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1196 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(obj); |
| 1197 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1198 | ScopedObjectAccess soa(env); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 1199 | InvokeWithJValues(soa, obj, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1202 | 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] | 1203 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 1204 | CHECK_NON_NULL_ARGUMENT(name); |
| 1205 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1206 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1207 | return FindFieldID(soa, java_class, name, sig, false); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1208 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1209 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1210 | static jfieldID GetStaticFieldID(JNIEnv* env, jclass java_class, const char* name, |
| 1211 | const char* sig) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1212 | CHECK_NON_NULL_ARGUMENT(java_class); |
| 1213 | CHECK_NON_NULL_ARGUMENT(name); |
| 1214 | CHECK_NON_NULL_ARGUMENT(sig); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1215 | ScopedObjectAccess soa(env); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1216 | return FindFieldID(soa, java_class, name, sig, true); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1217 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1218 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1219 | static jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fid) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1220 | CHECK_NON_NULL_ARGUMENT(obj); |
| 1221 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1222 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1223 | mirror::Object* o = soa.Decode<mirror::Object*>(obj); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1224 | ArtField* f = soa.DecodeField(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1225 | return soa.AddLocalReference<jobject>(f->GetObject(o)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1226 | } |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 1227 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1228 | static jobject GetStaticObjectField(JNIEnv* env, jclass, jfieldID fid) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1229 | CHECK_NON_NULL_ARGUMENT(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1230 | ScopedObjectAccess soa(env); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1231 | ArtField* f = soa.DecodeField(fid); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1232 | return soa.AddLocalReference<jobject>(f->GetObject(f->GetDeclaringClass())); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1235 | 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] | 1236 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_object); |
| 1237 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1238 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1239 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
| 1240 | mirror::Object* v = soa.Decode<mirror::Object*>(java_value); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1241 | ArtField* f = soa.DecodeField(fid); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1242 | f->SetObject<false>(o, v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1245 | static void SetStaticObjectField(JNIEnv* env, jclass, jfieldID fid, jobject java_value) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1246 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1247 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1248 | mirror::Object* v = soa.Decode<mirror::Object*>(java_value); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1249 | ArtField* f = soa.DecodeField(fid); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1250 | f->SetObject<false>(f->GetDeclaringClass(), v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1253 | #define GET_PRIMITIVE_FIELD(fn, instance) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1254 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(instance); \ |
| 1255 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(fid); \ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1256 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1257 | mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1258 | ArtField* f = soa.DecodeField(fid); \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1259 | return f->Get ##fn (o) |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1260 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1261 | #define GET_STATIC_PRIMITIVE_FIELD(fn) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1262 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(fid); \ |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1263 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1264 | ArtField* f = soa.DecodeField(fid); \ |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1265 | return f->Get ##fn (f->GetDeclaringClass()) |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1266 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1267 | #define SET_PRIMITIVE_FIELD(fn, instance, value) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1268 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(instance); \ |
| 1269 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); \ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1270 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1271 | mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1272 | ArtField* f = soa.DecodeField(fid); \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1273 | f->Set ##fn <false>(o, value) |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1274 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1275 | #define SET_STATIC_PRIMITIVE_FIELD(fn, value) \ |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1276 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(fid); \ |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1277 | ScopedObjectAccess soa(env); \ |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1278 | ArtField* f = soa.DecodeField(fid); \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1279 | f->Set ##fn <false>(f->GetDeclaringClass(), value) |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1280 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1281 | static jboolean GetBooleanField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1282 | GET_PRIMITIVE_FIELD(Boolean, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1285 | static jbyte GetByteField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1286 | GET_PRIMITIVE_FIELD(Byte, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1289 | static jchar GetCharField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1290 | GET_PRIMITIVE_FIELD(Char, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1293 | static jshort GetShortField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1294 | GET_PRIMITIVE_FIELD(Short, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1297 | static jint GetIntField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1298 | GET_PRIMITIVE_FIELD(Int, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1301 | static jlong GetLongField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1302 | GET_PRIMITIVE_FIELD(Long, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1305 | static jfloat GetFloatField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1306 | GET_PRIMITIVE_FIELD(Float, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1309 | static jdouble GetDoubleField(JNIEnv* env, jobject obj, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1310 | GET_PRIMITIVE_FIELD(Double, obj); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1313 | static jboolean GetStaticBooleanField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1314 | GET_STATIC_PRIMITIVE_FIELD(Boolean); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1317 | static jbyte GetStaticByteField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1318 | GET_STATIC_PRIMITIVE_FIELD(Byte); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1321 | static jchar GetStaticCharField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1322 | GET_STATIC_PRIMITIVE_FIELD(Char); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1325 | static jshort GetStaticShortField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1326 | GET_STATIC_PRIMITIVE_FIELD(Short); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1329 | static jint GetStaticIntField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1330 | GET_STATIC_PRIMITIVE_FIELD(Int); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1333 | static jlong GetStaticLongField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1334 | GET_STATIC_PRIMITIVE_FIELD(Long); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1337 | static jfloat GetStaticFloatField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1338 | GET_STATIC_PRIMITIVE_FIELD(Float); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1341 | static jdouble GetStaticDoubleField(JNIEnv* env, jclass, jfieldID fid) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1342 | GET_STATIC_PRIMITIVE_FIELD(Double); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static void SetBooleanField(JNIEnv* env, jobject obj, jfieldID fid, jboolean v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1346 | SET_PRIMITIVE_FIELD(Boolean, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | static void SetByteField(JNIEnv* env, jobject obj, jfieldID fid, jbyte v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1350 | SET_PRIMITIVE_FIELD(Byte, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | static void SetCharField(JNIEnv* env, jobject obj, jfieldID fid, jchar v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1354 | SET_PRIMITIVE_FIELD(Char, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | static void SetFloatField(JNIEnv* env, jobject obj, jfieldID fid, jfloat v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1358 | SET_PRIMITIVE_FIELD(Float, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | static void SetDoubleField(JNIEnv* env, jobject obj, jfieldID fid, jdouble v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1362 | SET_PRIMITIVE_FIELD(Double, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | static void SetIntField(JNIEnv* env, jobject obj, jfieldID fid, jint v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1366 | SET_PRIMITIVE_FIELD(Int, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | static void SetLongField(JNIEnv* env, jobject obj, jfieldID fid, jlong v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1370 | SET_PRIMITIVE_FIELD(Long, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | static void SetShortField(JNIEnv* env, jobject obj, jfieldID fid, jshort v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1374 | SET_PRIMITIVE_FIELD(Short, obj, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | static void SetStaticBooleanField(JNIEnv* env, jclass, jfieldID fid, jboolean v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1378 | SET_STATIC_PRIMITIVE_FIELD(Boolean, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static void SetStaticByteField(JNIEnv* env, jclass, jfieldID fid, jbyte v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1382 | SET_STATIC_PRIMITIVE_FIELD(Byte, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | static void SetStaticCharField(JNIEnv* env, jclass, jfieldID fid, jchar v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1386 | SET_STATIC_PRIMITIVE_FIELD(Char, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | static void SetStaticFloatField(JNIEnv* env, jclass, jfieldID fid, jfloat v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1390 | SET_STATIC_PRIMITIVE_FIELD(Float, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | static void SetStaticDoubleField(JNIEnv* env, jclass, jfieldID fid, jdouble v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1394 | SET_STATIC_PRIMITIVE_FIELD(Double, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | static void SetStaticIntField(JNIEnv* env, jclass, jfieldID fid, jint v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1398 | SET_STATIC_PRIMITIVE_FIELD(Int, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | static void SetStaticLongField(JNIEnv* env, jclass, jfieldID fid, jlong v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1402 | SET_STATIC_PRIMITIVE_FIELD(Long, v); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | static void SetStaticShortField(JNIEnv* env, jclass, jfieldID fid, jshort v) { |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1406 | SET_STATIC_PRIMITIVE_FIELD(Short, v); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1409 | static jobject CallStaticObjectMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1410 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1411 | va_start(ap, mid); |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1412 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1413 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1414 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1415 | jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1416 | va_end(ap); |
| 1417 | return local_result; |
| 1418 | } |
| 1419 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1420 | static jobject CallStaticObjectMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1421 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1422 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1423 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1424 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1427 | static jobject CallStaticObjectMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1428 | CHECK_NON_NULL_ARGUMENT(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1429 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1430 | JValue result(InvokeWithJValues(soa, nullptr, mid, args)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1431 | return soa.AddLocalReference<jobject>(result.GetL()); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1434 | static jboolean CallStaticBooleanMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1435 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1436 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1437 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1438 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1439 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1440 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1441 | return result.GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1444 | static jboolean CallStaticBooleanMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1445 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1446 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1447 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1450 | static jboolean CallStaticBooleanMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1451 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1452 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1453 | return InvokeWithJValues(soa, nullptr, mid, args).GetZ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1456 | static jbyte CallStaticByteMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1457 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1458 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1459 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1460 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1461 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1462 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1463 | return result.GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1466 | static jbyte CallStaticByteMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1467 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1468 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1469 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1472 | static jbyte CallStaticByteMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1473 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1474 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1475 | return InvokeWithJValues(soa, nullptr, mid, args).GetB(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1478 | static jchar CallStaticCharMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1479 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1480 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1481 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1482 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1483 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1484 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1485 | return result.GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1488 | static jchar CallStaticCharMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1489 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1490 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1491 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1494 | static jchar CallStaticCharMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1495 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1496 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1497 | return InvokeWithJValues(soa, nullptr, mid, args).GetC(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1500 | static jshort CallStaticShortMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1501 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1502 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1503 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1504 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1505 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1506 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1507 | return result.GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1510 | static jshort CallStaticShortMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1511 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1512 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1513 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1516 | static jshort CallStaticShortMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1517 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1518 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1519 | return InvokeWithJValues(soa, nullptr, mid, args).GetS(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1522 | static jint CallStaticIntMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1523 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1524 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1525 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1526 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1527 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1528 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1529 | return result.GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1532 | static jint CallStaticIntMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1533 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1534 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1535 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1538 | static jint CallStaticIntMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1539 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1540 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1541 | return InvokeWithJValues(soa, nullptr, mid, args).GetI(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1544 | static jlong CallStaticLongMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1545 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1546 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1547 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1548 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1549 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1550 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1551 | return result.GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1554 | static jlong CallStaticLongMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1555 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1556 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1557 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1560 | static jlong CallStaticLongMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1561 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1562 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1563 | return InvokeWithJValues(soa, nullptr, mid, args).GetJ(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1566 | static jfloat CallStaticFloatMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1567 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1568 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1569 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1570 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1571 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1572 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1573 | return result.GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1576 | static jfloat CallStaticFloatMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1577 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1578 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1579 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1582 | static jfloat CallStaticFloatMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1583 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1584 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1585 | return InvokeWithJValues(soa, nullptr, mid, args).GetF(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1588 | static jdouble CallStaticDoubleMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1589 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1590 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1591 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1592 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1593 | JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1594 | va_end(ap); |
Elliott Hughes | f24d3ce | 2012-04-11 17:43:37 -0700 | [diff] [blame] | 1595 | return result.GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1598 | static jdouble CallStaticDoubleMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1599 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1600 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1601 | return InvokeWithVarArgs(soa, nullptr, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1604 | static jdouble CallStaticDoubleMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1605 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1606 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1607 | return InvokeWithJValues(soa, nullptr, mid, args).GetD(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1610 | static void CallStaticVoidMethod(JNIEnv* env, jclass, jmethodID mid, ...) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1611 | va_list ap; |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1612 | va_start(ap, mid); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1613 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 25e8b91 | 2012-09-07 11:31:36 -0700 | [diff] [blame] | 1614 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1615 | InvokeWithVarArgs(soa, nullptr, mid, ap); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1616 | va_end(ap); |
| 1617 | } |
| 1618 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1619 | static void CallStaticVoidMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1620 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1621 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1622 | InvokeWithVarArgs(soa, nullptr, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1625 | static void CallStaticVoidMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1626 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(mid); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1627 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1628 | InvokeWithJValues(soa, nullptr, mid, args); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1631 | static jstring NewString(JNIEnv* env, const jchar* chars, jsize char_count) { |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1632 | if (UNLIKELY(char_count < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1633 | JavaVmExtFromEnv(env)->JniAbortF("NewString", "char_count < 0: %d", char_count); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1634 | return nullptr; |
| 1635 | } |
| 1636 | if (UNLIKELY(chars == nullptr && char_count > 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1637 | JavaVmExtFromEnv(env)->JniAbortF("NewString", "chars == null && char_count > 0"); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1638 | return nullptr; |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1639 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1640 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1641 | mirror::String* result = mirror::String::AllocFromUtf16(soa.Self(), char_count, chars); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1642 | return soa.AddLocalReference<jstring>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | static jstring NewStringUTF(JNIEnv* env, const char* utf) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1646 | if (utf == nullptr) { |
| 1647 | return nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1648 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1649 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1650 | mirror::String* result = mirror::String::AllocFromModifiedUtf8(soa.Self(), utf); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1651 | return soa.AddLocalReference<jstring>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1654 | static jsize GetStringLength(JNIEnv* env, jstring java_string) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1655 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1656 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1657 | return soa.Decode<mirror::String*>(java_string)->GetLength(); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | static jsize GetStringUTFLength(JNIEnv* env, jstring java_string) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1661 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1662 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1663 | return soa.Decode<mirror::String*>(java_string)->GetUtfLength(); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1666 | static void GetStringRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, |
| 1667 | jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1668 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1669 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1670 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Vladimir Marko | 795e341 | 2015-11-06 16:57:03 +0000 | [diff] [blame] | 1671 | if (start < 0 || length < 0 || length > s->GetLength() - start) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1672 | ThrowSIOOBE(soa, start, length, s->GetLength()); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1673 | } else { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1674 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1675 | if (s->IsCompressed()) { |
| 1676 | for (int i = 0; i < length; ++i) { |
| 1677 | buf[i] = static_cast<jchar>(s->CharAt(start+i)); |
| 1678 | } |
| 1679 | } else { |
| 1680 | const jchar* chars = static_cast<jchar*>(s->GetValue()); |
| 1681 | memcpy(buf, chars + start, length * sizeof(jchar)); |
| 1682 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1683 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1686 | static void GetStringUTFRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, |
| 1687 | char* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1688 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1689 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1690 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Vladimir Marko | 795e341 | 2015-11-06 16:57:03 +0000 | [diff] [blame] | 1691 | if (start < 0 || length < 0 || length > s->GetLength() - start) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1692 | ThrowSIOOBE(soa, start, length, s->GetLength()); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1693 | } else { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1694 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1695 | if (s->IsCompressed()) { |
| 1696 | for (int i = 0; i < length; ++i) { |
| 1697 | buf[i] = s->CharAt(start+i); |
| 1698 | } |
| 1699 | } else { |
| 1700 | const jchar* chars = s->GetValue(); |
| 1701 | size_t bytes = CountUtf8Bytes(chars + start, length); |
| 1702 | ConvertUtf16ToModifiedUtf8(buf, bytes, chars + start, length); |
| 1703 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1704 | } |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1707 | static const jchar* GetStringChars(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1708 | CHECK_NON_NULL_ARGUMENT(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1709 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1710 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1711 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1712 | if (heap->IsMovableObject(s) || s->IsCompressed()) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1713 | jchar* chars = new jchar[s->GetLength()]; |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1714 | if (s->IsCompressed()) { |
| 1715 | int32_t length = s->GetLength(); |
| 1716 | for (int i = 0; i < length; ++i) { |
| 1717 | chars[i] = s->CharAt(i); |
| 1718 | } |
| 1719 | } else { |
| 1720 | memcpy(chars, s->GetValue(), sizeof(jchar) * s->GetLength()); |
| 1721 | } |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1722 | if (is_copy != nullptr) { |
| 1723 | *is_copy = JNI_TRUE; |
| 1724 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1725 | return chars; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1726 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1727 | if (is_copy != nullptr) { |
| 1728 | *is_copy = JNI_FALSE; |
| 1729 | } |
| 1730 | return static_cast<jchar*>(s->GetValue()); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1733 | static void ReleaseStringChars(JNIEnv* env, jstring java_string, const jchar* chars) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1734 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1735 | ScopedObjectAccess soa(env); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1736 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1737 | if (s->IsCompressed() || (s->IsCompressed() == false && chars != s->GetValue())) { |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1738 | delete[] chars; |
| 1739 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1742 | static const jchar* GetStringCritical(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1743 | CHECK_NON_NULL_ARGUMENT(java_string); |
| 1744 | ScopedObjectAccess soa(env); |
| 1745 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1746 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1747 | if (heap->IsMovableObject(s)) { |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1748 | StackHandleScope<1> hs(soa.Self()); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1749 | HandleWrapper<mirror::String> h(hs.NewHandleWrapper(&s)); |
Hiroshi Yamauchi | 76f55b0 | 2015-08-21 16:10:39 -0700 | [diff] [blame] | 1750 | if (!kUseReadBarrier) { |
| 1751 | heap->IncrementDisableMovingGC(soa.Self()); |
| 1752 | } else { |
| 1753 | // For the CC collector, we only need to wait for the thread flip rather than the whole GC |
| 1754 | // to occur thanks to the to-space invariant. |
| 1755 | heap->IncrementDisableThreadFlip(soa.Self()); |
| 1756 | } |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1757 | } |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1758 | if (s->IsCompressed()) { |
| 1759 | if (is_copy != nullptr) { |
| 1760 | *is_copy = JNI_TRUE; |
| 1761 | } |
| 1762 | int32_t length = s->GetLength(); |
| 1763 | jchar* chars = new jchar[length]; |
| 1764 | for (int i = 0; i < length; ++i) { |
| 1765 | chars[i] = s->CharAt(i); |
| 1766 | } |
| 1767 | return chars; |
| 1768 | } else { |
| 1769 | if (is_copy != nullptr) { |
| 1770 | *is_copy = JNI_FALSE; |
| 1771 | } |
| 1772 | return static_cast<jchar*>(s->GetValue()); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1773 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1776 | static void ReleaseStringCritical(JNIEnv* env, |
| 1777 | jstring java_string, |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1778 | const jchar* chars) { |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1779 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string); |
| 1780 | ScopedObjectAccess soa(env); |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1781 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1782 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1783 | if (heap->IsMovableObject(s)) { |
Hiroshi Yamauchi | 76f55b0 | 2015-08-21 16:10:39 -0700 | [diff] [blame] | 1784 | if (!kUseReadBarrier) { |
| 1785 | heap->DecrementDisableMovingGC(soa.Self()); |
| 1786 | } else { |
| 1787 | heap->DecrementDisableThreadFlip(soa.Self()); |
| 1788 | } |
Fred Shih | 56890e2 | 2014-06-02 11:11:52 -0700 | [diff] [blame] | 1789 | } |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1790 | if (s->IsCompressed() || (s->IsCompressed() == false && s->GetValue() != chars)) { |
| 1791 | delete[] chars; |
| 1792 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1795 | static const char* GetStringUTFChars(JNIEnv* env, jstring java_string, jboolean* is_copy) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1796 | if (java_string == nullptr) { |
| 1797 | return nullptr; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1798 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1799 | if (is_copy != nullptr) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1800 | *is_copy = JNI_TRUE; |
| 1801 | } |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 1802 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1803 | mirror::String* s = soa.Decode<mirror::String*>(java_string); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1804 | size_t byte_count = s->GetUtfLength(); |
| 1805 | char* bytes = new char[byte_count + 1]; |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1806 | CHECK(bytes != nullptr); // bionic aborts anyway. |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 1807 | if (s->IsCompressed()) { |
| 1808 | for (size_t i = 0; i < byte_count; ++i) { |
| 1809 | bytes[i] = s->CharAt(i); |
| 1810 | } |
| 1811 | } else { |
| 1812 | const uint16_t* chars = s->GetValue(); |
| 1813 | ConvertUtf16ToModifiedUtf8(bytes, byte_count, chars, s->GetLength()); |
| 1814 | } |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1815 | bytes[byte_count] = '\0'; |
| 1816 | return bytes; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1819 | static void ReleaseStringUTFChars(JNIEnv*, jstring, const char* chars) { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1820 | delete[] chars; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Elliott Hughes | bd93599 | 2011-08-22 11:59:34 -0700 | [diff] [blame] | 1823 | static jsize GetArrayLength(JNIEnv* env, jarray java_array) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1824 | CHECK_NON_NULL_ARGUMENT_RETURN_ZERO(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1825 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1826 | mirror::Object* obj = soa.Decode<mirror::Object*>(java_array); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1827 | if (UNLIKELY(!obj->IsArrayInstance())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1828 | soa.Vm()->JniAbortF("GetArrayLength", "not an array: %s", PrettyTypeOf(obj).c_str()); |
| 1829 | return 0; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 1830 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1831 | mirror::Array* array = obj->AsArray(); |
Elliott Hughes | bd93599 | 2011-08-22 11:59:34 -0700 | [diff] [blame] | 1832 | return array->GetLength(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 1835 | static jobject GetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1836 | CHECK_NON_NULL_ARGUMENT(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1837 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1838 | mirror::ObjectArray<mirror::Object>* array = |
| 1839 | soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1840 | return soa.AddLocalReference<jobject>(array->Get(index)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 1843 | static void SetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index, |
| 1844 | jobject java_value) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1845 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1846 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1847 | mirror::ObjectArray<mirror::Object>* array = |
| 1848 | soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); |
| 1849 | mirror::Object* value = soa.Decode<mirror::Object*>(java_value); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1850 | array->Set<false>(index, value); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | static jbooleanArray NewBooleanArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1854 | return NewPrimitiveArray<jbooleanArray, mirror::BooleanArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static jbyteArray NewByteArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1858 | return NewPrimitiveArray<jbyteArray, mirror::ByteArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | static jcharArray NewCharArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1862 | return NewPrimitiveArray<jcharArray, mirror::CharArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | static jdoubleArray NewDoubleArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1866 | return NewPrimitiveArray<jdoubleArray, mirror::DoubleArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | static jfloatArray NewFloatArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1870 | return NewPrimitiveArray<jfloatArray, mirror::FloatArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | static jintArray NewIntArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1874 | return NewPrimitiveArray<jintArray, mirror::IntArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | static jlongArray NewLongArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1878 | return NewPrimitiveArray<jlongArray, mirror::LongArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1879 | } |
| 1880 | |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1881 | static jobjectArray NewObjectArray(JNIEnv* env, jsize length, jclass element_jclass, |
| 1882 | jobject initial_element) { |
| 1883 | if (UNLIKELY(length < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1884 | JavaVmExtFromEnv(env)->JniAbortF("NewObjectArray", "negative array length: %d", length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1885 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 1886 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1887 | CHECK_NON_NULL_ARGUMENT(element_jclass); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1888 | |
| 1889 | // Compute the array class corresponding to the given element class. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1890 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1891 | mirror::Class* array_class; |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1892 | { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1893 | mirror::Class* element_class = soa.Decode<mirror::Class*>(element_jclass); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1894 | if (UNLIKELY(element_class->IsPrimitive())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1895 | soa.Vm()->JniAbortF("NewObjectArray", "not an object type: %s", |
| 1896 | PrettyDescriptor(element_class).c_str()); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1897 | return nullptr; |
| 1898 | } |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1899 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | b74cd29 | 2014-05-29 14:31:33 -0700 | [diff] [blame] | 1900 | array_class = class_linker->FindArrayClass(soa.Self(), &element_class); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1901 | if (UNLIKELY(array_class == nullptr)) { |
| 1902 | return nullptr; |
| 1903 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1906 | // Allocate and initialize if necessary. |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1907 | mirror::ObjectArray<mirror::Object>* result = |
| 1908 | mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), array_class, length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1909 | if (result != nullptr && initial_element != nullptr) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1910 | mirror::Object* initial_object = soa.Decode<mirror::Object*>(initial_element); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1911 | if (initial_object != nullptr) { |
| 1912 | mirror::Class* element_class = result->GetClass()->GetComponentType(); |
| 1913 | if (UNLIKELY(!element_class->IsAssignableFrom(initial_object->GetClass()))) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1914 | soa.Vm()->JniAbortF("NewObjectArray", "cannot assign object of type '%s' to array with " |
| 1915 | "element type of '%s'", |
| 1916 | PrettyDescriptor(initial_object->GetClass()).c_str(), |
| 1917 | PrettyDescriptor(element_class).c_str()); |
| 1918 | return nullptr; |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1919 | } else { |
| 1920 | for (jsize i = 0; i < length; ++i) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1921 | result->SetWithoutChecks<false>(i, initial_object); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 1922 | } |
| 1923 | } |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1924 | } |
| 1925 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1926 | return soa.AddLocalReference<jobjectArray>(result); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | static jshortArray NewShortArray(JNIEnv* env, jsize length) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1930 | return NewPrimitiveArray<jshortArray, mirror::ShortArray>(env, length); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 1933 | static void* GetPrimitiveArrayCritical(JNIEnv* env, jarray java_array, jboolean* is_copy) { |
Mathieu Chartier | 3b60fea | 2014-04-24 17:17:21 -0700 | [diff] [blame] | 1934 | CHECK_NON_NULL_ARGUMENT(java_array); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1935 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 1936 | mirror::Array* array = soa.Decode<mirror::Array*>(java_array); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1937 | if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1938 | soa.Vm()->JniAbortF("GetPrimitiveArrayCritical", "expected primitive array, given %s", |
| 1939 | PrettyDescriptor(array->GetClass()).c_str()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1940 | return nullptr; |
| 1941 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1942 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1943 | if (heap->IsMovableObject(array)) { |
Hiroshi Yamauchi | 76f55b0 | 2015-08-21 16:10:39 -0700 | [diff] [blame] | 1944 | if (!kUseReadBarrier) { |
| 1945 | heap->IncrementDisableMovingGC(soa.Self()); |
| 1946 | } else { |
| 1947 | // For the CC collector, we only need to wait for the thread flip rather than the whole GC |
| 1948 | // to occur thanks to the to-space invariant. |
| 1949 | heap->IncrementDisableThreadFlip(soa.Self()); |
| 1950 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1951 | // 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] | 1952 | array = soa.Decode<mirror::Array*>(java_array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1953 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1954 | if (is_copy != nullptr) { |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 1955 | *is_copy = JNI_FALSE; |
| 1956 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1957 | return array->GetRawData(array->GetClass()->GetComponentSize(), 0); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1960 | static void ReleasePrimitiveArrayCritical(JNIEnv* env, jarray java_array, void* elements, |
| 1961 | jint mode) { |
| 1962 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 1963 | ScopedObjectAccess soa(env); |
| 1964 | mirror::Array* array = soa.Decode<mirror::Array*>(java_array); |
| 1965 | if (UNLIKELY(!array->GetClass()->IsPrimitiveArray())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1966 | soa.Vm()->JniAbortF("ReleasePrimitiveArrayCritical", "expected primitive array, given %s", |
| 1967 | PrettyDescriptor(array->GetClass()).c_str()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1968 | return; |
| 1969 | } |
| 1970 | const size_t component_size = array->GetClass()->GetComponentSize(); |
| 1971 | ReleasePrimitiveArray(soa, array, component_size, elements, mode); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1974 | static jboolean* GetBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1975 | return GetPrimitiveArray<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1978 | static jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1979 | return GetPrimitiveArray<jbyteArray, jbyte, mirror::ByteArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1982 | static jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1983 | return GetPrimitiveArray<jcharArray, jchar, mirror::CharArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1986 | static jdouble* GetDoubleArrayElements(JNIEnv* env, jdoubleArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1987 | return GetPrimitiveArray<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1990 | static jfloat* GetFloatArrayElements(JNIEnv* env, jfloatArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1991 | return GetPrimitiveArray<jfloatArray, jfloat, mirror::FloatArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1994 | static jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1995 | return GetPrimitiveArray<jintArray, jint, mirror::IntArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 1998 | static jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 1999 | return GetPrimitiveArray<jlongArray, jlong, mirror::LongArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 2002 | static jshort* GetShortArrayElements(JNIEnv* env, jshortArray array, jboolean* is_copy) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2003 | return GetPrimitiveArray<jshortArray, jshort, mirror::ShortArray>(env, array, is_copy); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2006 | static void ReleaseBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* elements, |
| 2007 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2008 | ReleasePrimitiveArray<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, elements, |
| 2009 | mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2012 | static void ReleaseByteArrayElements(JNIEnv* env, jbyteArray array, jbyte* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2013 | ReleasePrimitiveArray<jbyteArray, jbyte, mirror::ByteArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2016 | static void ReleaseCharArrayElements(JNIEnv* env, jcharArray array, jchar* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2017 | ReleasePrimitiveArray<jcharArray, jchar, mirror::CharArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2020 | static void ReleaseDoubleArrayElements(JNIEnv* env, jdoubleArray array, jdouble* elements, |
| 2021 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2022 | ReleasePrimitiveArray<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2025 | static void ReleaseFloatArrayElements(JNIEnv* env, jfloatArray array, jfloat* elements, |
| 2026 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2027 | ReleasePrimitiveArray<jfloatArray, jfloat, mirror::FloatArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2030 | static void ReleaseIntArrayElements(JNIEnv* env, jintArray array, jint* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2031 | ReleasePrimitiveArray<jintArray, jint, mirror::IntArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2034 | static void ReleaseLongArrayElements(JNIEnv* env, jlongArray array, jlong* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2035 | ReleasePrimitiveArray<jlongArray, jlong, mirror::LongArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2038 | static void ReleaseShortArrayElements(JNIEnv* env, jshortArray array, jshort* elements, |
| 2039 | jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2040 | ReleasePrimitiveArray<jshortArray, jshort, mirror::ShortArray>(env, array, elements, mode); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2043 | static void GetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize length, |
| 2044 | jboolean* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2045 | GetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, start, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2046 | length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2049 | static void GetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize length, |
| 2050 | jbyte* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2051 | GetPrimitiveArrayRegion<jbyteArray, jbyte, mirror::ByteArray>(env, array, start, 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 GetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize length, |
| 2055 | jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2056 | GetPrimitiveArrayRegion<jcharArray, jchar, mirror::CharArray>(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 GetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize length, |
| 2060 | jdouble* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2061 | GetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2062 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2065 | static void GetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize length, |
| 2066 | jfloat* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2067 | GetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2068 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2071 | static void GetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize length, |
| 2072 | jint* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2073 | GetPrimitiveArrayRegion<jintArray, jint, mirror::IntArray>(env, array, start, length, 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 GetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize length, |
| 2077 | jlong* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2078 | GetPrimitiveArrayRegion<jlongArray, jlong, mirror::LongArray>(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 GetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize length, |
| 2082 | jshort* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2083 | GetPrimitiveArrayRegion<jshortArray, jshort, mirror::ShortArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2084 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2087 | static void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize length, |
| 2088 | const jboolean* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2089 | SetPrimitiveArrayRegion<jbooleanArray, jboolean, mirror::BooleanArray>(env, array, start, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2090 | length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2093 | static void SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize length, |
| 2094 | const jbyte* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2095 | SetPrimitiveArrayRegion<jbyteArray, jbyte, mirror::ByteArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2098 | static void SetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize length, |
| 2099 | const jchar* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2100 | SetPrimitiveArrayRegion<jcharArray, jchar, mirror::CharArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2103 | static void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize length, |
| 2104 | const jdouble* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2105 | SetPrimitiveArrayRegion<jdoubleArray, jdouble, mirror::DoubleArray>(env, array, start, length, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2106 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2109 | static void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize length, |
| 2110 | const jfloat* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2111 | SetPrimitiveArrayRegion<jfloatArray, jfloat, mirror::FloatArray>(env, array, start, length, |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 2112 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2115 | static void SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize length, |
| 2116 | const jint* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2117 | SetPrimitiveArrayRegion<jintArray, jint, mirror::IntArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2120 | static void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize length, |
| 2121 | const jlong* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2122 | SetPrimitiveArrayRegion<jlongArray, jlong, mirror::LongArray>(env, array, start, length, buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2125 | static void SetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize length, |
| 2126 | const jshort* buf) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2127 | SetPrimitiveArrayRegion<jshortArray, jshort, mirror::ShortArray>(env, array, start, length, |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2128 | buf); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2131 | static jint RegisterNatives(JNIEnv* env, jclass java_class, const JNINativeMethod* methods, |
| 2132 | jint method_count) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2133 | return RegisterNativeMethods(env, java_class, methods, method_count, true); |
| 2134 | } |
| 2135 | |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2136 | static jint RegisterNativeMethods(JNIEnv* env, jclass java_class, const JNINativeMethod* methods, |
| 2137 | jint method_count, bool return_errors) { |
| 2138 | if (UNLIKELY(method_count < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2139 | JavaVmExtFromEnv(env)->JniAbortF("RegisterNatives", "negative method count: %d", |
| 2140 | method_count); |
| 2141 | return JNI_ERR; // Not reached except in unit tests. |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2142 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2143 | CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", java_class, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2144 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2145 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2146 | if (UNLIKELY(method_count == 0)) { |
| 2147 | LOG(WARNING) << "JNI RegisterNativeMethods: attempt to register 0 native methods for " |
| 2148 | << PrettyDescriptor(c); |
| 2149 | return JNI_OK; |
| 2150 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2151 | CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", methods, JNI_ERR); |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2152 | for (jint i = 0; i < method_count; ++i) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2153 | const char* name = methods[i].name; |
| 2154 | const char* sig = methods[i].signature; |
Sebastien Hertz | fa65e84 | 2014-07-03 09:39:53 +0200 | [diff] [blame] | 2155 | const void* fnPtr = methods[i].fnPtr; |
| 2156 | if (UNLIKELY(name == nullptr)) { |
| 2157 | ReportInvalidJNINativeMethod(soa, c, "method name", i, return_errors); |
| 2158 | return JNI_ERR; |
| 2159 | } else if (UNLIKELY(sig == nullptr)) { |
| 2160 | ReportInvalidJNINativeMethod(soa, c, "method signature", i, return_errors); |
| 2161 | return JNI_ERR; |
| 2162 | } else if (UNLIKELY(fnPtr == nullptr)) { |
| 2163 | ReportInvalidJNINativeMethod(soa, c, "native function", i, return_errors); |
| 2164 | return JNI_ERR; |
| 2165 | } |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 2166 | bool is_fast = false; |
Hiroshi Yamauchi | 36bce58 | 2015-05-12 12:16:10 -0700 | [diff] [blame] | 2167 | // Notes about fast JNI calls: |
| 2168 | // |
| 2169 | // On a normal JNI call, the calling thread usually transitions |
| 2170 | // from the kRunnable state to the kNative state. But if the |
| 2171 | // called native function needs to access any Java object, it |
| 2172 | // will have to transition back to the kRunnable state. |
| 2173 | // |
| 2174 | // There is a cost to this double transition. For a JNI call |
| 2175 | // that should be quick, this cost may dominate the call cost. |
| 2176 | // |
| 2177 | // On a fast JNI call, the calling thread avoids this double |
| 2178 | // transition by not transitioning from kRunnable to kNative and |
| 2179 | // stays in the kRunnable state. |
| 2180 | // |
| 2181 | // There are risks to using a fast JNI call because it can delay |
| 2182 | // a response to a thread suspension request which is typically |
| 2183 | // used for a GC root scanning, etc. If a fast JNI call takes a |
| 2184 | // long time, it could cause longer thread suspension latency |
| 2185 | // and GC pauses. |
| 2186 | // |
| 2187 | // Thus, fast JNI should be used with care. It should be used |
| 2188 | // for a JNI call that takes a short amount of time (eg. no |
| 2189 | // long-running loop) and does not block (eg. no locks, I/O, |
| 2190 | // etc.) |
| 2191 | // |
| 2192 | // A '!' prefix in the signature in the JNINativeMethod |
| 2193 | // indicates that it's a fast JNI call and the runtime omits the |
| 2194 | // thread state transition from kRunnable to kNative at the |
| 2195 | // entry. |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2196 | if (*sig == '!') { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 2197 | is_fast = true; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2198 | ++sig; |
| 2199 | } |
| 2200 | |
Andreas Gampe | 3f1dc56 | 2015-05-18 15:52:22 -0700 | [diff] [blame] | 2201 | // Note: the right order is to try to find the method locally |
| 2202 | // first, either as a direct or a virtual method. Then move to |
| 2203 | // the parent. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2204 | ArtMethod* m = nullptr; |
Andreas Gampe | 3f1dc56 | 2015-05-18 15:52:22 -0700 | [diff] [blame] | 2205 | bool warn_on_going_to_parent = down_cast<JNIEnvExt*>(env)->vm->IsCheckJniEnabled(); |
| 2206 | for (mirror::Class* current_class = c; |
| 2207 | current_class != nullptr; |
| 2208 | current_class = current_class->GetSuperClass()) { |
| 2209 | // Search first only comparing methods which are native. |
| 2210 | m = FindMethod<true>(current_class, name, sig); |
| 2211 | if (m != nullptr) { |
| 2212 | break; |
| 2213 | } |
| 2214 | |
| 2215 | // Search again comparing to all methods, to find non-native methods that match. |
| 2216 | m = FindMethod<false>(current_class, name, sig); |
| 2217 | if (m != nullptr) { |
| 2218 | break; |
| 2219 | } |
| 2220 | |
| 2221 | if (warn_on_going_to_parent) { |
| 2222 | LOG(WARNING) << "CheckJNI: method to register \"" << name << "\" not in the given class. " |
| 2223 | << "This is slow, consider changing your RegisterNatives calls."; |
| 2224 | warn_on_going_to_parent = false; |
| 2225 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2226 | } |
Andreas Gampe | 3f1dc56 | 2015-05-18 15:52:22 -0700 | [diff] [blame] | 2227 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2228 | if (m == nullptr) { |
Mathieu Chartier | 5c02d6c | 2015-05-04 10:18:24 -0700 | [diff] [blame] | 2229 | LOG(return_errors ? ERROR : INTERNAL_FATAL) << "Failed to register native method " |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 2230 | << PrettyDescriptor(c) << "." << name << sig << " in " |
| 2231 | << c->GetDexCache()->GetLocation()->ToModifiedUtf8(); |
Mathieu Chartier | 5c02d6c | 2015-05-04 10:18:24 -0700 | [diff] [blame] | 2232 | // Safe to pass in LOG(FATAL) since the log object aborts in destructor and only goes |
| 2233 | // out of scope after the DumpClass is done executing. |
| 2234 | c->DumpClass(LOG(return_errors ? ERROR : FATAL), mirror::Class::kDumpClassFullDetail); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2235 | ThrowNoSuchMethodError(soa, c, name, sig, "static or non-static"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2236 | return JNI_ERR; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2237 | } else if (!m->IsNative()) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 2238 | LOG(return_errors ? ERROR : FATAL) << "Failed to register non-native method " |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 2239 | << PrettyDescriptor(c) << "." << name << sig |
| 2240 | << " as native"; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2241 | ThrowNoSuchMethodError(soa, c, name, sig, "native"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2242 | return JNI_ERR; |
| 2243 | } |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2244 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 2245 | VLOG(jni) << "[Registering JNI native method " << PrettyMethod(m) << "]"; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2246 | |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 2247 | is_fast = is_fast || m->IsFastNative(); // Merge with @FastNative state. |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 2248 | m->RegisterNative(fnPtr, is_fast); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2249 | } |
| 2250 | return JNI_OK; |
| 2251 | } |
| 2252 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2253 | static jint UnregisterNatives(JNIEnv* env, jclass java_class) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2254 | CHECK_NON_NULL_ARGUMENT_RETURN(java_class, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2255 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2256 | mirror::Class* c = soa.Decode<mirror::Class*>(java_class); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2257 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 2258 | VLOG(jni) << "[Unregistering JNI native methods for " << PrettyClass(c) << "]"; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2259 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2260 | size_t unregistered_count = 0; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2261 | auto pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 2262 | for (auto& m : c->GetMethods(pointer_size)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2263 | if (m.IsNative()) { |
| 2264 | m.UnregisterNative(); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2265 | unregistered_count++; |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2266 | } |
| 2267 | } |
| 2268 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2269 | if (unregistered_count == 0) { |
| 2270 | LOG(WARNING) << "JNI UnregisterNatives: attempt to unregister native methods of class '" |
| 2271 | << PrettyDescriptor(c) << "' that contains no native methods"; |
| 2272 | } |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 2273 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 2276 | static jint MonitorEnter(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2277 | CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2278 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2279 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
| 2280 | o = o->MonitorEnter(soa.Self()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2281 | if (soa.Self()->IsExceptionPending()) { |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2282 | return JNI_ERR; |
| 2283 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2284 | soa.Env()->monitors.Add(o); |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2285 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 2288 | static jint MonitorExit(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2289 | CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNI_ERR); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2290 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2291 | mirror::Object* o = soa.Decode<mirror::Object*>(java_object); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2292 | o->MonitorExit(soa.Self()); |
| 2293 | if (soa.Self()->IsExceptionPending()) { |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2294 | return JNI_ERR; |
| 2295 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2296 | soa.Env()->monitors.Remove(o); |
Elliott Hughes | ab7b9dc | 2012-03-27 13:16:29 -0700 | [diff] [blame] | 2297 | return JNI_OK; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | static jint GetJavaVM(JNIEnv* env, JavaVM** vm) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2301 | CHECK_NON_NULL_ARGUMENT_RETURN(vm, JNI_ERR); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2302 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2303 | if (runtime != nullptr) { |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 2304 | *vm = runtime->GetJavaVM(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2305 | } else { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2306 | *vm = nullptr; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2307 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2308 | return (*vm != nullptr) ? JNI_OK : JNI_ERR; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2311 | static jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) { |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2312 | if (capacity < 0) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2313 | JavaVmExtFromEnv(env)->JniAbortF("NewDirectByteBuffer", "negative buffer capacity: %" PRId64, |
| 2314 | capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame] | 2315 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2316 | } |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2317 | if (address == nullptr && capacity != 0) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2318 | JavaVmExtFromEnv(env)->JniAbortF("NewDirectByteBuffer", |
| 2319 | "non-zero capacity for nullptr pointer: %" PRId64, capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame] | 2320 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2321 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2322 | |
Brian Carlstrom | 85a9336 | 2014-06-25 09:30:52 -0700 | [diff] [blame] | 2323 | // 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] | 2324 | if (capacity > INT_MAX) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2325 | JavaVmExtFromEnv(env)->JniAbortF("NewDirectByteBuffer", |
| 2326 | "buffer capacity greater than maximum jint: %" PRId64, |
| 2327 | capacity); |
Brian Carlstrom | 45d26c8 | 2014-06-24 23:36:28 -0700 | [diff] [blame] | 2328 | return nullptr; |
| 2329 | } |
Elliott Hughes | b568121 | 2013-03-29 17:29:22 -0700 | [diff] [blame] | 2330 | jlong address_arg = reinterpret_cast<jlong>(address); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2331 | jint capacity_arg = static_cast<jint>(capacity); |
| 2332 | |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 2333 | jobject result = env->NewObject(WellKnownClasses::java_nio_DirectByteBuffer, |
| 2334 | WellKnownClasses::java_nio_DirectByteBuffer_init, |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 2335 | address_arg, capacity_arg); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2336 | return static_cast<JNIEnvExt*>(env)->self->IsExceptionPending() ? nullptr : result; |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2339 | static void* GetDirectBufferAddress(JNIEnv* env, jobject java_buffer) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2340 | return reinterpret_cast<void*>(env->GetLongField( |
| 2341 | java_buffer, WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2344 | static jlong GetDirectBufferCapacity(JNIEnv* env, jobject java_buffer) { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2345 | return static_cast<jlong>(env->GetIntField( |
| 2346 | java_buffer, WellKnownClasses::java_nio_DirectByteBuffer_capacity)); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
Andreas Gampe | a876307 | 2014-12-20 00:08:35 -0800 | [diff] [blame] | 2349 | static jobjectRefType GetObjectRefType(JNIEnv* env ATTRIBUTE_UNUSED, jobject java_object) { |
| 2350 | if (java_object == nullptr) { |
| 2351 | return JNIInvalidRefType; |
| 2352 | } |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2353 | |
| 2354 | // Do we definitely know what kind of reference this is? |
| 2355 | IndirectRef ref = reinterpret_cast<IndirectRef>(java_object); |
| 2356 | IndirectRefKind kind = GetIndirectRefKind(ref); |
| 2357 | switch (kind) { |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 2358 | case kLocal: |
| 2359 | return JNILocalRefType; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2360 | case kGlobal: |
| 2361 | return JNIGlobalRefType; |
| 2362 | case kWeakGlobal: |
| 2363 | return JNIWeakGlobalRefType; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2364 | case kHandleScopeOrInvalid: |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 2365 | // Assume value is in a handle scope. |
| 2366 | return JNILocalRefType; |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 2367 | } |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 2368 | LOG(FATAL) << "IndirectRefKind[" << kind << "]"; |
Andreas Gampe | a876307 | 2014-12-20 00:08:35 -0800 | [diff] [blame] | 2369 | UNREACHABLE(); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2370 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2371 | |
| 2372 | private: |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2373 | static jint EnsureLocalCapacityInternal(ScopedObjectAccess& soa, jint desired_capacity, |
| 2374 | const char* caller) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2375 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2376 | // TODO: we should try to expand the table if necessary. |
Elliott Hughes | aa836f7 | 2013-08-20 16:57:23 -0700 | [diff] [blame] | 2377 | if (desired_capacity < 0 || desired_capacity > static_cast<jint>(kLocalsMax)) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2378 | LOG(ERROR) << "Invalid capacity given to " << caller << ": " << desired_capacity; |
| 2379 | return JNI_ERR; |
| 2380 | } |
| 2381 | // TODO: this isn't quite right, since "capacity" includes holes. |
Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 2382 | const size_t capacity = soa.Env()->locals.Capacity(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2383 | bool okay = (static_cast<jint>(kLocalsMax - capacity) >= desired_capacity); |
| 2384 | if (!okay) { |
| 2385 | soa.Self()->ThrowOutOfMemoryError(caller); |
| 2386 | } |
| 2387 | return okay ? JNI_OK : JNI_ERR; |
| 2388 | } |
| 2389 | |
| 2390 | template<typename JniT, typename ArtT> |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2391 | static JniT NewPrimitiveArray(JNIEnv* env, jsize length) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2392 | ScopedObjectAccess soa(env); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2393 | if (UNLIKELY(length < 0)) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2394 | soa.Vm()->JniAbortF("NewPrimitiveArray", "negative array length: %d", length); |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 2395 | return nullptr; |
Elliott Hughes | 96a9887 | 2012-12-19 14:21:15 -0800 | [diff] [blame] | 2396 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 2397 | ArtT* result = ArtT::Alloc(soa.Self(), length); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2398 | return soa.AddLocalReference<JniT>(result); |
| 2399 | } |
| 2400 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2401 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2402 | static ArtArrayT* DecodeAndCheckArrayType(ScopedObjectAccess& soa, JArrayT java_array, |
| 2403 | const char* fn_name, const char* operation) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2404 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2405 | ArtArrayT* array = soa.Decode<ArtArrayT*>(java_array); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2406 | if (UNLIKELY(ArtArrayT::GetArrayClass() != array->GetClass())) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2407 | soa.Vm()->JniAbortF(fn_name, |
| 2408 | "attempt to %s %s primitive array elements with an object of type %s", |
| 2409 | operation, |
| 2410 | PrettyDescriptor(ArtArrayT::GetArrayClass()->GetComponentType()).c_str(), |
| 2411 | PrettyDescriptor(array->GetClass()).c_str()); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2412 | return nullptr; |
| 2413 | } |
| 2414 | DCHECK_EQ(sizeof(ElementT), array->GetClass()->GetComponentSize()); |
| 2415 | return array; |
| 2416 | } |
| 2417 | |
| 2418 | template <typename ArrayT, typename ElementT, typename ArtArrayT> |
| 2419 | static ElementT* GetPrimitiveArray(JNIEnv* env, ArrayT java_array, jboolean* is_copy) { |
| 2420 | CHECK_NON_NULL_ARGUMENT(java_array); |
| 2421 | ScopedObjectAccess soa(env); |
| 2422 | ArtArrayT* array = DecodeAndCheckArrayType<ArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2423 | "GetArrayElements", |
| 2424 | "get"); |
| 2425 | if (UNLIKELY(array == nullptr)) { |
| 2426 | return nullptr; |
| 2427 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2428 | // Only make a copy if necessary. |
| 2429 | if (Runtime::Current()->GetHeap()->IsMovableObject(array)) { |
| 2430 | if (is_copy != nullptr) { |
| 2431 | *is_copy = JNI_TRUE; |
| 2432 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2433 | const size_t component_size = sizeof(ElementT); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2434 | size_t size = array->GetLength() * component_size; |
| 2435 | void* data = new uint64_t[RoundUp(size, 8) / 8]; |
| 2436 | memcpy(data, array->GetData(), size); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2437 | return reinterpret_cast<ElementT*>(data); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2438 | } else { |
| 2439 | if (is_copy != nullptr) { |
| 2440 | *is_copy = JNI_FALSE; |
| 2441 | } |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2442 | return reinterpret_cast<ElementT*>(array->GetData()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2443 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2446 | template <typename ArrayT, typename ElementT, typename ArtArrayT> |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2447 | static void ReleasePrimitiveArray(JNIEnv* env, ArrayT java_array, ElementT* elements, jint mode) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2448 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2449 | ScopedObjectAccess soa(env); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2450 | ArtArrayT* array = DecodeAndCheckArrayType<ArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2451 | "ReleaseArrayElements", |
| 2452 | "release"); |
| 2453 | if (array == nullptr) { |
| 2454 | return; |
| 2455 | } |
| 2456 | ReleasePrimitiveArray(soa, array, sizeof(ElementT), elements, mode); |
| 2457 | } |
| 2458 | |
| 2459 | static void ReleasePrimitiveArray(ScopedObjectAccess& soa, mirror::Array* array, |
| 2460 | size_t component_size, void* elements, jint mode) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2461 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2462 | void* array_data = array->GetRawData(component_size, 0); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2463 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2464 | bool is_copy = array_data != elements; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2465 | size_t bytes = array->GetLength() * component_size; |
Mathieu Chartier | d68ac70 | 2014-02-11 14:50:51 -0800 | [diff] [blame] | 2466 | if (is_copy) { |
| 2467 | // Sanity check: If elements is not the same as the java array's data, it better not be a |
| 2468 | // heap address. TODO: This might be slow to check, may be worth keeping track of which |
| 2469 | // copies we make? |
| 2470 | if (heap->IsNonDiscontinuousSpaceHeapAddress(reinterpret_cast<mirror::Object*>(elements))) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2471 | soa.Vm()->JniAbortF("ReleaseArrayElements", |
| 2472 | "invalid element pointer %p, array elements are %p", |
| 2473 | reinterpret_cast<void*>(elements), array_data); |
Mathieu Chartier | d68ac70 | 2014-02-11 14:50:51 -0800 | [diff] [blame] | 2474 | return; |
| 2475 | } |
Mathieu Chartier | 24555ad | 2014-10-06 13:41:33 -0700 | [diff] [blame] | 2476 | if (mode != JNI_ABORT) { |
| 2477 | memcpy(array_data, elements, bytes); |
| 2478 | } else if (kWarnJniAbort && memcmp(array_data, elements, bytes) != 0) { |
| 2479 | // Warn if we have JNI_ABORT and the arrays don't match since this is usually an error. |
| 2480 | LOG(WARNING) << "Possible incorrect JNI_ABORT in Release*ArrayElements"; |
| 2481 | soa.Self()->DumpJavaStack(LOG(WARNING)); |
| 2482 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2483 | } |
| 2484 | if (mode != JNI_COMMIT) { |
| 2485 | if (is_copy) { |
| 2486 | delete[] reinterpret_cast<uint64_t*>(elements); |
Mathieu Chartier | 3e8b2e1 | 2014-01-19 17:17:26 -0800 | [diff] [blame] | 2487 | } else if (heap->IsMovableObject(array)) { |
Mathieu Chartier | 1d27b34 | 2014-01-28 12:51:09 -0800 | [diff] [blame] | 2488 | // 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] | 2489 | if (!kUseReadBarrier) { |
| 2490 | heap->DecrementDisableMovingGC(soa.Self()); |
| 2491 | } else { |
| 2492 | heap->DecrementDisableThreadFlip(soa.Self()); |
| 2493 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2494 | } |
| 2495 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2498 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2499 | static void GetPrimitiveArrayRegion(JNIEnv* env, JArrayT java_array, |
| 2500 | jsize start, jsize length, ElementT* buf) { |
| 2501 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 2502 | ScopedObjectAccess soa(env); |
| 2503 | ArtArrayT* array = |
| 2504 | DecodeAndCheckArrayType<JArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2505 | "GetPrimitiveArrayRegion", |
| 2506 | "get region of"); |
| 2507 | if (array != nullptr) { |
Vladimir Marko | 795e341 | 2015-11-06 16:57:03 +0000 | [diff] [blame] | 2508 | if (start < 0 || length < 0 || length > array->GetLength() - start) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2509 | ThrowAIOOBE(soa, array, start, length, "src"); |
| 2510 | } else { |
| 2511 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
| 2512 | ElementT* data = array->GetData(); |
| 2513 | memcpy(buf, data + start, length * sizeof(ElementT)); |
| 2514 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2518 | template <typename JArrayT, typename ElementT, typename ArtArrayT> |
| 2519 | static void SetPrimitiveArrayRegion(JNIEnv* env, JArrayT java_array, |
| 2520 | jsize start, jsize length, const ElementT* buf) { |
| 2521 | CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_array); |
| 2522 | ScopedObjectAccess soa(env); |
| 2523 | ArtArrayT* array = |
| 2524 | DecodeAndCheckArrayType<JArrayT, ElementT, ArtArrayT>(soa, java_array, |
| 2525 | "SetPrimitiveArrayRegion", |
| 2526 | "set region of"); |
| 2527 | if (array != nullptr) { |
Vladimir Marko | 795e341 | 2015-11-06 16:57:03 +0000 | [diff] [blame] | 2528 | if (start < 0 || length < 0 || length > array->GetLength() - start) { |
Ian Rogers | 2d10b20 | 2014-05-12 19:15:18 -0700 | [diff] [blame] | 2529 | ThrowAIOOBE(soa, array, start, length, "dst"); |
| 2530 | } else { |
| 2531 | CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); |
| 2532 | ElementT* data = array->GetData(); |
| 2533 | memcpy(data + start, buf, length * sizeof(ElementT)); |
| 2534 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2535 | } |
| 2536 | } |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2537 | }; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 2538 | |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 2539 | const JNINativeInterface gJniNativeInterface = { |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 2540 | nullptr, // reserved0. |
| 2541 | nullptr, // reserved1. |
| 2542 | nullptr, // reserved2. |
| 2543 | nullptr, // reserved3. |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 2544 | JNI::GetVersion, |
| 2545 | JNI::DefineClass, |
| 2546 | JNI::FindClass, |
| 2547 | JNI::FromReflectedMethod, |
| 2548 | JNI::FromReflectedField, |
| 2549 | JNI::ToReflectedMethod, |
| 2550 | JNI::GetSuperclass, |
| 2551 | JNI::IsAssignableFrom, |
| 2552 | JNI::ToReflectedField, |
| 2553 | JNI::Throw, |
| 2554 | JNI::ThrowNew, |
| 2555 | JNI::ExceptionOccurred, |
| 2556 | JNI::ExceptionDescribe, |
| 2557 | JNI::ExceptionClear, |
| 2558 | JNI::FatalError, |
| 2559 | JNI::PushLocalFrame, |
| 2560 | JNI::PopLocalFrame, |
| 2561 | JNI::NewGlobalRef, |
| 2562 | JNI::DeleteGlobalRef, |
| 2563 | JNI::DeleteLocalRef, |
| 2564 | JNI::IsSameObject, |
| 2565 | JNI::NewLocalRef, |
| 2566 | JNI::EnsureLocalCapacity, |
| 2567 | JNI::AllocObject, |
| 2568 | JNI::NewObject, |
| 2569 | JNI::NewObjectV, |
| 2570 | JNI::NewObjectA, |
| 2571 | JNI::GetObjectClass, |
| 2572 | JNI::IsInstanceOf, |
| 2573 | JNI::GetMethodID, |
| 2574 | JNI::CallObjectMethod, |
| 2575 | JNI::CallObjectMethodV, |
| 2576 | JNI::CallObjectMethodA, |
| 2577 | JNI::CallBooleanMethod, |
| 2578 | JNI::CallBooleanMethodV, |
| 2579 | JNI::CallBooleanMethodA, |
| 2580 | JNI::CallByteMethod, |
| 2581 | JNI::CallByteMethodV, |
| 2582 | JNI::CallByteMethodA, |
| 2583 | JNI::CallCharMethod, |
| 2584 | JNI::CallCharMethodV, |
| 2585 | JNI::CallCharMethodA, |
| 2586 | JNI::CallShortMethod, |
| 2587 | JNI::CallShortMethodV, |
| 2588 | JNI::CallShortMethodA, |
| 2589 | JNI::CallIntMethod, |
| 2590 | JNI::CallIntMethodV, |
| 2591 | JNI::CallIntMethodA, |
| 2592 | JNI::CallLongMethod, |
| 2593 | JNI::CallLongMethodV, |
| 2594 | JNI::CallLongMethodA, |
| 2595 | JNI::CallFloatMethod, |
| 2596 | JNI::CallFloatMethodV, |
| 2597 | JNI::CallFloatMethodA, |
| 2598 | JNI::CallDoubleMethod, |
| 2599 | JNI::CallDoubleMethodV, |
| 2600 | JNI::CallDoubleMethodA, |
| 2601 | JNI::CallVoidMethod, |
| 2602 | JNI::CallVoidMethodV, |
| 2603 | JNI::CallVoidMethodA, |
| 2604 | JNI::CallNonvirtualObjectMethod, |
| 2605 | JNI::CallNonvirtualObjectMethodV, |
| 2606 | JNI::CallNonvirtualObjectMethodA, |
| 2607 | JNI::CallNonvirtualBooleanMethod, |
| 2608 | JNI::CallNonvirtualBooleanMethodV, |
| 2609 | JNI::CallNonvirtualBooleanMethodA, |
| 2610 | JNI::CallNonvirtualByteMethod, |
| 2611 | JNI::CallNonvirtualByteMethodV, |
| 2612 | JNI::CallNonvirtualByteMethodA, |
| 2613 | JNI::CallNonvirtualCharMethod, |
| 2614 | JNI::CallNonvirtualCharMethodV, |
| 2615 | JNI::CallNonvirtualCharMethodA, |
| 2616 | JNI::CallNonvirtualShortMethod, |
| 2617 | JNI::CallNonvirtualShortMethodV, |
| 2618 | JNI::CallNonvirtualShortMethodA, |
| 2619 | JNI::CallNonvirtualIntMethod, |
| 2620 | JNI::CallNonvirtualIntMethodV, |
| 2621 | JNI::CallNonvirtualIntMethodA, |
| 2622 | JNI::CallNonvirtualLongMethod, |
| 2623 | JNI::CallNonvirtualLongMethodV, |
| 2624 | JNI::CallNonvirtualLongMethodA, |
| 2625 | JNI::CallNonvirtualFloatMethod, |
| 2626 | JNI::CallNonvirtualFloatMethodV, |
| 2627 | JNI::CallNonvirtualFloatMethodA, |
| 2628 | JNI::CallNonvirtualDoubleMethod, |
| 2629 | JNI::CallNonvirtualDoubleMethodV, |
| 2630 | JNI::CallNonvirtualDoubleMethodA, |
| 2631 | JNI::CallNonvirtualVoidMethod, |
| 2632 | JNI::CallNonvirtualVoidMethodV, |
| 2633 | JNI::CallNonvirtualVoidMethodA, |
| 2634 | JNI::GetFieldID, |
| 2635 | JNI::GetObjectField, |
| 2636 | JNI::GetBooleanField, |
| 2637 | JNI::GetByteField, |
| 2638 | JNI::GetCharField, |
| 2639 | JNI::GetShortField, |
| 2640 | JNI::GetIntField, |
| 2641 | JNI::GetLongField, |
| 2642 | JNI::GetFloatField, |
| 2643 | JNI::GetDoubleField, |
| 2644 | JNI::SetObjectField, |
| 2645 | JNI::SetBooleanField, |
| 2646 | JNI::SetByteField, |
| 2647 | JNI::SetCharField, |
| 2648 | JNI::SetShortField, |
| 2649 | JNI::SetIntField, |
| 2650 | JNI::SetLongField, |
| 2651 | JNI::SetFloatField, |
| 2652 | JNI::SetDoubleField, |
| 2653 | JNI::GetStaticMethodID, |
| 2654 | JNI::CallStaticObjectMethod, |
| 2655 | JNI::CallStaticObjectMethodV, |
| 2656 | JNI::CallStaticObjectMethodA, |
| 2657 | JNI::CallStaticBooleanMethod, |
| 2658 | JNI::CallStaticBooleanMethodV, |
| 2659 | JNI::CallStaticBooleanMethodA, |
| 2660 | JNI::CallStaticByteMethod, |
| 2661 | JNI::CallStaticByteMethodV, |
| 2662 | JNI::CallStaticByteMethodA, |
| 2663 | JNI::CallStaticCharMethod, |
| 2664 | JNI::CallStaticCharMethodV, |
| 2665 | JNI::CallStaticCharMethodA, |
| 2666 | JNI::CallStaticShortMethod, |
| 2667 | JNI::CallStaticShortMethodV, |
| 2668 | JNI::CallStaticShortMethodA, |
| 2669 | JNI::CallStaticIntMethod, |
| 2670 | JNI::CallStaticIntMethodV, |
| 2671 | JNI::CallStaticIntMethodA, |
| 2672 | JNI::CallStaticLongMethod, |
| 2673 | JNI::CallStaticLongMethodV, |
| 2674 | JNI::CallStaticLongMethodA, |
| 2675 | JNI::CallStaticFloatMethod, |
| 2676 | JNI::CallStaticFloatMethodV, |
| 2677 | JNI::CallStaticFloatMethodA, |
| 2678 | JNI::CallStaticDoubleMethod, |
| 2679 | JNI::CallStaticDoubleMethodV, |
| 2680 | JNI::CallStaticDoubleMethodA, |
| 2681 | JNI::CallStaticVoidMethod, |
| 2682 | JNI::CallStaticVoidMethodV, |
| 2683 | JNI::CallStaticVoidMethodA, |
| 2684 | JNI::GetStaticFieldID, |
| 2685 | JNI::GetStaticObjectField, |
| 2686 | JNI::GetStaticBooleanField, |
| 2687 | JNI::GetStaticByteField, |
| 2688 | JNI::GetStaticCharField, |
| 2689 | JNI::GetStaticShortField, |
| 2690 | JNI::GetStaticIntField, |
| 2691 | JNI::GetStaticLongField, |
| 2692 | JNI::GetStaticFloatField, |
| 2693 | JNI::GetStaticDoubleField, |
| 2694 | JNI::SetStaticObjectField, |
| 2695 | JNI::SetStaticBooleanField, |
| 2696 | JNI::SetStaticByteField, |
| 2697 | JNI::SetStaticCharField, |
| 2698 | JNI::SetStaticShortField, |
| 2699 | JNI::SetStaticIntField, |
| 2700 | JNI::SetStaticLongField, |
| 2701 | JNI::SetStaticFloatField, |
| 2702 | JNI::SetStaticDoubleField, |
| 2703 | JNI::NewString, |
| 2704 | JNI::GetStringLength, |
| 2705 | JNI::GetStringChars, |
| 2706 | JNI::ReleaseStringChars, |
| 2707 | JNI::NewStringUTF, |
| 2708 | JNI::GetStringUTFLength, |
| 2709 | JNI::GetStringUTFChars, |
| 2710 | JNI::ReleaseStringUTFChars, |
| 2711 | JNI::GetArrayLength, |
| 2712 | JNI::NewObjectArray, |
| 2713 | JNI::GetObjectArrayElement, |
| 2714 | JNI::SetObjectArrayElement, |
| 2715 | JNI::NewBooleanArray, |
| 2716 | JNI::NewByteArray, |
| 2717 | JNI::NewCharArray, |
| 2718 | JNI::NewShortArray, |
| 2719 | JNI::NewIntArray, |
| 2720 | JNI::NewLongArray, |
| 2721 | JNI::NewFloatArray, |
| 2722 | JNI::NewDoubleArray, |
| 2723 | JNI::GetBooleanArrayElements, |
| 2724 | JNI::GetByteArrayElements, |
| 2725 | JNI::GetCharArrayElements, |
| 2726 | JNI::GetShortArrayElements, |
| 2727 | JNI::GetIntArrayElements, |
| 2728 | JNI::GetLongArrayElements, |
| 2729 | JNI::GetFloatArrayElements, |
| 2730 | JNI::GetDoubleArrayElements, |
| 2731 | JNI::ReleaseBooleanArrayElements, |
| 2732 | JNI::ReleaseByteArrayElements, |
| 2733 | JNI::ReleaseCharArrayElements, |
| 2734 | JNI::ReleaseShortArrayElements, |
| 2735 | JNI::ReleaseIntArrayElements, |
| 2736 | JNI::ReleaseLongArrayElements, |
| 2737 | JNI::ReleaseFloatArrayElements, |
| 2738 | JNI::ReleaseDoubleArrayElements, |
| 2739 | JNI::GetBooleanArrayRegion, |
| 2740 | JNI::GetByteArrayRegion, |
| 2741 | JNI::GetCharArrayRegion, |
| 2742 | JNI::GetShortArrayRegion, |
| 2743 | JNI::GetIntArrayRegion, |
| 2744 | JNI::GetLongArrayRegion, |
| 2745 | JNI::GetFloatArrayRegion, |
| 2746 | JNI::GetDoubleArrayRegion, |
| 2747 | JNI::SetBooleanArrayRegion, |
| 2748 | JNI::SetByteArrayRegion, |
| 2749 | JNI::SetCharArrayRegion, |
| 2750 | JNI::SetShortArrayRegion, |
| 2751 | JNI::SetIntArrayRegion, |
| 2752 | JNI::SetLongArrayRegion, |
| 2753 | JNI::SetFloatArrayRegion, |
| 2754 | JNI::SetDoubleArrayRegion, |
| 2755 | JNI::RegisterNatives, |
| 2756 | JNI::UnregisterNatives, |
| 2757 | JNI::MonitorEnter, |
| 2758 | JNI::MonitorExit, |
| 2759 | JNI::GetJavaVM, |
| 2760 | JNI::GetStringRegion, |
| 2761 | JNI::GetStringUTFRegion, |
| 2762 | JNI::GetPrimitiveArrayCritical, |
| 2763 | JNI::ReleasePrimitiveArrayCritical, |
| 2764 | JNI::GetStringCritical, |
| 2765 | JNI::ReleaseStringCritical, |
| 2766 | JNI::NewWeakGlobalRef, |
| 2767 | JNI::DeleteWeakGlobalRef, |
| 2768 | JNI::ExceptionCheck, |
| 2769 | JNI::NewDirectByteBuffer, |
| 2770 | JNI::GetDirectBufferAddress, |
| 2771 | JNI::GetDirectBufferCapacity, |
| 2772 | JNI::GetObjectRefType, |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 2773 | }; |
| 2774 | |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 2775 | const JNINativeInterface* GetJniNativeInterface() { |
| 2776 | return &gJniNativeInterface; |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Mathieu Chartier | 4d87df6 | 2016-01-07 15:14:19 -0800 | [diff] [blame] | 2779 | void (*gJniSleepForeverStub[])() = { |
| 2780 | nullptr, // reserved0. |
| 2781 | nullptr, // reserved1. |
| 2782 | nullptr, // reserved2. |
| 2783 | nullptr, // reserved3. |
| 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 | SleepForever, |
| 2974 | SleepForever, |
| 2975 | SleepForever, |
| 2976 | SleepForever, |
| 2977 | SleepForever, |
| 2978 | SleepForever, |
| 2979 | SleepForever, |
| 2980 | SleepForever, |
| 2981 | SleepForever, |
| 2982 | SleepForever, |
| 2983 | SleepForever, |
| 2984 | SleepForever, |
| 2985 | SleepForever, |
| 2986 | SleepForever, |
| 2987 | SleepForever, |
| 2988 | SleepForever, |
| 2989 | SleepForever, |
| 2990 | SleepForever, |
| 2991 | SleepForever, |
| 2992 | SleepForever, |
| 2993 | SleepForever, |
| 2994 | SleepForever, |
| 2995 | SleepForever, |
| 2996 | SleepForever, |
| 2997 | SleepForever, |
| 2998 | SleepForever, |
| 2999 | SleepForever, |
| 3000 | SleepForever, |
| 3001 | SleepForever, |
| 3002 | SleepForever, |
| 3003 | SleepForever, |
| 3004 | SleepForever, |
| 3005 | SleepForever, |
| 3006 | SleepForever, |
| 3007 | SleepForever, |
| 3008 | SleepForever, |
| 3009 | SleepForever, |
| 3010 | SleepForever, |
| 3011 | SleepForever, |
| 3012 | SleepForever, |
| 3013 | }; |
| 3014 | |
| 3015 | const JNINativeInterface* GetRuntimeShutdownNativeInterface() { |
| 3016 | return reinterpret_cast<JNINativeInterface*>(&gJniSleepForeverStub); |
| 3017 | } |
| 3018 | |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 3019 | void RegisterNativeMethods(JNIEnv* env, const char* jni_class_name, const JNINativeMethod* methods, |
Ian Rogers | bc93966 | 2013-08-15 10:26:54 -0700 | [diff] [blame] | 3020 | jint method_count) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 3021 | ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name)); |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 3022 | if (c.get() == nullptr) { |
Elliott Hughes | c8fece3 | 2013-01-02 11:27:23 -0800 | [diff] [blame] | 3023 | LOG(FATAL) << "Couldn't find class: " << jni_class_name; |
| 3024 | } |
| 3025 | JNI::RegisterNativeMethods(env, c.get(), methods, method_count, false); |
| 3026 | } |
| 3027 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 3028 | } // namespace art |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 3029 | |
| 3030 | std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs) { |
| 3031 | switch (rhs) { |
| 3032 | case JNIInvalidRefType: |
| 3033 | os << "JNIInvalidRefType"; |
| 3034 | return os; |
| 3035 | case JNILocalRefType: |
| 3036 | os << "JNILocalRefType"; |
| 3037 | return os; |
| 3038 | case JNIGlobalRefType: |
| 3039 | os << "JNIGlobalRefType"; |
| 3040 | return os; |
| 3041 | case JNIWeakGlobalRefType: |
| 3042 | os << "JNIWeakGlobalRefType"; |
| 3043 | return os; |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 3044 | default: |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 3045 | LOG(::art::FATAL) << "jobjectRefType[" << static_cast<int>(rhs) << "]"; |
| 3046 | UNREACHABLE(); |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 3047 | } |
| 3048 | } |