cs 598 scripting languages design and implementation 13. the deutsch-schiffman smalltalk- 80...

18
CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk-80 Implementation

Upload: mark-lyons

Post on 19-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

CS 598 Scripting Languages Design and Implementation

13. The Deutsch-Schiffman Smalltalk-80 Implementation

Page 2: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

2

Main references• [Kras83] Glenn Krasner (Ed.). Smalltalk-

80: Bits of History, Words of Advice. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.1983.

• [DesC84] L. Peter Deutsch and Allan M. Schiffman. 1984. Efficient implementation of the smalltalk-80 system. In Proceedings of the 11th ACM SIGACT-SIGPLAN symposium on Principles of programming languages (POPL '84). ACM, New York, NY, USA, 297-302.

• Keith Cooper’s slides:– http://www.cs.rice.edu/~keith/

512/2011/Lectures/L28ST80-1up.pdf

Page 3: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

3

The Smalltalk-80 system• Goal: acceptable performance on conventional machines.• Earlier implementation on the Xerox Dorado machine:

– The Xerox Alto is one of the first personal computers (a term that was already coined at the time), a general purpose computer designed for individual use (although not as a home computer). However it was expensive and, unlike modern personal computers, not based on a microprocessor.

– After the Alto, PARC developed more powerful workstations informally termed "the D-machines": Dandelion (least powerful, but the only to be made a product in one form), Dolphin; Dorado (most powerful; an ECL machine); and hybrids like the Dandel-Iris.

– The Dorado implementation used the Alto instruction set and extended it with microcode implementation of the Smalltalk virtual machine. “Keep the Alto macroinstruction set; implement the Smalltalk-80virtual machine mostly in microcode, and the remainder in Alto Code”[Kras83]

Page 4: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

4

Page 5: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

5

Page 6: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

6

Code translation

• The compiler translates Smalltalk code to v-code (virtual machine code that we called bytecode earlier).

• V-code is good for three reasons:– It is an intermediate representation so that we don’t

need a compiler for each target machine.– It is more compact than machine code.– Tools to examine the machine state (which in this

approach is the virtual machine) during execution become protable

Page 7: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

7

Code translation

• V-code has performance problems– No hardware interpreter (unless implementers

write a microprogramming).– Architecture difference from the traget machine

(e.g. stack vs. registers).– The virtual machine specification requires

expensive operations. The article mentions the need to performan reference counting operations everytime a varaible value is pushed onto the stack.

Page 8: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

8

Code translation

• Instead of using threaded code to implement an interpreter, the system dynamically translated the v-code onto n-code (native code).

• They do more than just macro expanding each v-code instruction.

Page 9: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

9

Code translation

• The system always compiles before execution.• They credit “B. Ramakrishna Rau. 1978. Levels

of representation of programs and the architecture of universal host machines. In Proceedings of the 11th annual workshop on Microprogramming (MICRO 11). IEEE Press, Piscataway, NJ, USA, 67-79” with the idea of dynamic translation.

Page 10: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

10

Page 11: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

11

“the only code that can directly access the parts of an object requiring mappingis code associated with that object’s class

Page 12: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

12

Page 13: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

13

Block contexts are

Page 14: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

14

Page 15: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

15

Hashing formulas for single mehtod cache (from [Kras83])

Page 16: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

16

Type prediction

• For a few special selectors like +, the translator generates in-line code for the common case along with the standard send code. For example. + generates a class check to verity that both argnments are small integers, native code for integer addition, and an overflow check on the result. If any of the checks fail, the send code is executed. This is a space-time tradeoff justified by measurements that indicate that the overwhelming majority ofarithmetic operations involve only small integers, even thoughthey are (in principle) polymorphic like all other operations inthe language.

Page 17: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

17

([Kras83])

Page 18: CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation

18