E-Book, Englisch, 269 Seiten
Craig Virtual Machines
1. Auflage 2010
ISBN: 978-1-84628-246-1
Verlag: Springer
Format: PDF
Kopierschutz: 1 - PDF Watermark
E-Book, Englisch, 269 Seiten
ISBN: 978-1-84628-246-1
Verlag: Springer
Format: PDF
Kopierschutz: 1 - PDF Watermark
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.
Autoren/Hrsg.
Weitere Infos & Material
1;Copyright Page
;4
2;Preface;6
3;Acknowledgements;8
4;Table of Contents
;9
5;1 Introduction
;14
5.1;1.1 Introduction;14
5.2;1.2 Interpreters;16
5.3;1.3 Landin's SEeD Machine;16
5.4;1.4 The Organisation of this Book;18
5.5;1.5 Omissions;20
6;2 VMs for Portability: BCPL
;24
6.1;2.1 Introduction;24
6.2;2.2 BCPL the Language;25
6.3;2.3 VM Operations;28
6.4;2.4 The OeODE Machine;30
6.5;2.5 OCODE Instructions and their Implementation
;31
6.5.1;2.5.1 Expression Instructions;31
6.5.2;2.5.2 Load and Store Instructions;33
6.5.3;2.5.3 Instructions Relating to Routines;33
6.5.4;2.5 .4 Control Instructions;35
6.5.5;2.5.5 Directives;36
6.6;2.6 The Intcode/Cintcode Machine
;37
7;3 The Java Virtual Machine
;40
7.1;3.1 Introduction;40
7.2;3.2 JVM Organisation: An Overview;41
7.2.1;3.2.1 The stack;42
7.2.2;3.2.2 Method areas;43
7.2.3;3.2.3 The PC register
;44
7.2.4;3.2.4 Other structures;45
7.3;3.3 Class Files;45
7.4;3.4 Object Representation at Runtime;53
7.5;3.5 Initialisation;55
7.6;3.6 Object Deletion;57
7.7;3.7 JVM Termination;58
7.8;3.8 Exception Handling;58
7.9;3.9 Instructions;59
7.9.1;3.9.1 Data-manipulation instructions;61
7.9.2;3.9.2 Control instructions;64
7.9.3;3.9.3 Stack-manipulating instructions;67
7.9.4;3.9.4 Support for object orientation
;69
7.9.5;3.9.5 Synchronisation;72
7.10;3.10 Concluding Remarks;72
8;4 DIY VMs
;73
8.1;4.1 Introduction;73
8.2;4.2 ALEX;74
8.2.1;4.2.1 Language Overview;74
8.2.2;4.2.2 What the Virtual Machine Must Support;77
8.2.3;4.2.3 Virtual Machine-Storage Structures;78
8.2.4;4.2.4 Virtual Machine-Registers;80
8.2.5;4.2 .5 Virtual Machine-Instruction Set;82
8.2.6;4.2.6 An Example;91
8.2.7;4.2.7 Implementation;93
8.2.8;4.2.8 Extensions;97
8.2.9;4.2.9 Alternatives;100
8.2.10;4.2.10 Specification;105
8.3;4.3 Issues;108
8.3.1;4.3.1 Indirect and Relative Jumps;109
8.3.2;4.3.2 More Data Types;110
8.3.3;4.3.3 Higher-Order Routines;118
8.3.4;4.3.4 Primitive Routines;118
8.4;4.4 Concluding Remarks;119
9;5 More Stack-Based VMs
;121
9.1;5.1 Introduction;121
9.2;5.2 A Simple Object-Oriented Language;122
9.2.1;5.2.1 Language Overview;122
9.2.2;5.2 .2 Virtual Machine-Storage Structures;123
9.2.3;5.2.3 Virtual Machine-Registers;125
9.2.4;5.2.4 Virtual Machine-Instruction Set;125
9.2.5;5.2.5 Extensions;128
9.2.6;5.2.6 Alternatives;128
9.3;5.3 A Parallel Language;129
9.3.1;5.3.1 Language Overview;129
9.3.2;5.3.2 Virtual Machine-Storage Structures;131
9.3.3;5.3.3 Virtual Machine-Registers;133
9.3.4;5.3.4 Virtual Machine-Instruction Set;134
9.3.5;5.3.5 Implementation;136
9.3.6;5.3.6 Extensions;138
9.3.7;5.3.7 Alternatives;140
9.3.8;5.3.8 Issues;141
9.4;5.4 Concluding Remarks;141
9.4.1;5.4.1 Some Optimisations;141
9.4.2;5.4.2 Combining the Languages;142
10;6 Case Study: An Event-Driven Language
;143
10.1;6.1 Introduction;143
10.2;6.2 The Structure of Rules;145
10.3;6.3 Events;148
10.4;6.4 Execution Cycle;148
10.5;6.5 Interpretation Rules;150
10.6;6.6 VM Specification;153
10.6.1;6.6.1 States and Notational Conventions;154
10.6.2;6.6.2 Infra-Rule Transitions;157
10.6.3;6.6.3 Extra-Rule Transitions;160
10.6.4;6.6.4 VM-Only Transitions;162
10.6.5;6.6.5 Introspective Operations;163
10.7;6.7 Rule Equivalences;165
10.8;6.8 Concluding Remarks;166
11;7 Register-Based Machines
;168
11.1;7.1 Introduction;168
11.2;7.2 The Register-Transfer Model;169
11.3;7.3 Register Machine Organisation;172
11.4;7.4 Parrot-General Organisation;176
11.5;7.5 Parrot Instruction Set;179
11.5.1;7.5.1 Control instructions;180
11.5.2;7.5.2 Data management instructions;180
11.5.3;7.5.3 Register and stack operations;181
11.6;7.6 DIY Register-Based Virtual Machine;182
11.6.1;7.6.1 Informal Design;183
11.6.2;7.6.2 Extensions;187
11.6.3;7.6.3 Transition Rules;188
11.7;7.7 Translating ALEXVM into RTM;194
11.8;7.8 Example Code;197
11.9;7.9 Correctness of the Translation;197
11.10;7.10 More Natural Compilation;207
11.11;7.11 Extensions;211
12;8 Implementation Techniques
;212
12.1;8.1 Stack-Based Machines;213
12.1.1;8.1.1 Direct Implementation;213
12.1.2;8.1.2 Translation;214
12.1.3;8.1.3 Threaded Code;218
12.2;8.2 Register Machines;220
12.2.1;8.2.1 Register sets;221
12.2.2;8.2.2 Addressing;221
12.2.3;8.2.3 Translation to Another VM;223
12.3;8.3 Using Transitions;223
12.4;8.4 Concluding Remarks;224
13;9 Open Issues
;226
13.1;9.1 Security;226
13.2;9.2 New Languages;227
13.3;9.3 Typed Instruction Sets and Intermediate Codes;227
13.4;9.4 High-Level Instructions;229
13.5;9.5 Additivity and Replacement;229
13.6;9.6 Compiler Correctness;229
13.7;9.7 Dynamic Code Insertion;230
13.8;9.8 Instrumentation;231
13.9;9.9 Including more Information about Source Code;232
13.10;9.10 Integration with Databases;233
13.11;9.11 Increased Inter-Operability;233
13.12;9.12 Code Mobility;234
13.13;9.13 Small Platforms;235
13.14;9.14 Real-Time VMs;237
13.15;9.15 Code Morphing;238
13.16;9.16 Greater Optimisation;238
13.17;9.17 Operating System Constructs;239
13.18;9.18 Virtual Machines for more General Portability;240
13.19;9.19 Distributed VMs;240
13.20;9.20 Objects and VMs;240
13.21;9.21 Virtual VMs;241
13.22;9.22 By Way of a Conclusion;242
14;A Compiling ALEX
;243
14.1;A.1 Introduction
;243
14.2;A.2 Notational Conventions;243
14.3;A.3 Compilation Rules;245
15;B Harrison Machine Compilation Rules
;251
15.1;B.1 Introduction;251
15.2;B.2 Compilation Rules;251
16;C Harrison Machine Instruction Set
;266
17;References;269
18;Index;272
"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."




