29
CS 598 Scripting Languages Design and Implementation 11. Byte code

CS 598 Scripting Languages Design and Implementation 11. Byte code

Embed Size (px)

DESCRIPTION

Byte codes (From Wikipedia) [cont.] Their use: – Ease interpretation – Enable portability. “Since bytecode instructions are processed by software, they may be arbitrarily complex, but are nonetheless often akin to traditional hardware instructions; virtual stack machines are the most common, but virtual register machines have also been built.” 3

Citation preview

Page 1: CS 598 Scripting Languages Design and Implementation 11. Byte code

CS 598 Scripting Languages Design and Implementation

11. Byte code

Page 2: CS 598 Scripting Languages Design and Implementation 11. Byte code

2

Byte codes(From Wikipedia)

• “Bytecode, also known as p-code (portable code), is a form of instruction set designed for efficient execution by a software interpreter.”

• “Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normally numeric addresses) which encode the result of parsing and semantic analysis of things like type, scope, and nesting depths of program objects.”

• “They therefore allow much better performance than direct interpretation of source code.”

Page 3: CS 598 Scripting Languages Design and Implementation 11. Byte code

3

Byte codes(From Wikipedia) [cont.]

• Their use:– Ease interpretation– Enable portability.

• “Since bytecode instructions are processed by software, they may be arbitrarily complex, but are nonetheless often akin to traditional hardware instructions;

• virtual stack machines are the most common, but virtual register machines have also been built.”

Page 4: CS 598 Scripting Languages Design and Implementation 11. Byte code

4

• In computer programming, a p-code machine, or portable code machine is a virtual machine designed to execute p-code (the assembly language of a hypothetical CPU). This term is applied both generically to all such machines (such as the Java Virtual Machine and MATLAB precompiled code), and to specific implementations, the most famous being the p-Machine of the Pascal-P system, particularly the UCSD Pascal implementation.

• Although the concept was first implemented circa 1966 (as O-code for BCPL and P - a code for the Euler Language), the term p-code first appeared in the early 1970s. Two early compilers generating p-code were the Pascal-P compiler in 1973, by Nori, Ammann, Jensen, Hageli, and Jacobi, and the Pascal-S compiler in 1975, by Niklaus Wirth.

• Programs that have been translated to p-code are interpreted by a software program that emulates the behavior of the hypothetical CPU. If there is sufficient commercial interest, a hardware implementation of the CPU specification may be built (e.g., the Pascal MicroEngine or a version of the Java processor).

Page 5: CS 598 Scripting Languages Design and Implementation 11. Byte code

5

Smalltalk Bytecod(From Part IV of the BlueBook)

• When a method is added to a class, the compiler is called to translate the method into bytecode.

• Theresulting code also contains a vector of literals (literal frame) that seerve the purpose of symbolic addresses.

• The header contains the number of arguments and temporaries.

Page 6: CS 598 Scripting Languages Design and Implementation 11. Byte code

6

Context

Page 7: CS 598 Scripting Languages Design and Implementation 11. Byte code

7

Context (Cont.)

Page 8: CS 598 Scripting Languages Design and Implementation 11. Byte code

8

Page 9: CS 598 Scripting Languages Design and Implementation 11. Byte code

9

Class rectangle

• Point:

Page 10: CS 598 Scripting Languages Design and Implementation 11. Byte code

10

Class Rectangle

Page 11: CS 598 Scripting Languages Design and Implementation 11. Byte code

11

Page 12: CS 598 Scripting Languages Design and Implementation 11. Byte code

12

Page 13: CS 598 Scripting Languages Design and Implementation 11. Byte code

13

Page 14: CS 598 Scripting Languages Design and Implementation 11. Byte code

14

Page 15: CS 598 Scripting Languages Design and Implementation 11. Byte code

15

Page 16: CS 598 Scripting Languages Design and Implementation 11. Byte code

16

Page 17: CS 598 Scripting Languages Design and Implementation 11. Byte code

17

Page 18: CS 598 Scripting Languages Design and Implementation 11. Byte code

18

Page 19: CS 598 Scripting Languages Design and Implementation 11. Byte code

19

Page 20: CS 598 Scripting Languages Design and Implementation 11. Byte code

20

Page 21: CS 598 Scripting Languages Design and Implementation 11. Byte code

21

Page 22: CS 598 Scripting Languages Design and Implementation 11. Byte code

22

Page 23: CS 598 Scripting Languages Design and Implementation 11. Byte code

23

Slim Binaries

• Michael Franz, Thomas Kistler:Slim Binaries. Commun. ACM 40(12): 87-94 (1997)

• Thomas Kistler, Michael Franz:A Tree-Based Alternative to Java Byte-Codes. International Journal of Parallel Programming 27(1): 21-33 (1999)

Page 24: CS 598 Scripting Languages Design and Implementation 11. Byte code

24

Page 25: CS 598 Scripting Languages Design and Implementation 11. Byte code

25

Page 26: CS 598 Scripting Languages Design and Implementation 11. Byte code

26

Virtual machineStack vs. registers

• Yunhe Shi, Kevin Casey, M. Anton Ertl, and David Gregg. 2008. Virtual machine showdown: Stack versus registers. ACM Trans. Archit. Code Optim. 4, 4, Article 2 (January 2008), 36 pages. DOI=http://dx.doi.org/10.1145/1328195.1328197

Page 27: CS 598 Scripting Languages Design and Implementation 11. Byte code

27

Page 28: CS 598 Scripting Languages Design and Implementation 11. Byte code

28

Page 29: CS 598 Scripting Languages Design and Implementation 11. Byte code

29