JavaConstantPool.st
changeset 749 e898eaeff091
parent 748 da0840b7798c
child 2108 ca8c4e7db2e8
--- a/JavaConstantPool.st	Thu Sep 23 13:52:13 2010 +0000
+++ b/JavaConstantPool.st	Fri Aug 19 08:58:19 2011 +0000
@@ -1,6 +1,10 @@
 "
- COPYRIGHT (c) 1997 by eXept Software AG
-              All Rights Reserved
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -8,15 +12,38 @@
  be provided or otherwise made available to, or used by, any
  other person.  No title to or ownership of the software is
  hereby transferred.
-"
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
 
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
 
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+"
 "{ Package: 'stx:libjava' }"
 
 Array variableSubclass:#JavaConstantPool
 	instanceVariableNames:'owner'
-	classVariableNames:''
+	classVariableNames:'ConstantPools'
 	poolDictionaries:''
 	category:'Languages-Java-Reader-Support'
 !
@@ -25,8 +52,12 @@
 
 copyright
 "
- COPYRIGHT (c) 1997 by eXept Software AG
-              All Rights Reserved
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -34,60 +65,95 @@
  be provided or otherwise made available to, or used by, any
  other person.  No title to or ownership of the software is
  hereby transferred.
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+
 "
+! !
+
+!JavaConstantPool class methodsFor:'initialization'!
+
+initialize
+    ConstantPools := OrderedCollection new: 1000.
 
+    "Modified: / 08-04-2011 / 17:28:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 09-04-2011 / 09:25:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
+!JavaConstantPool class methodsFor:'instance creation'!
+
+new: size 
+    "return an initialized instance"
+    
+    ^ ConstantPools add: ((super new: size)
+                initialize;
+                yourself).
+
+    "Created: / 08-04-2011 / 16:56:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 09-04-2011 / 09:24:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-04-2011 / 18:46:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!JavaConstantPool class methodsFor:'accessing'!
+
+allConstantPools
+    "linked list of all constant pools in system"
+    ^ ConstantPools.
+
+    "Created: / 08-04-2011 / 16:53:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 09-04-2011 / 09:24:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+allConstantPools: anOorderedCollection 
+    "linked list of all constant pools in system"
+    
+    ConstantPools := anOorderedCollection.
+
+    "Created: / 08-04-2011 / 17:07:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 09-04-2011 / 09:24:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-04-2011 / 18:47:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaConstantPool class methodsFor:'special'!
 
-compressPools
-    "unify all constants"
-
-    |strings nameandTypes jStrings|
-
-    strings := Set new.
-    nameandTypes := Set new.
-
-    self allInstancesDo:[:aPool |
-        aPool keysAndValuesDo:[:idx :aConst |
-            |existing nt|
+invalidateForClass: internalJavaClassName 
+    "Only alias, everybody calls invalidateForClass so why not me :)"
+    
+    ^self invalidateReferencesToClass: internalJavaClassName.
 
-            aConst isString ifTrue:[
-                existing := strings elementAt:aConst ifAbsent:nil.
-                existing isNil ifTrue:[
-                    strings add:aConst
-                ] ifFalse:[
-                    aPool at:idx put:existing
-                ]
-            ] ifFalse:[
-                (aConst isMemberOf:JavaFieldref) ifTrue:[
-                    nt := aConst nameandType.
-                    existing := nameandTypes elementAt:nt ifAbsent:nil.
-                    existing isNil ifTrue:[
-                        nameandTypes add:nt
-                    ] ifFalse:[
-                        aConst nameandType:existing
-                    ]
-                ] ifFalse:[
-                    (aConst isMemberOf:JavaNameandType) ifTrue:[
-                        existing := nameandTypes elementAt:aConst ifAbsent:nil.
-                        existing isNil ifTrue:[
-                            nameandTypes add:aConst
-                        ] ifFalse:[
-                            aPool at:idx put:existing
-                        ]
-                    ]
-                ]
-            ]
-        ].
-    ]
+    "Created: / 08-04-2011 / 16:52:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
 
-    "
-     self compressPools
-    "
+invalidateReferencesToClass: internalJavaClassName 
+    "Go over all constant pools and call invalidateForClass on all 
+     references. (usable when given class was unloaded etc)"
+    ConstantPools do: [:each | each invalidateForClass: internalJavaClassName].
 
-    "Modified: 19.8.1997 / 14:04:25 / cg"
+    "Created: / 08-04-2011 / 16:09:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaConstantPool methodsFor:'accessing'!
@@ -108,6 +174,60 @@
     "Created: 28.6.1996 / 21:12:22 / cg"
 ! !
 
+!JavaConstantPool methodsFor:'adding'!
+
+at: classRefIndex putClassRefWithNameAt: classNameIndex 
+    self at: classRefIndex
+        put: (JavaClassRef2 in: self withNameAt: classNameIndex).
+
+    "Created: / 13-05-2011 / 09:48:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+at: fieldRefIndex putFieldRefWithClassAt: classRefIndex andNameAndTypeAt: nameAndTypeIndex 
+    self at: fieldRefIndex
+        put: (JavaFieldRef2 
+                in: self
+                withNameAndTypeAt: nameAndTypeIndex
+                andClassAt: classRefIndex).
+
+    "Created: / 13-05-2011 / 09:08:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+at: interfaceMethodRefIndex putInterfaceMethodRefWithClassAt: classRefIndex andNameAndTypeAt: nameAndTypeIndex 
+    self at: interfaceMethodRefIndex
+        put: (JavaInterfaceMethodRef2 
+                in: self
+                withNameAndTypeAt: nameAndTypeIndex
+                andClassAt: classRefIndex).
+
+    "Created: / 13-05-2011 / 09:08:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+at: methodRefIndex putMethodRefWithClassAt: classRefIndex andNameAndTypeAt: nameAndTypeIndex
+    self at: methodRefIndex
+        put: (JavaMethodRef2 in: self withNameAndTypeAt: nameAndTypeIndex andClassAt:classRefIndex).
+
+    "Created: / 13-05-2011 / 09:07:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+at: nameAndTypeIndex putNameAndTypeWithNameAt: nameIndex andDescriptorAt: descriptorIndex
+    self at: nameAndTypeIndex
+        put: (JavaNameAndType2 in: self withNameAt: nameIndex andDescriptorAt: descriptorIndex).
+
+    "Created: / 13-05-2011 / 09:05:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!JavaConstantPool methodsFor:'initialization'!
+
+initialize
+    "Invoked when a new instance is created."
+
+    "/ please change as required (and remove this comment)
+    "/ owner := nil.
+
+    "/ super initialize.   -- commented since inherited method does nothing
+! !
+
 !JavaConstantPool methodsFor:'printing & storing'!
 
 displayString
@@ -123,38 +243,35 @@
 !JavaConstantPool methodsFor:'queries'!
 
 refersToMethod:aJavaMethod
+
+    self error: 'JV@2011-07-26: Update to new resolving scheme!!'.
+
     self do:[:constItem |
         (constItem == aJavaMethod) ifTrue:[^ true].
-        (constItem isMemberOf:JavaMethodref) ifTrue:[
-            self halt.
-        ].
-        (constItem isMemberOf:JavaUnresolvedMethodrefConstant) ifTrue:[
-            self halt.
+
+    ].
+    ^ false
+
+    "Created: / 29-07-1997 / 17:39:19 / cg"
+    "Modified: / 26-07-2011 / 18:00:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+refersToMethodNamed:aJavaMethodName
+
+    self error: 'JV@2011-07-26: Update to new resolving scheme!!'.
+    
+    self do:[:constItem |
+        (constItem isKindOf:JavaMethod) ifTrue:[
+            constItem name = aJavaMethodName ifTrue:[^ true].
+        ] ifFalse:[
+            
         ]
     ].
     ^ false
 
-    "Modified: 29.7.1997 / 17:36:49 / cg"
-    "Created: 29.7.1997 / 17:39:19 / cg"
-!
-
-refersToMethodNamed:aJavaMethodName
-    self do:[:constItem |
-        (constItem isKindOf:JavaMethod) ifTrue:[
-            constItem name = aJavaMethodName ifTrue:[^ true].
-        ] ifFalse:[
-            (constItem isMemberOf:JavaMethodref) ifTrue:[
-                constItem name = aJavaMethodName ifTrue:[^ true].
-            ].
-            (constItem isMemberOf:JavaUnresolvedMethodrefConstant) ifTrue:[
-                self halt.
-            ]
-        ]
-    ].
-    ^ false
-
-    "Created: / 29.7.1997 / 17:39:24 / cg"
-    "Modified: / 16.10.1998 / 01:22:02 / cg"
+    "Created: / 29-07-1997 / 17:39:24 / cg"
+    "Modified: / 16-10-1998 / 01:22:02 / cg"
+    "Modified: / 26-07-2011 / 17:54:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaConstantPool methodsFor:'special'!
@@ -170,6 +287,25 @@
     "Created: / 4.1.1998 / 00:40:11 / cg"
 !
 
+invalidateAll 
+    "go over all entries and call invalidate on all references"
+    
+    self do: 
+            [:entry | 
+            entry isJavaRef 
+                ifTrue: [ entry invalidate] ].
+
+    "Created: / 13-05-2011 / 09:37:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+invalidateForClass: internalJavaClassName
+"go over all entries and call invalidateForClass on all references"
+
+self do: [:entry | entry isJavaRef ifTrue:[entry invalidateForClass: internalJavaClassName]].
+
+    "Created: / 08-04-2011 / 16:11:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
 updateClassRefsFrom:oldClass to:newClass
 owner == oldClass ifTrue:[
     self halt.
@@ -223,5 +359,11 @@
 !JavaConstantPool class methodsFor:'documentation'!
 
 version
-    ^ '$Id$'
+    ^ '$Id: JavaConstantPool.st,v 1.15 2011/08/18 18:42:48 vrany Exp $'
+!
+
+version_SVN
+    ^ '$Id: JavaConstantPool.st,v 1.15 2011/08/18 18:42:48 vrany Exp $'
 ! !
+
+JavaConstantPool initialize!
\ No newline at end of file