The Internal Structure of Objects in VW Stphane

The Internal Structure of Objects in VW Stéphane Ducasse Stephane. Ducasse@univ-savoie. fr http: //www. listic. univ-savoie. fr/~ducasse/ S. Ducasse Smalltalk gives to the programmer the illusion of uniformity for example Small. Integers are defined as any other object but in memory they are different than objects. In that case 1

License: CC-Attribution-Share. Alike 2. 0 http: //creativecommons. org/licenses/by-sa/2. 0/ S. Ducasse 2

Three Ways to Create Classes (VW 30 Sq) • Non indexable, pointer Object subclass: #Packet instance. Variable. Names: 'contents addressee originator ' class. Variable. Names: '' pool. Dictionaries: '' category: 'Demo-LAN' • • • S. Ducasse Indexable pointer Arrayed. Collection variable. Subclass: #Array instance. Variable. Names: '' class. Variable. Names: '' pool. Dictionaries: '' category: 'Collections-Arrayed' 3

Three Ways to Create Classes • • Indexable, non pointer Limited. Precision. Real variable. Byte. Subclass: #Float instance. Variable. Names: '' class. Variable. Names: 'Pi Radians. Per. Degree ' pool. Dictionaries: '' category: 'Magnitude-Numbers' It is not possible to define named instance variables S. Ducasse 4

Let there be Code • Identifying subclass: | collection : = Sorted. Collection new. Smalltalk all. Behaviors. Do: [: each ||boolean| boolean : = each is. Meta not and: [each is. Obsolete not]. boolean : = boolean and: [each is. Fixed]. boolean if. True: [collection add: each name]]. ^collection S. Ducasse 5

Let there be Code • Identifying variable. Subclass: boolean : = each is. Meta not and: [each is. Obsolete not]. boolean : = boolean and: [each is. Pointers]. boolean : = boolean and: [each is. Variable]. boolean if. True: [collection add: each name]] • Identifying variable. Byte. Subclass: boolean : = each is. Meta not and: [each is. Obsolete not]. boolean : = boolean and: [each is. Bits]. boolean : = boolean and: [each is. Variable]. boolean if. True: [collection add: each name]] S. Ducasse 6

Format and other • • S. Ducasse The information for distinguishing between these three type is stored in the format instance variable of Behavior>>is. Bits "Answer whether the receiver contains just bits (not pointers). " ^format no. Mask: self pointers. Mask Behavior>>has. Immediate. Instances immediate type object? Behavior>>is. Fixed non-indexable type object? Behavior>>is. Pointers pointers type object? 7 Behavior>>is. Variable
![Format and other (ii) pointer type [is. Pointers] indexable type [is. Variable] variable. Subclass: Format and other (ii) pointer type [is. Pointers] indexable type [is. Variable] variable. Subclass:](http://slidetodoc.com/presentation_image_h2/a7fa4036004e568017933445e8009956/image-8.jpg)
Format and other (ii) pointer type [is. Pointers] indexable type [is. Variable] variable. Subclass: non-index type [is. Fixed] subclass: non-pointer [is. Bits] index type [is. Variable] variable. Byte. Subclass: non-index type [is. Fixed] subclass: immediate [has. Immediate. Instances] subclass: S. Ducasse 8

Object size in bytes • • object. Size. In. Bytes: an. Object |bytes. In. OTE bytes. In. OOP a. Class indexable. Field. Size inst. Var. Field. Size size| • bytes. In. OTE : = Object. Memory current bytes. Per. OTE. • bytes. In. OOP : = Object. Memory current bytes. Per. OOP. • a. Class : = an. Object class. • a. Class is. Pointers • if. True: [inst. Var. Field. Size : = a. Class inst. Size * bytes. In. OOP. • a. Class is. Variable • if. True: [indexable. Field. Size : = an. Object basic. Size * bytes. In. OOP] • if. False: [indexable. Field. Size : = 0]] • if. False: [inst. Var. Field. Size : = 0. • a. Class is. Variable • if. True: [indexable. Field. Size : = an. Object basic. Size + • (bytes. In. OOP -1) bit. And: bytes. In. OOP negated] • if. False: [indexable. Field. Size : = 0]]. S. Ducasse 9 • size : = bytes. In. OTE + inst. Var. Field. Size + indexable. Field. Size.

Analysis • • • • S. Ducasse OTE (Object. Table Entry) = 12 bytes: OTE is a description of an Object (class, iv, hash, gc flags, . . ) OOP (Object Oriented Pointer) = 4 bytes Pointers Type Internals new object. Size. In. Bytes: Work. Station new pointer, inst. Size = 3 (dependents name next. Node) * 4 = 12 not indexable Internals new object. Size. In. Bytes: (Work. Station new name: #abc) idem, because not recursive Internals new object. Size. In. Bytes: 1@2 12 + 2 * 4 = 20 bytes Indexable and Pointers Type Internals new object. Size. In. Bytes: (Ordered. Collection new: 10) Ordered. Collection new: 10 = 2 inst variable and 10 indexes class inst. Size = 2 * 4 basic. Size = 10 * 4 = 60 bytes 10

Analysis (ii) • • • Indexable pure Internals new object. Size. In. Bytes: Float pi 4 indexed variable * 4 = 16 bytes • Non pointer, non Index = immediate, but an immediate type object has no object table entry. The immediate object is stored into the OOP. Internals new object. Size. In. Bytes: 1 = 12 bytes, but the code should use is. Immediate • • S. Ducasse 11
- Slides: 11