-4

My question is regarding the java executable, the one that you use to run a Java program and that on Linux it is found for example in /usr/bin/java.

I have been experimenting a bit as I want to look into how everything happens behind the scenes, like how does the bytecode gets loaded, how is the execution of the actual Java program starting and other details that may not be so straightforward.

Until now I have looked at the execution with strace and found that a new thread is created and that thread is the one on which the Java program actually gets executed (from another question that I posted). From what I understand the java executable is a launcher of some sort, but I do not understand all the operations that happen behind the scenes.

So, what exactly is the java executable and is there any place where I can find the source code for it (this would really help me)?

danield
  • 195
  • 1
  • 7
  • java is usually symlinked on Linux. Find out to where with `readlink -f $(which java)`. That should be an ELF binary – g00se Sep 01 '21 at 13:42
  • My problem is not regarding which executable is on my system, and what exactly does that do in order to get to the point of actually running Java code. – danield Sep 01 '21 at 13:45
  • OK, then you probably need to look into Virtual Machine design and how that interprets Java bytecode – g00se Sep 01 '21 at 14:10

1 Answers1

2

The primary source file for the launcher in the current development JDK can be found here: https://github.com/openjdk/jdk/blob/master/src/java.base/share/native/libjli/java.c

As you see, it's quite short and delegates most of the work to other pieces of code, but should be useful as a starting point.

If you want to see the source for other JDK versions (this is basically the main development repo for future Java versions), you need to look into the appropriate repository.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614