02 B The Java Virtual Machine CS1102S: Data Structures and - - PowerPoint PPT Presentation

02 b the java virtual machine
SMART_READER_LITE
LIVE PREVIEW

02 B The Java Virtual Machine CS1102S: Data Structures and - - PowerPoint PPT Presentation

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM 02 B The Java Virtual Machine CS1102S: Data Structures and Algorithms Martin Henz January 22, 2010 Generated on Friday 22 nd January, 2010, 09:46 CS1102S: Data Structures and


slide-1
SLIDE 1

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM

02 B The Java Virtual Machine

CS1102S: Data Structures and Algorithms

Martin Henz

January 22, 2010

Generated on Friday 22nd January, 2010, 09:46 CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 1

slide-2
SLIDE 2

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM

1

Motivation for JVM

2

Virtual Machine Overview

3

A Quick Tour of the JVM

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 2

slide-3
SLIDE 3

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

1

Motivation for JVM Situation before Java Java’s Background Main Features

2

Virtual Machine Overview

3

A Quick Tour of the JVM

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 3

slide-4
SLIDE 4

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Trade-off Between Interpretation and Compilation

Compilation results in machine code, executed efficiently

  • n the target hardware

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 4

slide-5
SLIDE 5

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Trade-off Between Interpretation and Compilation

Compilation results in machine code, executed efficiently

  • n the target hardware

Drawbacks: security, portability

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 5

slide-6
SLIDE 6

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Trade-off Between Interpretation and Compilation

Compilation results in machine code, executed efficiently

  • n the target hardware

Drawbacks: security, portability Interpretation interprets one program piece at a time, using a portable and secure runtime system

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 6

slide-7
SLIDE 7

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Trade-off Between Interpretation and Compilation

Compilation results in machine code, executed efficiently

  • n the target hardware

Drawbacks: security, portability Interpretation interprets one program piece at a time, using a portable and secure runtime system Drawbacks: slow execution

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 7

slide-8
SLIDE 8

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Java’s Roots

James Gosling and Bill Joy developed Oak at FirstPerson Inc, a Sun subsidiary Oak was intended for programming devices Sun realized the potential of Java for the web and tried to establish it for client-side computing (“applets”) Security features, clean design and powerful libraries made Java attractive for server-side processing

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 8

slide-9
SLIDE 9

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

What is Java?

Java is not just the language

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 9

slide-10
SLIDE 10

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

What is Java?

Java is not just the language Java stands for a combination of techniques and concepts:

Language syntax Compiler Java Virtual Machine Java’s standard APIs

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 10

slide-11
SLIDE 11

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Features of Java

Portable : runtime system needs to be ported to hardware

  • platforms. Once runtime is available, any 100%

pure Java application can run on the platform.

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 11

slide-12
SLIDE 12

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Features of Java

Portable : runtime system needs to be ported to hardware

  • platforms. Once runtime is available, any 100%

pure Java application can run on the platform. Write Once, Run Anywhere

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 12

slide-13
SLIDE 13

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Features of Java

Portable : runtime system needs to be ported to hardware

  • platforms. Once runtime is available, any 100%

pure Java application can run on the platform. Write Once, Run Anywhere Efficient : Byte-code interpretation provides good efficiency trade-off.

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 13

slide-14
SLIDE 14

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Features of Java

Portable : runtime system needs to be ported to hardware

  • platforms. Once runtime is available, any 100%

pure Java application can run on the platform. Write Once, Run Anywhere Efficient : Byte-code interpretation provides good efficiency trade-off. Classes are loaded on-demand, resulting in fast start-up times of applications

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 14

slide-15
SLIDE 15

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Features of Java

Portable : runtime system needs to be ported to hardware

  • platforms. Once runtime is available, any 100%

pure Java application can run on the platform. Write Once, Run Anywhere Efficient : Byte-code interpretation provides good efficiency trade-off. Classes are loaded on-demand, resulting in fast start-up times of applications Secure : Extensive security model allows targeting various security requirements.

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 15

slide-16
SLIDE 16

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Features of Java

Portable : runtime system needs to be ported to hardware

  • platforms. Once runtime is available, any 100%

pure Java application can run on the platform. Write Once, Run Anywhere Efficient : Byte-code interpretation provides good efficiency trade-off. Classes are loaded on-demand, resulting in fast start-up times of applications Secure : Extensive security model allows targeting various security requirements. However, the Java license states: “not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility.”

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 16

slide-17
SLIDE 17

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Situation before Java Java’s Background Main Features

Primary Design Goals

Object-oriented Portable Supporting network computing Secure Easy to use/program

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 17

slide-18
SLIDE 18

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

1

Motivation for JVM

2

Virtual Machine Overview A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

3

A Quick Tour of the JVM

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 18

slide-19
SLIDE 19

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

T-Diagrams for Processor and Machine Code

586

x86 Processor

GTA x86

Program “GTA” (x86 code)

GTA x86 x86

“GTA” running on x86

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 19

slide-20
SLIDE 20

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

A Virtual Processor

Java programs are not executed directly, or compiled to native machine code, but compiled to virtual machine code

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 20

slide-21
SLIDE 21

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

A Virtual Processor

Java programs are not executed directly, or compiled to native machine code, but compiled to virtual machine code The virtual machine code is interpreted instruction-by-instruction by a program called the Java Virtual Machine (JVM)

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 21

slide-22
SLIDE 22

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

A Virtual Processor

Java programs are not executed directly, or compiled to native machine code, but compiled to virtual machine code The virtual machine code is interpreted instruction-by-instruction by a program called the Java Virtual Machine (JVM) The JVM is a program that read in virtual machine code in form of class files (often dynamically) and iterprets the instructions one after the other

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 22

slide-23
SLIDE 23

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

T-Diagrams for Execution of Jasmin Code

HelloWorld Java Java JVM x86 ✲ x86 HelloWorld JVM ✲ HelloWorld JVM JVM x86 x86

Compiling “HelloWorld” from Java to JVM code, and running the JVM code on a JVM running on an x86

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 23

slide-24
SLIDE 24

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

“Physical” Processors

Processor and main memory (often caches) Instruction counter points to memory location of instruction Registers keep track of intermediate computing results Instructions can write computing results to memory

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 24

slide-25
SLIDE 25

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Example

A typical x86 instruction: mov AX, 10; store the integer 10 in register AX Corresponding JVM instruction: bipush 10; push integer 10 onto operand stack istore_1; store top of stack to variable 1

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 25

slide-26
SLIDE 26

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Another Example

Adding two integer on x86: mov AX, 5; put 5 into AX mov BX, 10; put 10 into BX add; add numbers, result in AX Corresponding JVM instruction: bipush 5; push integer 5 onto operand stack bipush 10; push integer 10 onto operand stack iadd; add two numbers on top of stack istore_1; store top of stack to variable 1

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 26

slide-27
SLIDE 27

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

JVM Instructions

Arithmetic operations : iadd, lsub, frem Logical operations : iand, lor , ishl Numeric conversions : int2short , f2l Pushing constants : bipush, iconst−0 Stack manipulation : pop,dup Flow control : goto,ifne Managing local vars : astore, iload Arrays : aastore,aaload Objects : getfield , invokevirtual

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 27

slide-28
SLIDE 28

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Components of the Runtime System

Execution engine : virtual processor for executing byte code Memory manager : allocating memory for objects and arrays and performing garbage collection Error and exception manager : dealing with catching and throwing exceptions Native methods : handling methods provided in native machine code Thread interface : handling threads Class loader : (dynamically) loading Java classes from class files Security manager : verifying that classes are safe and resources are accessed in compliance with security policies

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 28

slide-29
SLIDE 29

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Main Advantages of Virtual Machines

Portability : Once compiled, the code runs on any architecture on which the virtual machine is available Security : It is easy to handle security requirements in software, by programming them within the virtual machine

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 29

slide-30
SLIDE 30

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Interpretation (Tcl in Tcl)

proc i n t e r p r e t e r ( ) { while {1} { set l i n e [ g e t n e x t l i n e ] set command [ g e t f i r s t w o r d $line ] set arguments [ a l l b u t f i r s t w o r d $line ] i f {$command == ” puts ” } { puts $arguments ; } i f . . . } }

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 30

slide-31
SLIDE 31

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Compilation (very simplified)

public static void compile ( String l i n e s [ ] , o u t f i l e ) { Scanner scanner = new Scanner ( l i n e s ) ; Parser parser = new Parser ( scanner ) ; SyntaxTree t = parser . getTree ( ) ; Code c = compiler . compile ( t ) ; writeCodeToFile ( o u t f i l e ) ; }

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 31

slide-32
SLIDE 32

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Virtual Machine (very simplified)

public static void execute ( byte bytecode [ ] ) { int pc = 0; / / program counter while ( true ) { int opcode = bytecode [ pc ] ; switch ( opcode ) { case OPC PUTS: . . . case OPC EXIT : return ; } }

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 32

slide-33
SLIDE 33

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Security

Virtual machine can check code before it gets executed (byte code verification) Virtual machine can check arguments of operations before they are used (runtime checks) Particular components such as memory system are in full control of the virtual machine; any level of security can be achieved, if desired

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 33

slide-34
SLIDE 34

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Efficiency

Slower than native code Much faster than interpretation Modern JVM implementations do just-in-time compilation If needed, Java can be compiled to native code

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 34

slide-35
SLIDE 35

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM A Virtual Processor Runtime System Virtual Machine Features and Drawbacks Security and Efficiency

Disadvantages

Complex instruction set to achieve security Hard to extend machine No parse tree! Compare Scheme’s quoting and eval

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 35

slide-36
SLIDE 36

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

1

Motivation for JVM

2

Virtual Machine Overview

3

A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 36

slide-37
SLIDE 37

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Example

public class HelloWorld { public static void main ( String args [ ] ) { System . out . p r i n t l n ( ” Hello World ! ” ) ; } }

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 37

slide-38
SLIDE 38

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

An Assembler for JVM Code

Jasmin is a compiler from a text format of JVM code to actual class files Provided free of change together with book “Java Virtual Machine”

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 38

slide-39
SLIDE 39

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

T-Diagrams for Execution via JVM

HelloWorld Jasmin Jasmin JVM x86 ✲ x86 HelloWorld JVM ✲ HelloWorld JVM JVM x86 x86

Compiling “HelloWorld” from Jasmin to JVM code, and running the JVM code on a JVM running on an x86

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 39

slide-40
SLIDE 40

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

What does a .class file look like?

ˆ@ˆCˆ@-ˆ@ˆN ˆ@ˆMˆ@ˆGˆAˆ@ˆPjava/lang/ObjectˆAˆ@ SourceFileˆAˆ@ˆF<init>ˆGˆ@ˆLˆAˆ@ˆDmainˆLˆ@ˆDˆ@ ˆAˆ@ˆDCodeˆAˆ@ˆV([Ljava/lang/String;)VˆAˆ@ˆC()VˆAˆ@ˆ HelloWorldˆGˆ@ˆBˆ@!ˆ@ˆEˆ@ˆMˆ@ˆ@ˆ@ˆ@ˆ@ˆBˆ@ˆAˆ@ˆDˆ@ ˆ@ˆAˆˆ@ˆ@ˆ@ˆQˆ@ˆAˆ@ˆAˆ@ˆ@ˆ@ˆE*<B7>ˆ@ˆA<B1>ˆ@ˆ@ˆ@ˆ@ˆ@ ˆBˆ@ˆBˆ@ˆ@ˆ@ˆQˆPˆB:ˆ@ˆPˆC:ˆAˆYˆ@ˆYˆA:ˆ@:ˆA<B1>ˆ@ˆ@ˆ@

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 40

slide-41
SLIDE 41

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Hex Dump of HelloWorld.class File

r-98-183-18-172:˜/Documents/jasmin-2.3 henz$ xxd HelloWorld.class 0000000: cafe babe 0003 002d 000e 0a00 0d00 0701 .......-........ 0000010: 0010 6a61 7661 2f6c 616e 672f 4f62 6a65 ..java/lang/Obje 0000020: 6374 0100 0a53 6f75 7263 6546 696c 6501 ct...SourceFile. 0000030: 0006 3c69 6e69 743e 0700 0c01 0004 6d61 ..<init>......ma 0000040: 696e 0c00 0400 0a01 0004 436f 6465 0100 in........Code.. 0000050: 1628 5b4c 6a61 7661 2f6c 616e 672f 5374 .([Ljava/lang/St 0000060: 7269 6e67 3b29 5601 0003 2829 5601 000c ring;)V...()V... 0000070: 4865 6c6c 6f57 6f72 6c64 2e6a 0100 0a48 HelloWorld.j...H 0000080: 656c 6c6f 576f 726c 6407 0002 0021 0005 elloWorld....!.. 0000090: 000d 0000 0000 0002 0001 0004 000a 0001 ................ 00000a0: 0008 0000 0011 0001 0001 0000 0005 2ab7 ..............*. 00000b0: 0001 b100 0000 0000 0900 0600 0900 0100 ................ 00000c0: 0800 0000 1d00 0200 0200 0000 1110 023a ...............: 00000d0: 0010 033a 0119 0019 013a 003a 01b1 0000 ...:.....:.:.... 00000e0: 0000 0001 0003 0000 0002 000b ............ r-98-183-18-172:˜/Documents/jasmin-2.3 henz$

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 41

slide-42
SLIDE 42

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Readable Text from .class File

Is there a way to get the JVM code for a given .class file?

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 42

slide-43
SLIDE 43

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Readable Text from .class File

Is there a way to get the JVM code for a given .class file? Yes, through a disassembler!

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 43

slide-44
SLIDE 44

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Readable Text from .class File

Is there a way to get the JVM code for a given .class file? Yes, through a disassembler! % javap -c HelloWorld

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 44

slide-45
SLIDE 45

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Readable Text from .class File

Is there a way to get the JVM code for a given .class file? Yes, through a disassembler! % javap -c HelloWorld This instruction disassembles the HelloWorld.class file into a textual representation of the JVM code (similar to Jasmin code)

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 45

slide-46
SLIDE 46

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Output of Disassembler

Compiled from "HelloWorld.j" public class HelloWorld extends java.lang.Object public HelloWorld(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: bipush 2 2: astore 4: bipush 3 6: astore 1 8: aload 10: aload 1 12: astore 14: astore 1 16: return

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 46

slide-47
SLIDE 47

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

T-Diagram for Disassembly of a .class File

HelloWorld JVM JVM Text x86 ✲ x86 HelloWorld Text

The “Text” resulting from the disassembly is similar to the Jasmin format and described in the Java Virtual Machine Specification

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 47

slide-48
SLIDE 48

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

HelloWorld in Jasmin

.class public HelloWorld .super java/lang/Object ; standard initializer ; (calls java.lang.Object’s initializer) .method public <init>()V aload_0 invokespecial java/lang/Object/<init>()V return .end method

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 48

slide-49
SLIDE 49

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

HelloWorld in Jasmin

; main() - prints out Hello World ; .method public static main([Ljava/lang/String;)V .limit stack 2 ; up to two items can be pushed ; push System.out onto the stack getstatic java/lang/System/out Ljava/io/PrintStream; ...

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 49

slide-50
SLIDE 50

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

HelloWorld in Jasmin

... ; push a string onto the stack ldc "Hello World!" ; call the PrintStream.println() method. invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V ; done return .end method

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 50

slide-51
SLIDE 51

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Puzzler Of The Week: Minute By Minute

public class Clock { public static void main ( String [ ] args ) { int minutes = 0; for ( int ms = 0; ms < 60∗60∗1000; ms++) i f (ms % 60∗1000 == 0) minutes ++; System . out . p r i n t l n ( minutes ) ; } } Question What does this program print?

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 51

slide-52
SLIDE 52

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Puzzler Of The Week: Minute By Minute

public class Clock { public static void main ( String [ ] args ) { int minutes = 0; for ( int ms = 0; ms < 60∗60∗1000; ms++) i f (ms % 60∗1000 == 0) minutes ++; System . out . p r i n t l n ( minutes ) ; } } Question What does this program print? Hint It’s not 60!

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 52

slide-53
SLIDE 53

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Next Few Weeks

Monday 25/1: Labs (playing with Java and JVM)

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 53

slide-54
SLIDE 54

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Next Few Weeks

Monday 25/1: Labs (playing with Java and JVM) Wednesday 27/1 lecture: Lists, Stacks, Queues I

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 54

slide-55
SLIDE 55

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Next Few Weeks

Monday 25/1: Labs (playing with Java and JVM) Wednesday 27/1 lecture: Lists, Stacks, Queues I Thursday 28/1: tutorials: Solutions for Assignment 1

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 55

slide-56
SLIDE 56

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Next Few Weeks

Monday 25/1: Labs (playing with Java and JVM) Wednesday 27/1 lecture: Lists, Stacks, Queues I Thursday 28/1: tutorials: Solutions for Assignment 1 Friady 29/1: Lists, Stacks, Queues II

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 56

slide-57
SLIDE 57

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Next Few Weeks

Monday 25/1: Labs (playing with Java and JVM) Wednesday 27/1 lecture: Lists, Stacks, Queues I Thursday 28/1: tutorials: Solutions for Assignment 1 Friady 29/1: Lists, Stacks, Queues II Assignment 2: Out on Wednesday 27/1, due Wednesday 2/2 6pm

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 57

slide-58
SLIDE 58

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Next Few Weeks

Monday 25/1: Labs (playing with Java and JVM) Wednesday 27/1 lecture: Lists, Stacks, Queues I Thursday 28/1: tutorials: Solutions for Assignment 1 Friady 29/1: Lists, Stacks, Queues II Assignment 2: Out on Wednesday 27/1, due Wednesday 2/2 6pm ...

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 58

slide-59
SLIDE 59

Motivation for JVM Virtual Machine Overview A Quick Tour of the JVM Hello World! HelloWorld in Jasmin

Next Few Weeks

Monday 25/1: Labs (playing with Java and JVM) Wednesday 27/1 lecture: Lists, Stacks, Queues I Thursday 28/1: tutorials: Solutions for Assignment 1 Friady 29/1: Lists, Stacks, Queues II Assignment 2: Out on Wednesday 27/1, due Wednesday 2/2 6pm ... 12/2: Midterm 1 (Java; Algorithm Analysis; Lists/Stacks/Queues; Trees)

CS1102S: Data Structures and Algorithms 02 B The Java Virtual Machine 59

slide-60
SLIDE 60