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

Post on 08-Jan-2018

230 views 0 download

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

Transcript of CS 598 Scripting Languages Design and Implementation 11. Byte code.

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.”

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.”

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).

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.

6

Context

7

Context (Cont.)

8

9

Class rectangle

• Point:

10

Class Rectangle

11

12

13

14

15

16

17

18

19

20

21

22

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)

24

25

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

27

28

29