#include <JniUtil.h>
Inheritance diagram for JniEnvAutoRef:
Public Member Functions | |
JniEnvAutoRef () | |
Uses GetEnv to access current thread's JNIEnv pointer. | |
void | suppressDetach () |
Suppresses default detach-on-destruct behavior. | |
~JniEnvAutoRef () | |
JniExceptionChecker | operator-> () const |
JNIEnv * | get () |
void | handleExcn (std::exception &ex) |
Private Attributes | |
bool | needDetach |
When an environment is already available, it is used automatically, but when unavailable, this class takes care of attaching the thread (in the constructor) and detaching it (in the destructor). For threads created within Fennel, attach/detach can be optimized by allocating a JniEnvAutoRef on a thread's initial stack frame so that it will be available to all methods called.
Definition at line 113 of file JniUtil.h.
JniEnvAutoRef::JniEnvAutoRef | ( | ) | [explicit] |
Uses GetEnv to access current thread's JNIEnv pointer.
Definition at line 523 of file JniUtil.cpp.
00524 : JniEnvRef(JniUtil::getAttachedJavaEnv(needDetach)) 00525 { 00526 }
JniEnvAutoRef::~JniEnvAutoRef | ( | ) |
Definition at line 528 of file JniUtil.cpp.
References JniUtil::detachJavaEnv(), and needDetach.
00529 { 00530 if (needDetach) { 00531 JniUtil::detachJavaEnv(); 00532 } 00533 }
void JniEnvAutoRef::suppressDetach | ( | ) |
Suppresses default detach-on-destruct behavior.
REVIEW jvs 13-Oct-2006: Get rid of this and arrange for all native-spawned threads to attach on start and detach on end.
Definition at line 535 of file JniUtil.cpp.
References needDetach.
Referenced by JavaTraceTarget::onThreadStart(), and JavaThreadTracker::onThreadStart().
00536 { 00537 needDetach = false; 00538 }
JniExceptionChecker JniEnvRef::operator-> | ( | ) | const [inline, inherited] |
JNIEnv* JniEnvRef::get | ( | ) | [inline, inherited] |
Definition at line 96 of file JniUtil.h.
Referenced by JniLocalRefReaper::JniLocalRefReaper().
00097 { 00098 return pEnv; 00099 }
void JniEnvRef::handleExcn | ( | std::exception & | ex | ) | [inherited] |
Definition at line 540 of file JniUtil.cpp.
References JavaExcn::getJavaException(), FennelExcn::getMessage(), and JniEnvRef::pEnv.
Referenced by Java_com_lucidera_farrago_fennel_LucidEraJni_registerStreamFactory(), Java_net_sf_farrago_fennel_FennelStorage_executeJavaCmd(), Java_net_sf_farrago_fennel_FennelStorage_tupleStreamFetch(), Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphClose(), Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphGetInputStreams(), Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphOpen(), Java_net_sf_farrago_fennel_FennelStorage_tupleStreamRestart(), Java_net_sf_farrago_fennel_FennelStorage_tupleStreamTransformFetch(), and JNI_OnLoad().
00541 { 00542 JavaExcn *pJavaExcn = dynamic_cast<JavaExcn *>(&ex); 00543 if (pJavaExcn) { 00544 pEnv->Throw(pJavaExcn->getJavaException()); 00545 return; 00546 } 00547 std::string what; 00548 FennelExcn *pFennelExcn = dynamic_cast<FennelExcn *>(&ex); 00549 if (pFennelExcn) { 00550 what = pFennelExcn->getMessage(); 00551 } else { 00552 std::bad_alloc *pBadAllocExcn = 00553 dynamic_cast<std::bad_alloc *>(&ex); 00554 if (pBadAllocExcn) { 00555 // Convert bad_alloc's terrible error mesage into something fit for 00556 // human consumption. 00557 what = FennelResource::instance().internalError("malloc failed"); 00558 } else { 00559 what = FennelResource::instance().internalError(ex.what()); 00560 } 00561 } 00562 // TODO: need special-case handling for out-of-memory here 00563 jclass classSQLException = pEnv->FindClass("java/sql/SQLException"); 00564 jstring jMessage = pEnv->NewStringUTF(what.c_str()); 00565 jmethodID constructor = pEnv->GetMethodID( 00566 classSQLException,"<init>","(Ljava/lang/String;)V"); 00567 jthrowable t = (jthrowable) 00568 pEnv->NewObject(classSQLException,constructor,jMessage); 00569 pEnv->Throw(t); 00570 }
bool JniEnvAutoRef::needDetach [private] |