77 "return an initialized instance" |
77 "return an initialized instance" |
78 |
78 |
79 ^ self basicNew initialize. |
79 ^ self basicNew initialize. |
80 ! ! |
80 ! ! |
81 |
81 |
82 !JavaFinalizationRegistry methodsFor:'* As yet uncategorized *'! |
82 !JavaFinalizationRegistry methodsFor:'finalization'! |
83 |
83 |
84 registerChange: anObject |
84 finalizationCycle |
85 "/Nothing to do" |
|
86 |
|
87 "Created: / 24-07-2012 / 03:31:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
88 ! ! |
|
89 |
|
90 !JavaFinalizationRegistry methodsFor:'initialization'! |
|
91 |
|
92 initialize |
|
93 "Invoked when a new instance is created." |
|
94 |
|
95 "/ please change as required (and remove this comment) |
|
96 activeReferees := Array new: 200. |
|
97 "/ super initialize. -- commented since inherited method does nothing |
|
98 |
|
99 "Modified (comment): / 24-07-2012 / 02:05:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
100 ! ! |
|
101 |
|
102 !JavaFinalizationRegistry methodsFor:'private'! |
|
103 |
|
104 collectionCycle |
|
105 |
85 |
106 | referees references living wasBlocked firstPendingReference lastPendingReference ref | |
86 | referees references living wasBlocked firstPendingReference lastPendingReference ref | |
107 |
87 |
108 referees := (activeReferees select:[:e|e notNil]) asArray. |
88 referees := (activeReferees select:[:e|e notNil]) asArray. |
109 references := Array new: referees size. |
89 references := Array new: referees size. |
141 ]. |
121 ]. |
142 wasBlocked ifFalse:[ OperatingSystem unblockInterrupts]. |
122 wasBlocked ifFalse:[ OperatingSystem unblockInterrupts]. |
143 |
123 |
144 self informReferenceHandler: firstPendingReference |
124 self informReferenceHandler: firstPendingReference |
145 |
125 |
146 "Created: / 24-07-2012 / 01:30:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
126 "Created: / 24-07-2012 / 15:14:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
147 ! |
127 ! |
|
128 |
|
129 finalizationLoop |
|
130 |
|
131 [ |
|
132 finalizationSemaphore waitWithTimeoutMs: 10000"10sec". |
|
133 self finalizationCycle |
|
134 ] loop |
|
135 |
|
136 "Created: / 24-07-2012 / 15:16:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
137 ! ! |
|
138 |
|
139 !JavaFinalizationRegistry methodsFor:'initialization'! |
|
140 |
|
141 initialize |
|
142 "Invoked when a new instance is created." |
|
143 |
|
144 "/ please change as required (and remove this comment) |
|
145 activeReferees := Array new: 200. |
|
146 "/ super initialize. -- commented since inherited method does nothing |
|
147 |
|
148 "Modified: / 24-07-2012 / 15:23:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
149 ! ! |
|
150 |
|
151 !JavaFinalizationRegistry methodsFor:'private'! |
148 |
152 |
149 firstFreeIndex |
153 firstFreeIndex |
150 activeReferees withIndexDo:[:value :index| |
154 activeReferees withIndexDo:[:value :index| |
151 value isNil ifTrue:[ |
155 value isNil ifTrue:[ |
152 ^index |
156 ^index |
341 finalizedClass classInit. |
345 finalizedClass classInit. |
342 (finalizedClass methodDictionary at: #'register(Ljava/lang/Object;)V') |
346 (finalizedClass methodDictionary at: #'register(Ljava/lang/Object;)V') |
343 valueWithReceiver: finalizedClass arguments: (Array with: object) |
347 valueWithReceiver: finalizedClass arguments: (Array with: object) |
344 |
348 |
345 "Created: / 24-07-2012 / 01:14:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
349 "Created: / 24-07-2012 / 01:14:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
350 ! |
|
351 |
|
352 registerChange: anObject |
|
353 "/Nothing to do, to be polymprph with Registry" |
|
354 |
|
355 "Created: / 24-07-2012 / 03:31:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
356 ! ! |
|
357 |
|
358 !JavaFinalizationRegistry methodsFor:'start & stop'! |
|
359 |
|
360 startFinalizationProcessAt:aPriority |
|
361 |
|
362 |p| |
|
363 |
|
364 finalizationProcess notNil ifTrue:[ |
|
365 finalizationProcess priority:aPriority. |
|
366 ^ self |
|
367 ]. |
|
368 |
|
369 finalizationSemaphore := Semaphore new name:'FinalizationSemaphore (Java)'. |
|
370 |
|
371 p := |
|
372 [ |
|
373 [ |
|
374 self finalizationLoop |
|
375 ] ifCurtailed:[ |
|
376 finalizationProcess := nil. |
|
377 finalizationSemaphore := nil |
|
378 ] |
|
379 ] newProcess. |
|
380 p name:'background finalizer (Java)'. |
|
381 p priority:aPriority. |
|
382 p restartable:true. |
|
383 p beSystemProcess. |
|
384 p resume. |
|
385 finalizationProcess := p |
|
386 |
|
387 "Created: / 24-07-2012 / 15:25:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
388 ! |
|
389 |
|
390 stopFinalizationProcess |
|
391 "stop the background finalizer" |
|
392 |
|
393 finalizationProcess notNil ifTrue:[ |
|
394 finalizationProcess terminate. |
|
395 finalizationProcess := nil |
|
396 ]. |
|
397 |
|
398 "Created: / 24-07-2012 / 15:26:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
399 ! ! |
|
400 |
|
401 !JavaFinalizationRegistry methodsFor:'utilities'! |
|
402 |
|
403 finalizeNow |
|
404 "Force finalization to run now" |
|
405 finalizationSemaphore signal |
|
406 |
|
407 "Created: / 24-07-2012 / 15:28:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
346 ! ! |
408 ! ! |
347 |
409 |
348 !JavaFinalizationRegistry class methodsFor:'documentation'! |
410 !JavaFinalizationRegistry class methodsFor:'documentation'! |
349 |
411 |
350 version_SVN |
412 version_SVN |