OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 clazz = env->FindClass(class_name); | 136 clazz = env->FindClass(class_name); |
137 } | 137 } |
138 CHECK(!ClearException(env) && clazz) << "Failed to find class " << class_name; | 138 CHECK(!ClearException(env) && clazz) << "Failed to find class " << class_name; |
139 return ScopedJavaLocalRef<jclass>(env, clazz); | 139 return ScopedJavaLocalRef<jclass>(env, clazz); |
140 } | 140 } |
141 | 141 |
142 jclass LazyGetClass( | 142 jclass LazyGetClass( |
143 JNIEnv* env, | 143 JNIEnv* env, |
144 const char* class_name, | 144 const char* class_name, |
145 base::subtle::AtomicWord* atomic_class_id) { | 145 base::subtle::AtomicWord* atomic_class_id) { |
146 COMPILE_ASSERT(sizeof(subtle::AtomicWord) >= sizeof(jclass), | 146 static_assert(sizeof(subtle::AtomicWord) >= sizeof(jclass), |
147 AtomicWord_SmallerThan_jMethodID); | 147 "AtomicWord_SmallerThan_jMethodID"); |
Mostyn Bramley-Moore
2015/11/23 06:44:14
s/jMethodID/jclass/ ?
Mark Mentovai
2015/11/23 14:21:37
Can you get rid of the underscores now that we’re
| |
148 subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_class_id); | 148 subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_class_id); |
149 if (value) | 149 if (value) |
150 return reinterpret_cast<jclass>(value); | 150 return reinterpret_cast<jclass>(value); |
151 ScopedJavaGlobalRef<jclass> clazz; | 151 ScopedJavaGlobalRef<jclass> clazz; |
152 clazz.Reset(GetClass(env, class_name)); | 152 clazz.Reset(GetClass(env, class_name)); |
153 subtle::AtomicWord null_aw = reinterpret_cast<subtle::AtomicWord>(NULL); | 153 subtle::AtomicWord null_aw = reinterpret_cast<subtle::AtomicWord>(NULL); |
154 subtle::AtomicWord cas_result = base::subtle::Release_CompareAndSwap( | 154 subtle::AtomicWord cas_result = base::subtle::Release_CompareAndSwap( |
155 atomic_class_id, | 155 atomic_class_id, |
156 null_aw, | 156 null_aw, |
157 reinterpret_cast<subtle::AtomicWord>(clazz.obj())); | 157 reinterpret_cast<subtle::AtomicWord>(clazz.obj())); |
(...skipping 23 matching lines...) Expand all Loading... | |
181 | 181 |
182 // If |atomic_method_id| set, it'll return immediately. Otherwise, it'll call | 182 // If |atomic_method_id| set, it'll return immediately. Otherwise, it'll call |
183 // into ::Get() above. If there's a race, it's ok since the values are the same | 183 // into ::Get() above. If there's a race, it's ok since the values are the same |
184 // (and the duplicated effort will happen only once). | 184 // (and the duplicated effort will happen only once). |
185 template<MethodID::Type type> | 185 template<MethodID::Type type> |
186 jmethodID MethodID::LazyGet(JNIEnv* env, | 186 jmethodID MethodID::LazyGet(JNIEnv* env, |
187 jclass clazz, | 187 jclass clazz, |
188 const char* method_name, | 188 const char* method_name, |
189 const char* jni_signature, | 189 const char* jni_signature, |
190 base::subtle::AtomicWord* atomic_method_id) { | 190 base::subtle::AtomicWord* atomic_method_id) { |
191 COMPILE_ASSERT(sizeof(subtle::AtomicWord) >= sizeof(jmethodID), | 191 static_assert(sizeof(subtle::AtomicWord) >= sizeof(jmethodID), |
192 AtomicWord_SmallerThan_jMethodID); | 192 "AtomicWord_SmallerThan_jMethodID"); |
193 subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_method_id); | 193 subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_method_id); |
194 if (value) | 194 if (value) |
195 return reinterpret_cast<jmethodID>(value); | 195 return reinterpret_cast<jmethodID>(value); |
196 jmethodID id = MethodID::Get<type>(env, clazz, method_name, jni_signature); | 196 jmethodID id = MethodID::Get<type>(env, clazz, method_name, jni_signature); |
197 base::subtle::Release_Store( | 197 base::subtle::Release_Store( |
198 atomic_method_id, reinterpret_cast<subtle::AtomicWord>(id)); | 198 atomic_method_id, reinterpret_cast<subtle::AtomicWord>(id)); |
199 return id; | 199 return id; |
200 } | 200 } |
201 | 201 |
202 // Various template instantiations. | 202 // Various template instantiations. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 env, static_cast<jstring>( | 291 env, static_cast<jstring>( |
292 env->CallObjectMethod(bytearray_output_stream.obj(), | 292 env->CallObjectMethod(bytearray_output_stream.obj(), |
293 bytearray_output_stream_tostring))); | 293 bytearray_output_stream_tostring))); |
294 | 294 |
295 return ConvertJavaStringToUTF8(exception_string); | 295 return ConvertJavaStringToUTF8(exception_string); |
296 } | 296 } |
297 | 297 |
298 | 298 |
299 } // namespace android | 299 } // namespace android |
300 } // namespace base | 300 } // namespace base |
OLD | NEW |