diff options
-rw-r--r-- | jvmaccess/inc/jvmaccess/virtualmachine.hxx | 23 | ||||
-rw-r--r-- | jvmaccess/source/virtualmachine.cxx | 59 |
2 files changed, 11 insertions, 71 deletions
diff --git a/jvmaccess/inc/jvmaccess/virtualmachine.hxx b/jvmaccess/inc/jvmaccess/virtualmachine.hxx index 978d0c9c4420..d5300fa2b67e 100644 --- a/jvmaccess/inc/jvmaccess/virtualmachine.hxx +++ b/jvmaccess/inc/jvmaccess/virtualmachine.hxx @@ -130,14 +130,16 @@ public: thread that has called JNI_CreateJavaVM in case the virtual machine has been started via the JNI Invocation API, and it must not already have called DetachCurrentThread; or it must be executing native code called - from a "primordial" virtual machine). This environment pointer is used - to obtain a reference to the thread's current context class loader - (java.lang.Thread.getCurrentClassLoader). If later a native thread is - attached to the virtual machine, that thread's context class loader - would be null, so the AttachGuard first of all sets it to the saved - value. In a nutshell, this means that all native threads attached to - the virtual machine use the context class loader of the "initial Java - thread." + from a "primordial" virtual machine). This environment pointer was + formerly used to obtain a reference to the thread's current context + class loader (java.lang.Thread.getCurrentClassLoader; if later a native + thread was attached to the virtual machine, that thread's context class + loader would be null, so the AttachGuard first of all set it to the + saved value; this feature has been removed again for performance reasons + and because the default context class loader is often not useful, so + that code relying on a context class loader has to set one explicitly, + anyway). This parameter is currently unused (but may be used again in + the future). */ VirtualMachine(JavaVM * pVm, int nVersion, bool bDestroy, JNIEnv * pMainThreadEnv); @@ -148,10 +150,6 @@ private: virtual ~VirtualMachine(); - void acquireInitialContextClassLoader(JNIEnv * pEnv); - - void releaseInitialContextClassLoader() const; - JNIEnv * attachThread(bool * pAttached) const; void detachThread() const; @@ -159,7 +157,6 @@ private: JavaVM * m_pVm; jint m_nVersion; bool m_bDestroy; - jobject m_aInitialContextClassLoader; friend class AttachGuard; // to access attachThread, detachThread }; diff --git a/jvmaccess/source/virtualmachine.cxx b/jvmaccess/source/virtualmachine.cxx index c047195629bc..b6d6043e1e6a 100644 --- a/jvmaccess/source/virtualmachine.cxx +++ b/jvmaccess/source/virtualmachine.cxx @@ -71,17 +71,15 @@ VirtualMachine::VirtualMachine(JavaVM * pVm, int nVersion, bool bDestroy, JNIEnv * pMainThreadEnv): m_pVm(pVm), m_nVersion(nVersion), m_bDestroy(bDestroy) { + (void) pMainThreadEnv; // avoid warnings #ifdef SOLAR_JAVA OSL_ENSURE(pVm != 0 && nVersion >= JNI_VERSION_1_2 && pMainThreadEnv != 0, "bad parameter"); #endif - - acquireInitialContextClassLoader(pMainThreadEnv); } VirtualMachine::~VirtualMachine() { - releaseInitialContextClassLoader(); if (m_bDestroy) { // Do not destroy the VM. Under Java 1.3, the AWT event loop thread is @@ -95,48 +93,6 @@ VirtualMachine::~VirtualMachine() } } -void VirtualMachine::acquireInitialContextClassLoader(JNIEnv * pEnv) -{ -#ifdef SOLAR_JAVA - jclass aClass = pEnv->FindClass("java/lang/Thread"); - jmethodID aMethod1 = pEnv->GetStaticMethodID(aClass, "currentThread", - "()Ljava/lang/Thread;"); - jobject aThread = pEnv->CallStaticObjectMethod(aClass, aMethod1); - jmethodID aMethod2 = pEnv->GetMethodID(aClass, "getContextClassLoader", - "()Ljava/lang/ClassLoader;"); - jobject aClassLoader = pEnv->CallObjectMethod(aThread, aMethod2); - OSL_ENSURE(!pEnv->ExceptionCheck(), "JNI: exception occured"); - pEnv->ExceptionClear(); - if (aClassLoader == 0) - m_aInitialContextClassLoader = 0; - else - { - m_aInitialContextClassLoader = pEnv->NewGlobalRef(aClassLoader); - OSL_ENSURE(m_aInitialContextClassLoader != 0, - "JNI: NewGlobalRef failed"); - } -#endif -} - -void VirtualMachine::releaseInitialContextClassLoader() const -{ -#ifdef SOLAR_JAVA - if (m_aInitialContextClassLoader != 0) - { - JNIEnv * pEnv; - jint n = m_pVm->AttachCurrentThread(reinterpret_cast< void ** >(&pEnv), - 0); - OSL_ENSURE(n == JNI_OK, "JNI: AttachCurrentThread failed"); - if (n == JNI_OK) - { - pEnv->DeleteGlobalRef(m_aInitialContextClassLoader); - n = m_pVm->DetachCurrentThread(); - OSL_ENSURE(n == JNI_OK, "JNI: DetachCurrentThread failed"); - } - } -#endif -} - JNIEnv * VirtualMachine::attachThread(bool * pAttached) const { #ifndef SOLAR_JAVA @@ -153,19 +109,6 @@ JNIEnv * VirtualMachine::attachThread(bool * pAttached) const if (m_pVm->AttachCurrentThread(reinterpret_cast< void ** >(&pEnv), 0) != JNI_OK) return 0; - if (m_aInitialContextClassLoader != 0) - { - jclass aClass = pEnv->FindClass("java/lang/Thread"); - jmethodID aMethod1 = pEnv->GetStaticMethodID( - aClass, "currentThread", "()Ljava/lang/Thread;"); - jobject aThread = pEnv->CallStaticObjectMethod(aClass, aMethod1); - jmethodID aMethod2 = pEnv->GetMethodID( - aClass, "setContextClassLoader", "(Ljava/lang/ClassLoader;)V"); - pEnv->CallVoidMethod(aThread, aMethod2, - m_aInitialContextClassLoader); - OSL_ENSURE(!pEnv->ExceptionCheck(), "JNI: exception occured"); - pEnv->ExceptionClear(); - } *pAttached = true; } else |