Apr 11, 2023 1Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine
Apr 11, 2023 2Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - start
JVM on Windows PCJVM on Windows PC
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on iMACJVM on iMAC
JVM on UNIXJVM on UNIX
JVM on LINUX PCJVM on LINUX PC
ProgramRunningProgramRunning
ProgramRunningProgramRunning
ProgramRunningProgramRunning
ProgramRunningProgramRunning
Apr 11, 2023 3Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - source
Java Source ProgramJava Source Program -Written in standard Java-Target machine irrelevant-Doesn’t matter which machine
it’s created on.
Apr 11, 2023 4Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - compile
Java ‘Compiler’Java ‘Compiler’
Java Source ProgramJava Source Program
>> javac MyProg.java
Java ‘compiler’ does syntactic analysisand parsing.
Translates source into Byte CodeMyProg.class
Apr 11, 2023 5Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - Byte Code
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
Bytecode is the same for ALL machines and ALL versions of Java
Up to this point everything looks and behaves identicallyon ALL machines
Bytecode is assembler-like, but thereis no really real machine that ‘understands’ bytecode.
Called Bytecode because most instructions are one or twobytes long
Apr 11, 2023 6Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine – ready-set-..
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
•Bytecode can be transported to any machine with a bytecode interpreter [called the “Java Virtual Machine”]•Assemblers run on real machines, so…..•Java Bytecode runs on a “Virtual Machine”
Apr 11, 2023 7Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine – go
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
•The Virtual Machine is like a simulator – it simulates a real machine, but…•It also ‘tells’ the real machine on which it is currently running to do the stuff the virtual machine would be doing•This requires it to be ‘tailor-made’ for the machine it is running on…
Apr 11, 2023 8Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - Linux
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on LINUX PCJVM on LINUX PC
Apr 11, 2023 9Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine – Linux-b
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on LINUX PCJVM on LINUX PC
ProgramRunningProgramRunning
Apr 11, 2023 10Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - Windows
JVM on Windows PCJVM on Windows PC
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
Apr 11, 2023 11Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine – Windows-b
JVM on Windows PCJVM on Windows PC
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
ProgramRunningProgramRunning
Apr 11, 2023 12Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - iMAC
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on iMACJVM on iMAC
Apr 11, 2023 13Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine – iMAC-b
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on iMACJVM on iMAC
ProgramRunningProgramRunning
Apr 11, 2023 14Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine - UNIX
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on UNIXJVM on UNIX
Apr 11, 2023 15Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine – UNIX-b
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on UNIXJVM on UNIX ProgramRunningProgramRunning
Apr 11, 2023 16Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Virtual Machine ..TA-Da
JVM on Windows PCJVM on Windows PC
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source ProgramJava Source Program
JVM on iMACJVM on iMAC
JVM on UNIXJVM on UNIX
JVM on LINUX PCJVM on LINUX PC
ProgramRunningProgramRunning
ProgramRunningProgramRunning
ProgramRunningProgramRunning
ProgramRunningProgramRunning
Apr 11, 2023 17Java Virtual Machine© Katrin BeckerAll rights reserved.
Once more from the topA slightly different
perspective….
Apr 11, 2023 18Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -1JVM source written in CJVM source written in C
Somebody writes the “Java Virtual Machine”;Jim Gosling probably wrote the first one.
Apr 11, 2023 19Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -2JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.c gets compiled to produce….
Apr 11, 2023 20Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -3JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
There has to be a specially tailored one of these for the specific
machine we are currently using.
Apr 11, 2023 21Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM –3bJVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
The ‘Java Virtual Machine’ is now ready to be used (invoked).
It can sit around on the system indefinitely.
Apr 11, 2023 22Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -4JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Java Source Program:MyProg.java
Java Source Program:MyProg.java
Along comes My Program,written in Java
Apr 11, 2023 23Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -5JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Java Source Program:MyProg.java
Java Source Program:MyProg.java
Java ‘Compiler’Java ‘Compiler’
>> javac MyProg.javaResults in…..
The Java compiler gets invoked –
It takes standard Java source as input
And produces standard Java ByteCode as output
Apr 11, 2023 24Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -6JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Java Source Program:MyProg.java
Java Source Program:MyProg.java
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Now I am free to take my MyProg.class toany computer I choose, Any brand; any flavour; anywhere in the worldPROVIDED…It has a working JVM.exe
Apr 11, 2023 25Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM –6bJVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Java Source Program:MyProg.java
Java Source Program:MyProg.java
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
When I say:>> java MyProg.class
The target machine loads, and then starts to run theJava Virtual Machine….
Apr 11, 2023 26Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -7JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Java Source Program:MyProg.java
Java Source Program:MyProg.java
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Machine-dependent Linker/Loader
Machine-dependent Linker/Loader
Apr 11, 2023 27Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -8JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Java Source Program:MyProg.java
Java Source Program:MyProg.java
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Machine-dependent Linker/Loader
Machine-dependent Linker/Loader
‘Java’ ProgramRunning bytecode
as input
‘Java’ ProgramRunning bytecode
as input
The JVM expectsa file containingByteCode as input
Apr 11, 2023 28Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -9JVM source written in CJVM source written in C
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Java Source Program:MyProg.java
Java Source Program:MyProg.java
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Machine-dependent Linker/Loader
Machine-dependent Linker/Loader
MyProg.class ProgramRunning
MyProg.class ProgramRunning
‘Java’ ProgramRunning bytecode
as input
‘Java’ ProgramRunning bytecode
as input
The output from the JVM is the output that your program produces (unless of course the JVM detects a problem)
Apr 11, 2023 29Java Virtual Machine© Katrin BeckerAll rights reserved.
Java Source :: JVM -10
Java ‘Compiler’Java ‘Compiler’
ByteCodeByteCode
Java Source Program:MyProg.java
Java Source Program:MyProg.java
C compiler compiles ‘JVM.c’C compiler compiles ‘JVM.c’
JVM.exe(executable version of
JVM)
JVM.exe(executable version of
JVM)
Machine-dependent Linker/Loader
Machine-dependent Linker/Loader
MyProg.class ProgramRunning
MyProg.class ProgramRunning
‘Java’ ProgramRunning bytecode
as input
‘Java’ ProgramRunning bytecode
as input
MyProg output
MyProg output
JVM source written in CJVM source written in C
Apr 11, 2023 30Java Virtual Machine© Katrin BeckerAll rights reserved.
The end.
Top Related