Kaydet (Commit) e5546342 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Let JavaVirtualMachine::getJavaVm start the VM it already found

Since b6995199 "Drop support for /etc/opt/ure
and ~/.ure from LibreOffice 4" there is no place any more where a plain URE will
store information about a selected JVM, so JavaVirtualMachine::getJavaVM will
go into an endless loop of jfw_startVM -> JFW_E_NO_SELECT ->
jfw_findAndSelectJRE -> jfw_startVM -> ...  The solution is to pass the JavaInfo
determined by jfw_findAndSelectJRE into the second invocation of jfw_startVM
(for which the parameter list of the latter needed to be changed), instead of
relying on jfw_findAndSelectJRE and jfw_startVM implicitly communicating that
information via user configuration files.

Change-Id: I5799f04c457e8a849c67ed827dc5e134c6563362
üst 39da5cf1
...@@ -482,6 +482,8 @@ JVMFWK_DLLPUBLIC javaFrameworkError SAL_CALL jfw_getJavaInfoByPath( ...@@ -482,6 +482,8 @@ JVMFWK_DLLPUBLIC javaFrameworkError SAL_CALL jfw_getJavaInfoByPath(
created and JFW_E_NEED_RESTART error is returned. If a VM is already running created and JFW_E_NEED_RESTART error is returned. If a VM is already running
then a JFW_E_RUNNING_JVM is returned.</p> then a JFW_E_RUNNING_JVM is returned.</p>
@param pInfo
[in] optional pointer to a specific JRE; must be caller-freed if not NULL
@param arOptions @param arOptions
[in] the array containing additional start arguments or NULL. [in] the array containing additional start arguments or NULL.
@param nSize @param nSize
...@@ -516,9 +518,9 @@ JVMFWK_DLLPUBLIC javaFrameworkError SAL_CALL jfw_getJavaInfoByPath( ...@@ -516,9 +518,9 @@ JVMFWK_DLLPUBLIC javaFrameworkError SAL_CALL jfw_getJavaInfoByPath(
JFW_E_FAILED_VERSION the &quot;Default Mode&quot; is active. The JRE determined by JFW_E_FAILED_VERSION the &quot;Default Mode&quot; is active. The JRE determined by
<code>JAVA_HOME</code>does not meet the version requirements. <code>JAVA_HOME</code>does not meet the version requirements.
*/ */
JVMFWK_DLLPUBLIC javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, JVMFWK_DLLPUBLIC javaFrameworkError SAL_CALL jfw_startVM(
sal_Int32 nSize, JavaVM **ppVM, JavaInfo const * pInfo, JavaVMOption * arOptions, sal_Int32 nSize,
JNIEnv **ppEnv); JavaVM ** ppVM, JNIEnv ** ppEnv);
/** determines the JRE that is to be used. /** determines the JRE that is to be used.
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "osl/module.hxx" #include "osl/module.hxx"
#include "jvmfwk/framework.h" #include "jvmfwk/framework.h"
#include "jvmfwk/vendorplugin.h" #include "jvmfwk/vendorplugin.h"
#include <cassert>
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <algorithm> #include <algorithm>
...@@ -290,10 +291,12 @@ javaFrameworkError SAL_CALL jfw_findAllJREs(JavaInfo ***pparInfo, sal_Int32 *pSi ...@@ -290,10 +291,12 @@ javaFrameworkError SAL_CALL jfw_findAllJREs(JavaInfo ***pparInfo, sal_Int32 *pSi
#endif #endif
} }
javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOptions, javaFrameworkError SAL_CALL jfw_startVM(
JavaVM **ppVM, JNIEnv **ppEnv) JavaInfo const * pInfo, JavaVMOption * arOptions, sal_Int32 cOptions,
JavaVM ** ppVM, JNIEnv ** ppEnv)
{ {
#ifndef SOLAR_JAVA #ifndef SOLAR_JAVA
(void) pInfo;
(void) arOptions; (void) arOptions;
(void) cOptions; (void) cOptions;
(void) ppVM; (void) ppVM;
...@@ -320,6 +323,8 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti ...@@ -320,6 +323,8 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti
std::vector<rtl::OString> vmParams; std::vector<rtl::OString> vmParams;
rtl::OString sUserClassPath; rtl::OString sUserClassPath;
jfw::CJavaInfo aInfo; jfw::CJavaInfo aInfo;
if (pInfo == NULL)
{
jfw::JFW_MODE mode = jfw::getMode(); jfw::JFW_MODE mode = jfw::getMode();
if (mode == jfw::JFW_MODE_APPLICATION) if (mode == jfw::JFW_MODE_APPLICATION)
{ {
...@@ -394,10 +399,13 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti ...@@ -394,10 +399,13 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti
} }
else else
OSL_ASSERT(0); OSL_ASSERT(0);
pInfo = aInfo.pInfo;
}
assert(pInfo != NULL);
//get the function jfw_plugin_startJavaVirtualMachine //get the function jfw_plugin_startJavaVirtualMachine
jfw::VendorSettings aVendorSettings; jfw::VendorSettings aVendorSettings;
rtl::OUString sLibPath = aVendorSettings.getPluginLibrary(aInfo.getVendor()); rtl::OUString sLibPath = aVendorSettings.getPluginLibrary(pInfo->sVendor);
#ifndef DISABLE_DYNLOADING #ifndef DISABLE_DYNLOADING
osl::Module modulePlugin(sLibPath); osl::Module modulePlugin(sLibPath);
...@@ -454,7 +462,7 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti ...@@ -454,7 +462,7 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti
//start Java //start Java
JavaVM *pVm = NULL; JavaVM *pVm = NULL;
SAL_INFO("jvmfwk", "starting java"); SAL_INFO("jvmfwk", "starting java");
javaPluginError plerr = (*pFunc)(aInfo, arOpt, index, & pVm, ppEnv); javaPluginError plerr = (*pFunc)(pInfo, arOpt, index, & pVm, ppEnv);
if (plerr == JFW_PLUGIN_E_VM_CREATION_FAILED) if (plerr == JFW_PLUGIN_E_VM_CREATION_FAILED)
{ {
errcode = JFW_E_VM_CREATION_FAILED; errcode = JFW_E_VM_CREATION_FAILED;
...@@ -677,13 +685,13 @@ javaFrameworkError SAL_CALL jfw_findAndSelectJRE(JavaInfo **pInfo) ...@@ -677,13 +685,13 @@ javaFrameworkError SAL_CALL jfw_findAndSelectJRE(JavaInfo **pInfo)
jfw::NodeJava javaNode(jfw::NodeJava::USER); jfw::NodeJava javaNode(jfw::NodeJava::USER);
javaNode.setJavaInfo(aCurrentInfo,true); javaNode.setJavaInfo(aCurrentInfo,true);
javaNode.write(); javaNode.write();
//remember that this JRE was selected in this process
jfw::setJavaSelected();
if (pInfo !=NULL) if (pInfo !=NULL)
{ {
//copy to out param //copy to out param
*pInfo = aCurrentInfo.cloneJavaInfo(); *pInfo = aCurrentInfo.cloneJavaInfo();
//remember that this JRE was selected in this process
jfw::setJavaSelected();
} }
} }
else else
......
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
#include <time.h> #include <time.h>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "boost/noncopyable.hpp"
#include "boost/scoped_array.hpp" #include "boost/scoped_array.hpp"
#define OUSTR(x) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x )) #define OUSTR(x) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x ))
...@@ -703,6 +704,23 @@ JavaVirtualMachine::getSupportedServiceNames() ...@@ -703,6 +704,23 @@ JavaVirtualMachine::getSupportedServiceNames()
return serviceGetSupportedServiceNames(); return serviceGetSupportedServiceNames();
} }
namespace {
struct JavaInfoGuard: private boost::noncopyable {
JavaInfoGuard(): info(0) {}
~JavaInfoGuard() { jfw_freeJavaInfo(info); }
void clear() {
jfw_freeJavaInfo(info);
info = 0;
}
JavaInfo * info;
};
}
css::uno::Any SAL_CALL css::uno::Any SAL_CALL
JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId) JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
throw (css::uno::RuntimeException) throw (css::uno::RuntimeException)
...@@ -727,6 +745,7 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId) ...@@ -727,6 +745,7 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
if (aId != aProcessId) if (aId != aProcessId)
return css::uno::Any(); return css::uno::Any();
JavaInfoGuard info;
while (!m_xVirtualMachine.is()) // retry until successful while (!m_xVirtualMachine.is()) // retry until successful
{ {
// This is the second attempt to create Java. m_bDontCreateJvm is // This is the second attempt to create Java. m_bDontCreateJvm is
...@@ -773,7 +792,7 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId) ...@@ -773,7 +792,7 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
if (getenv("STOC_FORCE_NO_JRE")) if (getenv("STOC_FORCE_NO_JRE"))
errcode = JFW_E_NO_SELECT; errcode = JFW_E_NO_SELECT;
else else
errcode = jfw_startVM(arOptions, index, & m_pJavaVm, errcode = jfw_startVM(info.info, arOptions, index, & m_pJavaVm,
& pMainThreadEnv); & pMainThreadEnv);
bool bStarted = false; bool bStarted = false;
...@@ -784,7 +803,8 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId) ...@@ -784,7 +803,8 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
{ {
// No Java configured. We silenty run the java configuration // No Java configured. We silenty run the java configuration
// Java. // Java.
javaFrameworkError errFind = jfw_findAndSelectJRE( NULL ); info.clear();
javaFrameworkError errFind = jfw_findAndSelectJRE(&info.info);
if (getenv("STOC_FORCE_NO_JRE")) if (getenv("STOC_FORCE_NO_JRE"))
errFind = JFW_E_NO_JAVA_FOUND; errFind = JFW_E_NO_JAVA_FOUND;
if (errFind == JFW_E_NONE) if (errFind == JFW_E_NONE)
...@@ -861,7 +881,9 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId) ...@@ -861,7 +881,9 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
if (bExist == sal_False if (bExist == sal_False
&& ! (pJavaInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)) && ! (pJavaInfo->nRequirements & JFW_REQUIRE_NEEDRESTART))
{ {
javaFrameworkError errFind = jfw_findAndSelectJRE( NULL ); info.clear();
javaFrameworkError errFind = jfw_findAndSelectJRE(
&info.info);
if (errFind == JFW_E_NONE) if (errFind == JFW_E_NONE)
{ {
continue; continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment