Java 运行时 traceInstructions() 方法



描述

Java 运行时 traceInstructions(boolean on) 方法启用/禁用指令跟踪。如果布尔型参数为 true,则此方法表示 Java 虚拟机在执行虚拟机中的每个指令时发出调试信息。此信息格式以及其输出到的文件或其他输出流取决于主机环境。如果虚拟机不支持此功能,则可能会忽略此请求。跟踪输出的目标取决于系统。如果布尔型参数为 false,则此方法会导致虚拟机停止执行其正在执行的详细指令跟踪。

声明

以下是 java.lang.Runtime.traceInstructions() 方法的声明

public void traceInstructions(boolean on)

参数

on - true 表示启用指令跟踪;false 表示禁用此功能。

返回值

此方法不返回值。

异常

示例:启用指令跟踪

以下示例演示了 Java Runtime traceInstructions() 方法的使用。我们使用 traceInstructions(true) 方法启用了当前 JVM 的指令跟踪。

package com.tutorialspoint;

public class RuntimeDemo {

   public static void main(String[] args) {

      // print the state of the program
      System.out.println("Program is starting...");

      // start tracing for instructions
      System.out.println("Enabling tracing...");
      Runtime.getRuntime().traceInstructions(true);
      System.out.println("Done!");
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果:

Program is starting...
Enabling tracing...
Done!

示例:禁用指令跟踪

以下示例演示了 Java Runtime traceInstructions() 方法的使用。我们使用 traceInstructions(false) 方法禁用了当前 JVM 的指令跟踪。

package com.tutorialspoint;

public class RuntimeDemo {

   public static void main(String[] args) {

      // print the state of the program
      System.out.println("Program is starting...");

      // start tracing for instructions
      System.out.println("Disabling tracing...");
      Runtime.getRuntime().traceInstructions(false);
      System.out.println("Done!");
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果:

Program is starting...
Disabling tracing...
Done!
java_lang_runtime.htm
广告

© . All rights reserved.