-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMOop.class.st
159 lines (115 loc) · 3.27 KB
/
VMOop.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"
A reified view of a `oop` (an integer address) for a `memory` manager.
This class is used for debuging and vizualisation to handle oops as first object-oriented programing citizens when coding visual inspectors.
They obviously *should not* be used for implementing runtime behavior.
VMOops are also indented to be robust and capable of dealing with corrupted things (because we rarely debug uncorrupted memory), or during low-level operations (durring GC for instance).
"
Class {
#name : #VMOop,
#superclass : #Object,
#instVars : [
'oop',
'memory'
],
#category : #'VMMaker-Tools'
}
{ #category : #'object access' }
VMOop >> bytes [
self ifBroken: [ ^ nil ].
^ memory bytesInObject: oop
]
{ #category : #'object access' }
VMOop >> classIndex [
self ifBroken: [ ^ nil ].
^ memory classIndexOf: oop
]
{ #category : #printing }
VMOop >> flags [
self ifBroken: [ ^ 'broken' ].
^ ((memory isGrey: oop) ifTrue: ['g'] ifFalse: ['.']),
((memory isImmutable: oop) ifTrue: ['i'] ifFalse: ['.']),
((memory isMarked: oop) ifTrue: ['m'] ifFalse: ['.']),
((memory isPinned: oop) ifTrue: ['p'] ifFalse: ['.']),
((memory isRemembered: oop) ifTrue: ['r'] ifFalse: ['.'])
]
{ #category : #printing }
VMOop >> format [
self ifBroken: [ ^ 'broken' ].
^ ((memory formatOf: oop) <= 16rF ifTrue: ['0'] ifFalse: ['']),
(memory formatOf: oop) printStringHex, ' ',
(memory formatStringOf: oop)
]
{ #category : #testing }
VMOop >> ifBroken: aBlock [
^ self isBroken ifTrue: aBlock.
]
{ #category : #testing }
VMOop >> isBroken [
oop ifNil: [ ^true ].
^ (memory memoryManager isValidAddress: oop) not.
]
{ #category : #printing }
VMOop >> label [
self ifBroken: [ ^ 'broken' ].
^ memory labelOfOop: oop
]
{ #category : #accessing }
VMOop >> memory [
^ memory
]
{ #category : #accessing }
VMOop >> memory: anObject [
memory := anObject
]
{ #category : #'object access' }
VMOop >> numSlots [
self ifBroken: [ ^ nil ].
^ memory numSlotsOfAny: oop
]
{ #category : #accessing }
VMOop >> oop [
^ oop
]
{ #category : #accessing }
VMOop >> oop: anObject [
oop := anObject
]
{ #category : #'object access' }
VMOop >> pointer: idx [
^ memory asVMOop: (self rawPointer: idx)
]
{ #category : #'object access' }
VMOop >> pointers [
"Return a collection of all pointed `VMOop` (in slots)"
| n |
n := self numSlots.
n ifNil: [ ^ #() ].
^ (1 to: n) collect: [ :i | self pointer: i-1 ].
]
{ #category : #printing }
VMOop >> printOn: aStream [
^ aStream print: oop
]
{ #category : #'object access' }
VMOop >> rawNumSlots [
self ifBroken: [ ^ nil ].
^ memory rawNumSlotsOf: oop
]
{ #category : #'object access' }
VMOop >> rawPointer: idx [
"0 based pointer, as a classic integer oop"
self ifBroken: [ ^ nil ].
(memory isFreeObject: oop) ifTrue: [ ^ memory fetchPointer: idx ofFreeChunk: oop ].
(memory isSegmentBridge: oop) ifTrue: [ ^ nil ].
((memory numSlotsOfAny: oop) > 0) ifTrue: [ ^ memory fetchPointer: idx ofMaybeForwardedObject: oop ].
^ nil.
]
{ #category : #printing }
VMOop >> type [
self ifBroken: [ ^ 'broken' ].
(memory isFreeObject: oop) ifTrue: [ ^ 'free'].
(memory isSegmentBridge: oop) ifTrue: [ ^ 'bridge'].
(memory isForwarded: oop) ifTrue: [ ^ 'forwarder'].
(memory classIndexOf: oop) <= memory lastClassIndexPun ifTrue: [ ^ 'pun/obj stack'].
^ 'object'
]