Add Instrumentation to the LibreOffice JVM

Pierre Vacher prrvchr at gmail.com
Mon Feb 3 20:16:24 UTC 2025


Hi Noel,

Great I'll try to do it...

I found the configuration file:
libreoffice/officecfg/registry/schema/org/openoffice/Office/Java.xcs
But I can't find the model to modify (ie: the xcu file).

And I think I found where the JVM is loaded:
/home/prrvchr/github/libreoffice/libreoffice/stoc/source/javaloader/javaloader.cxx
However I don't really understand what is done. I see that the
configuration is read (ie: line 315) but I don't see where it is applied...

We also have to add a Java Jar archive in the folder:
program/classes
I suppose. Do you have a preference for the name of the archive and the
name of the Java package?

Thank you for your help.

Pierre.

Le lun. 3 févr. 2025 à 06:55, Noel Grandin <noelgrandin at gmail.com> a écrit :

> Sounds quite reasonable to add this to the core product behind an option.
>
> On Sat, 01 Feb 2025 at 21:18, Pierre Vacher <prrvchr at gmail.com> wrote:
>
>> Hi all,
>>
>> I would like to add the Java Instrumentation
>> <https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html>
>> API to the extensions running under LibreOffice and written in Java.
>>
>> After some testing, I manage to load the Instrumentation
>> <https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html>
>> agent at JVM startup, having taken care to add the necessary startup option
>> (ie:
>> -javaagent:/home/prrvchr/github/jdbcDriverOOo/source/UnoAgent/dist/UnoAgent.jar)
>> and put this archive in the classpath (ie: Tools -> Options -> LibreOffice
>> -> Advanced -> Java Options).
>>
>> UnoAgent.jar is an archive containing only one class which itself
>> contains only two methods and this gives access to code injection and the
>> possibility of modifying the search path of the system bootloader. This
>> currently allows me to be able to deploy an SPI service type like
>> System.LoggerFinder,  and to be able to be the provider for the
>> System.Logger
>> <https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/System.Logger.html>
>> interface for all running applications on the JVM.
>>
>> If we want to make this feature accessible to any extension written in
>> Java, it is necessary to make three modifications: - Add the UnoAgent.jar
>> archive to the SDK. - Add an entry in the LibreOffice configuration (ie:
>> xcu file) to enable or disable instrumentation. - Load the JVM with the
>> parameters needed for instrumentation depending on the configuration.
>>
>> Please let me know what you think about this.
>>
>> Pierre
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20250203/0a8ae986/attachment.htm>


More information about the LibreOffice mailing list