author | vranyj1 |
Sat, 28 Jul 2012 09:50:36 +0000 | |
branch | jk_new_structure |
changeset 1565 | 09ba1af5dcf6 |
parent 1564 | 48e14e6b3eab |
child 1599 | 79a644cf787e |
permissions | -rw-r--r-- |
1548 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
3 |
||
4 |
New code and modifications done at SWING Research Group [1]: |
|
5 |
||
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 |
||
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 |
|
19 |
as of 1.9.2010 |
|
20 |
" |
|
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#JavaFinalizationRegistry |
|
1563 | 24 |
instanceVariableNames:'accessLock referees refereesTally new newTally |
25 |
finalizationSemaphore finalizationProcess' |
|
1548 | 26 |
classVariableNames:'' |
27 |
poolDictionaries:'' |
|
28 |
category:'Languages-Java-Support' |
|
29 |
! |
|
30 |
||
31 |
!JavaFinalizationRegistry class methodsFor:'documentation'! |
|
32 |
||
33 |
copyright |
|
34 |
" |
|
35 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
36 |
||
37 |
New code and modifications done at SWING Research Group [1]: |
|
38 |
||
39 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
40 |
SWING Research Group, Czech Technical University in Prague |
|
41 |
||
42 |
This software is furnished under a license and may be used |
|
43 |
only in accordance with the terms of that license and with the |
|
44 |
inclusion of the above copyright notice. This software may not |
|
45 |
be provided or otherwise made available to, or used by, any |
|
46 |
other person. No title to or ownership of the software is |
|
47 |
hereby transferred. |
|
48 |
||
49 |
[1] Code written at SWING Research Group contains a signature |
|
50 |
of one of the above copright owners. For exact set of such code, |
|
51 |
see the differences between this version and version stx:libjava |
|
52 |
as of 1.9.2010 |
|
53 |
||
54 |
" |
|
55 |
! |
|
56 |
||
57 |
documentation |
|
58 |
" |
|
59 |
A tricky class that implements Java-style finalization. |
|
60 |
Future versions may involve some C / VM optimization, |
|
61 |
if this algorithm prooves usefull |
|
62 |
||
63 |
[author:] |
|
64 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
65 |
||
66 |
[instance variables:] |
|
67 |
||
68 |
[class variables:] |
|
69 |
||
70 |
[see also:] |
|
71 |
||
72 |
" |
|
73 |
! ! |
|
74 |
||
75 |
!JavaFinalizationRegistry class methodsFor:'instance creation'! |
|
76 |
||
77 |
new |
|
78 |
"return an initialized instance" |
|
79 |
||
80 |
^ self basicNew initialize. |
|
81 |
! ! |
|
82 |
||
1551 | 83 |
!JavaFinalizationRegistry methodsFor:'finalization'! |
1548 | 84 |
|
1551 | 85 |
finalizationCycle |
1548 | 86 |
|
1563 | 87 |
| references living firstPendingReference lastPendingReference ref finished| |
1553
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
88 |
|
1563 | 89 |
references := Array new: refereesTally. |
90 |
living := Array new: refereesTally. |
|
1548 | 91 |
firstPendingReference := nil. |
1563 | 92 |
finished := self allObjectsIncludingContextsDo:[:o| |
1548 | 93 |
| index | |
1563 | 94 |
(o ~~ referees) ifTrue:[ |
95 |
(index := self references: o anyOf: referees tally: refereesTally) ~~ 0 ifTrue:[ |
|
1549 | 96 |
o class name == #'java/lang/ref/Finalizer' ifTrue:[ |
1550
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
97 |
self assert: (self getNextOf: o) isNil. |
1549 | 98 |
references at: index put: o |
99 |
] ifFalse:[ |
|
100 |
living at: index put: o. |
|
101 |
] |
|
102 |
]. |
|
1548 | 103 |
]. |
104 |
]. |
|
1563 | 105 |
finished ifFalse:[ ^ self ]. |
1548 | 106 |
living withIndexDo:[:each :index| |
1549 | 107 |
each isNil ifTrue:[ |
1548 | 108 |
ref := references at: index. |
1563 | 109 |
self unregisterAt: index. |
110 |
ref notNil ifTrue:[ |
|
111 |
firstPendingReference isNil ifTrue:[ |
|
112 |
firstPendingReference := lastPendingReference := ref |
|
113 |
] ifFalse:[ |
|
114 |
self setNextOf: lastPendingReference to: ref. |
|
115 |
lastPendingReference := ref. |
|
116 |
]. |
|
117 |
self setNextOf: lastPendingReference to: lastPendingReference |
|
1548 | 118 |
] ifFalse:[ |
1563 | 119 |
Logger log: 'background finalizer: referee registered but reference gone' severity: #error facility: #JVM |
120 |
] |
|
1548 | 121 |
]. |
122 |
]. |
|
1563 | 123 |
accessLock critical:[ |
124 |
"Copy new to referees, this somewhat delays finalization" |
|
125 |
refereesTally + newTally > referees size ifTrue:[ |
|
126 |
referees := self grow: referees min: refereesTally + newTally. |
|
127 |
]. |
|
128 |
referees replaceFrom: refereesTally + 1 to: refereesTally + newTally with: new startingAt: 1. |
|
129 |
new from: 1 to: newTally put: nil. |
|
130 |
refereesTally := refereesTally + newTally. |
|
131 |
newTally := 0. |
|
1553
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
132 |
]. |
1549 | 133 |
|
134 |
self informReferenceHandler: firstPendingReference |
|
1548 | 135 |
|
1551 | 136 |
"Created: / 24-07-2012 / 15:14:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1548 | 137 |
! |
138 |
||
1551 | 139 |
finalizationLoop |
140 |
||
141 |
[ |
|
142 |
finalizationSemaphore waitWithTimeoutMs: 10000"10sec". |
|
143 |
self finalizationCycle |
|
144 |
] loop |
|
145 |
||
146 |
"Created: / 24-07-2012 / 15:16:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
147 |
! ! |
|
148 |
||
149 |
!JavaFinalizationRegistry methodsFor:'initialization'! |
|
150 |
||
151 |
initialize |
|
152 |
"Invoked when a new instance is created." |
|
153 |
||
154 |
"/ please change as required (and remove this comment) |
|
1563 | 155 |
|
156 |
referees := Array new: 200. |
|
157 |
refereesTally := 0. |
|
158 |
new := Array new: 200. |
|
159 |
newTally := 0. |
|
1553
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
160 |
accessLock := RecursionLock new. |
1551 | 161 |
"/ super initialize. -- commented since inherited method does nothing |
162 |
||
1563 | 163 |
"Modified: / 28-07-2012 / 01:32:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1551 | 164 |
! ! |
165 |
||
166 |
!JavaFinalizationRegistry methodsFor:'private'! |
|
167 |
||
1563 | 168 |
allObjectsIncludingContextsDo:aBlock |
169 |
||
1564 | 170 |
| wasBlocked | |
171 |
||
172 |
wasBlocked := OperatingSystem blockInterrupts. |
|
173 |
||
174 |
(ObjectMemory allObjectsDo:aBlock) ifFalse:[ |
|
175 |
wasBlocked ifTrue:[ |
|
176 |
OperatingSystem unblockInterrupts. |
|
177 |
]. |
|
178 |
^false |
|
179 |
]. |
|
1563 | 180 |
ProcessorScheduler knownProcesses do:[:p | |
181 |
|con| |
|
182 |
||
183 |
con := p suspendedContext. |
|
184 |
[con notNil] whileTrue:[ |
|
185 |
aBlock value:con. |
|
186 |
con := con sender. |
|
1548 | 187 |
]. |
188 |
]. |
|
1564 | 189 |
wasBlocked ifTrue:[ |
190 |
OperatingSystem unblockInterrupts. |
|
191 |
]. |
|
192 |
||
1563 | 193 |
^ true |
1548 | 194 |
|
1563 | 195 |
"Created: / 28-07-2012 / 02:14:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1548 | 196 |
! |
197 |
||
1550
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
198 |
getNextOf: reference |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
199 |
|
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
200 |
^reference instVarAt: 3 |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
201 |
|
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
202 |
"Created: / 24-07-2012 / 11:22:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
203 |
! |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
204 |
|
1563 | 205 |
grow: array |
206 |
^self grow: array min: 30 |
|
1548 | 207 |
|
1563 | 208 |
"Created: / 28-07-2012 / 01:14:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
209 |
! |
|
1553
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
210 |
|
1563 | 211 |
grow: array min: min |
212 |
| grown | |
|
1548 | 213 |
|
1563 | 214 |
grown := Array new: ((array size * 2) max: min). |
215 |
grown replaceFrom: 1 with: array. |
|
216 |
^grown |
|
217 |
||
218 |
"Created: / 28-07-2012 / 01:27:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1548 | 219 |
! |
220 |
||
1549 | 221 |
informReferenceHandler: reference |
222 |
| referenceClass lock | |
|
223 |
||
224 |
reference isNil ifTrue:[ ^ self ]. |
|
225 |
||
226 |
referenceClass := Java classForName: 'java.lang.ref.Reference'. |
|
1550
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
227 |
lock := JavaVM monitorFor: (referenceClass instVarNamed: #lock). |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
228 |
|
1549 | 229 |
|
1550
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
230 |
lock enter. |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
231 |
[ |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
232 |
referenceClass instVarNamed: #pending put: reference. |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
233 |
lock notify. |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
234 |
] ensure:[ |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
235 |
lock exit. |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
236 |
]. |
1549 | 237 |
|
238 |
"Created: / 24-07-2012 / 03:42:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
239 |
! |
|
240 |
||
1563 | 241 |
references: object anyOf: aCollection tally: tally |
1548 | 242 |
"If object references any object in a collection, return |
243 |
index of value which it references, zero otherwise" |
|
244 |
||
1549 | 245 |
%{ |
246 |
OBJ cls, flags; |
|
247 |
int nInsts, inst; |
|
248 |
if (! __isNonNilObject(object)) { |
|
249 |
RETURN (__MKINT(0)); |
|
250 |
} |
|
251 |
||
252 |
if (__isArrayLike(aCollection)) { |
|
1563 | 253 |
int sz = __arraySize(aCollection); |
254 |
int tl = __intVal(tally); |
|
255 |
int nObjs = sz < tl ? sz : tl; |
|
256 |
char *minAddr = 0, *maxAddr = 0; |
|
1549 | 257 |
|
258 |
if (nObjs == 0) { |
|
259 |
RETURN (__MKINT(0)); |
|
260 |
} |
|
261 |
||
262 |
/* |
|
263 |
* a little optimization: use the fact that all old objects |
|
264 |
* refering to a new object are on the remSet; if I am not, |
|
265 |
* a trivial reject is possible, if all objects are newbees. |
|
266 |
* as a side effect, gather min/max addresses |
|
267 |
*/ |
|
268 |
if ((__qSpace(object) <= OLDSPACE) && !__isRemembered(object)) { |
|
269 |
int allNewBees = 1; |
|
270 |
int i; |
|
271 |
||
272 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
273 |
maxAddr = minAddr; |
|
274 |
||
275 |
for (i=0; i<nObjs; i++) { |
|
276 |
OBJ anObject; |
|
277 |
||
278 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
279 |
||
280 |
if (__isNonNilObject(anObject)) { |
|
281 |
int spc; |
|
282 |
||
283 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
284 |
allNewBees = 0; |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
if ((char *)anObject < minAddr) { |
|
289 |
minAddr = (char *)anObject; |
|
290 |
} else if ((char *)anObject > maxAddr) { |
|
291 |
maxAddr = (char *)anObject; |
|
292 |
} |
|
293 |
} |
|
294 |
if (allNewBees) { |
|
295 |
RETURN (__MKINT(0)); |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
/* |
|
300 |
* fetch min/max in searchList (if not already done) |
|
301 |
*/ |
|
302 |
if (minAddr == 0) { |
|
303 |
int i; |
|
1548 | 304 |
|
1549 | 305 |
for (i=0; i<nObjs; i++) { |
306 |
OBJ anObject; |
|
307 |
||
308 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
309 |
if ((char *)anObject < minAddr) { |
|
310 |
minAddr = (char *)anObject; |
|
311 |
} else if ((char *)anObject > maxAddr) { |
|
312 |
maxAddr = (char *)anObject; |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
cls = __qClass(object); |
|
318 |
flags = __ClassInstPtr(cls)->c_flags; |
|
319 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
320 |
nInsts = __BYTES2OBJS__(__qSize(object) - OHDR_SIZE); |
|
321 |
} else { |
|
322 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
323 |
} |
|
324 |
if (! nInsts) { |
|
325 |
RETURN (__MKINT(0)); |
|
326 |
} |
|
327 |
||
328 |
if (nObjs == 1) { |
|
329 |
/* better reverse the loop */ |
|
330 |
OBJ anObject; |
|
331 |
||
332 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
333 |
#if defined(memsrch4) |
|
334 |
if (memsrch4(__InstPtr(object)->i_instvars, (INT)anObject, nInsts)) { |
|
335 |
RETURN (__MKINT(1)); |
|
336 |
} |
|
337 |
#else |
|
338 |
for (inst=0; inst<nInsts; inst++) { |
|
339 |
if ((__InstPtr(object)->i_instvars[inst]) == anObject) { |
|
340 |
RETURN (__MKINT(1)); |
|
341 |
} |
|
342 |
} |
|
343 |
#endif |
|
1563 | 344 |
RETURN ( __MKINT( 0 ) ); |
1549 | 345 |
} |
346 |
||
347 |
for (inst=0; inst<nInsts; inst++) { |
|
348 |
OBJ instVar = __InstPtr(object)->i_instvars[inst]; |
|
349 |
int i; |
|
350 |
||
351 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
352 |
for (i=0; i<nObjs; i++) { |
|
353 |
OBJ anObject; |
|
354 |
||
355 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
356 |
if (instVar == anObject) { |
|
357 |
RETURN (__MKINT(i+1)); |
|
358 |
} |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
RETURN (__MKINT(0)); |
|
363 |
} |
|
364 |
%}. |
|
365 |
||
1563 | 366 |
1 to: (aCollection size min: tally) do:[:eachi| | each | |
367 |
each := aCollection at: eachi. |
|
1548 | 368 |
(object references: each) ifTrue:[^eachi]. |
369 |
]. |
|
370 |
^0 |
|
371 |
||
1563 | 372 |
"Created: / 28-07-2012 / 01:18:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1550
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
373 |
! |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
374 |
|
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
375 |
setNextOf: reference to: value |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
376 |
|
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
377 |
^reference instVarAt: 3 put: value |
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
378 |
|
fde50161f2b4
- more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents:
1549
diff
changeset
|
379 |
"Created: / 24-07-2012 / 11:22:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1548 | 380 |
! ! |
381 |
||
382 |
!JavaFinalizationRegistry methodsFor:'registering objects'! |
|
383 |
||
384 |
register: object |
|
385 |
"Register an object for being finalized" |
|
386 |
||
387 |
| index finalizedClass | |
|
1553
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
388 |
|
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
389 |
accessLock critical:[ |
1563 | 390 |
newTally = new size ifTrue:[ |
391 |
new := self grow: new |
|
392 |
]. |
|
393 |
index := newTally := newTally + 1. |
|
394 |
new at: index put: object. |
|
395 |
finalizedClass := Java classForName:'java.lang.ref.Finalizer'. |
|
396 |
finalizedClass classInit. |
|
397 |
(finalizedClass methodDictionary at: #'register(Ljava/lang/Object;)V') |
|
398 |
valueWithReceiver: finalizedClass arguments: (Array with: object). |
|
1553
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
399 |
]. |
ee3e63c04778
JavaVM: increased initial old space allocation, create huge LockTable to prevent its realloction
vranyj1
parents:
1552
diff
changeset
|
400 |
|
1548 | 401 |
"Created: / 24-07-2012 / 01:14:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1551 | 402 |
! |
403 |
||
404 |
registerChange: anObject |
|
405 |
"/Nothing to do, to be polymprph with Registry" |
|
406 |
||
407 |
"Created: / 24-07-2012 / 03:31:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1563 | 408 |
! |
409 |
||
410 |
unregisterAt: index |
|
411 |
"Unregister an object at index from being finalized" |
|
412 |
||
413 |
refereesTally < index ifTrue:[ |
|
414 |
referees at: index put: (referees at: refereesTally). |
|
415 |
]. |
|
416 |
referees at: refereesTally put: nil. |
|
417 |
refereesTally := refereesTally - 1. |
|
418 |
||
419 |
"Created: / 28-07-2012 / 01:24:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1551 | 420 |
! ! |
421 |
||
422 |
!JavaFinalizationRegistry methodsFor:'start & stop'! |
|
423 |
||
1565 | 424 |
resumeFinalizationProcess |
425 |
"stop the background finalizer" |
|
426 |
||
427 |
finalizationProcess notNil ifTrue:[ |
|
428 |
finalizationProcess resume. |
|
429 |
] ifFalse:[ |
|
430 |
self startFinalizationProcessAt: 5 |
|
431 |
]. |
|
432 |
||
433 |
"Created: / 28-07-2012 / 10:53:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
434 |
! |
|
435 |
||
1551 | 436 |
startFinalizationProcessAt:aPriority |
437 |
||
438 |
|p| |
|
439 |
||
440 |
finalizationProcess notNil ifTrue:[ |
|
441 |
finalizationProcess priority:aPriority. |
|
442 |
^ self |
|
443 |
]. |
|
444 |
||
445 |
finalizationSemaphore := Semaphore new name:'FinalizationSemaphore (Java)'. |
|
446 |
||
447 |
p := |
|
448 |
[ |
|
449 |
[ |
|
450 |
self finalizationLoop |
|
451 |
] ifCurtailed:[ |
|
452 |
finalizationProcess := nil. |
|
453 |
finalizationSemaphore := nil |
|
454 |
] |
|
455 |
] newProcess. |
|
456 |
p name:'background finalizer (Java)'. |
|
457 |
p priority:aPriority. |
|
458 |
p restartable:true. |
|
459 |
p beSystemProcess. |
|
460 |
p resume. |
|
461 |
finalizationProcess := p |
|
462 |
||
463 |
"Created: / 24-07-2012 / 15:25:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
464 |
! |
|
465 |
||
466 |
stopFinalizationProcess |
|
467 |
"stop the background finalizer" |
|
468 |
||
469 |
finalizationProcess notNil ifTrue:[ |
|
470 |
finalizationProcess terminate. |
|
471 |
finalizationProcess := nil |
|
472 |
]. |
|
473 |
||
474 |
"Created: / 24-07-2012 / 15:26:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1565 | 475 |
! |
476 |
||
477 |
suspendFinalizationProcess |
|
478 |
"stop the background finalizer" |
|
479 |
||
480 |
finalizationProcess notNil ifTrue:[ |
|
481 |
finalizationProcess suspend. |
|
482 |
]. |
|
483 |
||
484 |
"Created: / 28-07-2012 / 10:53:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1551 | 485 |
! ! |
486 |
||
487 |
!JavaFinalizationRegistry methodsFor:'utilities'! |
|
488 |
||
489 |
finalizeNow |
|
490 |
"Force finalization to run now" |
|
1564 | 491 |
finalizationSemaphore signal. |
492 |
finalizationSemaphore signal. |
|
1551 | 493 |
|
494 |
"Created: / 24-07-2012 / 15:28:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1548 | 495 |
! ! |
496 |
||
497 |
!JavaFinalizationRegistry class methodsFor:'documentation'! |
|
498 |
||
499 |
version_SVN |
|
500 |
^ '$Id:: $' |
|
501 |
! ! |