Lines Matching refs:env
107 [[maybe_unused]] static jmethodID FindMethod(JNIEnv* env, const char* className, in FindMethod() argument
111 jclass clazz = env->FindClass(className); in FindMethod()
112 jmethodID methodId = env->GetMethodID(clazz, methodName, descriptor); in FindMethod()
113 env->DeleteLocalRef(clazz); in FindMethod()
117 [[maybe_unused]] static bool AppendJString(JNIEnv* env, jstring text, in AppendJString() argument
119 const char* utfText = env->GetStringUTFChars(text, NULL); in AppendJString()
124 env->ReleaseStringUTFChars(text, utfText); in AppendJString()
133 [[maybe_unused]] static bool GetExceptionSummary(JNIEnv* env, jthrowable thrown, in GetExceptionSummary() argument
136 jclass exceptionClass = env->GetObjectClass(thrown); // Always succeeds in GetExceptionSummary()
137 jmethodID getName = FindMethod(env, "java/lang/Class", "getName", "()Ljava/lang/String;"); in GetExceptionSummary()
138 jstring className = (jstring)env->CallObjectMethod(exceptionClass, getName); in GetExceptionSummary()
141 env->ExceptionClear(); in GetExceptionSummary()
142 env->DeleteLocalRef(exceptionClass); in GetExceptionSummary()
145 env->DeleteLocalRef(exceptionClass); in GetExceptionSummary()
148 if (!AppendJString(env, className, dst)) { in GetExceptionSummary()
150 env->ExceptionClear(); in GetExceptionSummary()
151 env->DeleteLocalRef(className); in GetExceptionSummary()
154 env->DeleteLocalRef(className); in GetExceptionSummary()
158 FindMethod(env, "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"); in GetExceptionSummary()
159 jstring message = (jstring)env->CallObjectMethod(thrown, getMessage); in GetExceptionSummary()
164 bool success = (ExpandableStringAppend(dst, ": ") && AppendJString(env, message, dst)); in GetExceptionSummary()
175 env->ExceptionClear(); in GetExceptionSummary()
177 env->DeleteLocalRef(message); in GetExceptionSummary()
182 [[maybe_unused]] static jobject NewStringWriter(JNIEnv* env) { in NewStringWriter() argument
183 jclass clazz = env->FindClass("java/io/StringWriter"); in NewStringWriter()
184 jmethodID init = env->GetMethodID(clazz, "<init>", "()V"); in NewStringWriter()
185 jobject instance = env->NewObject(clazz, init); in NewStringWriter()
186 env->DeleteLocalRef(clazz); in NewStringWriter()
190 [[maybe_unused]] static jstring StringWriterToString(JNIEnv* env, jobject stringWriter) { in StringWriterToString() argument
192 FindMethod(env, "java/io/StringWriter", "toString", "()Ljava/lang/String;"); in StringWriterToString()
193 return (jstring)env->CallObjectMethod(stringWriter, toString); in StringWriterToString()
196 [[maybe_unused]] static jobject NewPrintWriter(JNIEnv* env, jobject writer) { in NewPrintWriter() argument
197 jclass clazz = env->FindClass("java/io/PrintWriter"); in NewPrintWriter()
198 jmethodID init = env->GetMethodID(clazz, "<init>", "(Ljava/io/Writer;)V"); in NewPrintWriter()
199 jobject instance = env->NewObject(clazz, init, writer); in NewPrintWriter()
200 env->DeleteLocalRef(clazz); in NewPrintWriter()
204 [[maybe_unused]] static bool GetStackTrace(JNIEnv* env, jthrowable thrown, in GetStackTrace() argument
212 jobject sw = NewStringWriter(env); in GetStackTrace()
217 jobject pw = NewPrintWriter(env, sw); in GetStackTrace()
219 env->DeleteLocalRef(sw); in GetStackTrace()
224 FindMethod(env, "java/lang/Throwable", "printStackTrace", "(Ljava/io/PrintWriter;)V"); in GetStackTrace()
225 env->CallVoidMethod(thrown, printStackTrace, pw); in GetStackTrace()
227 jstring trace = StringWriterToString(env, sw); in GetStackTrace()
229 env->DeleteLocalRef(pw); in GetStackTrace()
231 env->DeleteLocalRef(sw); in GetStackTrace()
238 bool success = AppendJString(env, trace, dst); in GetStackTrace()
239 env->DeleteLocalRef(trace); in GetStackTrace()
243 [[maybe_unused]] static void GetStackTraceOrSummary(JNIEnv* env, jthrowable thrown, in GetStackTraceOrSummary() argument
251 jthrowable pendingException = env->ExceptionOccurred(); in GetStackTraceOrSummary()
253 env->ExceptionClear(); in GetStackTraceOrSummary()
264 if (!GetStackTrace(env, thrown, dst)) { in GetStackTraceOrSummary()
266 env->ExceptionClear(); in GetStackTraceOrSummary()
267 GetExceptionSummary(env, thrown, dst); in GetStackTraceOrSummary()
272 env->Throw(pendingException); in GetStackTraceOrSummary()
273 env->DeleteLocalRef(pendingException); in GetStackTraceOrSummary()
277 [[maybe_unused]] static void DiscardPendingException(JNIEnv* env, const char* className) { in DiscardPendingException() argument
278 jthrowable exception = env->ExceptionOccurred(); in DiscardPendingException()
279 env->ExceptionClear(); in DiscardPendingException()
286 GetExceptionSummary(env, exception, &summary); in DiscardPendingException()
291 env->DeleteLocalRef(exception); in DiscardPendingException()
294 [[maybe_unused]] static int ThrowException(JNIEnv* env, const char* className, const char* ctorSig, in ThrowException() argument
302 DiscardPendingException(env, className); in ThrowException()
308 exceptionClass = env->FindClass(className); in ThrowException()
316 jmethodID init = env->GetMethodID(exceptionClass, "<init>", ctorSig); in ThrowException()
323 jobject instance = env->NewObjectV(exceptionClass, init, args); in ThrowException()
330 if (env->Throw((jthrowable)instance) != JNI_OK) { in ThrowException()
343 env->DeleteLocalRef(exceptionClass); in ThrowException()
348 [[maybe_unused]] static jstring CreateExceptionMsg(JNIEnv* env, const char* msg) { in CreateExceptionMsg() argument
349 jstring detailMessage = env->NewStringUTF(msg); in CreateExceptionMsg()
353 env->ExceptionClear(); in CreateExceptionMsg()
363 [[maybe_unused]] static int jniRegisterNativeMethods(JNIEnv* env, const char* className, in jniRegisterNativeMethods() argument
367 jclass clazz = env->FindClass(className); in jniRegisterNativeMethods()
373 int result = env->RegisterNatives(clazz, methods, numMethods); in jniRegisterNativeMethods()
374 env->DeleteLocalRef(clazz); in jniRegisterNativeMethods()
381 jthrowable thrown = env->ExceptionOccurred(); in jniRegisterNativeMethods()
385 if (GetExceptionSummary(env, thrown, &summary)) { in jniRegisterNativeMethods()
389 env->DeleteLocalRef(thrown); in jniRegisterNativeMethods()
410 [[maybe_unused]] static int jniThrowException(JNIEnv* env, const char* className, const char* msg) { in jniThrowException() argument
412 jstring _detailMessage = CreateExceptionMsg(env, msg); in jniThrowException()
413 int _status = ThrowException(env, className, "(Ljava/lang/String;)V", _detailMessage); in jniThrowException()
415 env->DeleteLocalRef(_detailMessage); in jniThrowException()
423 [[maybe_unused]] static int jniThrowErrnoException(JNIEnv* env, const char* functionName, in jniThrowErrnoException() argument
426 jstring _detailMessage = CreateExceptionMsg(env, functionName); in jniThrowErrnoException()
427 int _status = ThrowException(env, "android/system/ErrnoException", "(Ljava/lang/String;I)V", in jniThrowErrnoException()
430 env->DeleteLocalRef(_detailMessage); in jniThrowErrnoException()
449 [[maybe_unused]] static int jniThrowExceptionFmt(JNIEnv* env, const char* className, in jniThrowExceptionFmt() argument
456 return jniThrowException(env, className, msgBuf); in jniThrowExceptionFmt()
459 [[maybe_unused]] static int jniThrowNullPointerException(JNIEnv* env, const char* msg) { in jniThrowNullPointerException() argument
460 return jniThrowException(env, "java/lang/NullPointerException", msg); in jniThrowNullPointerException()
463 [[maybe_unused]] static int jniThrowRuntimeException(JNIEnv* env, const char* msg) { in jniThrowRuntimeException() argument
464 return jniThrowException(env, "java/lang/RuntimeException", msg); in jniThrowRuntimeException()
467 [[maybe_unused]] static int jniThrowIOException(JNIEnv* env, int errno_value) { in jniThrowIOException() argument
471 return jniThrowException(env, "java/io/IOException", message); in jniThrowIOException()
478 [[maybe_unused]] static inline jstring jniCreateString(JNIEnv* env, const jchar* unicodeChars, in jniCreateString() argument
480 return env->NewString(unicodeChars, len); in jniCreateString()
483 [[maybe_unused]] static inline jstring jniCreateString(JNIEnv* env, const char16_t* unicodeChars, in jniCreateString() argument
485 return jniCreateString(env, reinterpret_cast<const jchar*>(unicodeChars), len); in jniCreateString()
492 [[maybe_unused]] static void jniLogException(JNIEnv* env, int priority, const char* tag,
497 GetStackTraceOrSummary(env, exception, &summary);
507 int jniRegisterNativeMethods(JNIEnv* env, const char* className, const JNINativeMethod* gMethods,
510 void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowable thrown);
512 int jniThrowException(JNIEnv* env, const char* className, const char* msg);
514 int jniThrowNullPointerException(JNIEnv* env, const char* msg);