[VisualWorks top] [Lecture] [OOA/OOD] [Jun] [Bibliography] [Quotations]

In Praise of Learning: Lecture


contents

  1. コンピュータの歴史 *
  2. アルゴリズム *
  3. 自動メモリ管理 (garbage collection)
  4. プログラム制御構造
  5. 仮想マシン (Virtual Machine)
  6. プログラミング手法
  7. Smalltalk
  8. ソフトウェア工学
  9. 二次元グラフィクス *

[contents]


コンピュータの歴史

[contents]


アルゴリズム

[contents]


自動メモリ管理 (garbage collection)

オブジェクトポインタとオブジェクトテーブルとヒープストレージ

SmalltalkLecture03.pdf

garbage collection (ゴミ集め)

ゴミ処理問題や産業廃棄物問題をほったらかしにしていると、必然的に滅亡します。

オブジェクトポインタ
オブジェクトポインタ

直接指さない

オブジェクトテーブル、オブジェクト

直接アドレッシングと間接アドレッシング

SmalltalkLecture02.pdf

直接アドレッシング (direct addressing) と間接アドレッシング (indirect addressing) の比較
直接アドレッシング (direct addressing) 間接アドレッシング (indirect addressing)
リンクリストに直接ヒープ内のアドレスのポインタを格納する。 テーブルを用意し、要素のリンクリストにはテーブルの相対アドレスを格納する。
例えば、セミラティス (ループがあるのでツリーではない) 内の要素の一つのアドレスが変わったとする。
また、ある要素と別の要素を交換したいとする。
後始末がたいへん。何かするたびにセミラティス内の要素を全部廻って調査しなければならない。 テーブル内の相対アドレスを書き換えるだけで済む。

メモリ管理

SmalltalkLecture04.pdf

自動メモリ管理機構 3 態 (3 garbage collections)

オブジェクトの生き死に

SmalltalkLecture13.pdf

[contents]


プログラム制御構造

SmalltalkLecture11.pdf

遅延評価
aBlock value.
継続
[ 4 [ 5 [ ] value] value].
分岐
aBoolean ifTrue: trueBlock ifFalse: falseBlock.
繰り返し
anInteger timesRepeat: repeatBlock.
anArray do: repeatBlock.
巻き戻し
doBlock ensure: (valueNowOrOnUnwindDo) rewindBlock.
例外
Object errorSignal handle: exceptionBlock do: doBlock.
フォーク
aBlock fork.
プロミス
p := [... p send: v ....] promise.
...
p receive
プロセス
aBlock newProcess.
aProcess resume.
aProcess terminate.
aProcess priority: Processor userInterruptPriority.
セマフォ
aSemaphore := Semaphore new.
aSemaphore wait.
aSemaphore signal.

一般性と重送信

Q: なぜ型変換なしに計算ができるのか? (実はやってくれている)

SmalltalkLecture09.pdf

coercing, double dispatching

SmallInteger>>- aNumber
    "Answer the result of subtracting the argument from the receiver.
    Fail if the argument or the result is not a SmallInteger.
    No Lookup."

    <primitive: 2>
    ^aNumber differenceFromInteger: self
ちなみに、原始メソッド 1 番は加算 (Blue Book, p.612)。
+ aNumber
    "Answer the result of adding the receiver to the argument.
    Fail if the argument or the result is not a SmallInteger.
    No Lookup."

    <primitive: 1>
    ^aNumber sumFromInteger: self

立役者

generality の返り値
大きさを持つものの具象クラスの一般性
Jun3dPoint 220
Jun2dPoint 200
Point 180
JunPenLocation 170
Complex 150
JunAngle 120
MetaNumeric 120
JunPenAngle 110
Double 90
Float 80
FixedPoint 70
Fraction 60
Integer 40
SmallInteger 20

generality が異なるもの同志を演算する場合、generality が小さいものは大きいものの generality と一致するまで、強制 (coerce:) 的に変換されていく。


    ArithmeticValue>>retry: aSymbol coercing: aNumber 
        "Arithmetic represented by the symbol, aSymbol, could not be 
        performed with the receiver and the argument, aNumber, because
        of the differences in representation.  Coerce either the receiver or the
        argument, depending on which has higher generality, and try again.  
        If the generalities are the same, then this message
        should not have been sent so an error notification is provided."

        self generality < aNumber generality
            ifTrue: [^(aNumber coerce: self) perform: aSymbol with: aNumber].
        self generality > aNumber generality
            ifTrue: [^self perform: aSymbol with: (self coerce: aNumber)].
        self error: 'coercion attempt failed'

[contents]


仮想マシン (Virtual Machine)

仮想マシンならば……

  1. multi platform
  2. change mechanism
  3. do it <-> program it

仮想マシンって……

オブジェクト内部構造

SmalltalkLecture08.pdf

(JunSystem compiledMethodAt: #update:) symbolic
 'normal CompiledMethod numArgs=1 numTemps=0 frameSize=12

literals: (#finishedSnapshot #returnFromSnapshot #login #prologue 
#aboutToQuit #aboutToSnapshot #epilogue #logout #condenseChanges 
''no operation'' #yourself )

1 <10> push local 0
2 <1C> push #finishedSnapshot
3 <A6> send =
4 <C1> jump false 7
5 <47> push true
6 <6D> jump 10
7 <10> push local 0
8 <1D> push #returnFromSnapshot
9 <A6> send =
10 <E8 12> jump false 30
12 <10> push local 0
13 <1D> push #returnFromSnapshot
14 <A6> send =
15 <C4> jump false 21
16 <44> push self
17 <CE 17> non-immediate send class
19 <72> send login
20 <66> pop
21 <10> push local 0
22 <1C> push #finishedSnapshot
23 <A6> send =
24 <C4> jump false 30
25 <44> push self
26 <CE 17> non-immediate send class
28 <73> send prologue
29 <66> pop
30 <10> push local 0
31 <20> push #aboutToQuit
32 <A6> send =
33 <C1> jump false 36
34 <47> push true
35 <6D> jump 39
36 <10> push local 0
37 <21> push #aboutToSnapshot
38 <A6> send =
39 <E8 12> jump false 59
41 <10> push local 0
42 <21> push #aboutToSnapshot
43 <A6> send =
44 <C4> jump false 50
45 <44> push self
46 <CE 17> non-immediate send class
48 <76> send epilogue
49 <66> pop
50 <10> push local 0
51 <20> push #aboutToQuit
52 <A6> send =
53 <C4> jump false 59
54 <44> push self
55 <CE 17> non-immediate send class
57 <77> send logout
58 <66> pop
59 <10> push local 0
60 <24> push #condenseChanges
61 <A6> send =
62 <C3> jump false 67
63 <25> push ''no operation''
64 <CC 0A> no-check send yourself
66 <66> pop
67 <60> push self; return
'

オブジェクトの 4 つの根源的な型

4 つの型

    "任意のオブジェクトの大きさをバイト単位で計算します。"
    | byteSizeOfObject |
    byteSizeOfObject := 
            [:anObject | 
            | bytesInOTE bytesInOOP aClass indexableFieldSize instVarFieldSize byteSize |
            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.
                            aClass hasImmediateInstances ifTrue: [bytesInOTE := 0]]].
            byteSize := bytesInOTE + instVarFieldSize + indexableFieldSize.
            byteSize yourself].
    ^byteSizeOfObject value: (OrderedCollection new: 10)

Squeak での


    | aClass baseHeaderSize objectHeadersSize bytesInOOP 
      instVarFieldSize indexableFieldSize byteSize |
    aClass := anObject class.
    ((aClass == SmallInteger) or: [aClass == Character]) ifTrue: [^0].
    baseHeaderSize := self baseHeaderSize.
    objectHeadersSize := aClass indexIfCompact > 0 
                ifTrue: [baseHeaderSize] 
                ifFalse: 
                    [((self sizeInWordsOf: anObject) + 1 ) > 16r3F
                        ifTrue: [baseHeaderSize * 3]
                        ifFalse: [baseHeaderSize * 2]].
    bytesInOOP := aClass isBytes ifTrue: [1] ifFalse: [4].
    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 + 3) bitAnd: 16r1FFFFFFC]
                ifFalse: [indexableFieldSize := 0]].
    byteSize := objectHeadersSize + instVarFieldSize + indexableFieldSize.
    ^byteSize

オブジェクトの寿命

SmalltalkLecture07.pdf

Context, BlockClosure, CompiledCode, -> ContextStory

[contents]


プログラミング手法

Smalltalk City

SmalltalkLecture06.pdf

ブロックの読み方

selectorBlock: aBlock での、ブロック引数の個数は? メソッド selectorBlock: の中で aBlock value: を送信しているところを探しなさい。

Assertion (表明)

message pattern signature

ex)
    anAssertion requireThat: [anObject isKindOf: Foo].
ex)
    anObject assert: assertBlock do: doBlock ensure: ensureBlock
        ^assertBlock value = true ifTrue: [[doBlock value]
                valueNowOrOnUnwindDo: [ensureBlock value]]
または
        assertBlock value.
        ^[doBlock value]
            valueNowOrOnUnwindDo: [ensureBlock value]

[contents]


Smalltalk

Smalltalk 上での日常生活

SmalltalkLecture12.pdf

メッセージとメソッド

SmalltalkLecture08.pdf

MVC はグラフ

SmalltalkLecture17.pdf

依存関係と監視プロセス

SmalltalkLecture18.pdf
Memory Observer: 一定時間間隔で,オブジェクトメモリの中を調べて,現在,存在しているオブジェクトの数と,使用されているメモリ領域の大きさをモニタするオブジェクト; ソース

プロジェクト

SmalltalkLecture21.pdf

格納庫, 交換, プラグイン

SmalltalkLecture22.pdf

手を動かせ

[contents]


ソフトウェア工学

メトリクス

SmalltalkLecture23.pdf

オブジェクト指向らしさ

OOM を Squeak に移してみました

[contents]


二次元グラフィクス

see Smalltalk Idioms.

Mask, Halftone, Stipple

MaskVisualWorks
HalftoneBitBlt
StippleOpenGL

[contents]


[VisualWorks top] [Lecture] [OOA/OOD] [Jun] [Bibliography] [Quotations]