Lines Matching refs:env

41     scoped_local_ref(C_JNIEnv* env, T localRef = NULL)  in scoped_local_ref()  argument
42 : mEnv(env), mLocalRef(localRef) in scoped_local_ref()
68 static jclass findClass(C_JNIEnv* env, const char* className) { in findClass() argument
69 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in findClass()
70 return (*env)->FindClass(e, className); in findClass()
73 extern "C" int jniRegisterNativeMethods(C_JNIEnv* env, const char* className, in jniRegisterNativeMethods() argument
76 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in jniRegisterNativeMethods()
80 scoped_local_ref<jclass> c(env, findClass(env, className)); in jniRegisterNativeMethods()
87 if ((*env)->RegisterNatives(e, c.get(), gMethods, numMethods) < 0) { in jniRegisterNativeMethods()
101 static bool getExceptionSummary(C_JNIEnv* env, jthrowable exception, std::string& result) { in getExceptionSummary() argument
102 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in getExceptionSummary()
105 … scoped_local_ref<jclass> exceptionClass(env, (*env)->GetObjectClass(e, exception)); // can't fail in getExceptionSummary()
106 scoped_local_ref<jclass> classClass(env, in getExceptionSummary()
107 (*env)->GetObjectClass(e, exceptionClass.get())); // java.lang.Class, can't fail in getExceptionSummary()
109 (*env)->GetMethodID(e, classClass.get(), "getName", "()Ljava/lang/String;"); in getExceptionSummary()
110 scoped_local_ref<jstring> classNameStr(env, in getExceptionSummary()
111 (jstring) (*env)->CallObjectMethod(e, exceptionClass.get(), classGetNameMethod)); in getExceptionSummary()
113 (*env)->ExceptionClear(e); in getExceptionSummary()
117 const char* classNameChars = (*env)->GetStringUTFChars(e, classNameStr.get(), NULL); in getExceptionSummary()
119 (*env)->ExceptionClear(e); in getExceptionSummary()
124 (*env)->ReleaseStringUTFChars(e, classNameStr.get(), classNameChars); in getExceptionSummary()
128 (*env)->GetMethodID(e, exceptionClass.get(), "getMessage", "()Ljava/lang/String;"); in getExceptionSummary()
129 scoped_local_ref<jstring> messageStr(env, in getExceptionSummary()
130 (jstring) (*env)->CallObjectMethod(e, exception, getMessage)); in getExceptionSummary()
137 const char* messageChars = (*env)->GetStringUTFChars(e, messageStr.get(), NULL); in getExceptionSummary()
140 (*env)->ReleaseStringUTFChars(e, messageStr.get(), messageChars); in getExceptionSummary()
143 (*env)->ExceptionClear(e); // clear OOM in getExceptionSummary()
152 static bool getStackTrace(C_JNIEnv* env, jthrowable exception, std::string& result) { in getStackTrace() argument
153 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in getStackTrace()
155 scoped_local_ref<jclass> stringWriterClass(env, findClass(env, "java/io/StringWriter")); in getStackTrace()
160 jmethodID stringWriterCtor = (*env)->GetMethodID(e, stringWriterClass.get(), "<init>", "()V"); in getStackTrace()
162 (*env)->GetMethodID(e, stringWriterClass.get(), "toString", "()Ljava/lang/String;"); in getStackTrace()
164 scoped_local_ref<jclass> printWriterClass(env, findClass(env, "java/io/PrintWriter")); in getStackTrace()
170 (*env)->GetMethodID(e, printWriterClass.get(), "<init>", "(Ljava/io/Writer;)V"); in getStackTrace()
172 scoped_local_ref<jobject> stringWriter(env, in getStackTrace()
173 (*env)->NewObject(e, stringWriterClass.get(), stringWriterCtor)); in getStackTrace()
178 scoped_local_ref<jobject> printWriter(env, in getStackTrace()
179 (*env)->NewObject(e, printWriterClass.get(), printWriterCtor, stringWriter.get())); in getStackTrace()
184 … scoped_local_ref<jclass> exceptionClass(env, (*env)->GetObjectClass(e, exception)); // can't fail in getStackTrace()
186 … (*env)->GetMethodID(e, exceptionClass.get(), "printStackTrace", "(Ljava/io/PrintWriter;)V"); in getStackTrace()
187 (*env)->CallVoidMethod(e, exception, printStackTraceMethod, printWriter.get()); in getStackTrace()
189 if ((*env)->ExceptionCheck(e)) { in getStackTrace()
193 scoped_local_ref<jstring> messageStr(env, in getStackTrace()
194 (jstring) (*env)->CallObjectMethod(e, stringWriter.get(), stringWriterToStringMethod)); in getStackTrace()
199 const char* utfChars = (*env)->GetStringUTFChars(e, messageStr.get(), NULL); in getStackTrace()
206 (*env)->ReleaseStringUTFChars(e, messageStr.get(), utfChars); in getStackTrace()
210 extern "C" int jniThrowException(C_JNIEnv* env, const char* className, const char* msg) { in jniThrowException() argument
211 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in jniThrowException()
213 if ((*env)->ExceptionCheck(e)) { in jniThrowException()
215 scoped_local_ref<jthrowable> exception(env, (*env)->ExceptionOccurred(e)); in jniThrowException()
216 (*env)->ExceptionClear(e); in jniThrowException()
220 getExceptionSummary(env, exception.get(), text); in jniThrowException()
225 scoped_local_ref<jclass> exceptionClass(env, findClass(env, className)); in jniThrowException()
232 if ((*env)->ThrowNew(e, exceptionClass.get(), msg) != JNI_OK) { in jniThrowException()
241 int jniThrowExceptionFmt(C_JNIEnv* env, const char* className, const char* fmt, va_list args) { in jniThrowExceptionFmt() argument
244 return jniThrowException(env, className, msgBuf); in jniThrowExceptionFmt()
247 int jniThrowNullPointerException(C_JNIEnv* env, const char* msg) { in jniThrowNullPointerException() argument
248 return jniThrowException(env, "java/lang/NullPointerException", msg); in jniThrowNullPointerException()
251 int jniThrowRuntimeException(C_JNIEnv* env, const char* msg) { in jniThrowRuntimeException() argument
252 return jniThrowException(env, "java/lang/RuntimeException", msg); in jniThrowRuntimeException()
255 int jniThrowIOException(C_JNIEnv* env, int errnum) { in jniThrowIOException() argument
258 return jniThrowException(env, "java/io/IOException", message); in jniThrowIOException()
261 static std::string jniGetStackTrace(C_JNIEnv* env, jthrowable exception) { in jniGetStackTrace() argument
262 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in jniGetStackTrace()
264 scoped_local_ref<jthrowable> currentException(env, (*env)->ExceptionOccurred(e)); in jniGetStackTrace()
273 (*env)->ExceptionClear(e); in jniGetStackTrace()
277 if (!getStackTrace(env, exception, trace)) { in jniGetStackTrace()
278 (*env)->ExceptionClear(e); in jniGetStackTrace()
279 getExceptionSummary(env, exception, trace); in jniGetStackTrace()
283 (*env)->Throw(e, currentException.get()); // rethrow in jniGetStackTrace()
289 void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception) { in jniLogException() argument
290 std::string trace(jniGetStackTrace(env, exception)); in jniLogException()
311 jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd) { in jniCreateFileDescriptor() argument
312 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in jniCreateFileDescriptor()
314 jobject fileDescriptor = (*env)->NewObject(e, JniConstants::fileDescriptorClass, ctor); in jniCreateFileDescriptor()
318 jniSetFileDescriptorOfFD(env, fileDescriptor, fd); in jniCreateFileDescriptor()
323 int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor) { in jniGetFDFromFileDescriptor() argument
324 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in jniGetFDFromFileDescriptor()
327 return (*env)->GetIntField(e, fileDescriptor, fid); in jniGetFDFromFileDescriptor()
333 void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value) { in jniSetFileDescriptorOfFD() argument
334 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in jniSetFileDescriptorOfFD()
336 (*env)->SetIntField(e, fileDescriptor, fid, value); in jniSetFileDescriptorOfFD()
339 jobject jniGetReferent(C_JNIEnv* env, jobject ref) { in jniGetReferent() argument
340 JNIEnv* e = reinterpret_cast<JNIEnv*>(env); in jniGetReferent()
342 return (*env)->CallObjectMethod(e, ref, get); in jniGetReferent()