Lines Matching refs:env
53 static jmethodID FindMethod(JNIEnv* env, in FindMethod() argument
59 jclass clazz = (*env)->FindClass(env, className); in FindMethod()
60 jmethodID methodId = (*env)->GetMethodID(env, clazz, methodName, descriptor); in FindMethod()
61 (*env)->DeleteLocalRef(env, clazz); in FindMethod()
65 static bool AppendJString(JNIEnv* env, jstring text, struct ExpandableString* dst) { in AppendJString() argument
66 const char* utfText = (*env)->GetStringUTFChars(env, text, NULL); in AppendJString()
71 (*env)->ReleaseStringUTFChars(env, text, utfText); in AppendJString()
80 static bool GetExceptionSummary(JNIEnv* env, jthrowable thrown, struct ExpandableString* dst) { in GetExceptionSummary() argument
82 jclass exceptionClass = (*env)->GetObjectClass(env, thrown); // Always succeeds in GetExceptionSummary()
83 jmethodID getName = FindMethod(env, "java/lang/Class", "getName", "()Ljava/lang/String;"); in GetExceptionSummary()
84 jstring className = (jstring) (*env)->CallObjectMethod(env, exceptionClass, getName); in GetExceptionSummary()
87 (*env)->ExceptionClear(env); in GetExceptionSummary()
88 (*env)->DeleteLocalRef(env, exceptionClass); in GetExceptionSummary()
91 (*env)->DeleteLocalRef(env, exceptionClass); in GetExceptionSummary()
94 if (!AppendJString(env, className, dst)) { in GetExceptionSummary()
96 (*env)->ExceptionClear(env); in GetExceptionSummary()
97 (*env)->DeleteLocalRef(env, className); in GetExceptionSummary()
100 (*env)->DeleteLocalRef(env, className); in GetExceptionSummary()
105 FindMethod(env, "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"); in GetExceptionSummary()
106 jstring message = (jstring) (*env)->CallObjectMethod(env, thrown, getMessage); in GetExceptionSummary()
108 success = (ExpandableStringAppend(dst, ": ") && AppendJString(env, message, dst)); in GetExceptionSummary()
109 } else if ((*env)->ExceptionOccurred(env) == NULL) { in GetExceptionSummary()
123 (*env)->ExceptionClear(env); in GetExceptionSummary()
125 (*env)->DeleteLocalRef(env, message); in GetExceptionSummary()
130 static jobject NewStringWriter(JNIEnv* env) { in NewStringWriter() argument
131 jclass clazz = (*env)->FindClass(env, "java/io/StringWriter"); in NewStringWriter()
132 jmethodID init = (*env)->GetMethodID(env, clazz, "<init>", "()V"); in NewStringWriter()
133 jobject instance = (*env)->NewObject(env, clazz, init); in NewStringWriter()
134 (*env)->DeleteLocalRef(env, clazz); in NewStringWriter()
138 static jstring StringWriterToString(JNIEnv* env, jobject stringWriter) { in StringWriterToString() argument
140 FindMethod(env, "java/io/StringWriter", "toString", "()Ljava/lang/String;"); in StringWriterToString()
141 return (jstring) (*env)->CallObjectMethod(env, stringWriter, toString); in StringWriterToString()
144 static jobject NewPrintWriter(JNIEnv* env, jobject writer) { in NewPrintWriter() argument
145 jclass clazz = (*env)->FindClass(env, "java/io/PrintWriter"); in NewPrintWriter()
146 jmethodID init = (*env)->GetMethodID(env, clazz, "<init>", "(Ljava/io/Writer;)V"); in NewPrintWriter()
147 jobject instance = (*env)->NewObject(env, clazz, init, writer); in NewPrintWriter()
148 (*env)->DeleteLocalRef(env, clazz); in NewPrintWriter()
152 static bool GetStackTrace(JNIEnv* env, jthrowable thrown, struct ExpandableString* dst) { in GetStackTrace() argument
159 jobject sw = NewStringWriter(env); in GetStackTrace()
164 jobject pw = NewPrintWriter(env, sw); in GetStackTrace()
166 (*env)->DeleteLocalRef(env, sw); in GetStackTrace()
171 FindMethod(env, "java/lang/Throwable", "printStackTrace", "(Ljava/io/PrintWriter;)V"); in GetStackTrace()
172 (*env)->CallVoidMethod(env, thrown, printStackTrace, pw); in GetStackTrace()
174 jstring trace = ((*env)->ExceptionOccurred(env) != NULL) ? NULL : StringWriterToString(env, sw); in GetStackTrace()
176 (*env)->DeleteLocalRef(env, pw); in GetStackTrace()
178 (*env)->DeleteLocalRef(env, sw); in GetStackTrace()
185 bool success = AppendJString(env, trace, dst); in GetStackTrace()
186 (*env)->DeleteLocalRef(env, trace); in GetStackTrace()
190 static void GetStackTraceOrSummary(JNIEnv* env, jthrowable thrown, struct ExpandableString* dst) { in GetStackTraceOrSummary() argument
197 jthrowable pendingException = (*env)->ExceptionOccurred(env); in GetStackTraceOrSummary()
199 (*env)->ExceptionClear(env); in GetStackTraceOrSummary()
210 if (!GetStackTrace(env, thrown, dst)) { in GetStackTraceOrSummary()
212 (*env)->ExceptionClear(env); in GetStackTraceOrSummary()
213 GetExceptionSummary(env, thrown, dst); in GetStackTraceOrSummary()
218 (*env)->Throw(env, pendingException); in GetStackTraceOrSummary()
219 (*env)->DeleteLocalRef(env, pendingException); in GetStackTraceOrSummary()
223 static void DiscardPendingException(JNIEnv* env, const char* className) { in DiscardPendingException() argument
224 jthrowable exception = (*env)->ExceptionOccurred(env); in DiscardPendingException()
225 (*env)->ExceptionClear(env); in DiscardPendingException()
232 GetExceptionSummary(env, exception, &summary); in DiscardPendingException()
236 (*env)->DeleteLocalRef(env, exception); in DiscardPendingException()
239 static int ThrowException(JNIEnv* env, const char* className, const char* ctorSig, ...) { in ThrowException() argument
246 DiscardPendingException(env, className); in ThrowException()
252 exceptionClass = (*env)->FindClass(env, className); in ThrowException()
259 jmethodID init = (*env)->GetMethodID(env, exceptionClass, "<init>", ctorSig); in ThrowException()
265 jobject instance = (*env)->NewObjectV(env, exceptionClass, init, args); in ThrowException()
271 if ((*env)->Throw(env, (jthrowable)instance) != JNI_OK) { in ThrowException()
284 (*env)->DeleteLocalRef(env, exceptionClass); in ThrowException()
289 static jstring CreateExceptionMsg(JNIEnv* env, const char* msg) { in CreateExceptionMsg() argument
290 jstring detailMessage = (*env)->NewStringUTF(env, msg); in CreateExceptionMsg()
294 (*env)->ExceptionClear(env); in CreateExceptionMsg()
309 #define THROW_EXCEPTION_WITH_MESSAGE(env, className, ctorSig, msg, ...) ({ \ argument
310 jstring _detailMessage = CreateExceptionMsg(env, msg); \
311 int _status = ThrowException(env, className, ctorSig, _detailMessage, ## __VA_ARGS__); \
313 (*env)->DeleteLocalRef(env, _detailMessage); \
321 int jniRegisterNativeMethods(JNIEnv* env, const char* className, in jniRegisterNativeMethods() argument
325 jclass clazz = (*env)->FindClass(env, className); in jniRegisterNativeMethods()
329 int result = (*env)->RegisterNatives(env, clazz, methods, numMethods); in jniRegisterNativeMethods()
330 (*env)->DeleteLocalRef(env, clazz); in jniRegisterNativeMethods()
337 jthrowable thrown = (*env)->ExceptionOccurred(env); in jniRegisterNativeMethods()
341 if (GetExceptionSummary(env, thrown, &summary)) { in jniRegisterNativeMethods()
345 (*env)->DeleteLocalRef(env, thrown); in jniRegisterNativeMethods()
351 void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowable thrown) { in jniLogException() argument
354 GetStackTraceOrSummary(env, thrown, &summary); in jniLogException()
360 int jniThrowException(JNIEnv* env, const char* className, const char* message) { in jniThrowException() argument
361 return THROW_EXCEPTION_WITH_MESSAGE(env, className, "(Ljava/lang/String;)V", message); in jniThrowException()
364 int jniThrowExceptionFmt(JNIEnv* env, const char* className, const char* fmt, va_list args) { in jniThrowExceptionFmt() argument
367 return jniThrowException(env, className, msgBuf); in jniThrowExceptionFmt()
370 int jniThrowNullPointerException(JNIEnv* env, const char* msg) { in jniThrowNullPointerException() argument
371 return jniThrowException(env, "java/lang/NullPointerException", msg); in jniThrowNullPointerException()
374 int jniThrowRuntimeException(JNIEnv* env, const char* msg) { in jniThrowRuntimeException() argument
375 return jniThrowException(env, "java/lang/RuntimeException", msg); in jniThrowRuntimeException()
378 int jniThrowIOException(JNIEnv* env, int errno_value) { in jniThrowIOException() argument
381 return jniThrowException(env, "java/io/IOException", message); in jniThrowIOException()
384 int jniThrowErrnoException(JNIEnv* env, const char* functionName, int errno_value) { in jniThrowErrnoException() argument
385 return THROW_EXCEPTION_WITH_MESSAGE(env, "android/system/ErrnoException", in jniThrowErrnoException()
389 jstring jniCreateString(JNIEnv* env, const jchar* unicodeChars, jsize len) { in jniCreateString() argument
390 return (*env)->NewString(env, unicodeChars, len); in jniCreateString()