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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 clazz = static_cast<jclass>( | 115 clazz = static_cast<jclass>( |
116 env->CallObjectMethod(g_class_loader.Get().obj(), | 116 env->CallObjectMethod(g_class_loader.Get().obj(), |
117 g_class_loader_load_class_method_id, | 117 g_class_loader_load_class_method_id, |
118 ConvertUTF8ToJavaString(env, dotted_name).obj())); | 118 ConvertUTF8ToJavaString(env, dotted_name).obj())); |
119 } else { | 119 } else { |
120 clazz = env->FindClass(class_name); | 120 clazz = env->FindClass(class_name); |
121 } | 121 } |
122 CHECK(!ClearException(env) && clazz) << "Failed to find class " << class_name; | 122 if (ClearException(env) || !clazz) { |
123 LOG(FATAL) << "Failed to find class " << class_name; | |
124 } | |
123 return ScopedJavaLocalRef<jclass>(env, clazz); | 125 return ScopedJavaLocalRef<jclass>(env, clazz); |
124 } | 126 } |
125 | 127 |
126 jclass LazyGetClass( | 128 jclass LazyGetClass( |
127 JNIEnv* env, | 129 JNIEnv* env, |
128 const char* class_name, | 130 const char* class_name, |
129 base::subtle::AtomicWord* atomic_class_id) { | 131 base::subtle::AtomicWord* atomic_class_id) { |
130 static_assert(sizeof(subtle::AtomicWord) >= sizeof(jclass), | 132 static_assert(sizeof(subtle::AtomicWord) >= sizeof(jclass), |
131 "AtomicWord can't be smaller than jclass"); | 133 "AtomicWord can't be smaller than jclass"); |
132 subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_class_id); | 134 subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_class_id); |
(...skipping 16 matching lines...) Expand all Loading... | |
149 } | 151 } |
150 | 152 |
151 template<MethodID::Type type> | 153 template<MethodID::Type type> |
152 jmethodID MethodID::Get(JNIEnv* env, | 154 jmethodID MethodID::Get(JNIEnv* env, |
153 jclass clazz, | 155 jclass clazz, |
154 const char* method_name, | 156 const char* method_name, |
155 const char* jni_signature) { | 157 const char* jni_signature) { |
156 jmethodID id = type == TYPE_STATIC ? | 158 jmethodID id = type == TYPE_STATIC ? |
157 env->GetStaticMethodID(clazz, method_name, jni_signature) : | 159 env->GetStaticMethodID(clazz, method_name, jni_signature) : |
158 env->GetMethodID(clazz, method_name, jni_signature); | 160 env->GetMethodID(clazz, method_name, jni_signature); |
159 CHECK(base::android::ClearException(env) || id) << | 161 if (base::android::ClearException(env) || !id) { |
Yaron
2016/05/05 17:08:30
Am I crazy? Wasn't this inverted?
Torne
2016/05/05 17:33:22
Yes, this was inverted, you aren't crazy. It just
| |
160 "Failed to find " << | 162 LOG(FATAL) << "Failed to find " << |
161 (type == TYPE_STATIC ? "static " : "") << | 163 (type == TYPE_STATIC ? "static " : "") << |
162 "method " << method_name << " " << jni_signature; | 164 "method " << method_name << " " << jni_signature; |
165 } | |
163 return id; | 166 return id; |
164 } | 167 } |
165 | 168 |
166 // If |atomic_method_id| set, it'll return immediately. Otherwise, it'll call | 169 // If |atomic_method_id| set, it'll return immediately. Otherwise, it'll call |
167 // into ::Get() above. If there's a race, it's ok since the values are the same | 170 // into ::Get() above. If there's a race, it's ok since the values are the same |
168 // (and the duplicated effort will happen only once). | 171 // (and the duplicated effort will happen only once). |
169 template<MethodID::Type type> | 172 template<MethodID::Type type> |
170 jmethodID MethodID::LazyGet(JNIEnv* env, | 173 jmethodID MethodID::LazyGet(JNIEnv* env, |
171 jclass clazz, | 174 jclass clazz, |
172 const char* method_name, | 175 const char* method_name, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 env->ExceptionDescribe(); | 226 env->ExceptionDescribe(); |
224 env->ExceptionClear(); | 227 env->ExceptionClear(); |
225 | 228 |
226 // Set the exception_string in BuildInfo so that breakpad can read it. | 229 // Set the exception_string in BuildInfo so that breakpad can read it. |
227 // RVO should avoid any extra copies of the exception string. | 230 // RVO should avoid any extra copies of the exception string. |
228 base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo( | 231 base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo( |
229 GetJavaExceptionInfo(env, java_throwable)); | 232 GetJavaExceptionInfo(env, java_throwable)); |
230 } | 233 } |
231 | 234 |
232 // Now, feel good about it and die. | 235 // Now, feel good about it and die. |
233 CHECK(false) << "Please include Java exception stack in crash report"; | 236 LOG(FATAL) << "Please include Java exception stack in crash report"; |
234 } | 237 } |
235 | 238 |
236 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { | 239 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { |
237 ScopedJavaLocalRef<jclass> throwable_clazz = | 240 ScopedJavaLocalRef<jclass> throwable_clazz = |
238 GetClass(env, "java/lang/Throwable"); | 241 GetClass(env, "java/lang/Throwable"); |
239 jmethodID throwable_printstacktrace = | 242 jmethodID throwable_printstacktrace = |
240 MethodID::Get<MethodID::TYPE_INSTANCE>( | 243 MethodID::Get<MethodID::TYPE_INSTANCE>( |
241 env, throwable_clazz.obj(), "printStackTrace", | 244 env, throwable_clazz.obj(), "printStackTrace", |
242 "(Ljava/io/PrintStream;)V"); | 245 "(Ljava/io/PrintStream;)V"); |
243 | 246 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 env, static_cast<jstring>( | 278 env, static_cast<jstring>( |
276 env->CallObjectMethod(bytearray_output_stream.obj(), | 279 env->CallObjectMethod(bytearray_output_stream.obj(), |
277 bytearray_output_stream_tostring))); | 280 bytearray_output_stream_tostring))); |
278 | 281 |
279 return ConvertJavaStringToUTF8(exception_string); | 282 return ConvertJavaStringToUTF8(exception_string); |
280 } | 283 } |
281 | 284 |
282 | 285 |
283 } // namespace android | 286 } // namespace android |
284 } // namespace base | 287 } // namespace base |
OLD | NEW |