src/JavaClass.st
branchjk_new_structure
changeset 1109 9bd0544f9046
parent 1098 dd1e76f6f964
child 1135 79bdd1501934
--- a/src/JavaClass.st	Sun Nov 13 22:57:59 2011 +0000
+++ b/src/JavaClass.st	Mon Nov 14 20:16:09 2011 +0000
@@ -1343,17 +1343,23 @@
      however, <init> is not invoked for it."
     
     | newJavaObject  
-      sz            "{ Class: SmallInteger }" |
-
-    (accessFlags bitAnd: A_ABSTRACT_OR_INTERFACE) ~~ 0 
-        ifTrue: 
-            [ JavaVM throwInstantiationExceptionFor: self.
-            ^ nil ].            
+      sz            "{ Class: SmallInteger }" 
+      finalizeM |
+
+    (accessFlags bitAnd: A_ABSTRACT_OR_INTERFACE) ~~ 0 ifTrue: [ 
+        JavaVM throwInstantiationExceptionFor: self.
+        ^ nil 
+    ].            
     newJavaObject := super basicNew.
-    initValues notNil 
-        ifTrue: 
-            [ sz := self instSize.
-            1 to: sz do: [:i | newJavaObject instVarAt: i put: (initValues at: i) ]. ].
+    initValues notNil ifTrue: [ sz := self instSize.
+        1 to: sz do: [:i | newJavaObject instVarAt: i put: (initValues at: i) ].
+    ].
+    JavaVM finalizationEnabled ifTrue:[
+        finalizeM := self lookupMethodFor: #'finalize()V'.
+        finalizeM byteCode = #[177] "See Object#finalize()" ifFalse:[
+            newJavaObject registerForFinalization.
+        ].
+    ].
     ^ newJavaObject
 
     "
@@ -1363,6 +1369,7 @@
 
     "Modified: / 13-11-1998 / 14:10:45 / cg"
     "Modified: / 10-03-2011 / 22:38:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 14-11-2011 / 21:14:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 newWith_String:argString