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()
104 FindMethod(env, "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"); in GetExceptionSummary()
105 jstring message = (jstring) (*env)->CallObjectMethod(env, thrown, getMessage); in GetExceptionSummary()
110 bool success = (ExpandableStringAppend(dst, ": ") && AppendJString(env, message, dst)); in GetExceptionSummary()
121 (*env)->ExceptionClear(env); in GetExceptionSummary()
123 (*env)->DeleteLocalRef(env, message); in GetExceptionSummary()
128 static jobject NewStringWriter(JNIEnv* env) { in NewStringWriter() argument
129 jclass clazz = (*env)->FindClass(env, "java/io/StringWriter"); in NewStringWriter()
130 jmethodID init = (*env)->GetMethodID(env, clazz, "<init>", "()V"); in NewStringWriter()
131 jobject instance = (*env)->NewObject(env, clazz, init); in NewStringWriter()
132 (*env)->DeleteLocalRef(env, clazz); in NewStringWriter()
136 static jstring StringWriterToString(JNIEnv* env, jobject stringWriter) { in StringWriterToString() argument
138 FindMethod(env, "java/io/StringWriter", "toString", "()Ljava/lang/String;"); in StringWriterToString()
139 return (jstring) (*env)->CallObjectMethod(env, stringWriter, toString); in StringWriterToString()
142 static jobject NewPrintWriter(JNIEnv* env, jobject writer) { in NewPrintWriter() argument
143 jclass clazz = (*env)->FindClass(env, "java/io/PrintWriter"); in NewPrintWriter()
144 jmethodID init = (*env)->GetMethodID(env, clazz, "<init>", "(Ljava/io/Writer;)V"); in NewPrintWriter()
145 jobject instance = (*env)->NewObject(env, clazz, init, writer); in NewPrintWriter()
146 (*env)->DeleteLocalRef(env, clazz); in NewPrintWriter()
150 static bool GetStackTrace(JNIEnv* env, jthrowable thrown, struct ExpandableString* dst) { in GetStackTrace() argument
157 jobject sw = NewStringWriter(env); in GetStackTrace()
162 jobject pw = NewPrintWriter(env, sw); in GetStackTrace()
164 (*env)->DeleteLocalRef(env, sw); in GetStackTrace()
169 FindMethod(env, "java/lang/Throwable", "printStackTrace", "(Ljava/io/PrintWriter;)V"); in GetStackTrace()
170 (*env)->CallVoidMethod(env, thrown, printStackTrace, pw); in GetStackTrace()
172 jstring trace = StringWriterToString(env, sw); in GetStackTrace()
174 (*env)->DeleteLocalRef(env, pw); in GetStackTrace()
176 (*env)->DeleteLocalRef(env, sw); in GetStackTrace()
183 bool success = AppendJString(env, trace, dst); in GetStackTrace()
184 (*env)->DeleteLocalRef(env, trace); in GetStackTrace()
188 static void GetStackTraceOrSummary(JNIEnv* env, jthrowable thrown, struct ExpandableString* dst) { in GetStackTraceOrSummary() argument
195 jthrowable pendingException = (*env)->ExceptionOccurred(env); in GetStackTraceOrSummary()
197 (*env)->ExceptionClear(env); in GetStackTraceOrSummary()
208 if (!GetStackTrace(env, thrown, dst)) { in GetStackTraceOrSummary()
210 (*env)->ExceptionClear(env); in GetStackTraceOrSummary()
211 GetExceptionSummary(env, thrown, dst); in GetStackTraceOrSummary()
216 (*env)->Throw(env, pendingException); in GetStackTraceOrSummary()
217 (*env)->DeleteLocalRef(env, pendingException); in GetStackTraceOrSummary()
221 static void DiscardPendingException(JNIEnv* env, const char* className) { in DiscardPendingException() argument
222 jthrowable exception = (*env)->ExceptionOccurred(env); in DiscardPendingException()
223 (*env)->ExceptionClear(env); in DiscardPendingException()
230 GetExceptionSummary(env, exception, &summary); in DiscardPendingException()
234 (*env)->DeleteLocalRef(env, exception); in DiscardPendingException()
237 static int ThrowException(JNIEnv* env, const char* className, const char* ctorSig, ...) { in ThrowException() argument
244 DiscardPendingException(env, className); in ThrowException()
250 exceptionClass = (*env)->FindClass(env, className); in ThrowException()
257 jmethodID init = (*env)->GetMethodID(env, exceptionClass, "<init>", ctorSig); in ThrowException()
263 jobject instance = (*env)->NewObjectV(env, exceptionClass, init, args); in ThrowException()
269 if ((*env)->Throw(env, (jthrowable)instance) != JNI_OK) { in ThrowException()
282 (*env)->DeleteLocalRef(env, exceptionClass); in ThrowException()
287 static jstring CreateExceptionMsg(JNIEnv* env, const char* msg) { in CreateExceptionMsg() argument
288 jstring detailMessage = (*env)->NewStringUTF(env, msg); in CreateExceptionMsg()
292 (*env)->ExceptionClear(env); in CreateExceptionMsg()
307 #define THROW_EXCEPTION_WITH_MESSAGE(env, className, ctorSig, msg, ...) ({ \ argument
308 jstring _detailMessage = CreateExceptionMsg(env, msg); \
309 int _status = ThrowException(env, className, ctorSig, _detailMessage, ## __VA_ARGS__); \
311 (*env)->DeleteLocalRef(env, _detailMessage); \
319 int jniRegisterNativeMethods(JNIEnv* env, const char* className, in jniRegisterNativeMethods() argument
323 jclass clazz = (*env)->FindClass(env, className); in jniRegisterNativeMethods()
327 int result = (*env)->RegisterNatives(env, clazz, methods, numMethods); in jniRegisterNativeMethods()
328 (*env)->DeleteLocalRef(env, clazz); in jniRegisterNativeMethods()
335 jthrowable thrown = (*env)->ExceptionOccurred(env); in jniRegisterNativeMethods()
339 if (GetExceptionSummary(env, thrown, &summary)) { in jniRegisterNativeMethods()
343 (*env)->DeleteLocalRef(env, thrown); in jniRegisterNativeMethods()
349 void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowable thrown) { in jniLogException() argument
352 GetStackTraceOrSummary(env, thrown, &summary); in jniLogException()
358 int jniThrowException(JNIEnv* env, const char* className, const char* message) { in jniThrowException() argument
359 return THROW_EXCEPTION_WITH_MESSAGE(env, className, "(Ljava/lang/String;)V", message); in jniThrowException()
362 int jniThrowExceptionFmt(JNIEnv* env, const char* className, const char* fmt, va_list args) { in jniThrowExceptionFmt() argument
365 return jniThrowException(env, className, msgBuf); in jniThrowExceptionFmt()
368 int jniThrowNullPointerException(JNIEnv* env, const char* msg) { in jniThrowNullPointerException() argument
369 return jniThrowException(env, "java/lang/NullPointerException", msg); in jniThrowNullPointerException()
372 int jniThrowRuntimeException(JNIEnv* env, const char* msg) { in jniThrowRuntimeException() argument
373 return jniThrowException(env, "java/lang/RuntimeException", msg); in jniThrowRuntimeException()
376 int jniThrowIOException(JNIEnv* env, int errno_value) { in jniThrowIOException() argument
379 return jniThrowException(env, "java/io/IOException", message); in jniThrowIOException()
382 int jniThrowErrnoException(JNIEnv* env, const char* functionName, int errno_value) { in jniThrowErrnoException() argument
383 return THROW_EXCEPTION_WITH_MESSAGE(env, "android/system/ErrnoException", in jniThrowErrnoException()
387 jstring jniCreateString(JNIEnv* env, const jchar* unicodeChars, jsize len) { in jniCreateString() argument
388 return (*env)->NewString(env, unicodeChars, len); in jniCreateString()