# HG changeset patch # User vranyj1 # Date 1343140627 0 # Node ID 2af2aa41bddb11c710758ba013dafb588c9a0a1c # Parent fde50161f2b48ca9b2ed4c47df2675772aeef4a6 - JavaFinalizationRegistry class definition added:6 methods changed: #initialize #registerChange: category of: #collectionCycle #registerChange: - JavaVM changed: #commonOpenStreamUsing: #initializeVM - Java changed: #flushAllJavaResources - extensions ... diff -r fde50161f2b4 -r 2af2aa41bddb src/Java.st --- a/src/Java.st Tue Jul 24 10:22:56 2012 +0000 +++ b/src/Java.st Tue Jul 24 14:37:07 2012 +0000 @@ -1077,14 +1077,17 @@ GroovyEvaluator flushWorkspaceBinding . GroovyCompiler flushGroovyClassLoader. JavaClass flushClassesInitOrder. - self flushClasses + self flushClasses. + JavaVM finalizationLobby notNil ifTrue:[ + JavaVM finalizationLobby stopFinalizationProcess + ] " Java flushAllJavaResources" "Modified: / 06-11-2001 / 09:49:37 / cg" "Modified: / 02-11-2011 / 21:34:13 / Marcel Hlopko " - "Modified: / 18-02-2012 / 22:25:24 / Jan Vrany " + "Modified: / 24-07-2012 / 15:33:14 / Jan Vrany " ! flushClasses diff -r fde50161f2b4 -r 2af2aa41bddb src/JavaFinalizationRegistry.st --- a/src/JavaFinalizationRegistry.st Tue Jul 24 10:22:56 2012 +0000 +++ b/src/JavaFinalizationRegistry.st Tue Jul 24 14:37:07 2012 +0000 @@ -21,7 +21,7 @@ "{ Package: 'stx:libjava' }" Object subclass:#JavaFinalizationRegistry - instanceVariableNames:'activeReferees' + instanceVariableNames:'activeReferees finalizationSemaphore finalizationProcess' classVariableNames:'' poolDictionaries:'' category:'Languages-Java-Support' @@ -79,29 +79,9 @@ ^ self basicNew initialize. ! ! -!JavaFinalizationRegistry methodsFor:'* As yet uncategorized *'! - -registerChange: anObject - "/Nothing to do" - - "Created: / 24-07-2012 / 03:31:18 / Jan Vrany " -! ! - -!JavaFinalizationRegistry methodsFor:'initialization'! +!JavaFinalizationRegistry methodsFor:'finalization'! -initialize - "Invoked when a new instance is created." - - "/ please change as required (and remove this comment) - activeReferees := Array new: 200. - "/ super initialize. -- commented since inherited method does nothing - - "Modified (comment): / 24-07-2012 / 02:05:14 / Jan Vrany " -! ! - -!JavaFinalizationRegistry methodsFor:'private'! - -collectionCycle +finalizationCycle | referees references living wasBlocked firstPendingReference lastPendingReference ref | @@ -143,9 +123,33 @@ self informReferenceHandler: firstPendingReference - "Created: / 24-07-2012 / 01:30:07 / Jan Vrany " + "Created: / 24-07-2012 / 15:14:50 / Jan Vrany " ! +finalizationLoop + + [ + finalizationSemaphore waitWithTimeoutMs: 10000"10sec". + self finalizationCycle + ] loop + + "Created: / 24-07-2012 / 15:16:51 / Jan Vrany " +! ! + +!JavaFinalizationRegistry methodsFor:'initialization'! + +initialize + "Invoked when a new instance is created." + + "/ please change as required (and remove this comment) + activeReferees := Array new: 200. + "/ super initialize. -- commented since inherited method does nothing + + "Modified: / 24-07-2012 / 15:23:18 / Jan Vrany " +! ! + +!JavaFinalizationRegistry methodsFor:'private'! + firstFreeIndex activeReferees withIndexDo:[:value :index| value isNil ifTrue:[ @@ -343,6 +347,64 @@ valueWithReceiver: finalizedClass arguments: (Array with: object) "Created: / 24-07-2012 / 01:14:26 / Jan Vrany " +! + +registerChange: anObject + "/Nothing to do, to be polymprph with Registry" + + "Created: / 24-07-2012 / 03:31:18 / Jan Vrany " +! ! + +!JavaFinalizationRegistry methodsFor:'start & stop'! + +startFinalizationProcessAt:aPriority + + |p| + + finalizationProcess notNil ifTrue:[ + finalizationProcess priority:aPriority. + ^ self + ]. + + finalizationSemaphore := Semaphore new name:'FinalizationSemaphore (Java)'. + + p := + [ + [ + self finalizationLoop + ] ifCurtailed:[ + finalizationProcess := nil. + finalizationSemaphore := nil + ] + ] newProcess. + p name:'background finalizer (Java)'. + p priority:aPriority. + p restartable:true. + p beSystemProcess. + p resume. + finalizationProcess := p + + "Created: / 24-07-2012 / 15:25:06 / Jan Vrany " +! + +stopFinalizationProcess + "stop the background finalizer" + + finalizationProcess notNil ifTrue:[ + finalizationProcess terminate. + finalizationProcess := nil + ]. + + "Created: / 24-07-2012 / 15:26:38 / Jan Vrany " +! ! + +!JavaFinalizationRegistry methodsFor:'utilities'! + +finalizeNow + "Force finalization to run now" + finalizationSemaphore signal + + "Created: / 24-07-2012 / 15:28:45 / Jan Vrany " ! ! !JavaFinalizationRegistry class methodsFor:'documentation'! diff -r fde50161f2b4 -r 2af2aa41bddb src/JavaVM.st --- a/src/JavaVM.st Tue Jul 24 10:22:56 2012 +0000 +++ b/src/JavaVM.st Tue Jul 24 14:37:07 2012 +0000 @@ -1922,7 +1922,7 @@ self initializeSystemClassLoader. ObjectMemory addDependent: self. StartupTime := OperatingSystem getOSTime. - + FinalizationLobby startFinalizationProcessAt: 5. " @@ -1934,7 +1934,7 @@ "Modified: / 15-10-2010 / 15:27:45 / Jan Kurs " "Modified: / 24-02-2012 / 13:59:29 / Marcel Hlopko " "Modified: / 24-02-2012 / 14:37:06 / Marcel Hlopko " - "Modified: / 24-07-2012 / 02:44:46 / Jan Vrany " + "Modified (format): / 24-07-2012 / 15:31:51 / Jan Vrany " ! initializeVMIfNoEventThreadRunning @@ -4438,8 +4438,13 @@ retry := false. [ stream := aBlock value ] on:OpenError do:[:ex| (ex errorCode) == (OperatingSystem errorNumberFor:#EMFILE) ifTrue:[ - ObjectMemory garbageCollect. - retry := true. + [ + FinalizationLobby finalizeNow. + ObjectMemory garbageCollect. + retry := true. + ] on: Error do:[:ex| + Logger log: 'Failed to force finalization: ', ex description severity: #error facility: #JVM + ]. ] ifFalse:[ ex pass. ]. diff -r fde50161f2b4 -r 2af2aa41bddb src/libjava.rc --- a/src/libjava.rc Tue Jul 24 10:22:56 2012 +0000 +++ b/src/libjava.rc Tue Jul 24 14:37:07 2012 +0000 @@ -3,7 +3,7 @@ // automagically generated from the projectDefinition: stx_libjava. // VS_VERSION_INFO VERSIONINFO - FILEVERSION 6,2,1903,1903 + FILEVERSION 6,2,1905,1905 PRODUCTVERSION 6,2,1,1 #if (__BORLANDC__) FILEFLAGSMASK VS_FF_DEBUG | VS_FF_PRERELEASE @@ -20,12 +20,12 @@ BEGIN VALUE "CompanyName", "eXept Software AG\0" VALUE "FileDescription", "Smalltalk/X Class library (LIB)\0" - VALUE "FileVersion", "6.2.1903.1903\0" + VALUE "FileVersion", "6.2.1905.1905\0" VALUE "InternalName", "stx:libjava\0" VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\nCopyright Jan Vrany, Jan Kurs and Marcel Hlopko\b SWING Research Group, Czech Technical University In Prague\0" VALUE "ProductName", "Smalltalk/X\0" VALUE "ProductVersion", "6.2.1.1\0" - VALUE "ProductDate", "Tue, 24 Jul 2012 10:25:45 GMT\0" + VALUE "ProductDate", "Tue, 24 Jul 2012 14:41:08 GMT\0" END END