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