- JavaVM
changed:
#_java_io_FileInputStream_open:
#initialize
#initializeVM
- JavaFinalizationRegistry
added:
#copyright
#version_SVN
- JavaObject
added: #finalizationLobby
- stx_libjava
changed:
#classNamesAndAttributes
#extensionMethodNames
#preRequisites
- extensions
...
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/JavaFinalizationRegistry.st Tue Jul 24 01:42:45 2012 +0000
@@ -0,0 +1,195 @@
+"
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+
+ New code and modifications done at SWING Research Group [1]:
+
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+ SWING Research Group, Czech Technical University in Prague
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+
+ [1] Code written at SWING Research Group contains a signature
+ of one of the above copright owners. For exact set of such code,
+ see the differences between this version and version stx:libjava
+ as of 1.9.2010
+"
+"{ Package: 'stx:libjava' }"
+
+Object subclass:#JavaFinalizationRegistry
+ instanceVariableNames:'activeReferees'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Languages-Java-Support'
+!
+
+!JavaFinalizationRegistry class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+
+ New code and modifications done at SWING Research Group [1]:
+
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+ SWING Research Group, Czech Technical University in Prague
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+
+ [1] Code written at SWING Research Group contains a signature
+ of one of the above copright owners. For exact set of such code,
+ see the differences between this version and version stx:libjava
+ as of 1.9.2010
+
+"
+!
+
+documentation
+"
+ A tricky class that implements Java-style finalization.
+ Future versions may involve some C / VM optimization,
+ if this algorithm prooves usefull
+
+ [author:]
+ Jan Vrany <jan.vrany@fit.cvut.cz>
+
+ [instance variables:]
+
+ [class variables:]
+
+ [see also:]
+
+"
+! !
+
+!JavaFinalizationRegistry class methodsFor:'instance creation'!
+
+new
+ "return an initialized instance"
+
+ ^ self basicNew initialize.
+! !
+
+!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 (comment): / 24-07-2012 / 02:05:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaFinalizationRegistry methodsFor:'private'!
+
+collectionCycle
+
+ | referees references living wasBlocked firstPendingReference lastPendingReference|
+
+ referees := (activeReferees collect:[:e|e notNil]) asArray.
+ references := Array new: referees size.
+ living := Array new: referees size.
+ firstPendingReference := nil.
+
+ ObjectMemory allObjectsIncludingContextsDo:[:o|
+ | index |
+
+ (index := self references: o anyOf: referees) ~~ 0 ifTrue:[
+ o class name == #'java/lang/ref/Finalizer' ifTrue:[
+ self assert: (o instVarNamed: #next) isNil.
+ references at: index put: o
+ ] ifFalse:[
+ living at: index put: o.
+ ]
+ ].
+ ].
+
+ wasBlocked := OperatingSystem blockInterrupts.
+
+ living withIndexDo:[:each :index|
+ each notNil ifTrue:[
+ | ref |
+
+ ref := references at: index.
+ references at: index put: nil.
+ firstPendingReference isNil ifTrue:[
+ firstPendingReference := lastPendingReference := ref
+ ] ifFalse:[
+ lastPendingReference instVarNamed: #'next' put: ref.
+ lastPendingReference := ref.
+ ].
+ lastPendingReference instVarNamed: #'next' put: lastPendingReference.
+ ].
+ ].
+ firstPendingReference notNil ifTrue:[
+ (Java classForName: 'java.lang.ref.Reference')
+ instVarNamed: #pending put: firstPendingReference
+ ].
+ wasBlocked ifFalse:[ OperatingSystem unblockInterrupts.]
+
+ "Created: / 24-07-2012 / 01:30:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+firstFreeIndex
+ activeReferees withIndexDo:[:value :index|
+ value isNil ifTrue:[
+ ^index
+ ].
+ ].
+ self grow.
+
+ "Created: / 24-07-2012 / 01:19:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+grow
+
+ self shouldImplement.
+
+ "Created: / 24-07-2012 / 01:20:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+references: object anyOf: collection
+ "If object references any object in a collection, return
+ index of value which it references, zero otherwise"
+
+ "This is naturaly a candidate for optimization, look
+ at Object>>referencesAny:"
+
+ collection withIndexDo:[:each :eachi|
+ (object references: each) ifTrue:[^eachi].
+ ].
+ ^0
+
+ "Created: / 24-07-2012 / 01:49:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaFinalizationRegistry methodsFor:'registering objects'!
+
+register: object
+ "Register an object for being finalized"
+
+ | index finalizedClass |
+ index := self firstFreeIndex.
+ activeReferees at: index put: object.
+ ((finalizedClass := Java classForName:'java.lang.ref.Finalizer') methodDictionary at: #'register(Ljava/lang/Object;)V')
+ valueWithReceiver: finalizedClass arguments: (Array with: object)
+
+ "Created: / 24-07-2012 / 01:14:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaFinalizationRegistry class methodsFor:'documentation'!
+
+version_SVN
+ ^ '$Id:: $'
+! !
--- a/src/JavaObject.st Mon Jul 23 22:31:28 2012 +0000
+++ b/src/JavaObject.st Tue Jul 24 01:42:45 2012 +0000
@@ -143,14 +143,13 @@
!JavaObject methodsFor:'finalization'!
-finalize
+finalizationLobby
+
+ ^super finalizationLobby
- Logger log: 'Finalizing ', self printString severity: #info facility: #JVM.
- [ self perform: #'finalize()V' ] on: Error, (Java classForName:'java.lang.Throwable') do:[:error|
- Logger log: 'Error when finalizing ', self printString severity: #error facility: #JVM.
- ]
+ "/ ^JavaVM finalizationLobby "/ Do not use this yet!!
- "Created: / 14-11-2011 / 12:32:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 24-07-2012 / 01:04:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaObject methodsFor:'initialization'!
--- a/src/JavaVM.st Mon Jul 23 22:31:28 2012 +0000
+++ b/src/JavaVM.st Tue Jul 24 01:42:45 2012 +0000
@@ -1400,7 +1400,6 @@
AssertionsEnabled := true.
ClassRegistry := JavaClassRegistry new.
FinalizationEnabled := true.
- FinalizationLobby := Registry new.
EagerResolvingEnabled := false.
"
@@ -1410,7 +1409,7 @@
"Modified: / 02-12-1998 / 23:02:22 / cg"
"Modified: / 09-10-2011 / 20:29:10 / Marcel Hlopko <hlopik@gmail.com>"
"Modified: / 08-12-2011 / 21:06:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 09-04-2012 / 21:01:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 24-07-2012 / 02:10:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
initializeAdditionalJavaProtocol
@@ -1884,6 +1883,7 @@
ZipCache := OrderedCollection new.
ZipEntryCache := OrderedCollection new.
ZipInflaters := OrderedCollection new.
+ FinalizationLobby := JavaFinalizationRegistry new.
"/ force re-resolving;
"/ otherwise, class-inits would not be called
@@ -1923,6 +1923,8 @@
ObjectMemory addDependent: self.
StartupTime := OperatingSystem getOSTime.
+
+
"
JavaVM initialize.
JavaVM initializeVM."
@@ -1932,7 +1934,7 @@
"Modified: / 15-10-2010 / 15:27:45 / Jan Kurs <kurs.jan@post.cz>"
"Modified: / 24-02-2012 / 13:59:29 / Marcel Hlopko <hlopik@gmail.com>"
"Modified: / 24-02-2012 / 14:37:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 23-07-2012 / 22:35:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 24-07-2012 / 02:44:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
initializeVMIfNoEventThreadRunning
@@ -5661,11 +5663,10 @@
fd instVarNamed:'fd' put:fileNo.
"Kludge for finalization..."
- fs finalizationLobby registerChange: fs
"Created: / 04-01-1998 / 16:47:12 / cg"
"Modified: / 28-01-1999 / 17:24:07 / cg"
- "Modified (format): / 18-07-2012 / 23:29:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 24-07-2012 / 02:17:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_java_io_FileInputStream_read: nativeContext
--- a/src/Make.proto Mon Jul 23 22:31:28 2012 +0000
+++ b/src/Make.proto Tue Jul 24 01:42:45 2012 +0000
@@ -167,6 +167,7 @@
$(OUTDIR)JavaError.$(O) JavaError.$(H): JavaError.st $(INCLUDE_TOP)/stx/libbasic/Error.$(H) $(INCLUDE_TOP)/stx/libbasic/Exception.$(H) $(INCLUDE_TOP)/stx/libbasic/GenericException.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
$(OUTDIR)JavaExceptionTableEntry.$(O) JavaExceptionTableEntry.$(H): JavaExceptionTableEntry.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
$(OUTDIR)JavaField.$(O) JavaField.$(H): JavaField.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
+$(OUTDIR)JavaFinalizationRegistry.$(O) JavaFinalizationRegistry.$(H): JavaFinalizationRegistry.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
$(OUTDIR)JavaLanguage.$(O) JavaLanguage.$(H): JavaLanguage.st $(INCLUDE_TOP)/stx/libbasic/ProgrammingLanguage.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
$(OUTDIR)JavaLibraries.$(O) JavaLibraries.$(H): JavaLibraries.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
$(OUTDIR)JavaLocalVariableTable.$(O) JavaLocalVariableTable.$(H): JavaLocalVariableTable.st $(INCLUDE_TOP)/stx/libbasic/Array.$(H) $(INCLUDE_TOP)/stx/libbasic/ArrayedCollection.$(H) $(INCLUDE_TOP)/stx/libbasic/SequenceableCollection.$(H) $(INCLUDE_TOP)/stx/libbasic/Collection.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
--- a/src/Make.spec Mon Jul 23 22:31:28 2012 +0000
+++ b/src/Make.spec Tue Jul 24 01:42:45 2012 +0000
@@ -163,6 +163,7 @@
JavaMetaclass \
GroovyMetaclass \
JavaNioSupport \
+ JavaFinalizationRegistry \
@@ -281,6 +282,7 @@
$(OUTDIR)JavaMetaclass.$(O) \
$(OUTDIR)GroovyMetaclass.$(O) \
$(OUTDIR)JavaNioSupport.$(O) \
+ $(OUTDIR)JavaFinalizationRegistry.$(O) \
$(OUTDIR)extensions.$(O) \
--- a/src/abbrev.stc Mon Jul 23 22:31:28 2012 +0000
+++ b/src/abbrev.stc Tue Jul 24 01:42:45 2012 +0000
@@ -140,3 +140,4 @@
JavaRefsAndConstantPoolTestCase JavaRefsAndConstantPoolTestCase stx:libjava 'Languages-Java-Tests-RuntimeConstantPool' 1
JavaNioSupport JavaNioSupport stx:libjava 'Languages-Java-Support-Native' 0
JavaNativeMemoryTests JavaNativeMemoryTests stx:libjava 'Languages-Java-Tests' 1
+JavaFinalizationRegistry JavaFinalizationRegistry stx:libjava 'Languages-Java-Support' 0
--- a/src/bc.mak Mon Jul 23 22:31:28 2012 +0000
+++ b/src/bc.mak Tue Jul 24 01:42:45 2012 +0000
@@ -115,6 +115,7 @@
$(OUTDIR)JavaError.$(O) JavaError.$(H): JavaError.st $(INCLUDE_TOP)\stx\libbasic\Error.$(H) $(INCLUDE_TOP)\stx\libbasic\Exception.$(H) $(INCLUDE_TOP)\stx\libbasic\GenericException.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
$(OUTDIR)JavaExceptionTableEntry.$(O) JavaExceptionTableEntry.$(H): JavaExceptionTableEntry.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
$(OUTDIR)JavaField.$(O) JavaField.$(H): JavaField.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
+$(OUTDIR)JavaFinalizationRegistry.$(O) JavaFinalizationRegistry.$(H): JavaFinalizationRegistry.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
$(OUTDIR)JavaLanguage.$(O) JavaLanguage.$(H): JavaLanguage.st $(INCLUDE_TOP)\stx\libbasic\ProgrammingLanguage.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
$(OUTDIR)JavaLibraries.$(O) JavaLibraries.$(H): JavaLibraries.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
$(OUTDIR)JavaLocalVariableTable.$(O) JavaLocalVariableTable.$(H): JavaLocalVariableTable.st $(INCLUDE_TOP)\stx\libbasic\Array.$(H) $(INCLUDE_TOP)\stx\libbasic\ArrayedCollection.$(H) $(INCLUDE_TOP)\stx\libbasic\SequenceableCollection.$(H) $(INCLUDE_TOP)\stx\libbasic\Collection.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
--- a/src/libInit.cc Mon Jul 23 22:31:28 2012 +0000
+++ b/src/libInit.cc Tue Jul 24 01:42:45 2012 +0000
@@ -52,6 +52,7 @@
_JavaError_Init(pass,__pRT__,snd);
_JavaExceptionTableEntry_Init(pass,__pRT__,snd);
_JavaField_Init(pass,__pRT__,snd);
+_JavaFinalizationRegistry_Init(pass,__pRT__,snd);
_JavaLanguage_Init(pass,__pRT__,snd);
_JavaLibraries_Init(pass,__pRT__,snd);
_JavaLocalVariableTable_Init(pass,__pRT__,snd);
--- a/src/libjava.rc Mon Jul 23 22:31:28 2012 +0000
+++ b/src/libjava.rc Tue Jul 24 01:42:45 2012 +0000
@@ -25,7 +25,7 @@
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", "Mon, 23 Jul 2012 21:44:03 GMT\0"
+ VALUE "ProductDate", "Tue, 24 Jul 2012 01:47:12 GMT\0"
END
END
--- a/src/stx_libjava.st Mon Jul 23 22:31:28 2012 +0000
+++ b/src/stx_libjava.st Tue Jul 24 01:42:45 2012 +0000
@@ -156,16 +156,16 @@
^ #(
#'squeak:petitparser'
- #'stx:goodies/sunit' "TestCase - superclass of JavaTestCaseProxy "
- #'stx:libbasic' "LimitedPrecisionReal - superclass of extended ShortFloat "
- #'stx:libbasic2' "BitArray - superclass of extended BooleanArray "
- #'stx:libbasic3' "MessageTracer - referenced by JavaMethod>>setBreakPoint "
- #'stx:libcomp' "ReturnNode - referenced by ProxyMethodCompiler>>generate "
+ #'stx:goodies/sunit' "TestSuite - referenced by stx_libjava class>>testSuite "
+ #'stx:libbasic' "Method - superclass of ProxyMethod "
+ #'stx:libbasic2' "Socket - superclass of JavaSocket "
+ #'stx:libbasic3' "WrappedMethod - extended "
+ #'stx:libcomp' "Parser::ParseError - referenced by GroovyCompiler>>error:line:from:to: "
#'stx:libhtml' "URL - referenced by JavaEmbeddedFrameView>>setupAppletFrameIn:initializeJava: "
#'stx:libtool' "WorkspaceApplication - referenced by GroovyEvaluator>>evaluate:in:receiver:notifying:logged:ifFail: "
- #'stx:libview' "TopView - superclass of JavaTopView "
- #'stx:libview2' "GIFReader - referenced by JavaVM class>>_GifImageDecoder_parseImage: "
- #'stx:libwidg' "Scroller - referenced by JavaVM class>>processEvent: "
+ #'stx:libview' "SimpleView - superclass of JavaView "
+ #'stx:libview2' "Plug - referenced by JavaSourceCodeCache>>findMethodLine:inMethods: "
+ #'stx:libwidg' "HorizontalScrollBar - referenced by JavaVM class>>_WScrollPanePeer__getHScrollbarHeight: "
#'stx:libwidg2' "ComboBoxView - referenced by JavaVM class>>processEvent: "
)
! !
@@ -392,6 +392,7 @@
(JavaRefsAndConstantPoolTestCase autoload)
JavaNioSupport
(JavaNativeMemoryTests autoload)
+ JavaFinalizationRegistry
)
!
@@ -614,7 +615,7 @@
"Return a SVN revision number of myself.
This number is updated after a commit"
- ^ "$SVN-Revision:"'1890 '"$"
+ ^ "$SVN-Revision:"'1902M '"$"
! !
!stx_libjava class methodsFor:'file generation'!