0

I tried to find online, but didn't find answer. Usually we debug a Java program by breaking at some line of the application.

I want to know is there a way to debug a Java program by breaking at the entry point of JVM itself?

For example, to run a simple Java program, we can do:

java Foo

My question is, how can we debug what's going into JVM (by invoking java) before our class is loaded? Is there some way to achieve this?

6
  • 1
    What are you trying to debug that requires you to dig into the internals of the JVM? There are other tools for monitoring VM actions, what is causing the need to achieve this using your IDE's debugger? Commented May 14, 2020 at 19:01
  • @VinceEmigh: To know what's happening behind the scenes. Commented May 14, 2020 at 19:02
  • 1
    There's a lot going on behind the scenes, such as JIT compilation (viewed using JIT Watch). If you really want to debug the VM (with readable results), you'll probably have to use a native debugger on an open-source VM. Most Java IDEs don't support this level of probing, typically because it's not needed to solve problems and would be quite a task to implement. Commented May 14, 2020 at 19:06
  • 1
    It would be interesting to see any Java code that runs before your application code you run, similar to how you can use process launch -s in lldb to see code that runs before main in a C program. However, I doubt it will help debug any issues related to memory or hanging threads in your application, since suspend-on-start covers even static initializers Commented May 14, 2020 at 19:11
  • 2
    If you really want to get inside the JVM itself, you'd need some native debugger as pointed out - something like gdb on Unix. Then you can do gdb --args java Foo provided that you use a JDK which have debug information (OpenJDK). For everything else - e.g. monitoring the application - why not using a profiler like YourKit? Commented May 14, 2020 at 19:20

1 Answer 1

1

You may use InTrace to instrument the Classloader classes which do the loading.

Below links might be helpful :

InTrace

DebugJVMIssuesOracleDocs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.