How to compile program from compiler

It’s a good idea to get a rough idea of ​​how programs written by programmers work and down to the operating system, CPU, and hardware.

It is not easy to know everything. I explained in the course. Below is the Java Hello World Program

public class Main {
public static void main (String [] args) {
System.out.println (“Hello World”);

Can the computer run the program directly? The computer is electornic hardware, so it will work with electornic on / off. On / off is defined as 0 1.

To run a Java program. The first step is to use a Java compiler. You have to compile. The Java Compiler takes the Java source code and generates the byte code. It checks for grammar and then generates an abstract syntax tree, which generates code bytecode.

You should get a byte code for Main

public static void main (java.lang.String []);
descriptor: ([Ljava / lang / String;) V
stack = 2, locals = 1, args_size = 1
0: getstatic # 2 // Field java / lang / System.out: Ljava / io / PrintStream;
3: ldc # 3 // String Hello World
5: invokevirtual # 4 // Method java / io / PrintStream.println: (Ljava / lang / String;) V
8: return
line 3: 0
line 4: 8

Bytecode is not all, but some are left out. The byte code must run on a Java Virtual Machine. In other words, you can run bytecode on JVM software (also hardware). The JVM is written by sereis.

JVM is software, usually written in C ++, so it can be interpreted by interpreting bytecode or using JIT.

OK, so the JVM is written in C ++. I do not understand whether the machine understands C ++. So we have to convert C ++ to machine code assembly. It is similar to CPU instruction in assembly, but the source text is then assembled by an assembler to obtain machine instructions for assembly instruction. So the JVM C ++ code is now machine code, which is called exe on windows platform. Code that can be run directly on the platform

Platform is a combination of hardware + OS. Can I just run the native code directly from the hardware? You need the help of software called operating system. The operating system runs the JVM native code on the CPU. The JVM runs the bytecode.

So System.out.println (“Hello”) asks if the JVM can run it directly. It cannot run. Print out stream variable under System class. The println method is the native method. The native method, for example, contains instructions for addition, subtraction, multiplication, and multiplication in the JVM. But for people like reading a file and printing it out. No instruction. Then call the C ++ API to print from the JVM.

Is there any print from C ++? This is called a system call. What is a system call? From a operating system to a user program. For example, the API you want to call file read, write, memory allocation is called a system call.

If you make an OS system call from the User Program (JVM), you have to switch from user mode to kernel mode by removing the currently running JVM process. Suppose you have to do a process switching. The previous JVM process was running on the CPU and the OS process was running again.

OS Police. Can I print from system call? The OS has to command the hardware, so what to do? You need to call the device driver to do it.

In that case, the OS interrupts the return information, such as typing the necessary information for the device driver into the data memory. There is a kind of waiting. There are other processes that are currently being rotated during the IO printing process.

Here comes Hello World: 3