: Iain D. Craig
: Virtual Machines
: Springer-Verlag
: 9781846282461
: 1
: CHF 141.10
:
: Hardware
: English
: 269
: Wasserzeichen/DRM
: PC/MAC/eReader/Tablet
: PDF
I love virtual machines (VMs) and I have done for a long time.If that makes me 'sad' or an 'anorak', so be it. I love them because they are so much fun, as well as being so useful. They have an element of original sin (writing assembly programs and being in control of an entire machine), while still being able to claim that one is being a respectable member of the community (being structured, modular, high-level, object-oriented, and so on). They also allow one to design machines of one's own, unencumbered by the restrictions of a starts optimising it for some physical particular processor (at least, until one processor or other). I have been building virtual machines, on and off, since 1980 or there­ abouts. It has always been something of a hobby for me; it has also turned out to be a technique of great power and applicability. I hope to continue working on them, perhaps on some of the ideas outlined in the last chapter (I certainly want to do some more work with register-based VMs and concur­ rency). I originally wanted to write the book from a purely semantic viewpoint.
"7 Register-Based Machines (S. 157-158)

7.1 Introduction

The virt ual machines described so far have all had th e same property: they use at least one stack and a collection of special-purpose regist ers. This has been taken as the way to const ruct virtu al machines. It is certainly a relatively quick and easy way to do it and it is a target machine for which it is particularly easy to generate code. There are, however, alternatives, the primary being that based on the Register- Transfer Model (RTM) . This is the model upon which most hardware processors are based.

There have been many machine simulato rs over the years and there are programming environments , particularly for real-time and embedded systems, that allow programs for one processor to be executed using a simulated processor. However, t he use of the RTM for virt ual machines is relat ively new; the largest implementation to date (2004) is the Parrot virt ual machine for Perl6. This chapte r is concerned with this alternative organisation for virt ual machines.

Section 7.2 is concerned with the arguments surrounding registerbased machines, both pro and con. Section 7.3 contains a description of one way to organise a regist er-based virt ual machine. Since the only really public register-based virtual machine of any st rength is t hat for Parrot , Section 7.4 is a description of Parrot s general organisation , while Section 7.5 contains a description of Parrots instruction set (the description is only partial because th e published documentation is, as yet , incomplete- th e best way to understand t he Parrot VM is to read its code). In Section 7.6, a DIY register machine is presented.

In Section 7.7, it is shown how the two-stack code for the simple ALEX programming language can be converte d (macro processed, in essence) into code for the DIY register-t ran sfer machine. The following section contains examples of such translat ions using a simple function. The correct ness of the translat ion from two-stack to register-machine code is the subject of Section 7.9 In Section 7.10 a more natural compilation of ALEX to register-machine code is presented. In the last section, Section 7.11 some extensions to the register machine are considered. 7.2 The Register-Transfer Model Almost all work on abstract machines has concentrated on stack-based architectures.

The SECD machine is the classic of this form, of course. The Pascal-S , Pascal P4, UCSD Pascal, Smalltalk and Java abstract machines are also stack-based. One good reason for constructing stack-based machines is that expressions can be directly evaluated on the stack . Stacks are also used to represent scope, thus making procedures and block structures easy to implement. Stacks are required to implement recursion , a feature of ISWIM, Algol60 and most modern programming languages . Stack-based architectures are good for compiler writers, therefore."
Copyright Page225
4225
Preface6
Acknowledgements8
Table of Contents8
98
1 Introduction8
148
1.1 Introduction14
1.2 Interpreters16
1.3 Landin's SEeD Machine16
1.4 The Organisation of this Book18
1.5 Omissions20
2 VMs for Portability: BCPL20
2420
2.1 Introduction24
2.2 BCPL the Language25
2.3 VM Operations28
2.4 The OeODE Machine30
2.5 OCODE Instructions and their Implementation30
3130
2.5.1 Expression Instructions31
2.5.2 Load and Store Instructions33
2.5.3 Instructions Relating to Routines33
2.5 .4 Control Instructions35
2.5.5 Directives36
2.6 The Intcode/Cintcode Machine36
3736
3 The Java Virtual Machine36
4036
3.1 Introduction40
3.2 JVM Organisation: An Overview41
3.2.1 The stack42
3.2.2 Method areas43
3.2.3 The PC register43
4443
3.2.4 Other structures45
3.3 Class Files45
3.4 Object Representation at Runtime53
3.5 Initialisation55
3.6 Object Deletion57
3.7 JVM Termination58
3.8 Exception Handling58
3.9 Instructions59
3.9.1 Data-manipulation instructions61
3.9.2 Control instructions64
3.9.3 Stack-manipulating instructions67
3.9.4 Support for object orientation67
6967
3.9.5 Synchronisation72
3.10 Concluding Remarks72
4 DIY VMs72
7372
4.1 Introduction73
4.2 ALEX74
4.2.1 Language Overview74
4.2.2 What the Virtual Machine Must Support77
4.2.3 Virtual Machine-Storage Structures78
4.2.4 Virtual Machine-Registers80
4.2 .5 Virtual Machine-Instruction Set82
4.2.6 An Example91
4.2.7 Implementation93
4.2.8 Extensions97
4.2.9 Alternatives100
4.2.10 Specification105
4.3 Issues108
4.3.1 Indirect and Relative Jumps109
4.3.2 More Data Types110
4.3.3 Higher-Order Routines118
4.3.4 Primitive Routines118
4.4 Concluding Remarks119
5 More Stack-Based VMs119
121119
5.1 Introduction121
5.2 A Simple Object-Oriented Language122
5.2.1 Language Overview122
5.2 .2 Virtual Machine-Storage Structures123
5.2.3 Virtual Machine-Registers125
5.2.4 Virtual Machine-Instruction Set125
5.2.5 Extensions128
5.2.6 Alternatives128
5.3 A Parallel Language129
5.3.1 Language Overview129
5.3.2 Virtual Machine-Storage Structures131
5.3.3 Virtual Machine-Registers133
5.3.4 Virtual Machine-Instruction Set134
5.3.5 Implementation136
5.3.6 Extensions138
5.3.7 Alternatives140
5.3.8 Issues141
5.4 Concluding Remarks141
5.4.1 Some Optimisations141
5.4.2 Combining the Languages142
6 Case Study: An Event-Driven Language142
143142
6.1 Introduction143
6.2 The Structure of Rules145
6.3 Events148
6.4 Execution Cycle148
6.5 Interpretation Rules150
6.6 VM Specification153
6.6.1 States and Notational Conventions154
6.6.2 Infra-Rule Transitions157
6.6.3 Extra-Rule Transitions160
6.6.4 VM-Only Transitions162
6.6.5 Introspective Operations163
6.7 Rule Equivalences165
6.8 Concluding Remarks166
7 Register-Bas