An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes
Paper · 1989 · Craig Chambers, David Ungar and Elgin Lee
Summary
In SELF, asking a point for its horizontal coordinate can retrieve a stored value or run a calculation. The caller sends the same message either way. This lets a method for printing points work with both Cartesian and polar coordinates, even though the objects store different data. It also gives the implementation a difficult job. An operation as simple as reading a coordinate may require searching for a slot, following inheritance links, and deciding whether to execute code. Since SELF uses prototypes in place of classes and asks programmers for no type declarations, the compiler needs another way to find out when it can dispense with that work.
The authors give the compiler a starting point in the way objects are stored. A prototype and its copies can share a map that describes their slots, their fixed contents, and the locations of values that can vary. The compiler generates native code on demand and can produce several versions of a method, each for a particular receiver map. Within a version, knowing the receiver’s map often makes it possible to resolve messages in advance. A read can become a load, a write can become a store, and a short method can be inserted directly into its caller. The compiler also keeps separate paths where it knows different facts about a value. For common operations, it can introduce a run-time test that supplies a missing fact and retain ordinary dispatch for the cases outside the prediction.
On the Stanford integer benchmarks, the median reported ratio of Smalltalk time to SELF time is 1.8 for direct translations from C and 2.2 for the more object-oriented SELF versions. On the Richards operating-system simulation, the ratio is 2.8. Optimized C finishes every benchmark sooner. The paper also explains how the implementation supports interactive changes and stack inspection. Compiled methods record which definitions they rely on, so edits can invalidate affected code selectively. Separate records let the system display calls that were inlined and therefore have no physical stack frame of their own. Stack display worked in the implementation described, while breakpoints and the handling of edits that invalidate currently executing methods remained unfinished.
Deep dive: An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes
How SELF uses shared object maps and a compiler that specializes methods at run time to make prototypes and dynamic message dispatch efficient. · about 32 minutes to read
The problem and its context
One message can mean a read or a computation
In code and programming languages, an object can expose an operation while keeping its representation private. SELF applies this principle even to operations that would ordinarily count as variable accesses. An object consists of named slots. When it receives a message, the system looks for a slot whose name matches the message. A slot containing an ordinary object yields that object. A slot containing a method causes the method to run. The sender can use the same expression for either operation.
The paper’s points make this concrete. A Cartesian point has an x slot containing the coordinate itself. In the illustrated object, that value is 3. A polar point stores its distance and angle. When asked for x, it inherits a method that calculates the coordinate, producing 1.25 in the paper’s example. A shared printing method asks its receiver for x and y and prints the results. Each point supplies the coordinates in the way appropriate to its representation, and the printing method can be shared without branching on how a point stores them.
A parent slot refers to another object that can supply behavior. If lookup fails to find the requested name locally, it can continue through the receiver’s parents and their ancestors. SELF’s multiple inheritance rules determine how competing matches are resolved. In the point example, a Cartesian point has a parent that supplies operations related to its coordinate representation. A polar point has a different parent for its own representation. Both routes reach common point behavior, including printing and addition. The parent objects that hold shared behavior are called traits in the example.
State changes follow the same principle as reads. An assignable data slot has a corresponding assignment slot. Sending the assignment message invokes the assignment primitive, an operation supplied by the implementation, to put the argument in the data slot. A slot without an assignment counterpart is read-only to a running program. Parent slots can be assignable as well. An object can therefore change where it inherits behavior as its state changes. The paper gives the example of a collection that could inherit different behavior when empty. For a compiler, that possibility matters because a route through the parent graph can depend on the contents of a writable slot.
Prototypes and methods pose different storage and execution problems
SELF creates objects by cloning existing objects. The copy is shallow, so object references in slots carry over without recursively copying their targets. A running program commonly clones an object and changes the values of its assignable slots. It takes a special reflective operation to make a structural change of the kind a programmer might request while editing an object. This difference between updating a value and changing an object’s structure is what makes a compact implementation possible.
A class-based system has an obvious place to put descriptions shared by many objects. The class can hold information about layout, inherited behavior, and methods, leaving each instance to store the values that belong to it. In a straightforward prototype implementation, an object could carry all the information necessary to describe itself. That would duplicate names, slot descriptions, and references across copies, even when the objects differed only in a few values. A prototype language needs to let individual objects change their structure. Its implementation can still take advantage of structure that happens to be shared.
Methods also fit into SELF’s object rules. A method is an object with code. When called, it acts as a prototype for an activation record, the state of a particular invocation. The activation receives the original message receiver in its self slot and the supplied values in its argument slots. Since self is a parent slot, lookup in the activation can continue to the receiver. A method inherited from shared point traits can thus send x to the particular point being printed. Knowing the location of the method definition and knowing the identity or layout of its receiver are different pieces of information.
Blocks add another source of late decisions. A block is an object with a value method that runs in the context of its lexical surroundings, meaning the method or block in which it was written. Its invocation inherits the enclosing self. A block can also perform a non-local return, which leaves the enclosing ordinary method and returns to that method’s caller. These rules let SELF express selection and iteration through ordinary messages that invoke blocks. In a direct implementation, a conditional can consequently require allocating block objects, finding the selection method, calling it, and then invoking a block.
What earlier Smalltalk implementations gave the authors
SELF borrows dynamic typing and blocks from Smalltalk. The authors describe the freedom from type declarations as valuable during exploratory programming, when objects and methods can change rapidly. The difficulty is that the compiler begins with little explicit type information. It can know the type of a literal, but in a general compiled method it may have little information about the receiver, arguments, or values read from writable slots.
The Deutsch–Schiffman implementation of Smalltalk already translated byte-coded methods to machine code on demand. It also used inline caching. A call site can take a shorter dispatch path when the receiver matches the case it has cached. This helps when the same message at the same site repeatedly goes to receivers of a compatible type. As described by the SELF authors, the implementation compiled a single native version of a source method. Different receiver classes could inherit that method, so the compiler could still lack a definite receiver class when compiling its body. SELF adopts on-demand translation and inline caching, then changes what gets compiled together under one version.
The paper also describes Smalltalk’s use of special byte codes for frequent operations. The parser could turn particular Boolean and loop messages into branches and open-code the blocks. Identity comparison had its own treatment, and arithmetic such as + could use a primitive for integer receivers and dispatch normally in other cases. These choices sped up important operations, especially in an interpreter. They also placed restrictions on the permissible receivers and block expressions of some control messages, and made some source definitions ineffective when changed. The SELF authors wanted machine code with comparably direct operations while still letting message lookup and the editable definitions determine what they meant.
Another line of work added type information through declarations. Atkinson’s Hurricane compiled an annotated subset of Smalltalk, while Johnson’s TS Typed Smalltalk used fully annotated programs. The paper also discusses the difficulty of inferring useful types automatically in Smalltalk. The question for SELF is whether an implementation can recover enough precise information from the objects and the execution itself. The authors pursue this locally. They start with a receiver that has actually entered a method and use the facts available to compile a version for that receiver’s kind of object.
The method, step by step
Share the layout and keep each object’s own state
The first step is to identify what a clone can share with its prototype. The paper calls the prototype and the copies that differ only in their assignable values a clone family. Each member stores its own writable values and a reference to the family’s map. Here, a map is a runtime record describing an object layout and its fixed properties. It is internal to the implementation. A SELF programmer still works with objects, slots, and parents.
A map records the slot name and whether the slot is a parent. For a constant slot, the map stores the referenced object itself. For an assignable data slot, it stores the offset where the current value can be found in the object. An assignment slot identifies the corresponding data slot. Parent slots also carry priority information used by lookup. If the objects are methods, the map contains a reference to the byte-coded representation of the method’s source. Copies of a method’s activation can therefore share its code while carrying their own execution state.
Consider the Cartesian points. Each stores its current x and y values. The shared map says where those values are, identifies the assignment operations for them, and contains the constant parent reference. Thus the compiler can use a map to answer two kinds of question. It can determine where to find a particular value in a point, and it can know which parent to search for an inherited operation. Reading the current x needs the particular point. Following the constant parent can be resolved from the map.
Maps are immutable with respect to the structural information they describe. If the programmer changes an object’s format or replaces a value held in a constant slot, the resulting object gets a new map. Other family members can keep their original map. Assigning a fresh coordinate to an existing writable slot leaves the layout intact. Changing the layout or the reference in a constant parent slot changes information that compiled code could have relied on. The distinction between these operations carries from storage all the way through to invalidation.
The paper illustrates the storage saving with a schematic point representation. A standalone record that carries every slot name and its value would require at least 10 words per point in that example. Sharing its descriptions gives an illustrated per-point cost of 3 words, covering the coordinates and the reference to the map. The actual heap layout includes a separate header word. The paper calculates the full clone-family cost for the described data objects as follows.
W = (2 + a)n + 5s + 8
W is the total number of storage words. n is the number of objects in the family, s is the number of slots described by the map, and a is the number of assignable data slots in each object. The 2 denotes the two header words of an object. The term 5s covers the five words in each slot description, and 8 accounts for the fixed words in the shared map in this layout.
For Cartesian points, the paper substitutes a layout with the two coordinate slots, their two assignment slots, and a parent slot.
W = 4n + 33
W again counts total storage words and n counts the points sharing the map. The 4 is the storage per point in the full layout, including its header words and writable coordinates. The 33 is the shared map’s cost. The shared part is paid once for the family, which is what puts a large family on similar footing to instances sharing a class description.
Lay out the heap so references can be scanned directly
The memory system also has to find references quickly. A garbage collector may need to find pointers into a region whose objects are being moved. A reflective change that resizes an object may require redirecting references to its new address. A browser may ask which other objects refer to a particular object. These operations all benefit from scanning a large region without decoding each object separately.
SELF uses tagged words. In the described layout a word is 32 bits, with a low-order 2-bit tag and 30 remaining bits interpreted according to that tag. The tag distinguishes immediate numbers, references to heap objects, and the mark at the beginning of an object. An immediate integer can be held directly in a word. Some integer operations, including addition, subtraction, and comparison, can work on tagged values without first converting them. Heap references carry addresses directly, so the system need not consult an object table to follow them.
Packed byte arrays complicate scanning because arbitrary bytes can resemble tagged references. The paper describes Smalltalk scanners that handle the problem by decoding each object’s header, determining whether its contents can include references, and advancing by the object’s size. SELF divides each garbage-collection space into a region for references and a region for packed bytes. The regions grow toward each other. A scanner can stay within the reference region and inspect it word by word. Packed byte data are outside the range it scans, and the scanner need not interpret each header to decide how far to advance.
The implementation places a temporary sentinel just past the end of the scan. The sentinel is chosen to satisfy the scan’s matching criterion, so the loop can defer testing for the boundary until it finds a match. If the caller also wants to identify the object that owns a matching word, it can work backward from the match until it finds the tagged mark word. Keeping these operations separate lets a search for matching references use a simple loop even when the caller ultimately needs the objects that hold them.
The object header contains the mark and a tagged map reference. The mark carries information for scavenging and hashing. Maps themselves have headers and share a map that describes maps. The system uses generational scavenging, which organizes objects by age for reclamation, with tenuring decisions informed by object survival and a mark-and-sweep collector for tenured objects. Maps in new-space are linked so the system can finalize unreachable maps after a scavenge. That cleanup also matters to the compiler because maps serve as anchors for information about which generated code depends on them.
Parse once and compile when a receiver arrives
When source enters SELF, the parser converts a method into a byte code object. It contains a packed array of instructions and a separate object array for literals and message names. A byte has a 3-bit opcode and a 5-bit index field. An index-extension instruction allows the encoding to refer beyond the directly addressable part of the object array. Storing a method in this form avoids parsing its text afresh every time a new compiled version is needed.
The byte codes describe a stack-oriented execution. They cover obtaining literals or self, sending messages, and returning from an enclosing method. The send forms include a send with a supplied receiver, a send to self, and sends delegated through parents. In the point printing method, the byte codes can describe sending x, sending print to its result, printing the punctuation, and then obtaining and printing y. Whether x loads a coordinate or runs a conversion remains a question for lookup and compilation.
Primitive calls use the ordinary send representation in byte code. Their source names begin with an underscore, and a caller can name a failure block using IfFail:. If the primitive fails, it can pass an error code to that block. This makes conditions such as an invalid operand or arithmetic overflow part of the operation the compiler has to preserve. The byte code can be read as an instruction for an interpreter, but the implementation described uses it to generate native code on demand. The method applies to executing programs, without a separate training dataset.
When a source method first runs for a receiver type, the compiler can build a version for that type. For ordinary objects the receiver’s map provides the relevant type information. An inherited method can therefore have separate compiled forms for objects with different maps. The same source method stays available to all its callers. The generated version carries information the general source cannot assume about every possible receiver.
From SELF source to specialized native code
The steps in order.
Resolve messages and inline the operation actually found
Knowing the receiver at compile time can move lookup out of the program’s execution path. If the slot contains a short, nonrecursive method, the compiler can put its body directly into the caller. If it contains a constant, the compiler can use the constant. For assignable data, it can issue a load from the known offset. For an assignment slot, it can issue a store to the corresponding field. Each transformation depends on the result of lookup. The same message name can lead to different machine code when lookup finds a different kind of slot.
Inline expansion also applies to the value method of a block when it is suitable for inlining. Once a block’s body is present in the caller, the compiler may discover that the program has no further use for the block object on that path. It can then omit allocation of that object. This matters for control structures because a block may be present solely to express a branch that the generated code can already implement directly.
The paper traces these steps with min:, a method that compares its receiver with an argument using < and sends ifTrue:False: to the result. The two supplied blocks yield the receiver or the argument. The paper treats accesses to local argument slots as register accesses in the walkthrough, allowing it to show what happens to the remaining operations. A general implementation of the method would have to dispatch the comparison based on the actual receiver. The compiler instead begins with an integer-specific version in which the receiver of < is already known.
Looking up < for integer receivers exposes a method that calls _IntLTPrim:IfFail:. Inlining that method removes the dispatch of < and reveals the primitive call and its failure block. This is important to the authors’ account of extensibility. The definition that connects the message < to the integer primitive comes from the program’s methods. If the definition changes, the saved dependency lets the system discard code that relied on it. The transformation follows the current definition at the time of compilation.
Primitive inlining is a separate step. The implementation can compile certain primitive operations, such as frequent integer arithmetic or comparisons and array operations, directly into machine instructions. If the operands to a side-effect-free primitive are all known at compile time, the compiler can evaluate it then and use the result. This is constant folding. The distinction between inlining a method and generating instructions for a primitive explains how SELF can have a built-in implementation for an integer comparison while keeping the programmer-visible comparison method editable.
For min:, the compiler starts with a known integer receiver and still needs to check the argument. The open-coded primitive tests the argument’s tag. An integer argument can be compared directly with the receiver. That comparison produces the known result true or false on its respective branch. If the argument fails the integer test, the code invokes the comparison’s failure block. Its return value can be unknown to the compiler. The same call to ifTrue:False: would, at this point, have to accommodate those distinct possibilities.
Delay a control-flow merge to retain type information
At a merge, several execution paths converge on the same instruction. The compiler can have a precise fact on an incoming path and lose the ability to use it once that path joins another. In the integer comparison, one path carries true, another carries false, and the failure path carries a value supplied by the failure block. A single send compiled after the merge cannot assume any particular one of these receivers.
Message splitting changes where the merge takes place. The compiler copies a send onto the incoming paths and lets control merge afterwards. The copy that receives true can be compiled by looking up ifTrue:False: for that object. Its definition invokes the first block. The copy that receives false invokes the other block. On the failure path, the compiler can keep a send that dispatches on whatever the failure block returns. The compiler emits several versions of the operation, and a particular invocation follows only its own path.
Once the two Boolean methods are inlined, the compiler sees which value send each makes. It can inline the selected block and discover that the objects representing the two argument blocks are no longer needed on those paths. What remains is code to compare the values and choose a result. A language-level conditional assembled from method calls and blocks has become a small stretch of branching machine code through ordinary lookup, inlining, and elimination of unused allocations.
The paper treats splitting as a finer-grained counterpart to customized compilation. Customization gives the entry to a method a definite receiver type. Splitting gives part of the method facts that are definite only along a particular path. The first implementation described is local in the information it can exploit. It splits a message using knowledge about the result of the preceding message. The wider analysis discussed for the next implementation is a separate development.
Introduce a test where the compiler has only a prediction
The path through the failure block still illustrates a case in which the compiler lacks a receiver type for ifTrue:False:. The compiler can use a rule about common message usage to predict that this receiver will be Boolean. Its predictions are tied to particular message names. The examples in the paper include integer receivers for arithmetic or comparisons and the objects true and false for the conditional.
A prediction gives the compiler a reason to emit a test. For the remaining conditional in min:, it inserts comparisons with true and false. On a path where a comparison succeeds, the receiver is known and the compiler can use splitting and inlining again. For a value that matches neither, the original message still runs through ordinary dispatch. Thus an object with its own definition of the conditional can receive it even when the compiler predicted the common Boolean case.
The paper’s final graph for the integer version leaves two simple compare-and-branch sequences on the path for two integers. The argument tag is checked, and then the values are compared to select the result. If the primitive takes its failure path, the code still evaluates the failure block and handles its return through the guarded Boolean cases or general dispatch. The point of this example is that the fast path follows from a chain of small decisions. Customization reveals the comparison method, primitive inlining exposes the outcome branches, splitting keeps their facts separate, and block inlining removes allocations that no longer serve a purpose.
Record the assumptions that an edit can change
The compiler’s direct loads, embedded constants, and inlined methods are only valid while their underlying assumptions hold. The interactive system therefore keeps two-way links between cached native code and the map information used to build it. If an edit changes relevant information, the runtime follows the links and invalidates the affected compiled methods. The next time a version is needed, the compiler uses the current definitions.
The links cover the method definition being compiled and the slots found for inlined messages. A link also records a parent slot traversed during compile-time lookup, because replacing its reference can lead to another definition. Finally, there is a dependency when lookup searches an object and fails to find a matching slot. This last case is easy to overlook. If an inherited operation was used because an earlier object lacked an override, adding that override can invalidate the lookup even though the inherited definition has never changed. The map provides an anchor for dependencies on that failed search.
Changing or removing an existing slot is handled through the corresponding slot’s dependents. Adding a slot calls for checking the map’s dependents. The links form circular lists and are doubly linked to support removal when generated code is invalidated or a map is reclaimed. The code object also keeps track of embedded object references in its native instructions. This allows the collector to update those references if the objects move. The resulting code cache holds machine instructions together with the information needed to keep them usable in a changing heap and program.
Preserve the source-level call stack
Inlining changes the relation between what the programmer wrote and what the machine executes. A caller and several inlined callees can share one physical stack frame. A source-level argument can live in a register, at an offset on the stack, or as a constant carried by the metadata. In the paper’s account, the debugger presents the state as it would appear in byte-coded execution. It needs enough information to recover the logical calls from the actual frames.
The compiler records every scope it generates within a compiled method, including inlined methods and blocks. A scope record describes its position in the call chain and the locations or known values of its slots. A block scope also has a link to its lexical surroundings. In the min: illustration, the original receiver and argument occupy registers, while several values used by the inlined conditional are known statically. The debugger can show these values even when native execution never allocated a separate frame for the conditional.
The compiler also records a mapping between machine program counters and byte code positions within scopes. Several byte codes can lead to the same machine address when optimization removes intermediate work. One byte code can also correspond to several addresses when a send is split. To reconstruct the position of a halted execution, the debugger finds the latest mapped address at or before the machine’s current program counter and then the latest byte code associated with that mapped address. Scope records supply the surrounding logical calls.
The mapping was designed to work in the reverse direction for breakpoints. A byte code duplicated by splitting could require breakpoints at multiple machine addresses. A source-level step across byte codes that share an address might appear to advance even when there is no machine instruction between them. The system demonstrated stack reconstruction through a primitive that displayed the virtual stack and resumed execution. The mapping described capabilities that an interactive breakpoint facility could use, while the running implementation stopped at stack display.
Experiments and results
The language benchmarks and how they were timed
The primary experiment compares the first-generation SELF implementation with ParcPlace Smalltalk-80 and with code generated by Sun’s optimizing C compiler. The benchmark machine is a Sun-4/260. The implementation also ran on Sun-3 hardware, which the paper uses for a separate memory-scanning comparison. Keeping the hardware and the task attached to each result matters because the paper reports both whole-program timings and a low-level scanning rate.
The program workloads include the Stanford integer benchmarks and Richards, an operating-system simulation. The authors translated the C programs into Smalltalk and SELF. They also adapted sumToTest and recurseTest from Smalltalk benchmarks. sumToTest iterates through a range and accumulates a total, exercising repeated control and arithmetic. Its test uses an upper bound of 10000. recurseTest starts with 14 and exercises branching and recursive sends. These small tests sit alongside the larger simulation and the suite of integer programs. There is no training or held-out split. The comparison is between implementations running versions of named programs.
For much of the Stanford suite, the authors made a second kind of SELF translation. To express the program in a more object-oriented way, the SELF-OO column shows each C function’s first argument serving as the receiver for its corresponding SELF method. The paper marks unchanged programs with parentheses in that column. The timings thus support two comparisons. The direct translations compare language systems on closely related program structures. The SELF-OO versions show how the same SELF implementation performs when the source places more of the work on receivers.
The paper gives milliseconds of CPU time for SELF and C and milliseconds of real time for Smalltalk. The authors say that real and CPU times were practically the same for the SELF and C runs on this setup, which is their reason for treating the figures as comparable. The table’s relative results divide the time for one implementation by the time for another on the same workload. A higher Smalltalk-to-SELF ratio favors SELF. For SELF-to-C or Smalltalk-to-C, a lower ratio indicates a result closer to the optimized C timing.
Whole-program timing
The authors identify the Stanford-suite median and the Richards result as especially informative. For the Stanford integer benchmarks, they report median ratios of 1.8 for Smalltalk over direct SELF and 2.2 for Smalltalk over SELF-OO. The corresponding median ratios against C are 11.2 for Smalltalk, 5.8 for direct SELF, and 5.1 for SELF-OO. These are the paper’s separate medians of the reported implementation-pair ratios.
The individual workloads show appreciable variation. On tree, Smalltalk takes 1760 milliseconds and direct SELF takes 1750, a Smalltalk-to-SELF ratio reported as 1.0. The object-oriented version takes 1480 milliseconds. On puzzle, Smalltalk takes 16510 milliseconds and direct SELF takes 5290, yielding a reported ratio of 3.1. The small tests also give different results. The Smalltalk-to-SELF ratio is 1.4 on sumToTest and 3.2 on recurseTest. The headline comparison describes the general performance of the system on this test set, with substantial variation by workload.
Richards shows SELF well ahead of Smalltalk while optimized C retains a clear advantage. The paper reports a Smalltalk-to-SELF ratio of 2.8, a Smalltalk-to-C ratio of 10.6, and a SELF-to-C ratio of 4.5. Richards was left unchanged in the SELF-OO column. Its repeated timing there does not represent a separately measured object-oriented rewrite.
Richards running time on the Sun-4/260
SELF finishes Richards sooner than Smalltalk, and optimized C has the shortest running time.
The numbers
| System or setting | ms |
|---|---|
| ParcPlace Smalltalk-80, real time | 7740 |
| First-generation SELF, CPU time (this paper) | 2760 |
| Optimized C, CPU time | 730 |
The perm benchmark gives a comparison in which both kinds of SELF source were measured. The paper reports a Smalltalk-to-SELF ratio of 2.4 for the direct translation and 3.7 for SELF-OO. Its SELF-to-C ratios are 5.5 and 3.5, respectively. This benchmark helps give the median some context. The object-oriented rewrite can materially affect timing on an individual program, and the speed of the native C version remains visible alongside that improvement.
Stanford perm benchmark running time on the Sun-4/260
The object-oriented rewrite improves SELF's time on perm, while optimized C remains fastest.
The numbers
| System or setting | ms |
|---|---|
| ParcPlace Smalltalk-80, real time | 1559 |
| Direct SELF translation, CPU time | 660 |
| SELF-OO rewrite, CPU time (this paper) | 420 |
| Optimized C, CPU time | 120 |
The authors give several possible sources for the remaining gap to C. They judge their implementation of conventional optimizations, including register allocation and peephole optimization, to be weaker than the C compiler’s. They also point to operations that SELF checks, including integer overflow, array bounds, and stack overflow on calls. Finally, they identify missing type information about arguments and assignable slots as a likely contributor. The timing comparison leaves these influences combined.
Memory scanning and message throughput
For the memory system, the authors report early scans on 68020-based Sun-3/50 machines. SELF scanned approximately 3 megabytes per second. They measured 1.6 megabytes per second for the fastest Smalltalk implementation on the same machine, using nonsegregated memory spaces. This operation measures the scanning of memory for references. It gives evidence about the scanning design and leaves whole-collector cost to a different measurement.
The authors also propose MiMS, millions of messages per second, to express how much language-level work is done per unit of time. They count sends whose language semantics include dispatch. A reference to a receiver slot qualifies because the message could resolve to a data slot or to a method. Access to a local slot of a method invocation is outside the count because it can only access its local data. A message remains part of the workload even if the compiler has replaced its dispatch with inline code.
MiMS = M ÷ T
MiMS is throughput in millions of messages per second. M is the number of qualifying messages expressed in millions, and T is the total time for the benchmark expressed in seconds. The numerator counts the workload’s sends as defined by the authors, while the denominator measures the whole benchmark.
The reported value for Richards on the Sun-4/260 is 3.3 MiMS. The paper expresses that same result as a language-level message every 300ns on average. Using the machine’s 60ns cycle time, the authors describe the result as about 5 cycles per message. They also cite a machine figure of 1.6 cycles per instruction, yielding their estimate of around 3 instructions per message. This is an average over the run. Since optimized sends can disappear as distinct machine operations, it would take a different measurement to time a full dispatch in isolation.
What the ablations show
The compiler walkthrough explains the mechanism
The paper gives no timed ablation that disables each compiler technique separately, but it offers a staged compilation example, a comparison of source styles on the same implementation, a storage calculation, and a cross-system memory-scanning comparison. These analyses answer different questions about the observed performance.
The min: walkthrough shows what each compiler transformation makes possible. Receiver customization gives the compiler an integer receiver for <. Inlining exposes the integer primitive that the current method actually calls. Primitive inlining gives the compiler access to the branching structure of the operation. Splitting keeps the identities of the Boolean results known far enough downstream to resolve their conditional methods. Inlining those methods and their block invocations removes the need to create the block objects on the known paths. Prediction then supplies guards for common receivers on the remaining path.
The order matters for interpreting the example. If the compiler stopped after inlining <, it would still have a primitive call and a send of the conditional. Inlining the primitive exposes the Boolean results, while the merge would still hide which Boolean a particular execution path produced. The advantage of splitting is visible because the paper shows that intermediate state. By the end, the common path has lost several kinds of runtime work together. The example establishes how the generated code becomes simpler. The timing tables measure the complete implementation and give no independent share of the speedup to any one transformation.
Source style changes what the compiler can see
The direct and SELF-OO columns keep the implementation fixed while changing the expression of the program. On towers, direct SELF takes 900 milliseconds and the SELF-OO version takes 560. On queens, the corresponding times are 520 and 470. The authors obtain improvements of varying size from changing the source style. This is consistent with a compiler that starts from knowledge of the receiver, since moving a function argument into the receiver position can bring some operations within the scope of customization.
That explanation remains an interpretation of the source-style comparison. Rewriting a program can change the arrangement of methods and sends along with which object is called the receiver. The paper does not report counts of eliminated dispatches for the rewritten workloads. The comparison demonstrates that the system can reward the more object-oriented forms used here, while the program-level measurements leave the precise causes of each improvement open.
The paper also places the results alongside work that used declarations. Hurricane reports a factor of 2 over the Deutsch–Schiffman system on a 68020-based Sun-3. For a benchmark close to sumToTest, Johnson reports 62ms, while SELF records 18 milliseconds on a machine the authors describe as 3 to 4 times faster. The authors regard the latter performances as roughly comparable after considering the machine difference. These are comparisons with published results under their respective conditions. Their main bearing on the paper’s argument is that the SELF implementation can reach a similar range of performance on the cited cases while deriving its information during compilation.
Storage and scanning have separate explanations
The map calculation identifies which costs shrink as families grow. It shifts slot names, constant values, and layout descriptions from each copy into a shared map. Each additional member carries its own writable fields and headers. It is a structural comparison between ways of representing the point objects and clarifies the paper’s claim that implementing prototypes need not require repeating class-like information in every object.
The scan result addresses a different memory cost. Segregating packed bytes saves the scanner from visiting those bytes or parsing each object to find its boundary. The sentinel also makes it possible for the search loop to defer testing the end of the space. The paper compares the resulting SELF scanner to a Smalltalk scanner on the same machine. The figures establish the rate each implementation attained. A measurement within SELF with segregation or the sentinel disabled would be needed to attribute a particular share of the difference to either choice.
Limitations
Limits identified by the authors
The compiler knows the receiver type within a customized method, but an argument can still have an unknown type. The integer min: example shows the consequence even on a short method. The compiler has to test the argument before using the integer comparison. An unknown value read from an assignable field can create a similar need for dispatch or testing. The authors propose extending customization to argument types. They point out that the gain then has to cover the cost of checking those types when entering the compiled method.
Assignable parents present a different obstacle. The first-generation compiler can make a compile-time lookup through constant parents. If lookup has to follow an assignable parent, the map alone cannot establish which object it will reach. The paper describes limited support in the next system, where customization can be extended with information about assignable parents traversed during runtime lookup and the method’s entry code checks those parent values. Better optimization of dynamic inheritance is left open. The general compilation strategy thus works most directly when the relevant lookup paths are stable.
The authors also identify limits on the compiler’s decisions about inlining and prediction. The inliner uses a fixed cutoff based on byte code count. The authors want it to consider where the call occurs, since a frequently executed call in a loop and a call in a rarely used failure block offer different returns for spending compilation time and code space. Predictions in the implementation use predetermined message names and types. The paper proposes using runtime profiles or information from inheritance to select predictions more adaptively. That proposal concerns where to specialize. A failed prediction already has a general dispatch path.
Compilation time is another limit on the interactive experience. The paper reports that compiling and optimizing the Stanford integer programs takes over seven seconds for almost 900 lines of SELF, and that Richards takes nearly three seconds for over 400 lines. The authors say this is too slow for their interactive environment. Their proposed approach is to produce lightly optimized code while the user is waiting and queue more expensive compilation for later. The benchmark execution results and these compilation delays describe different costs, both of which matter when assessing the experience of editing and immediately running a program.
Selective invalidation also has an unfinished case. A method can depend on a definition that changes while the method is still executing. Its code is still needed by the live activation, and some of the assumptions behind that code may already be stale. The authors propose recompiling the method immediately and rebuilding the stack for the replacement. They had not implemented this procedure and did not know whether it could meet their response-time requirements. Stack reconstruction for inspection is a demonstrated capability. It does not by itself establish that a live computation can resume using rebuilt frames.
The debugger has a related boundary. It displays the logical stack when invoked by the stack-dump primitive and then resumes execution. The program-counter mapping was intended to support breakpoints and stepping, but breakpoints were unimplemented. The article’s claim about debugging can therefore be read specifically as evidence that optimization need not remove the information required for a source-level view of the stack. A debugger that exercises the full breakpoint and process-control design remains outside the demonstration.
Limits of the comparisons
The timing experiment supports a comparison on the chosen benchmark programs and hardware. The workloads are translations of an integer suite and an operating-system simulation, supplemented by small tests. The authors also report having written collections, a parser, and a prototype graphical interface in SELF, but the benchmark table gives no matching timing study for such larger programs or graphical workloads. The authors explicitly leave open whether the techniques are practical at larger scales.
Maps are economical when many objects share layout and fixed contents. The point calculation exposes how that economy depends on sharing. If structural edits create many distinct maps or objects tend to have unique shapes, the shared cost is spread across fewer objects. The paper presents a representation and explains why it expects sharing to occur often. It does not give a distribution of family sizes or a full accounting of the maps and their dependency records across the measured workloads.
Native code specialization raises a corresponding question about code space. A source method used with many receiver maps may be compiled into many versions. Splitting can replicate sends, and inlining can increase the amount of code recorded in each version. The benefits are visible in the worked example, but the runtime table gives no measurements of code-cache growth or how it varies with the number of receiver maps used in a program. The authors explicitly leave the relative gains and the associated time and space costs for further analysis.
Finally, the C and Smalltalk comparisons combine language semantics with implementation choices. SELF’s checks for primitive errors and its weaker conventional optimizations are among the explanations the authors offer for the C timings. Their Smalltalk comparison includes parser choices, code generation, and other implementation differences beyond receiver customization. Even the fast scanning comparison is between systems with different implementations. Taken together, the measurements establish that this combination of techniques can make SELF competitive with the Smalltalk baseline. How much of that result transfers to another implementation depends on the costs of its dispatch, allocation, compilation, and runtime checks.
What came after
The direction closest to this implementation was to enlarge the region over which the compiler could keep type information. In its account of the second-generation SELF system, the paper describes type-flow analysis that tracks what is known about the values of local slots during compilation. The original splitter in the walkthrough relies on the result of the preceding message. The extended design can use facts about local values and can duplicate intervening operations when the point where a fact is lost lies before the message that could use it. The paper also describes work on standard optimization techniques, including instruction scheduling, code motion, and global register allocation. It distinguishes the compiler already under construction from the goal of generating highly optimized paths across larger regions, including loop bodies.
A subsequent paper, Optimizing Dynamically-Typed Object-Oriented Languages With Polymorphic Inline Caches, takes up the inline caching side of dynamic dispatch. In this setting, polymorphic means that a single send site can encounter several receiver types. The extension is to keep dispatch information for several such cases at that site. A send with a receiver that matches a cached case can use the corresponding target, with general lookup available when the site has no applicable entry.
This addresses a different point in execution from receiver customization. A customized method starts by knowing the receiver type for its own version. Within its body it can still encounter a send whose receiver depends on an argument, a slot value, or a computation. An inline cache operates at the send site, where the actual receiver arrives. The polymorphic form accommodates sites that repeatedly see several types. The connection to the earlier SELF implementation is clearest on the paths that retain dispatch. Customization and inlining remove sends when lookup can be resolved during compilation. Caching makes the remaining sends cheaper when their receivers follow a recurring pattern.
Cite
Cite as Craig Chambers, David Ungar and Elgin Lee. 1989. An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes. OOPSLA 1989.
@inproceedings{chambers1989efficient,
title = {{An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes}},
author = {Craig Chambers, David Ungar and Elgin Lee},
booktitle = {OOPSLA 1989},
year = {1989},
url = {https://bibliography.selflanguage.org/_static/implementation.pdf}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/chambers-1989-efficient-implementation-self-dynamically-typed/