diff options
author | Serge Krot <Serge.Krot@cib.de> | 2020-03-25 16:56:18 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-09-24 15:01:32 +0200 |
commit | b2c1ba213143444163a0d4208f163fc1726421a7 (patch) | |
tree | 3ebbc619ce7bad03923523b5ba656ef8b58cf825 | |
parent | 4e4362daade150f3f34520bd5e6e4673ea88efce (diff) |
speed-up: preload JVM when PreloadJVM is set
Change-Id: I57f77f127f7cb45fb181b755b40873d47015e5b2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91059
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | desktop/source/app/app.cxx | 48 | ||||
-rw-r--r-- | officecfg/registry/schema/org/openoffice/Office/Common.xcs | 7 | ||||
-rw-r--r-- | stoc/source/javaloader/javaloader.cxx | 8 |
3 files changed, 62 insertions, 1 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index 6e067efad529..dd38a74aa89e 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -74,6 +74,7 @@ #include <com/sun/star/office/Quickstart.hpp> #include <com/sun/star/system/XSystemShellExecute.hpp> #include <com/sun/star/system/SystemShellExecute.hpp> +#include <com/sun/star/loader/XImplementationLoader.hpp> #include <desktop/exithelper.h> #include <sal/log.hxx> @@ -120,6 +121,7 @@ #include <vcl/graphicfilter.hxx> #include <vcl/window.hxx> #include "langselect.hxx" +#include <salhelper/thread.hxx> #if defined MACOSX #include <errno.h> @@ -1173,6 +1175,36 @@ void Desktop::AppEvent( const ApplicationEvent& rAppEvent ) namespace { +class JVMloadThread : public salhelper::Thread { +public: + JVMloadThread() : salhelper::Thread("Preload JVM thread") + { + } + +private: + virtual void execute() override final + { + Reference< XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory(); + + Reference< css::loader::XImplementationLoader > xJavaComponentLoader( + xSMgr->createInstance("com.sun.star.comp.stoc.JavaComponentLoader"), + css::uno::UNO_QUERY_THROW); + + if (xJavaComponentLoader.is()) + { + const css::uno::Reference< ::com::sun::star::registry::XRegistryKey > xRegistryKey; + try + { + xJavaComponentLoader->activate("", "", "", xRegistryKey); + } + catch (...) + { + SAL_WARN("desktop.app", "Cannot activate factory during JVM preloading"); + } + } + } +}; + struct ExecuteGlobals { Reference < css::document::XDocumentEventListener > xGlobalBroadcaster; @@ -1180,6 +1212,7 @@ struct ExecuteGlobals bool bUseSystemFileDialog; std::unique_ptr<SvtLanguageOptions> pLanguageOptions; std::unique_ptr<SvtPathOptions> pPathOptions; + rtl::Reference< JVMloadThread > xJVMloadThread; ExecuteGlobals() : bRestartRequested( false ) @@ -1212,6 +1245,15 @@ int Desktop::Main() // Detect desktop environment - need to do this as early as possible css::uno::setCurrentContext( new DesktopContext( css::uno::getCurrentContext() ) ); + if (officecfg::Office::Common::Misc::PreloadJVM::get() && pExecGlobals) + { + SAL_INFO("desktop.app", "Preload JVM"); + + // pre-load JVM + pExecGlobals->xJVMloadThread = new JVMloadThread(); + pExecGlobals->xJVMloadThread->launch(); + } + CommandLineArgs& rCmdLineArgs = GetCommandLineArgs(); Translate::SetReadStringHook(ReplaceStringHookProc); @@ -1566,6 +1608,12 @@ int Desktop::doShutdown() if (m_aUpdateThread.joinable()) m_aUpdateThread.join(); + if (pExecGlobals->xJVMloadThread.is()) + { + pExecGlobals->xJVMloadThread->join(); + pExecGlobals->xJVMloadThread.clear(); + } + pExecGlobals->bRestartRequested = pExecGlobals->bRestartRequested || OfficeRestartManager::get(comphelper::getProcessComponentContext())-> isRestartRequested(true); diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 048f64ab3f18..f764d3d7aa45 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -5824,6 +5824,13 @@ </info> <value>true</value> </prop> + <prop oor:name="PreloadJVM" oor:type="xs:boolean" oor:nillable="false"> + <info> + <desc>Specifies if the JVM should be preloaded during LO start up.</desc> + <label>PreloadJVM</label> + </info> + <value>false</value> + </prop> <prop oor:name="FilePickerPlacesUrls" oor:type="oor:string-list" oor:nillable="false"> <info> <desc>List of URLs of the places the user bookmarked in the file picker dialog.</desc> diff --git a/stoc/source/javaloader/javaloader.cxx b/stoc/source/javaloader/javaloader.cxx index 2b40cdd219db..73b0ddf557ff 100644 --- a/stoc/source/javaloader/javaloader.cxx +++ b/stoc/source/javaloader/javaloader.cxx @@ -304,11 +304,17 @@ sal_Bool SAL_CALL JavaComponentLoader::writeRegistryInfo( return loader->writeRegistryInfo(xKey, blabla, rLibName); } - css::uno::Reference<XInterface> SAL_CALL JavaComponentLoader::activate( const OUString & rImplName, const OUString & blabla, const OUString & rLibName, const css::uno::Reference<XRegistryKey> & xKey) { + if (rImplName.isEmpty() && blabla.isEmpty() && rLibName.isEmpty()) + { + // preload JVM was requested + (void)getJavaLoader(); + return css::uno::Reference<XInterface>(); + } + const css::uno::Reference<XImplementationLoader> & loader = getJavaLoader(); if (!loader.is()) throw CannotActivateFactoryException("Could not create Java implementation loader"); |