SlideShare ist ein Scribd-Unternehmen logo
1 von 11
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
Smalltalk gives to the programmer the illusion of
uniformity for example SmallIntegers are defined
as any other object but in memory they are
different than objects. In that case the object
The Internal Structure of
Objects in VW
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
• Non indexable, pointer
Object subclass: #Packet
instanceVariableNames: 'contents addressee originator '
classVariableNames: ''
poolDictionaries: ''
category: 'Demo-LAN'
• Indexable pointer
• ArrayedCollection variableSubclass: #Array
• instanceVariableNames: ''
• classVariableNames: ''
• poolDictionaries: ''
• category: 'Collections-Arrayed'
Three Ways to Create Classes (VW30 Sq)
S.Ducasse 4
• Indexable, non pointer
•
LimitedPrecisionReal variableByteSubclass: #Float
instanceVariableNames: ''
classVariableNames: 'Pi RadiansPerDegree '
poolDictionaries: ''
category: 'Magnitude-Numbers'
It is not possible to define named instance variables
Three Ways to Create Classes
S.Ducasse 5
• Identifying subclass:
| collection |
collection := SortedCollection new.
Smalltalk allBehaviorsDo: [:each ||boolean|
boolean := each isMeta not and: [each isObsolete not].
boolean := boolean and: [each isFixed].
boolean ifTrue: [collection add: each name]].
^collection
Let there be Code
S.Ducasse 6
• Identifying variableSubclass:
boolean := each isMeta not and: [each isObsolete not].
boolean := boolean and: [each isPointers].
boolean := boolean and: [each isVariable].
boolean ifTrue: [collection add: each name]]
• Identifying variableByteSubclass:
boolean := each isMeta not and: [each isObsolete not].
boolean := boolean and: [each isBits].
boolean := boolean and: [each isVariable].
boolean ifTrue: [collection add: each name]]
Let there be Code
S.Ducasse 7
• The information for distinguishing between these three
type is stored in the format instance variable of Behavior.
• Behavior>>isBits
• "Answer whether the receiver contains just bits (not
pointers)."
• ^format noMask: self pointersMask
• Behavior>>hasImmediateInstances
immediate type object?
• Behavior>>isFixed
non-indexable type object?
• Behavior>>isPointers
pointers type object?
• Behavior>>isVariable
Format and other
S.Ducasse 8
pointer type [isPointers]
indexable type [isVariable] variableSubclass:
non-index type [isFixed] subclass:
non-pointer [isBits]
index type [isVariable] variableByteSubclass:
non-index type [isFixed] subclass:
immediate [hasImmediateInstances] subclass:
Format and other (ii)
S.Ducasse 9
• objectSizeInBytes: anObject
• |bytesInOTE bytesInOOP aClass indexableFieldSize instVarFieldSize size|
• bytesInOTE := ObjectMemory current bytesPerOTE.
• bytesInOOP := ObjectMemory current bytesPerOOP.
• aClass := anObject class.
• aClass isPointers
• ifTrue: [instVarFieldSize := aClass instSize * bytesInOOP.
• aClass isVariable
• ifTrue: [indexableFieldSize := anObject basicSize * bytesInOOP]
• ifFalse: [indexableFieldSize := 0]]
• ifFalse: [instVarFieldSize := 0.
• aClass isVariable
• ifTrue: [indexableFieldSize := anObject basicSize +
• (bytesInOOP -1) bitAnd: bytesInOOP
negated]
• ifFalse:[indexableFieldSize := 0]].
• size := bytesInOTE + instVarFieldSize + indexableFieldSize.
• ^size
Object size in bytes
S.Ducasse 10
• OTE (ObjectTable 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 objectSizeInBytes:WorkStation new
• pointer, instSize = 3 (dependents name nextNode) * 4 = 12 not indexable
• Internals new objectSizeInBytes: (WorkStation new name: #abc)
• idem, because not recursive
• Internals new objectSizeInBytes: 1@2
• 12 + 2 * 4 = 20 bytes
• Indexable and Pointers Type
• Internals new objectSizeInBytes: (OrderedCollection new: 10)
• OrderedCollection new: 10
• = 2 inst variable and 10 indexes
• class instSize = 2 * 4
• basicSize = 10 * 4
• = 60 bytes
Analysis
S.Ducasse 11
• Indexable pure
• Internals new objectSizeInBytes: 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 objectSizeInBytes: 1
• = 12 bytes, but the code should use isImmediate
Analysis (ii)

Weitere ähnliche Inhalte

Andere mochten auch (20)

Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
 
06 debugging
06 debugging06 debugging
06 debugging
 
12 - Conditions and Loops
12 - Conditions and Loops12 - Conditions and Loops
12 - Conditions and Loops
 
Stoop 390-instruction stream
Stoop 390-instruction streamStoop 390-instruction stream
Stoop 390-instruction stream
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop 436-strategy
Stoop 436-strategyStoop 436-strategy
Stoop 436-strategy
 
15 - Streams
15 - Streams15 - Streams
15 - Streams
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 
Debugging VisualWorks
Debugging VisualWorksDebugging VisualWorks
Debugging VisualWorks
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)
 
14 - Exceptions
14 - Exceptions14 - Exceptions
14 - Exceptions
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 

Ähnlich wie Stoop 301-internal objectstructureinvw

iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev introVonbo
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone developmentVonbo
 
Drupalcon cph
Drupalcon cphDrupalcon cph
Drupalcon cphcyberswat
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsPetr Dvorak
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORPESUG
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Managementstable|kernel
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not JavaChris Adamson
 
JavaScript!
JavaScript!JavaScript!
JavaScript!RTigger
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jqueryKostas Mavridis
 
Slot Composition
Slot CompositionSlot Composition
Slot CompositionESUG
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its TypesMuhammad Hammad Waseem
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JSIvano Malavolta
 

Ähnlich wie Stoop 301-internal objectstructureinvw (20)

iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev intro
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone development
 
Drupalcon cph
Drupalcon cphDrupalcon cph
Drupalcon cph
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
Lecture 3-ARC
Lecture 3-ARCLecture 3-ARC
Lecture 3-ARC
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Management
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
Introduction to java and oop
Introduction to java and oopIntroduction to java and oop
Introduction to java and oop
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
About Python
About PythonAbout Python
About Python
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 
Evolve your coding with some BDD
Evolve your coding with some BDDEvolve your coding with some BDD
Evolve your coding with some BDD
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS
 

Mehr von The World of Smalltalk (20)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
10 reflection
10 reflection10 reflection
10 reflection
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 

Kürzlich hochgeladen

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 

Kürzlich hochgeladen (20)

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 

Stoop 301-internal objectstructureinvw

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse Stephane.Ducasse@univ-savoie.fr http://www.listic.univ-savoie.fr/~ducasse/ Smalltalk gives to the programmer the illusion of uniformity for example SmallIntegers are defined as any other object but in memory they are different than objects. In that case the object The Internal Structure of Objects in VW
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 • Non indexable, pointer Object subclass: #Packet instanceVariableNames: 'contents addressee originator ' classVariableNames: '' poolDictionaries: '' category: 'Demo-LAN' • Indexable pointer • ArrayedCollection variableSubclass: #Array • instanceVariableNames: '' • classVariableNames: '' • poolDictionaries: '' • category: 'Collections-Arrayed' Three Ways to Create Classes (VW30 Sq)
  • 4. S.Ducasse 4 • Indexable, non pointer • LimitedPrecisionReal variableByteSubclass: #Float instanceVariableNames: '' classVariableNames: 'Pi RadiansPerDegree ' poolDictionaries: '' category: 'Magnitude-Numbers' It is not possible to define named instance variables Three Ways to Create Classes
  • 5. S.Ducasse 5 • Identifying subclass: | collection | collection := SortedCollection new. Smalltalk allBehaviorsDo: [:each ||boolean| boolean := each isMeta not and: [each isObsolete not]. boolean := boolean and: [each isFixed]. boolean ifTrue: [collection add: each name]]. ^collection Let there be Code
  • 6. S.Ducasse 6 • Identifying variableSubclass: boolean := each isMeta not and: [each isObsolete not]. boolean := boolean and: [each isPointers]. boolean := boolean and: [each isVariable]. boolean ifTrue: [collection add: each name]] • Identifying variableByteSubclass: boolean := each isMeta not and: [each isObsolete not]. boolean := boolean and: [each isBits]. boolean := boolean and: [each isVariable]. boolean ifTrue: [collection add: each name]] Let there be Code
  • 7. S.Ducasse 7 • The information for distinguishing between these three type is stored in the format instance variable of Behavior. • Behavior>>isBits • "Answer whether the receiver contains just bits (not pointers)." • ^format noMask: self pointersMask • Behavior>>hasImmediateInstances immediate type object? • Behavior>>isFixed non-indexable type object? • Behavior>>isPointers pointers type object? • Behavior>>isVariable Format and other
  • 8. S.Ducasse 8 pointer type [isPointers] indexable type [isVariable] variableSubclass: non-index type [isFixed] subclass: non-pointer [isBits] index type [isVariable] variableByteSubclass: non-index type [isFixed] subclass: immediate [hasImmediateInstances] subclass: Format and other (ii)
  • 9. S.Ducasse 9 • objectSizeInBytes: anObject • |bytesInOTE bytesInOOP aClass indexableFieldSize instVarFieldSize size| • bytesInOTE := ObjectMemory current bytesPerOTE. • bytesInOOP := ObjectMemory current bytesPerOOP. • aClass := anObject class. • aClass isPointers • ifTrue: [instVarFieldSize := aClass instSize * bytesInOOP. • aClass isVariable • ifTrue: [indexableFieldSize := anObject basicSize * bytesInOOP] • ifFalse: [indexableFieldSize := 0]] • ifFalse: [instVarFieldSize := 0. • aClass isVariable • ifTrue: [indexableFieldSize := anObject basicSize + • (bytesInOOP -1) bitAnd: bytesInOOP negated] • ifFalse:[indexableFieldSize := 0]]. • size := bytesInOTE + instVarFieldSize + indexableFieldSize. • ^size Object size in bytes
  • 10. S.Ducasse 10 • OTE (ObjectTable 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 objectSizeInBytes:WorkStation new • pointer, instSize = 3 (dependents name nextNode) * 4 = 12 not indexable • Internals new objectSizeInBytes: (WorkStation new name: #abc) • idem, because not recursive • Internals new objectSizeInBytes: 1@2 • 12 + 2 * 4 = 20 bytes • Indexable and Pointers Type • Internals new objectSizeInBytes: (OrderedCollection new: 10) • OrderedCollection new: 10 • = 2 inst variable and 10 indexes • class instSize = 2 * 4 • basicSize = 10 * 4 • = 60 bytes Analysis
  • 11. S.Ducasse 11 • Indexable pure • Internals new objectSizeInBytes: 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 objectSizeInBytes: 1 • = 12 bytes, but the code should use isImmediate Analysis (ii)