简体   繁体   English

JVM-在正在运行的(非仪表化)会话中获取类的实例

[英]JVM - get hold of instance of a class in a running (non-instrumented) session

I need to stop a process by invoking a particular method on an instance of a given class. 我需要通过在给定类的实例上调用特定方法来停止进程。 The process has been running for a day, and if I shut it down hard, I lose a lot of work. 该过程已经运行了一天,如果我将其关闭,将会失去很多工作。 Due to a bug in the API, the GUI is wrongly wired and doesn't call the correct stop function. 由于API中的错误,GUI的接线错误,并且未调用正确的停止功能。 I have an interactive Java (Scala) interpreter attached, so if I could get hold of the instance of the process, I could easily invoke the correct method. 我附加了一个交互式Java(Scala)解释器,因此,如果我可以掌握该流程的实例,则可以轻松地调用正确的方法。

I am not in a debugging session, there is no com.sun.jdi. 我不在调试会话中,没有com.sun.jdi。 I can see the instance in a stack trace dump, but StackTraceElement doesn't contain actual instances, just classes and line numbers. 我可以在堆栈跟踪转储中看到该实例,但是StackTraceElement不包含实际实例,仅包含类和行号。

Is there any way in a running session, without specific instrumentation, to get hold of that instance -- through its class, through a thread dump? 在没有特定工具的情况下,正在运行的会话中是否可以通过其类,通过线程转储来获取该实例?

It is possible to get all instances of the given class using JVMTI IterateOverInstancesOfClass function. 可以使用JVMTI IterateOverInstancesOfClass函数获取给定类的所有实例。 See an example in this answer . 请参阅此答案中的示例。

Create a JNI library that will find the required instance using the above function and invoke a method on it from JNI_OnLoad entry. 创建一个JNI库,该库将使用上述函数查找所需的实例,并从JNI_OnLoad条目对其调用一个方法。 Then invoke System.load from the interpreter console to load this library. 然后从解释器控制台调用System.load来加载此库。

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

相关问题 Kotlin JaCoCo - IllegalClassFormatException。 请提供原始的非仪器类 - Kotlin JaCoCo - IllegalClassFormatException. Please supply original non-instrumented classes 如何在正在运行的JVM中查找类实例 - How to find a class instance in a running JVM 在 GraalVM 上运行的 JVM 字节码可以通过自定义“TruffleInstrument”进行检测吗? - Can JVM bytecode running on the GraalVM be instrumented by a custom `TruffleInstrument`? 使用PID获取正在运行的JVM的主类 - Get main class of a running JVM using PID 如何从一个JVM进程获取有关不同的Java进程(另一个运行不同进程的JVM实例)的信息? - How to get information about a different java process (another JVM instance running different processes) from one JVM process? JVM是否将始终创建Object类的实例 - Will JVM always create instance of Object class 获取JVM默认加载的密钥库实例 - Get instance of keystore that JVM loads by default 实例化一个类并在不同的JVM中运行其方法 - Instantiating a class and running its methods in a different JVM Spring 3类可以保存并返回单个bean实例吗? - Spring 3 class to hold and return a single bean instance? 对仪器罐和非仪器罐的性能影响是什么 - what is the performacne impact on instrumented jars vs non instrumented jars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM