877
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
1152
|
3 |
|
1155
|
4 |
New code and modifications done at SWING Research Group [1]:
|
1152
|
5 |
|
877
|
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
7 |
SWING Research Group, Czech Technical University in Prague
|
|
8 |
|
|
9 |
This software is furnished under a license and may be used
|
|
10 |
only in accordance with the terms of that license and with the
|
|
11 |
inclusion of the above copyright notice. This software may not
|
|
12 |
be provided or otherwise made available to, or used by, any
|
|
13 |
other person. No title to or ownership of the software is
|
|
14 |
hereby transferred.
|
|
15 |
|
1155
|
16 |
[1] Code written at SWING Research Group contains a signature
|
|
17 |
of one of the above copright owners. For exact set of such code,
|
|
18 |
see the differences between this version and version stx:libjava
|
1152
|
19 |
as of 1.9.2010
|
877
|
20 |
"
|
752
|
21 |
"{ Package: 'stx:libjava' }"
|
|
22 |
|
|
23 |
Object subclass:#JavaNativeMemory
|
1524
|
24 |
instanceVariableNames:'chunks defaultMallocatedMemoryChunkSize'
|
|
25 |
classVariableNames:'DefaultMallocatedMemoryChunkSize'
|
752
|
26 |
poolDictionaries:''
|
|
27 |
category:'Languages-Java-Support'
|
|
28 |
!
|
|
29 |
|
1524
|
30 |
Object subclass:#MallocatedMemoryChunk
|
|
31 |
instanceVariableNames:'base size data flist alist'
|
|
32 |
classVariableNames:''
|
|
33 |
poolDictionaries:''
|
|
34 |
privateIn:JavaNativeMemory
|
|
35 |
!
|
|
36 |
|
|
37 |
Link subclass:#FreeListEntry
|
1520
|
38 |
instanceVariableNames:'start stop'
|
|
39 |
classVariableNames:''
|
|
40 |
poolDictionaries:''
|
1524
|
41 |
privateIn:JavaNativeMemory::MallocatedMemoryChunk
|
1520
|
42 |
!
|
|
43 |
|
877
|
44 |
!JavaNativeMemory class methodsFor:'documentation'!
|
|
45 |
|
|
46 |
copyright
|
|
47 |
"
|
|
48 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
1152
|
49 |
|
1155
|
50 |
New code and modifications done at SWING Research Group [1]:
|
1152
|
51 |
|
877
|
52 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
53 |
SWING Research Group, Czech Technical University in Prague
|
|
54 |
|
|
55 |
This software is furnished under a license and may be used
|
|
56 |
only in accordance with the terms of that license and with the
|
|
57 |
inclusion of the above copyright notice. This software may not
|
|
58 |
be provided or otherwise made available to, or used by, any
|
|
59 |
other person. No title to or ownership of the software is
|
|
60 |
hereby transferred.
|
|
61 |
|
1155
|
62 |
[1] Code written at SWING Research Group contains a signature
|
|
63 |
of one of the above copright owners. For exact set of such code,
|
|
64 |
see the differences between this version and version stx:libjava
|
1152
|
65 |
as of 1.9.2010
|
877
|
66 |
|
|
67 |
"
|
|
68 |
! !
|
752
|
69 |
|
1524
|
70 |
!JavaNativeMemory class methodsFor:'initialization'!
|
|
71 |
|
|
72 |
initialize
|
|
73 |
"Invoked at system start or when the class is dynamically loaded."
|
|
74 |
|
|
75 |
"/ please change as required (and remove this comment)
|
|
76 |
|
|
77 |
DefaultMallocatedMemoryChunkSize := 1024 * 1024"1MB"
|
|
78 |
|
|
79 |
"Modified: / 10-07-2012 / 18:54:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
80 |
! !
|
|
81 |
|
752
|
82 |
!JavaNativeMemory class methodsFor:'instance creation'!
|
|
83 |
|
|
84 |
new
|
|
85 |
"return an initialized instance"
|
|
86 |
|
|
87 |
^ self basicNew initialize.
|
|
88 |
! !
|
|
89 |
|
|
90 |
!JavaNativeMemory methodsFor:'accessing'!
|
|
91 |
|
1524
|
92 |
defaultMallocatedMemoryChunkSize
|
|
93 |
^ defaultMallocatedMemoryChunkSize
|
|
94 |
!
|
|
95 |
|
|
96 |
defaultMallocatedMemoryChunkSize:something
|
|
97 |
defaultMallocatedMemoryChunkSize := something.
|
|
98 |
! !
|
|
99 |
|
|
100 |
!JavaNativeMemory methodsFor:'accessing-tests'!
|
|
101 |
|
|
102 |
chunks
|
|
103 |
"For tests only!!!!!!"
|
|
104 |
^chunks
|
|
105 |
|
|
106 |
"Created: / 11-07-2012 / 09:13:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
107 |
! !
|
|
108 |
|
|
109 |
!JavaNativeMemory methodsFor:'allocation'!
|
|
110 |
|
|
111 |
free: address
|
|
112 |
(self chunkFor: address) free: address
|
|
113 |
|
|
114 |
"Created: / 10-07-2012 / 18:57:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
115 |
!
|
752
|
116 |
|
1524
|
117 |
malloc: size
|
|
118 |
| address chunk |
|
|
119 |
|
|
120 |
chunks do:[:each|
|
|
121 |
address := each malloc: size.
|
|
122 |
address notNil ifTrue:[ ^ address ]
|
|
123 |
].
|
|
124 |
size > defaultMallocatedMemoryChunkSize ifTrue:[
|
|
125 |
self breakPoint: #jv.
|
|
126 |
chunk := MallocatedMemoryChunk new: size.
|
|
127 |
] ifFalse:[
|
|
128 |
chunk := MallocatedMemoryChunk new: defaultMallocatedMemoryChunkSize
|
|
129 |
].
|
|
130 |
chunk base: (chunks isEmpty ifTrue:[0] ifFalse:[chunks last base + chunks last size]).
|
|
131 |
chunks add: chunk.
|
|
132 |
address := chunk malloc: size.
|
|
133 |
^address
|
|
134 |
|
|
135 |
"Created: / 10-07-2012 / 18:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
136 |
! !
|
|
137 |
|
|
138 |
!JavaNativeMemory methodsFor:'byte access'!
|
|
139 |
|
|
140 |
byteAt:address
|
|
141 |
^(self chunkFor: address) byteAt: address
|
752
|
142 |
|
|
143 |
"Created: / 09-12-2010 / 17:32:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
144 |
!
|
|
145 |
|
1524
|
146 |
byteAt:address put: value
|
|
147 |
(self chunkFor: address) byteAt: address put: value
|
|
148 |
|
|
149 |
"Created: / 10-07-2012 / 19:01:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
150 |
!
|
|
151 |
|
|
152 |
doubleAt:address
|
|
153 |
^(self chunkFor: address) doubleAt: address
|
|
154 |
|
|
155 |
"Created: / 11-07-2012 / 10:13:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
156 |
!
|
|
157 |
|
|
158 |
doubleAt:address put: value
|
|
159 |
(self chunkFor: address) doubleAt: address put: value
|
|
160 |
|
|
161 |
"Created: / 11-07-2012 / 10:13:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
162 |
!
|
|
163 |
|
1525
|
164 |
sint64At:address
|
|
165 |
"Returns signed 64bit integer at given address"
|
|
166 |
^(self chunkFor: address) sint64At: address
|
1524
|
167 |
|
1525
|
168 |
"Created: / 16-07-2012 / 16:00:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1524
|
169 |
!
|
|
170 |
|
1525
|
171 |
sint64At:address put: value
|
|
172 |
"Stores signed 64bit integer at given address"
|
|
173 |
^(self chunkFor: address) sint64At: address put: value
|
752
|
174 |
|
1525
|
175 |
"Created: / 16-07-2012 / 16:00:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1524
|
176 |
! !
|
|
177 |
|
|
178 |
!JavaNativeMemory methodsFor:'byte transfer'!
|
|
179 |
|
|
180 |
bcopy: dstAddr length: length from: bytearray offset: offset
|
|
181 |
(self chunkFor: dstAddr) bcopy: dstAddr length: length from: bytearray offset: offset
|
|
182 |
|
|
183 |
"Created: / 11-07-2012 / 10:34:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
184 |
!
|
|
185 |
|
|
186 |
bcopy: srcAddr length: length into: bytearray offset: offset
|
|
187 |
(self chunkFor: srcAddr) bcopy: srcAddr length: length into: bytearray offset: offset
|
|
188 |
|
|
189 |
"Created: / 11-07-2012 / 10:32:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
190 |
!
|
|
191 |
|
|
192 |
bcopy: srcAddr to: dstAddr length: length
|
|
193 |
"The bcopy... method copies n bytes from src to dest. The result is correct,
|
|
194 |
even when both areas overlap."
|
|
195 |
|
|
196 |
| srcChunk dstChunk |
|
|
197 |
srcChunk := self chunkFor: srcAddr.
|
|
198 |
dstChunk := self chunkFor: dstAddr.
|
|
199 |
|
|
200 |
srcChunk == dstChunk ifTrue:[
|
|
201 |
"/Easy, same chunk
|
|
202 |
srcChunk bcopy: srcAddr to: dstAddr length: length.
|
|
203 |
^self.
|
|
204 |
].
|
|
205 |
"/ Worse, different chunks...
|
|
206 |
self breakPoint: #jv.
|
|
207 |
self shouldImplement.
|
|
208 |
|
|
209 |
"Created: / 11-07-2012 / 10:21:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1520
|
210 |
!
|
|
211 |
|
1524
|
212 |
memset: s value: c length: n
|
|
213 |
"The memset() function fills the first n bytes of the memory area pointed to by s with
|
|
214 |
the constant byte c"
|
|
215 |
|
|
216 |
(self chunkFor: s) memset: s value: c length: n
|
|
217 |
|
|
218 |
"Created: / 11-07-2012 / 10:27:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
219 |
! !
|
|
220 |
|
|
221 |
!JavaNativeMemory methodsFor:'error reporting'!
|
|
222 |
|
|
223 |
errorSegmentationViolation: message
|
|
224 |
self error: message
|
|
225 |
|
|
226 |
"Created: / 10-07-2012 / 18:59:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
227 |
! !
|
|
228 |
|
|
229 |
!JavaNativeMemory methodsFor:'initialization'!
|
1520
|
230 |
|
1524
|
231 |
initialize
|
|
232 |
"Invoked when a new instance is created."
|
|
233 |
|
|
234 |
"/ please change as required (and remove this comment)
|
|
235 |
chunks := OrderedCollection new.
|
|
236 |
defaultMallocatedMemoryChunkSize := DefaultMallocatedMemoryChunkSize
|
|
237 |
"/ super initialize. -- commented since inherited method does nothing
|
|
238 |
|
|
239 |
"Modified: / 11-07-2012 / 09:11:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
240 |
! !
|
|
241 |
|
|
242 |
!JavaNativeMemory methodsFor:'private'!
|
|
243 |
|
|
244 |
chunkFor: address
|
|
245 |
^chunks
|
|
246 |
detect:[:chunk|address between: chunk base + 1 and: chunk base + chunk size]
|
|
247 |
ifNone:[ self errorSegmentationViolation: 'No chunk for address ', address printString ].
|
|
248 |
|
|
249 |
"Created: / 10-07-2012 / 18:57:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
752
|
250 |
! !
|
|
251 |
|
1524
|
252 |
!JavaNativeMemory::MallocatedMemoryChunk class methodsFor:'instance creation'!
|
|
253 |
|
|
254 |
new
|
|
255 |
"return an initialized instance"
|
|
256 |
|
|
257 |
^ self new: 1024 * 1024"1MB"
|
|
258 |
|
|
259 |
"Modified: / 10-07-2012 / 18:36:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
260 |
!
|
|
261 |
|
|
262 |
new: size
|
|
263 |
"return an initialized instance"
|
|
264 |
|
|
265 |
^ self basicNew initializeWithSize: size
|
|
266 |
|
|
267 |
"Created: / 10-07-2012 / 18:36:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
268 |
! !
|
|
269 |
|
|
270 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'accessing'!
|
|
271 |
|
|
272 |
base
|
|
273 |
^ base
|
|
274 |
!
|
752
|
275 |
|
1524
|
276 |
base:something
|
|
277 |
base := something.
|
|
278 |
!
|
|
279 |
|
|
280 |
size
|
|
281 |
^ size
|
|
282 |
!
|
|
283 |
|
|
284 |
size:something
|
|
285 |
size := something.
|
|
286 |
! !
|
|
287 |
|
|
288 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'accessing-tests'!
|
|
289 |
|
|
290 |
data
|
|
291 |
"For tests only!!!!!!"
|
|
292 |
^ data
|
|
293 |
|
|
294 |
"Modified (comment): / 11-07-2012 / 10:01:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
295 |
! !
|
|
296 |
|
|
297 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'allocation'!
|
|
298 |
|
|
299 |
free: gaddress
|
752
|
300 |
|
|
301 |
"Frees the memory"
|
|
302 |
|
1524
|
303 |
| address aentry aentryPrev |
|
752
|
304 |
|
1524
|
305 |
address := gaddress - base.
|
|
306 |
aentry := alist.
|
1520
|
307 |
aentryPrev := nil.
|
|
308 |
[ aentry notNil and:[aentry start ~~ address ] ] whileTrue:[
|
|
309 |
aentryPrev := aentry.
|
|
310 |
aentry := aentry next.
|
|
311 |
].
|
|
312 |
aentry isNil ifTrue:[
|
|
313 |
self errorFreeingUnallocatedMemory: 'Never allocated'.
|
|
314 |
^self.
|
|
315 |
].
|
752
|
316 |
|
1520
|
317 |
"/Remove from allocated list
|
|
318 |
aentryPrev notNil ifTrue:[
|
|
319 |
aentryPrev next: aentry next.
|
|
320 |
] ifFalse:[
|
1524
|
321 |
alist := aentry next.
|
1520
|
322 |
].
|
752
|
323 |
|
1524
|
324 |
flist := self insert: aentry into: flist join: true.
|
1520
|
325 |
|
|
326 |
"/Insert free entry
|
752
|
327 |
|
|
328 |
"Created: / 07-12-2010 / 23:33:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
329 |
!
|
|
330 |
|
1524
|
331 |
malloc: sz
|
752
|
332 |
|
|
333 |
"Allocate new chunk of memory, size bytes long"
|
|
334 |
|
1520
|
335 |
| fentry aentry |
|
1524
|
336 |
fentry := flist.
|
|
337 |
[ fentry notNil and:[fentry size < sz] ] whileTrue:[
|
1520
|
338 |
fentry := fentry next.
|
|
339 |
].
|
|
340 |
fentry isNil ifTrue:[
|
1524
|
341 |
^nil "Not enough memory in this chunk or too fragmented"
|
1520
|
342 |
].
|
752
|
343 |
|
1520
|
344 |
"/ create allocation entry
|
1524
|
345 |
aentry := FreeListEntry new
|
1520
|
346 |
start: fentry start;
|
1524
|
347 |
stop: fentry start + sz - 1.
|
1520
|
348 |
|
|
349 |
"/Update free entry
|
1524
|
350 |
(fentry start + sz) > size ifTrue:[
|
|
351 |
"No more free memory in this chunk"
|
|
352 |
flist := nil
|
|
353 |
] ifFalse:[
|
|
354 |
fentry start: fentry start + sz.
|
|
355 |
].
|
|
356 |
alist := self insert: aentry into: alist join: false.
|
1520
|
357 |
|
1524
|
358 |
^aentry start + base
|
752
|
359 |
|
|
360 |
"Created: / 07-12-2010 / 23:25:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
361 |
! !
|
|
362 |
|
1524
|
363 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'byte access'!
|
|
364 |
|
|
365 |
byteAt:address
|
|
366 |
^data at: address - base
|
|
367 |
|
|
368 |
"Created: / 09-12-2010 / 17:32:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
369 |
!
|
|
370 |
|
|
371 |
byteAt:address put: value
|
|
372 |
data at: address - base put: value
|
|
373 |
|
|
374 |
"Created: / 10-07-2012 / 19:01:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
375 |
!
|
|
376 |
|
|
377 |
doubleAt:address
|
|
378 |
^data doubleAt: address - base
|
|
379 |
|
|
380 |
"Created: / 11-07-2012 / 10:12:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
381 |
!
|
|
382 |
|
|
383 |
doubleAt:address put: value
|
|
384 |
data doubleAt: address - base put: value
|
752
|
385 |
|
1524
|
386 |
"Created: / 11-07-2012 / 10:12:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
387 |
!
|
|
388 |
|
1525
|
389 |
sint64At:address
|
|
390 |
"Returns signed 64bit integer at given address"
|
1524
|
391 |
|
1525
|
392 |
^data longLongAt: address
|
|
393 |
|
|
394 |
"Created: / 16-07-2012 / 16:00:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1524
|
395 |
!
|
752
|
396 |
|
1525
|
397 |
sint64At:address put: value
|
|
398 |
"Stores signed 64bit integer at given address"
|
1524
|
399 |
|
1525
|
400 |
^ data longLongAt: address put: value.
|
|
401 |
|
|
402 |
"Created: / 16-07-2012 / 16:00:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1524
|
403 |
! !
|
|
404 |
|
|
405 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'byte transfer'!
|
|
406 |
|
|
407 |
bcopy: dstAddr length: length from: bytearray offset: offset
|
|
408 |
|
|
409 |
data replaceBytesFrom: dstAddr - base to: dstAddr - base + length - 1 with: bytearray startingAt: offset + 1
|
|
410 |
|
|
411 |
"Created: / 11-07-2012 / 10:36:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1520
|
412 |
!
|
|
413 |
|
1524
|
414 |
bcopy: srcAddr length: length into: bytearray offset: offset
|
|
415 |
|
|
416 |
bytearray replaceBytesFrom: offset + 1 to: offset + length with: data startingAt: srcAddr - base
|
|
417 |
|
|
418 |
"Created: / 11-07-2012 / 10:33:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
419 |
!
|
|
420 |
|
|
421 |
bcopy: srcAddr to: dstAddr length: length
|
|
422 |
"The bcopy... method copies n bytes from src to dest. The result is correct,
|
|
423 |
even when both areas overlap."
|
1520
|
424 |
|
1524
|
425 |
srcAddr == dstAddr ifTrue:[ ^ self ].
|
|
426 |
srcAddr < dstAddr ifTrue:[
|
|
427 |
(srcAddr + length - 1) < dstAddr ifTrue:[
|
|
428 |
"/No overlap"
|
|
429 |
data replaceBytesFrom: dstAddr - base to: dstAddr - base + length - 1
|
|
430 |
with: data
|
|
431 |
startingAt: srcAddr - base.
|
|
432 |
] ifFalse:[
|
|
433 |
"/Overlap
|
|
434 |
self breakPoint: #jv.
|
|
435 |
self shouldImplement
|
|
436 |
].
|
|
437 |
] ifFalse:[
|
|
438 |
data replaceBytesFrom: dstAddr - base to: dstAddr - base + length - 1
|
|
439 |
with: data
|
|
440 |
startingAt: srcAddr - base.
|
|
441 |
]
|
|
442 |
|
|
443 |
"Created: / 11-07-2012 / 10:22:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
444 |
!
|
|
445 |
|
|
446 |
memset: s value: c length: n
|
|
447 |
"The memset() function fills the first n bytes of the memory area pointed to by s with
|
|
448 |
the constant byte c"
|
|
449 |
|
|
450 |
data from: s - base to: s - base + n - 1 put: c
|
|
451 |
|
|
452 |
"Created: / 11-07-2012 / 10:27:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
453 |
! !
|
|
454 |
|
|
455 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'error reporting'!
|
|
456 |
|
|
457 |
errorFreeingUnallocatedMemory: message
|
|
458 |
self error: message
|
|
459 |
|
|
460 |
"Created: / 10-07-2012 / 18:40:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1520
|
461 |
!
|
|
462 |
|
|
463 |
errorOutOfMemory: message
|
1524
|
464 |
JavaVM throwOutOfMemoryError: message
|
|
465 |
|
|
466 |
"Created: / 10-07-2012 / 18:38:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
467 |
!
|
1520
|
468 |
|
1524
|
469 |
errorSegmentationViolation: message
|
|
470 |
self error: message
|
|
471 |
|
|
472 |
"Created: / 10-07-2012 / 19:00:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
752
|
473 |
! !
|
|
474 |
|
1524
|
475 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'initialization'!
|
752
|
476 |
|
1524
|
477 |
initializeWithSize: sz
|
752
|
478 |
"Invoked when a new instance is created."
|
|
479 |
|
1524
|
480 |
size := sz.
|
|
481 |
data:= ByteArray new: sz.
|
|
482 |
flist := FreeListEntry new start: 1; stop: sz.
|
|
483 |
alist := nil.
|
1520
|
484 |
|
752
|
485 |
|
|
486 |
"/ super initialize. -- commented since inherited method does nothing
|
|
487 |
|
1524
|
488 |
"Created: / 10-07-2012 / 18:37:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1520
|
489 |
! !
|
|
490 |
|
1524
|
491 |
!JavaNativeMemory::MallocatedMemoryChunk methodsFor:'private'!
|
1520
|
492 |
|
|
493 |
insert: entry into: list join: join
|
|
494 |
"Inserts an entry into given list. Returns new
|
|
495 |
list. If join is true, possibly adjacent entries are joined"
|
|
496 |
|
|
497 |
| current prev |
|
|
498 |
|
|
499 |
list isNil ifTrue:[ ^ entry ].
|
|
500 |
current := list.
|
|
501 |
prev := nil.
|
|
502 |
[ current notNil and:[ current stop < entry start ] ] whileTrue:[
|
|
503 |
prev := current.
|
|
504 |
current := current next.
|
|
505 |
].
|
|
506 |
prev isNil ifTrue:[
|
|
507 |
entry next: current join: join.
|
|
508 |
^entry.
|
|
509 |
].
|
|
510 |
prev next: entry join: join.
|
|
511 |
entry next: current join: join.
|
|
512 |
^list
|
|
513 |
|
|
514 |
"Created: / 09-07-2012 / 11:29:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
515 |
! !
|
|
516 |
|
1524
|
517 |
!JavaNativeMemory::MallocatedMemoryChunk::FreeListEntry methodsFor:'accessing'!
|
1520
|
518 |
|
|
519 |
next
|
|
520 |
^nextLink
|
|
521 |
|
|
522 |
"Created: / 09-07-2012 / 11:57:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
523 |
!
|
|
524 |
|
|
525 |
next: next
|
|
526 |
self next: next join: false.
|
|
527 |
|
|
528 |
"Created: / 09-07-2012 / 11:58:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
529 |
!
|
|
530 |
|
|
531 |
size
|
|
532 |
^stop
|
|
533 |
|
|
534 |
"Created: / 09-07-2012 / 10:49:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
535 |
!
|
|
536 |
|
|
537 |
start
|
|
538 |
^ start
|
|
539 |
|
|
540 |
"Created: / 09-07-2012 / 11:23:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
541 |
!
|
|
542 |
|
|
543 |
start:something
|
|
544 |
start := something.
|
|
545 |
!
|
|
546 |
|
|
547 |
stop
|
|
548 |
^ stop
|
|
549 |
|
|
550 |
"Created: / 09-07-2012 / 11:23:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
551 |
!
|
|
552 |
|
|
553 |
stop:something
|
|
554 |
stop := something.
|
|
555 |
! !
|
|
556 |
|
1524
|
557 |
!JavaNativeMemory::MallocatedMemoryChunk::FreeListEntry methodsFor:'printing & storing'!
|
1520
|
558 |
|
|
559 |
printOn:aStream
|
|
560 |
"append a printed representation if the receiver to the argument, aStream"
|
|
561 |
|
|
562 |
super printOn:aStream.
|
|
563 |
aStream nextPutAll:'('.
|
|
564 |
start printOn:aStream.
|
|
565 |
aStream nextPutAll:'..'.
|
|
566 |
stop printOn:aStream.
|
|
567 |
aStream nextPutAll:')'.
|
|
568 |
|
|
569 |
"Modified: / 09-07-2012 / 11:54:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
570 |
! !
|
|
571 |
|
1524
|
572 |
!JavaNativeMemory::MallocatedMemoryChunk::FreeListEntry methodsFor:'utilities'!
|
1520
|
573 |
|
|
574 |
next: next join: join
|
|
575 |
(join and:[next notNil]) ifTrue:[
|
|
576 |
stop + 1 == next start ifTrue:[
|
|
577 |
stop := next stop.
|
|
578 |
(nextLink notNil and:[stop + 1 == nextLink start]) ifTrue:[
|
|
579 |
stop := nextLink stop.
|
|
580 |
nextLink := nextLink next.
|
|
581 |
].
|
|
582 |
^self
|
|
583 |
].
|
|
584 |
].
|
|
585 |
nextLink := next.
|
|
586 |
|
|
587 |
"Created: / 09-07-2012 / 11:49:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
752
|
588 |
! !
|
|
589 |
|
|
590 |
!JavaNativeMemory class methodsFor:'documentation'!
|
|
591 |
|
|
592 |
version_SVN
|
|
593 |
^ '$Id$'
|
|
594 |
! !
|
1524
|
595 |
|
|
596 |
JavaNativeMemory initialize!
|