From f2c6bbf4606d3e5274e5ba621e3a8b7f939d2f82 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 11 Dec 2014 11:48:33 +0100 Subject: Store JNI_info in JniUnoEnvironmentData instead of Bridge ...to have it available during JNI-UNO's uno_initEnvironment (see next) Change-Id: I7a2f27b512fc74f418b4648d92dafbf0304eaa96 --- bridges/source/jni_uno/jni_bridge.cxx | 167 ++++++++++--------- bridges/source/jni_uno/jni_bridge.h | 9 +- bridges/source/jni_uno/jni_data.cxx | 198 +++++++++++------------ bridges/source/jni_uno/jni_java2uno.cxx | 16 +- bridges/source/jni_uno/jni_uno2java.cxx | 22 +-- bridges/source/jni_uno/jniunoenvironmentdata.hxx | 9 +- 6 files changed, 222 insertions(+), 199 deletions(-) (limited to 'bridges') diff --git a/bridges/source/jni_uno/jni_bridge.cxx b/bridges/source/jni_uno/jni_bridge.cxx index ea28c5d536a7..192aaf1b690b 100644 --- a/bridges/source/jni_uno/jni_bridge.cxx +++ b/bridges/source/jni_uno/jni_bridge.cxx @@ -84,14 +84,14 @@ void SAL_CALL Mapping_map_to_uno( Bridge const * bridge = static_cast< Mapping const * >( mapping )->m_bridge; JNI_guarded_context jni( - bridge->m_jni_info, + bridge->getJniInfo(), (static_cast( bridge->m_java_env->pContext) ->machine)); JNI_interface_type_info const * info = static_cast< JNI_interface_type_info const * >( - bridge->m_jni_info->get_type_info( + bridge->getJniInfo()->get_type_info( jni, (typelib_TypeDescription *)td ) ); uno_Interface * pUnoI = bridge->map_to_uno( jni, javaI, info ); if (0 != *ppUnoI) @@ -136,7 +136,7 @@ void SAL_CALL Mapping_map_to_java( Bridge const * bridge = static_cast< Mapping const * >( mapping )->m_bridge; JNI_guarded_context jni( - bridge->m_jni_info, + bridge->getJniInfo(), (static_cast( bridge->m_java_env->pContext) ->machine)); @@ -149,14 +149,14 @@ void SAL_CALL Mapping_map_to_java( Bridge const * bridge = static_cast< Mapping const * >( mapping )->m_bridge; JNI_guarded_context jni( - bridge->m_jni_info, + bridge->getJniInfo(), (static_cast( bridge->m_java_env->pContext) ->machine)); JNI_interface_type_info const * info = static_cast< JNI_interface_type_info const * >( - bridge->m_jni_info->get_type_info( + bridge->getJniInfo()->get_type_info( jni, (typelib_TypeDescription *)td ) ); jobject jlocal = bridge->map_to_java( jni, pUnoI, info ); if (0 != *ppJavaI) @@ -235,13 +235,17 @@ Bridge::Bridge( m_java_env( java_env ), m_registered_java2uno( registered_java2uno ) { - // bootstrapping bridge jni_info - m_jni_info = JNI_info::get_jni_info( - static_cast(m_java_env->pContext) - ->machine); - assert(m_java_env != 0); assert(m_uno_env != 0); + + // uno_initEnvironment (below) cannot report errors directly, so it clears + // its pContext upon error to indirectly report errors from here: + if (static_cast(m_java_env->pContext) + == nullptr) + { + throw BridgeRuntimeError("error during JNI-UNO's uno_initEnvironment"); + } + (*((uno_Environment *)m_uno_env)->acquire)( (uno_Environment *)m_uno_env ); (*m_java_env->acquire)( m_java_env ); @@ -264,7 +268,10 @@ Bridge::~Bridge() (*((uno_Environment *)m_uno_env)->release)( (uno_Environment *)m_uno_env ); } - +JNI_info const * Bridge::getJniInfo() const { + return static_cast(m_java_env->pContext) + ->info; +} void JNI_context::java_exc_occurred() const { @@ -418,40 +425,46 @@ extern "C" { void SAL_CALL java_env_dispose(uno_Environment * env) { auto * envData = static_cast(env->pContext); - jobject async; - { - osl::MutexGuard g(envData->mutex); - async = envData->asynchronousFinalizer; - envData->asynchronousFinalizer = nullptr; - } - if (async != nullptr) { - try { - jvmaccess::VirtualMachine::AttachGuard g( - envData->machine->getVirtualMachine()); - JNIEnv * jniEnv = g.getEnvironment(); - jclass cl = jniEnv->FindClass( - "com/sun/star/lib/util/AsynchronousFinalizer"); - if (cl == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in FindClass"); - } else { - jmethodID id = jniEnv->GetMethodID(cl, "drain", "()V"); - if (id == nullptr) { + if (envData != nullptr) { + jobject async; + { + osl::MutexGuard g(envData->mutex); + async = envData->asynchronousFinalizer; + envData->asynchronousFinalizer = nullptr; + } + if (async != nullptr) { + try { + jvmaccess::VirtualMachine::AttachGuard g( + envData->machine->getVirtualMachine()); + JNIEnv * jniEnv = g.getEnvironment(); + jclass cl = jniEnv->FindClass( + "com/sun/star/lib/util/AsynchronousFinalizer"); + if (cl == nullptr) { jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in GetMethodID"); + SAL_WARN("bridges", "exception in FindClass"); } else { - jniEnv->CallObjectMethod(async, id); - if (jniEnv->ExceptionOccurred()) { + jmethodID id = jniEnv->GetMethodID(cl, "drain", "()V"); + if (id == nullptr) { jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in CallObjectMethod"); + SAL_WARN("bridges", "exception in GetMethodID"); + } else { + jniEnv->CallObjectMethod(async, id); + if (jniEnv->ExceptionOccurred()) { + jniEnv->ExceptionClear(); + SAL_WARN( + "bridges", "exception in CallObjectMethod"); + } } } + jniEnv->DeleteGlobalRef(async); + } catch ( + jvmaccess::VirtualMachine::AttachGuard::CreationException &) + { + SAL_WARN( + "bridges", + ("ignoring jvmaccess::VirtualMachine::AttachGuard" + "::CreationException")); } - jniEnv->DeleteGlobalRef(async); - } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) { - SAL_WARN( - "bridges", - "jvmaccess::VirtualMachine::AttachGuard::CreationException"); } } } @@ -469,50 +482,60 @@ void SAL_CALL java_env_disposing(uno_Environment * env) { SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_initEnvironment( uno_Environment * java_env ) SAL_THROW_EXTERN_C() { - // JavaComponentLoader::getJavaLoader (in - // stoc/source/javaloader/javaloader.cxx) stores a - // jvmaccess::UnoVirtualMachine pointer into java_env->pContext; replace it - // here with a pointer to a full JniUnoEnvironmentData: - auto * envData = new jni_uno::JniUnoEnvironmentData( - static_cast(java_env->pContext)); - java_env->pContext = envData; - java_env->dispose = java_env_dispose; - java_env->environmentDisposing = java_env_disposing; - java_env->pExtEnv = 0; // no extended support try { - jvmaccess::VirtualMachine::AttachGuard g( - envData->machine->getVirtualMachine()); - JNIEnv * jniEnv = g.getEnvironment(); - jclass cl = jniEnv->FindClass( - "com/sun/star/lib/util/AsynchronousFinalizer"); - if (cl == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in FindClass"); - //TODO: report failure - } else { - jmethodID id = jniEnv->GetMethodID(cl, "", "()V"); - if (id == nullptr) { + // JavaComponentLoader::getJavaLoader (in + // stoc/source/javaloader/javaloader.cxx) stores a + // jvmaccess::UnoVirtualMachine pointer into java_env->pContext; replace + // it here with either a pointer to a full JniUnoEnvironmentData upon + // success, or with a null pointer upon failure (as this function cannot + // directly report back failure, so it uses that way to indirectly + // report failure later from within the Bridge ctor): + rtl::Reference vm( + static_cast(java_env->pContext)); + java_env->pContext = nullptr; + java_env->dispose = java_env_dispose; + java_env->environmentDisposing = java_env_disposing; + java_env->pExtEnv = 0; // no extended support + std::unique_ptr envData( + new jni_uno::JniUnoEnvironmentData(vm)); + { + jvmaccess::VirtualMachine::AttachGuard g( + envData->machine->getVirtualMachine()); + JNIEnv * jniEnv = g.getEnvironment(); + jclass cl = jniEnv->FindClass( + "com/sun/star/lib/util/AsynchronousFinalizer"); + if (cl == nullptr) { jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in GetMethodID"); + SAL_WARN("bridges", "exception in FindClass"); //TODO: report failure } else { - jobject o = jniEnv->NewObject(cl, id); - if (o == nullptr) { + jmethodID id = jniEnv->GetMethodID(cl, "", "()V"); + if (id == nullptr) { jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in NewObject"); + SAL_WARN("bridges", "exception in GetMethodID"); //TODO: report failure } else { - o = jniEnv->NewGlobalRef(o); + jobject o = jniEnv->NewObject(cl, id); if (o == nullptr) { jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in NewGlobalRef"); + SAL_WARN("bridges", "exception in NewObject"); //TODO: report failure } else { - envData->asynchronousFinalizer = o; + o = jniEnv->NewGlobalRef(o); + if (o == nullptr) { + jniEnv->ExceptionClear(); + SAL_WARN("bridges", "exception in NewGlobalRef"); + //TODO: report failure + } else { + envData->asynchronousFinalizer = o; + } } } } } + java_env->pContext = envData.release(); + } catch (const BridgeRuntimeError & e) { + SAL_WARN("bridges", "BridgeRuntimeError \"" << e.m_message << "\""); } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) { SAL_WARN( "bridges", @@ -581,13 +604,7 @@ SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_ext_getMapping( } catch (const BridgeRuntimeError & err) { - SAL_WARN( - "bridges", - "ingoring BridgeRuntimeError \"" << err.m_message << "\""); - } - catch (const ::jvmaccess::VirtualMachine::AttachGuard::CreationException &) - { - SAL_WARN("bridges", "attaching current thread to java failed"); + SAL_WARN("bridges", "BridgeRuntimeError \"" << err.m_message << "\""); } *ppMapping = mapping; diff --git a/bridges/source/jni_uno/jni_bridge.h b/bridges/source/jni_uno/jni_bridge.h index e1a2aadecbb6..8a216e01c46d 100644 --- a/bridges/source/jni_uno/jni_bridge.h +++ b/bridges/source/jni_uno/jni_bridge.h @@ -21,7 +21,6 @@ #define INCLUDED_BRIDGES_SOURCE_JNI_UNO_JNI_BRIDGE_H #include "jni_base.h" -#include "jni_info.h" #include "jni_helper.h" #include "osl/diagnose.h" @@ -36,13 +35,15 @@ namespace jni_uno { -//==== holds environments and mappings ========================================= +class JNI_info; struct Bridge; + struct Mapping : public uno_Mapping { Bridge * m_bridge; }; +// Holds environments and mappings: struct Bridge { mutable oslInterlockedCount m_ref; @@ -54,8 +55,6 @@ struct Bridge Mapping m_uno2java; bool m_registered_java2uno; - JNI_info const * m_jni_info; - ~Bridge(); explicit Bridge( uno_Environment * java_env, uno_ExtEnvironment * uno_env, @@ -107,6 +106,8 @@ struct Bridge uno_Interface * map_to_uno( JNI_context const & jni, jobject javaI, JNI_interface_type_info const * info ) const; + + JNI_info const * getJniInfo() const; }; } diff --git a/bridges/source/jni_uno/jni_data.cxx b/bridges/source/jni_uno/jni_data.cxx index 745a655ae231..5e3730248453 100644 --- a/bridges/source/jni_uno/jni_data.cxx +++ b/bridges/source/jni_uno/jni_data.cxx @@ -231,7 +231,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jchar *) uno_data = jni->CallCharMethodA( - java_data.l, m_jni_info->m_method_Character_charValue, 0 ); + java_data.l, getJniInfo()->m_method_Character_charValue, 0 ); jni.ensure_no_exception(); } else @@ -249,7 +249,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jboolean *) uno_data = jni->CallBooleanMethodA( - java_data.l, m_jni_info->m_method_Boolean_booleanValue, 0 ); + java_data.l, getJniInfo()->m_method_Boolean_booleanValue, 0 ); jni.ensure_no_exception(); } else @@ -267,7 +267,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jbyte *) uno_data = jni->CallByteMethodA( - java_data.l, m_jni_info->m_method_Byte_byteValue, 0 ); + java_data.l, getJniInfo()->m_method_Byte_byteValue, 0 ); jni.ensure_no_exception(); } else @@ -286,7 +286,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jshort *) uno_data = jni->CallShortMethodA( - java_data.l, m_jni_info->m_method_Short_shortValue, 0 ); + java_data.l, getJniInfo()->m_method_Short_shortValue, 0 ); jni.ensure_no_exception(); } else @@ -305,7 +305,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jint *) uno_data = jni->CallIntMethodA( - java_data.l, m_jni_info->m_method_Integer_intValue, 0 ); + java_data.l, getJniInfo()->m_method_Integer_intValue, 0 ); jni.ensure_no_exception(); } else @@ -324,7 +324,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jlong *) uno_data = jni->CallLongMethodA( - java_data.l, m_jni_info->m_method_Long_longValue, 0 ); + java_data.l, getJniInfo()->m_method_Long_longValue, 0 ); jni.ensure_no_exception(); } else @@ -342,7 +342,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jfloat *) uno_data = jni->CallFloatMethodA( - java_data.l, m_jni_info->m_method_Float_floatValue, 0 ); + java_data.l, getJniInfo()->m_method_Float_floatValue, 0 ); jni.ensure_no_exception(); } else @@ -360,7 +360,7 @@ void Bridge::map_to_uno( else if (special_wrapped_integral_types) { *(jdouble *) uno_data = jni->CallDoubleMethodA( - java_data.l, m_jni_info->m_method_Double_doubleValue, 0 ); + java_data.l, getJniInfo()->m_method_Double_doubleValue, 0 ); jni.ensure_no_exception(); } else @@ -410,7 +410,7 @@ void Bridge::map_to_uno( // type name JLocalAutoRef jo_type_name( jni, jni->GetObjectField( - java_data.l, m_jni_info->m_field_Type__typeName ) ); + java_data.l, getJniInfo()->m_field_Type__typeName ) ); if (! jo_type_name.is()) { throw BridgeRuntimeError( @@ -454,7 +454,7 @@ void Bridge::map_to_uno( if (assign) uno_any_destruct( pAny, 0 ); uno_any_construct( - pAny, 0, m_jni_info->m_XInterface_type_info->m_td.get(), 0 ); + pAny, 0, getJniInfo()->m_XInterface_type_info->m_td.get(), 0 ); break; } @@ -462,11 +462,11 @@ void Bridge::map_to_uno( JLocalAutoRef jo_wrapped_holder( jni ); if (JNI_FALSE != jni->IsInstanceOf( - java_data.l, m_jni_info->m_class_Any )) + java_data.l, getJniInfo()->m_class_Any )) { // boxed any jo_type.reset( jni->GetObjectField( - java_data.l, m_jni_info->m_field_Any__type ) ); + java_data.l, getJniInfo()->m_field_Any__type ) ); if (! jo_type.is()) { throw BridgeRuntimeError( @@ -477,7 +477,7 @@ void Bridge::map_to_uno( // wrapped value jo_wrapped_holder.reset( jni->GetObjectField( - java_data.l, m_jni_info->m_field_Any__object ) ); + java_data.l, getJniInfo()->m_field_Any__object ) ); java_data.l = jo_wrapped_holder.get(); } else @@ -490,7 +490,7 @@ void Bridge::map_to_uno( // get type name JLocalAutoRef jo_type_name( jni, jni->GetObjectField( - jo_type.get(), m_jni_info->m_field_Type__typeName ) ); + jo_type.get(), getJniInfo()->m_field_Type__typeName ) ); jni.ensure_no_exception(); OUString type_name( jstring_to_oustring( jni, (jstring) jo_type_name.get() ) ); @@ -519,33 +519,33 @@ void Bridge::map_to_uno( case typelib_TypeClass_CHAR: pAny->pData = &pAny->pReserved; *(jchar *) pAny->pData = jni->CallCharMethodA( - java_data.l, m_jni_info->m_method_Character_charValue, 0 ); + java_data.l, getJniInfo()->m_method_Character_charValue, 0 ); jni.ensure_no_exception(); break; case typelib_TypeClass_BOOLEAN: pAny->pData = &pAny->pReserved; *(jboolean *) pAny->pData = jni->CallBooleanMethodA( - java_data.l, m_jni_info->m_method_Boolean_booleanValue, 0 ); + java_data.l, getJniInfo()->m_method_Boolean_booleanValue, 0 ); jni.ensure_no_exception(); break; case typelib_TypeClass_BYTE: pAny->pData = &pAny->pReserved; *(jbyte *) pAny->pData = jni->CallByteMethodA( - java_data.l, m_jni_info->m_method_Byte_byteValue, 0 ); + java_data.l, getJniInfo()->m_method_Byte_byteValue, 0 ); jni.ensure_no_exception(); break; case typelib_TypeClass_SHORT: case typelib_TypeClass_UNSIGNED_SHORT: pAny->pData = &pAny->pReserved; *(jshort *) pAny->pData = jni->CallShortMethodA( - java_data.l, m_jni_info->m_method_Short_shortValue, 0 ); + java_data.l, getJniInfo()->m_method_Short_shortValue, 0 ); jni.ensure_no_exception(); break; case typelib_TypeClass_LONG: case typelib_TypeClass_UNSIGNED_LONG: pAny->pData = &pAny->pReserved; *(jint *) pAny->pData = jni->CallIntMethodA( - java_data.l, m_jni_info->m_method_Integer_intValue, 0 ); + java_data.l, getJniInfo()->m_method_Integer_intValue, 0 ); jni.ensure_no_exception(); break; case typelib_TypeClass_HYPER: @@ -554,7 +554,7 @@ void Bridge::map_to_uno( { pAny->pData = &pAny->pReserved; *(jlong *) pAny->pData = jni->CallLongMethodA( - java_data.l, m_jni_info->m_method_Long_longValue, 0 ); + java_data.l, getJniInfo()->m_method_Long_longValue, 0 ); jni.ensure_no_exception(); } else @@ -562,7 +562,7 @@ void Bridge::map_to_uno( std::unique_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (sal_Int64) ) ); *(jlong *) mem.get() = jni->CallLongMethodA( - java_data.l, m_jni_info->m_method_Long_longValue, 0 ); + java_data.l, getJniInfo()->m_method_Long_longValue, 0 ); jni.ensure_no_exception(); pAny->pData = mem.release(); } @@ -572,7 +572,7 @@ void Bridge::map_to_uno( { pAny->pData = &pAny->pReserved; *(jfloat *) pAny->pData = jni->CallFloatMethodA( - java_data.l, m_jni_info->m_method_Float_floatValue, 0 ); + java_data.l, getJniInfo()->m_method_Float_floatValue, 0 ); jni.ensure_no_exception(); } else @@ -580,7 +580,7 @@ void Bridge::map_to_uno( std::unique_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (float) ) ); *(jfloat *) mem.get() = jni->CallFloatMethodA( - java_data.l, m_jni_info->m_method_Float_floatValue, 0 ); + java_data.l, getJniInfo()->m_method_Float_floatValue, 0 ); jni.ensure_no_exception(); pAny->pData = mem.release(); } @@ -592,7 +592,7 @@ void Bridge::map_to_uno( *(jdouble *) pAny->pData = jni->CallDoubleMethodA( java_data.l, - m_jni_info->m_method_Double_doubleValue, 0 ); + getJniInfo()->m_method_Double_doubleValue, 0 ); jni.ensure_no_exception(); } else @@ -602,7 +602,7 @@ void Bridge::map_to_uno( *(jdouble *) mem.get() = jni->CallDoubleMethodA( java_data.l, - m_jni_info->m_method_Double_doubleValue, 0 ); + getJniInfo()->m_method_Double_doubleValue, 0 ); jni.ensure_no_exception(); pAny->pData = mem.release(); } @@ -676,7 +676,7 @@ void Bridge::map_to_uno( } *(jint *) uno_data = jni->GetIntField( - java_data.l, m_jni_info->m_field_Enum_m_value ); + java_data.l, getJniInfo()->m_field_Enum_m_value ); break; } case typelib_TypeClass_STRUCT: @@ -698,7 +698,7 @@ void Bridge::map_to_uno( } if (0 == info) - info = m_jni_info->get_type_info( jni, type ); + info = getJniInfo()->get_type_info( jni, type ); JNI_compound_type_info const * comp_info = static_cast< JNI_compound_type_info const * >( info ); @@ -890,17 +890,17 @@ void Bridge::map_to_uno( assert( type_equals( type, - m_jni_info->m_Exception_type.getTypeLibType() ) + getJniInfo()->m_Exception_type.getTypeLibType() ) || type_equals( type, - m_jni_info->m_RuntimeException_type. + getJniInfo()->m_RuntimeException_type. getTypeLibType() ) ); assert( 0 == nPos ); // first member // call getMessage() jo_field.reset( jni->CallObjectMethodA( java_data.l, - m_jni_info->m_method_Throwable_getMessage, 0 ) + getJniInfo()->m_method_Throwable_getMessage, 0 ) ); jni.ensure_no_exception(); checkNull = true; @@ -1052,7 +1052,7 @@ void Bridge::map_to_uno( typelib_TypeClass_INTERFACE == element_type->eTypeClass) { element_info = - m_jni_info->get_type_info( jni, element_td.get() ); + getJniInfo()->get_type_info( jni, element_td.get() ); } else { @@ -1131,7 +1131,7 @@ void Bridge::map_to_uno( else { if (0 == info) - info = m_jni_info->get_type_info( jni, type ); + info = getJniInfo()->get_type_info( jni, type ); JNI_interface_type_info const * iface_info = static_cast< JNI_interface_type_info const * >( info ); uno_Interface * pUnoI = map_to_uno( jni, java_data.l, iface_info ); @@ -1196,8 +1196,8 @@ void Bridge::map_to_java( jvalue arg; arg.c = *(jchar const *) uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Character, - m_jni_info->m_ctor_Character_with_char, &arg ); + getJniInfo()->m_class_Character, + getJniInfo()->m_ctor_Character_with_char, &arg ); jni.ensure_no_exception(); } else @@ -1237,8 +1237,8 @@ void Bridge::map_to_java( jvalue arg; arg.z = *(jboolean const *) uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Boolean, - m_jni_info->m_ctor_Boolean_with_boolean, &arg ); + getJniInfo()->m_class_Boolean, + getJniInfo()->m_ctor_Boolean_with_boolean, &arg ); jni.ensure_no_exception(); } else @@ -1276,8 +1276,8 @@ void Bridge::map_to_java( jvalue arg; arg.b = *(jbyte const *) uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Byte, - m_jni_info->m_ctor_Byte_with_byte, &arg ); + getJniInfo()->m_class_Byte, + getJniInfo()->m_ctor_Byte_with_byte, &arg ); jni.ensure_no_exception(); } else @@ -1316,8 +1316,8 @@ void Bridge::map_to_java( jvalue arg; arg.s = *(jshort const *) uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Short, - m_jni_info->m_ctor_Short_with_short, &arg ); + getJniInfo()->m_class_Short, + getJniInfo()->m_ctor_Short_with_short, &arg ); jni.ensure_no_exception(); } else @@ -1356,8 +1356,8 @@ void Bridge::map_to_java( jvalue arg; arg.i = *(jint const *) uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Integer, - m_jni_info->m_ctor_Integer_with_int, &arg ); + getJniInfo()->m_class_Integer, + getJniInfo()->m_ctor_Integer_with_int, &arg ); jni.ensure_no_exception(); } else @@ -1396,8 +1396,8 @@ void Bridge::map_to_java( jvalue arg; arg.j = *(jlong const *) uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Long, - m_jni_info->m_ctor_Long_with_long, &arg ); + getJniInfo()->m_class_Long, + getJniInfo()->m_ctor_Long_with_long, &arg ); jni.ensure_no_exception(); } else @@ -1435,8 +1435,8 @@ void Bridge::map_to_java( jvalue arg; arg.f = *(jfloat const *) uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Float, - m_jni_info->m_ctor_Float_with_float, &arg ); + getJniInfo()->m_class_Float, + getJniInfo()->m_ctor_Float_with_float, &arg ); jni.ensure_no_exception(); } else @@ -1476,8 +1476,8 @@ void Bridge::map_to_java( jvalue arg; arg.d = *(double const *)uno_data; java_data->l = jni->NewObjectA( - m_jni_info->m_class_Double, - m_jni_info->m_ctor_Double_with_double, &arg ); + getJniInfo()->m_class_Double, + getJniInfo()->m_ctor_Double_with_double, &arg ); jni.ensure_no_exception(); } else @@ -1499,7 +1499,7 @@ void Bridge::map_to_java( if (0 == java_data->l) { java_data->l = jni->NewObjectArray( - 1, m_jni_info->m_class_String, jo_in.get() ); + 1, getJniInfo()->m_class_String, jo_in.get() ); jni.ensure_no_exception(); } else @@ -1533,7 +1533,7 @@ void Bridge::map_to_java( if (0 == java_data->l) { java_data->l = jni->NewObjectArray( - 1, m_jni_info->m_class_Type, jo_in.get() ); + 1, getJniInfo()->m_class_Type, jo_in.get() ); jni.ensure_no_exception(); } else @@ -1563,7 +1563,7 @@ void Bridge::map_to_java( { case typelib_TypeClass_VOID: jo_any.reset( - jni->NewLocalRef( m_jni_info->m_object_Any_VOID ) ); + jni->NewLocalRef( getJniInfo()->m_object_Any_VOID ) ); break; case typelib_TypeClass_UNSIGNED_SHORT: { @@ -1571,16 +1571,16 @@ void Bridge::map_to_java( args[ 0 ].s = *(jshort const *) pAny->pData; JLocalAutoRef jo_val( jni, jni->NewObjectA( - m_jni_info->m_class_Short, - m_jni_info->m_ctor_Short_with_short, args ) ); + getJniInfo()->m_class_Short, + getJniInfo()->m_ctor_Short_with_short, args ) ); jni.ensure_no_exception(); // box up in com.sun.star.uno.Any - args[ 0 ].l = m_jni_info->m_object_Type_UNSIGNED_SHORT; + args[ 0 ].l = getJniInfo()->m_object_Type_UNSIGNED_SHORT; args[ 1 ].l = jo_val.get(); jo_any.reset( jni->NewObjectA( - m_jni_info->m_class_Any, - m_jni_info->m_ctor_Any_with_Type_Object, args ) ); + getJniInfo()->m_class_Any, + getJniInfo()->m_ctor_Any_with_Type_Object, args ) ); jni.ensure_no_exception(); break; } @@ -1590,16 +1590,16 @@ void Bridge::map_to_java( args[ 0 ].i = *(jint const *) pAny->pData; JLocalAutoRef jo_val( jni, jni->NewObjectA( - m_jni_info->m_class_Integer, - m_jni_info->m_ctor_Integer_with_int, args ) ); + getJniInfo()->m_class_Integer, + getJniInfo()->m_ctor_Integer_with_int, args ) ); jni.ensure_no_exception(); // box up in com.sun.star.uno.Any - args[ 0 ].l = m_jni_info->m_object_Type_UNSIGNED_LONG; + args[ 0 ].l = getJniInfo()->m_object_Type_UNSIGNED_LONG; args[ 1 ].l = jo_val.get(); jo_any.reset( jni->NewObjectA( - m_jni_info->m_class_Any, - m_jni_info->m_ctor_Any_with_Type_Object, args ) ); + getJniInfo()->m_class_Any, + getJniInfo()->m_ctor_Any_with_Type_Object, args ) ); jni.ensure_no_exception(); break; } @@ -1609,16 +1609,16 @@ void Bridge::map_to_java( args[ 0 ].j = *(jlong const *) pAny->pData; JLocalAutoRef jo_val( jni, jni->NewObjectA( - m_jni_info->m_class_Long, - m_jni_info->m_ctor_Long_with_long, args ) ); + getJniInfo()->m_class_Long, + getJniInfo()->m_ctor_Long_with_long, args ) ); jni.ensure_no_exception(); // box up in com.sun.star.uno.Any - args[ 0 ].l = m_jni_info->m_object_Type_UNSIGNED_HYPER; + args[ 0 ].l = getJniInfo()->m_object_Type_UNSIGNED_HYPER; args[ 1 ].l = jo_val.get(); jo_any.reset( jni->NewObjectA( - m_jni_info->m_class_Any, - m_jni_info->m_ctor_Any_with_Type_Object, args ) ); + getJniInfo()->m_class_Any, + getJniInfo()->m_ctor_Any_with_Type_Object, args ) ); jni.ensure_no_exception(); break; } @@ -1664,8 +1664,8 @@ void Bridge::map_to_java( args[ 1 ].l = jo_any.get(); jo_any.reset( jni->NewObjectA( - m_jni_info->m_class_Any, - m_jni_info->m_ctor_Any_with_Type_Object, args ) ); + getJniInfo()->m_class_Any, + getJniInfo()->m_ctor_Any_with_Type_Object, args ) ); jni.ensure_no_exception(); break; } @@ -1684,7 +1684,7 @@ void Bridge::map_to_java( jo_any.reset( map_to_java( jni, pUnoI, - m_jni_info->m_XInterface_type_info ) ); + getJniInfo()->m_XInterface_type_info ) ); } // else: empty XInterface ref maps to null-ref } @@ -1692,7 +1692,7 @@ void Bridge::map_to_java( { JNI_interface_type_info const * iface_info = static_cast< JNI_interface_type_info const * >( - m_jni_info->get_type_info( jni, pAny->pType ) ); + getJniInfo()->get_type_info( jni, pAny->pType ) ); if (0 != pUnoI) { jo_any.reset( map_to_java( jni, pUnoI, iface_info ) ); @@ -1703,8 +1703,8 @@ void Bridge::map_to_java( args[ 1 ].l = jo_any.get(); jo_any.reset( jni->NewObjectA( - m_jni_info->m_class_Any, - m_jni_info->m_ctor_Any_with_Type_Object, args ) ); + getJniInfo()->m_class_Any, + getJniInfo()->m_ctor_Any_with_Type_Object, args ) ); jni.ensure_no_exception(); } break; @@ -1730,8 +1730,8 @@ void Bridge::map_to_java( args[1].l = jo_any.get(); jo_any.reset( jni->NewObjectA( - m_jni_info->m_class_Any, - m_jni_info->m_ctor_Any_with_Type_Object, args)); + getJniInfo()->m_class_Any, + getJniInfo()->m_ctor_Any_with_Type_Object, args)); jni.ensure_no_exception(); break; } @@ -1755,7 +1755,7 @@ void Bridge::map_to_java( if (0 == java_data->l) { java_data->l = jni->NewObjectArray( - 1, m_jni_info->m_class_Object, jo_any.get() ); + 1, getJniInfo()->m_class_Object, jo_any.get() ); jni.ensure_no_exception(); } else @@ -1825,7 +1825,7 @@ void Bridge::map_to_java( case typelib_TypeClass_EXCEPTION: { if (0 == info) - info = m_jni_info->get_type_info( jni, type ); + info = getJniInfo()->get_type_info( jni, type ); JNI_compound_type_info const * comp_info = static_cast< JNI_compound_type_info const * >( info ); @@ -1885,8 +1885,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Character, - m_jni_info->m_ctor_Character_with_char, + getJniInfo()->m_class_Character, + getJniInfo()->m_ctor_Character_with_char, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -1904,8 +1904,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Boolean, - m_jni_info->m_ctor_Boolean_with_boolean, + getJniInfo()->m_class_Boolean, + getJniInfo()->m_ctor_Boolean_with_boolean, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -1923,8 +1923,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Byte, - m_jni_info->m_ctor_Byte_with_byte, + getJniInfo()->m_class_Byte, + getJniInfo()->m_ctor_Byte_with_byte, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -1943,8 +1943,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Short, - m_jni_info->m_ctor_Short_with_short, + getJniInfo()->m_class_Short, + getJniInfo()->m_ctor_Short_with_short, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -1963,8 +1963,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Integer, - m_jni_info->m_ctor_Integer_with_int, + getJniInfo()->m_class_Integer, + getJniInfo()->m_ctor_Integer_with_int, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -1983,8 +1983,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Long, - m_jni_info->m_ctor_Long_with_long, + getJniInfo()->m_class_Long, + getJniInfo()->m_ctor_Long_with_long, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -2002,8 +2002,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Float, - m_jni_info->m_ctor_Float_with_float, + getJniInfo()->m_class_Float, + getJniInfo()->m_ctor_Float_with_float, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -2021,8 +2021,8 @@ void Bridge::map_to_java( JLocalAutoRef jo( jni, jni->NewObjectA( - m_jni_info->m_class_Double, - m_jni_info->m_ctor_Double_with_double, + getJniInfo()->m_class_Double, + getJniInfo()->m_ctor_Double_with_double, &arg ) ); jni.ensure_no_exception(); jni->SetObjectField( @@ -2196,7 +2196,7 @@ void Bridge::map_to_java( case typelib_TypeClass_STRING: jo_ar.reset( jni->NewObjectArray( - nElements, m_jni_info->m_class_String, 0 ) ); + nElements, getJniInfo()->m_class_String, 0 ) ); jni.ensure_no_exception(); if (in_param) { @@ -2214,7 +2214,7 @@ void Bridge::map_to_java( break; case typelib_TypeClass_TYPE: jo_ar.reset( - jni->NewObjectArray( nElements, m_jni_info->m_class_Type, 0 ) ); + jni->NewObjectArray( nElements, getJniInfo()->m_class_Type, 0 ) ); jni.ensure_no_exception(); if (in_param) { @@ -2236,7 +2236,7 @@ void Bridge::map_to_java( case typelib_TypeClass_ANY: jo_ar.reset( jni->NewObjectArray( - nElements, m_jni_info->m_class_Object, 0 ) ); + nElements, getJniInfo()->m_class_Object, 0 ) ); jni.ensure_no_exception(); if (in_param) { @@ -2302,7 +2302,7 @@ void Bridge::map_to_java( case typelib_TypeClass_EXCEPTION: { JNI_type_info const * element_info = - m_jni_info->get_type_info( jni, element_type ); + getJniInfo()->get_type_info( jni, element_type ); jo_ar.reset( jni->NewObjectArray( nElements, element_info->m_class, 0 ) ); @@ -2364,7 +2364,7 @@ void Bridge::map_to_java( { JNI_interface_type_info const * iface_info = static_cast< JNI_interface_type_info const * >( - m_jni_info->get_type_info( jni, element_type ) ); + getJniInfo()->get_type_info( jni, element_type ) ); jo_ar.reset( jni->NewObjectArray( nElements, iface_info->m_class, 0 ) ); @@ -2439,7 +2439,7 @@ void Bridge::map_to_java( if (0 != pUnoI) { if (0 == info) - info = m_jni_info->get_type_info( jni, type ); + info = getJniInfo()->get_type_info( jni, type ); JNI_interface_type_info const * iface_info = static_cast< JNI_interface_type_info const * >( info ); jo_iface.reset( map_to_java( jni, pUnoI, iface_info ) ); @@ -2450,7 +2450,7 @@ void Bridge::map_to_java( if (0 == java_data->l) { if (0 == info) - info = m_jni_info->get_type_info( jni, type ); + info = getJniInfo()->get_type_info( jni, type ); java_data->l = jni->NewObjectArray( 1, info->m_class, jo_iface.get() ); jni.ensure_no_exception(); diff --git a/bridges/source/jni_uno/jni_java2uno.cxx b/bridges/source/jni_uno/jni_java2uno.cxx index 4c19043b19d4..8d432cd98d22 100644 --- a/bridges/source/jni_uno/jni_java2uno.cxx +++ b/bridges/source/jni_uno/jni_java2uno.cxx @@ -47,8 +47,8 @@ jobject Bridge::map_to_java( args[ 0 ].l = jo_oid.get(); args[ 1 ].l = info->m_type; jobject jo_iface = jni->CallObjectMethodA( - m_jni_info->m_object_java_env, - m_jni_info->m_method_IEnvironment_getRegisteredInterface, args ); + getJniInfo()->m_object_java_env, + getJniInfo()->m_method_IEnvironment_getRegisteredInterface, args ); jni.ensure_no_exception(); if (0 == jo_iface) // no registered iface @@ -63,7 +63,7 @@ jobject Bridge::map_to_java( acquire(); args2[ 0 ].j = reinterpret_cast< sal_Int64 >( this ); (*pUnoI->acquire)( pUnoI ); - args2[ 1 ].l = m_jni_info->m_object_java_env; + args2[ 1 ].l = getJniInfo()->m_object_java_env; args2[ 2 ].j = reinterpret_cast< sal_Int64 >( pUnoI ); typelib_typedescription_acquire( info->m_td.get() ); args2[ 3 ].j = reinterpret_cast< sal_Int64 >( info->m_td.get() ); @@ -77,8 +77,8 @@ jobject Bridge::map_to_java( args2[ 7 ].l = envData->asynchronousFinalizer; } jo_iface = jni->CallStaticObjectMethodA( - m_jni_info->m_class_JNI_proxy, - m_jni_info->m_method_JNI_proxy_create, args2 ); + getJniInfo()->m_class_JNI_proxy, + getJniInfo()->m_method_JNI_proxy_create, args2 ); jni.ensure_no_exception(); } @@ -125,7 +125,7 @@ void Bridge::handle_uno_exc( JNI_context const & jni, uno_Any * uno_exc ) const // call toString() JLocalAutoRef jo_descr( jni, jni->CallObjectMethodA( - jo_exc.get(), m_jni_info->m_method_Object_toString, 0 ) ); + jo_exc.get(), getJniInfo()->m_method_Object_toString, 0 ) ); jni.ensure_no_exception(); throw BridgeRuntimeError( "throwing java exception failed: " @@ -376,7 +376,7 @@ JNICALL Java_com_sun_star_bridges_jni_1uno_JNI_1proxy_dispatch_1call( jobjectArray jo_args /* may be 0 */ ) { Bridge const * bridge = reinterpret_cast< Bridge const * >( bridge_handle ); - JNI_info const * jni_info = bridge->m_jni_info; + JNI_info const * jni_info = bridge->getJniInfo(); JNI_context jni( jni_info, jni_env, static_cast< jobject >( @@ -623,7 +623,7 @@ JNICALL Java_com_sun_star_bridges_jni_1uno_JNI_1proxy_finalize__J( JNIEnv * jni_env, jobject jo_proxy, jlong bridge_handle ) { Bridge const * bridge = reinterpret_cast< Bridge const * >( bridge_handle ); - JNI_info const * jni_info = bridge->m_jni_info; + JNI_info const * jni_info = bridge->getJniInfo(); JNI_context jni( jni_info, jni_env, static_cast< jobject >( diff --git a/bridges/source/jni_uno/jni_uno2java.cxx b/bridges/source/jni_uno/jni_uno2java.cxx index 578c3d0cece0..1885c888751d 100644 --- a/bridges/source/jni_uno/jni_uno2java.cxx +++ b/bridges/source/jni_uno/jni_uno2java.cxx @@ -75,7 +75,7 @@ void Bridge::handle_java_exc( JLocalAutoRef jo_class( jni, jni->GetObjectClass( jo_exc.get() ) ); JLocalAutoRef jo_class_name( jni, jni->CallObjectMethodA( - jo_class.get(), m_jni_info->m_method_Class_getName, 0 ) ); + jo_class.get(), getJniInfo()->m_method_Class_getName, 0 ) ); jni.ensure_no_exception(); OUString exc_name( jstring_to_oustring( jni, (jstring) jo_class_name.get() ) ); @@ -86,7 +86,7 @@ void Bridge::handle_java_exc( // call toString() JLocalAutoRef jo_descr( jni, jni->CallObjectMethodA( - jo_exc.get(), m_jni_info->m_method_Object_toString, 0 ) ); + jo_exc.get(), getJniInfo()->m_method_Object_toString, 0 ) ); jni.ensure_no_exception(); throw BridgeRuntimeError( "non-UNO exception occurred: " @@ -129,7 +129,7 @@ void Bridge::call_java( assert( function_pos_offset == 0 || function_pos_offset == 1 ); JNI_guarded_context jni( - m_jni_info, + getJniInfo(), static_cast(m_java_env->pContext)->machine); // assure fully initialized iface_td: @@ -208,7 +208,7 @@ void Bridge::call_java( JNI_interface_type_info const * info = static_cast< JNI_interface_type_info const * >( - m_jni_info->get_type_info( jni, &iface_td->aBase ) ); + getJniInfo()->get_type_info( jni, &iface_td->aBase ) ); jmethodID method_id = info->m_methods[ function_pos ]; #if OSL_DEBUG_LEVEL > 0 @@ -219,20 +219,20 @@ void Bridge::call_java( jni.ensure_no_exception(); JLocalAutoRef jo_descr( jni, jni->CallObjectMethodA( - jo_method.get(), m_jni_info->m_method_Object_toString, 0 ) ); + jo_method.get(), getJniInfo()->m_method_Object_toString, 0 ) ); jni.ensure_no_exception(); trace_buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); trace_buf.append( " on " ); jo_descr.reset( jni->CallObjectMethodA( - javaI, m_jni_info->m_method_Object_toString, 0 ) ); + javaI, getJniInfo()->m_method_Object_toString, 0 ) ); jni.ensure_no_exception(); trace_buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); trace_buf.append( " (" ); JLocalAutoRef jo_class( jni, jni->GetObjectClass( javaI ) ); jo_descr.reset( jni->CallObjectMethodA( - jo_class.get(), m_jni_info->m_method_Object_toString, 0 ) ); + jo_class.get(), getJniInfo()->m_method_Object_toString, 0 ) ); jni.ensure_no_exception(); trace_buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); trace_buf.append( ")" ); @@ -427,7 +427,7 @@ inline UNO_proxy::UNO_proxy( m_oid( oid ), m_type_info( info ) { - JNI_info const * jni_info = bridge->m_jni_info; + JNI_info const * jni_info = bridge->getJniInfo(); JLocalAutoRef jo_string_array( jni, jni->NewObjectArray( 1, jni_info->m_class_String, jo_oid ) ); jni.ensure_no_exception(); @@ -529,7 +529,7 @@ void SAL_CALL UNO_proxy_free( uno_ExtEnvironment * env, void * proxy ) try { JNI_guarded_context jni( - bridge->m_jni_info, + bridge->getJniInfo(), (static_cast(bridge->m_java_env->pContext) ->machine)); @@ -617,7 +617,7 @@ void SAL_CALL UNO_proxy_dispatch( bridge->call_java( that->m_javaI, iface_td, attrib_td->nIndex, 1, // get, then set method - bridge->m_jni_info->m_void_type.getTypeLibType(), + bridge->getJniInfo()->m_void_type.getTypeLibType(), ¶m, 1, 0, uno_args, uno_exc ); } @@ -672,7 +672,7 @@ void SAL_CALL UNO_proxy_dispatch( if (0 == pInterface) { - JNI_info const * jni_info = bridge->m_jni_info; + JNI_info const * jni_info = bridge->getJniInfo(); JNI_guarded_context jni( jni_info, (static_cast( diff --git a/bridges/source/jni_uno/jniunoenvironmentdata.hxx b/bridges/source/jni_uno/jniunoenvironmentdata.hxx index 843d29e9abc5..4ca91adae994 100644 --- a/bridges/source/jni_uno/jniunoenvironmentdata.hxx +++ b/bridges/source/jni_uno/jniunoenvironmentdata.hxx @@ -29,16 +29,21 @@ #include #include +#include + namespace jni_uno { // The pContext payload of a JNI uno_Environment: struct JniUnoEnvironmentData: boost::noncopyable { explicit JniUnoEnvironmentData( rtl::Reference const & theMachine): - machine(theMachine), asynchronousFinalizer(nullptr) + machine(theMachine), info(JNI_info::get_jni_info(theMachine)), + asynchronousFinalizer(nullptr) {} - rtl::Reference machine; + rtl::Reference const machine; + JNI_info const * const info; + osl::Mutex mutex; jobject asynchronousFinalizer; }; -- cgit