summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorSerge Krot <Serge.Krot@cib.de>2020-03-25 16:56:18 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-09-24 15:01:32 +0200
commitb2c1ba213143444163a0d4208f163fc1726421a7 (patch)
tree3ebbc619ce7bad03923523b5ba656ef8b58cf825 /desktop
parent4e4362daade150f3f34520bd5e6e4673ea88efce (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>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/app/app.cxx48
1 files changed, 48 insertions, 0 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);