简体   繁体   English

检测Java 9+运行时模块

[英]Instrumenting Java 9+ runtime modules

Our tool ( http://plse.cs.washington.edu/daikon ) calculates program invariants by inserting instrumentation into the java byte codes for a program. 我们的工具( http://plse.cs.washington.edu/daikon )通过将检测插入程序的Java字节码中来计算程序不变量。 In order to get more accurate results, we need to track values into and out of Java runtime calls. 为了获得更准确的结果,我们需要跟踪Java运行时调用中的值。 Thus, we need to instrument the Java runtime as well. 因此,我们还需要检测Java运行时。 Prior to Java 9, we did this by reading rt.jar, instrumenting its methods and writing out a modified version as dcomp-rt.jar. 在Java 9之前,我们通过阅读rt.jar,检测其方法并将其修改后的版本写为dcomp-rt.jar来实现。 The user code is instrumented during runtime via the normal ClassFileTransformer::transform method. 在运行时通过普通的ClassFileTransformer :: transform方法检测用户代码。 Now hundreds of runtime methods are loaded prior to the first time we get control at 'transform'; 现在,在我们第一次通过“转换”获得控制之前,已经加载了数百种运行时方法。 thus, again prior to Java 9, we placed dcomp-rt.jar on the bootclasspath to ensure our modified java runtime methods were loaded instead of the standard ones. 因此,再次在Java 9之前,我们将dcomp-rt.jar放在bootclasspath上,以确保加载修改后的Java运行时方法而不是标准方法。 The user program invocation would look something like: 用户程序调用如下所示:

java -cp .:/homes/gws/markro/invariants/daikon/daikon.jar -Xbootclasspath/p:/homes/gws/markro/invariants/daikon/java/dcomp_rt.jar:.:/homes/gws/markro/invariants/daikon/daikon.jar -javaagent:/homes/gws/markro/invariants/daikon/java/dcomp_premain.jar={various dcomp arguments} {user program} {user program arguments}

Now to Java 9+. 现在到Java 9+。 Our first approach was to read in and instrument the class files within the Java runtime jmod files (via the new "jrt:/" file system) and create a dcomp_rt.jar as before. 我们的第一种方法是读入Java运行时jmod文件中的类文件并对其进行检测(通过新的“ jrt:/”文件系统),并像以前一样创建dcomp_rt.jar。 The problem we are experiencing is that we cannot get the system to use the contents of this jar instead of jrt:/java.base (for example). 我们遇到的问题是,我们无法使系统使用此jar的内容代替jrt:/java.base(例如)。 We tried various --module-path and -Xbootclasspath (only /a is avail now, might be part of problem) options to no avail. 我们尝试了各种--module-path和-Xbootclasspath(仅/ a现在可用,可能是问题的一部分)选项无效。 Still hoping there might be a way to do this? 还是希望有办法做到这一点?

If not, I'm guessing we need to make modified versions of each of the interesting runtime jmods and then use a --patch-module argument for each of them. 如果没有,我猜我们需要为每个有趣的运行时jmods修改版本,然后为每个jmods使用--patch-module参数。 Would this ensure our modified code is loaded instead of the standard runtime? 这样是否可以确保加载修改后的代码而不是标准运行时?

Any thoughts/suggestions? 有什么想法/建议吗?

Well it looks like --patch-module does the trick. 看起来--patch-module可以解决问题。 I made the same dcomp_rt.jar but with only classes from java.base.jmod. 我做了相同的dcomp_rt.jar,但只有java.base.jmod中的类。 Then used: 然后使用:

 --patch-module java.base={full path}/dcomp_rt.jar

Running java with -verbose:class showed all base classes being loaded from my jar. 使用-verbose:class运行java会显示所有基本类都从我的jar中加载。

Is this the best way to accomplish my goal? 这是实现我的目标的最佳方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM