作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了简单的代理:
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
printf("Agent start");
}
和简单的客户端:
public class Agent {
//java -agentpath:/path_to_lib Agent
public static void main(String[] args) throws InterruptedException {
System.out.println("Main");
}}
如果我运行程序,我将看到以下输出:
Main
Agent start
为什么 main 方法在 Agent_OnLoad 之前调用?
最佳答案
在虚拟机启动期间,Agent_OnLoad
函数在 main 之前被调用,但是 stdout
缓冲区在到达换行符
后打印。在 printf
末尾添加 \n
以查看其工作情况。以下答案详细解释了这一点:
Why does printf
not flush after the call unless a newline is in the format string?
此外,您可以通过在 printf
上放置断点(如果您使用调试器)来确认这一点,以查看它会在启动时被调用,但直到缓冲区才会打印到达换行
字符。
关于java - 关闭jvm后调用方法Agent_OnLoad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40330957/
我正在使用 JVM 工具界面。我正在尝试使用 SetSystemProperty() 调用在 Agent_OnLoad 事件中创建 SystemProperty。如果该属性存在,它会正确设置一个新值。
我目前是第一次使用 JVMTI。 我主要使用JVM(TM) Tool Interface Documentation如果有任何问题出现。 但是我找不到的是:除了通过调用 GetEnv(...) 来获取
我是一名优秀的程序员,十分优秀!