From aaf76786709800dcf42a587db4dae6cf381e2eb6 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 22 Oct 2020 20:00:57 -0700 Subject: [PATCH] util: Automatically load the java .so in the gem5 ops wrapper. The java wrapper which provides access to the gem5 ops is implemented using JNI in a .so file which needs to be loaded before the class can be used. Rather than expecting the caller to do that, we can use a static block in the class definition. We know that will be called at the right time, and it's one less detail (arguably an implementation detail) that the caller won't have to worry about. Change-Id: I2b4b18ebb12030ea6f4e6463c6cd512afed74cfd Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28177 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- util/m5/README.md | 9 ++------- util/m5/src/java/gem5/Ops.java | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/util/m5/README.md b/util/m5/README.md index 9a350e2f3..691347816 100644 --- a/util/m5/README.md +++ b/util/m5/README.md @@ -341,14 +341,9 @@ library only if that trigger mechanism is supported for that ABI. # Java jar -To use the gem5 java jar, you will need to load the corresponding .so. - -```shell -System.loadLibrary("gem5Ops"); -``` - In your java source, import the gem5Op class which will have methods for -calling each of the gem5 operations. +calling each of the gem5 operations. The .so library will be loaded +automatically. ```shell import gem5.Ops diff --git a/util/m5/src/java/gem5/Ops.java b/util/m5/src/java/gem5/Ops.java index fea5aaddd..cc92505dd 100644 --- a/util/m5/src/java/gem5/Ops.java +++ b/util/m5/src/java/gem5/Ops.java @@ -42,6 +42,10 @@ package gem5; */ public class Ops { + static { + System.loadLibrary("gem5Ops"); + } + public native void arm(long address); public native void quiesce(); public native void quiesce_ns(long ns); -- 2.30.2