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