--- a/JavaClass.st Fri Aug 16 19:52:36 2013 +0200
+++ b/JavaClass.st Fri Sep 06 02:45:44 2013 +0200
@@ -21,13 +21,21 @@
"{ Package: 'stx:libjava' }"
JavaBehavior subclass:#JavaClass
- instanceVariableNames:'classLoader fullName sourceFile sourceString binaryFilePath
- fields staticFields annotations protectionDomain signatureJ'
+ instanceVariableNames:'classLoader fullName sourceFile sourceString classfileBytes
+ fields staticFields annotations protectionDomain signatureJ
+ versions'
classVariableNames:'ArgumentConversionErrorSignal OrderOfClassInits'
poolDictionaries:'JavaConstants'
category:'Languages-Java-Classes'
!
+Object subclass:#JavaClassVersionDiedHandler
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:JavaClass
+!
+
!JavaClass class methodsFor:'documentation'!
copyright
@@ -465,6 +473,13 @@
"Modified: / 4.11.1998 / 19:31:33 / cg"
! !
+!JavaClass class methodsFor:'others'!
+
+version_HG
+
+ ^ '$Changeset: <not expanded> $'
+! !
+
!JavaClass class methodsFor:'signature parsing'!
initialValueFromSignature:aSignature
@@ -588,10 +603,6 @@
annotations := something.
!
-binaryFile
- ^ binaryFilePath
-!
-
classLoader
^ classLoader
!
@@ -602,6 +613,10 @@
"Modified: / 18-02-2012 / 20:21:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+classfileBytes
+ ^ classfileBytes
+!
+
compiledMethodAt:name
"redefined to find the constructor"
@@ -744,13 +759,6 @@
^ name "/ fullName
!
-nameSpace
- ^ NameSpace name:#JAVA
-
- "Created: / 20-01-1997 / 13:04:30 / cg"
- "Modified: / 11-04-2012 / 23:25:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
nameWithoutNameSpacePrefix
^ fullName
@@ -842,6 +850,12 @@
^ sourceFile
!
+sourceString
+ ^sourceString
+
+ "Created: / 19-04-2013 / 09:28:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
staticFields
^ staticFields
!
@@ -860,6 +874,28 @@
"Created: / 04-02-2011 / 12:35:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+topNameSpaceName
+ "Return the nameSpace of my topOwningClass (if private) or my own nameSpace."
+
+ "/ All classes loaded by system, ext or primordial class loader should go
+ "/ to namespace JAVA. The rest should go a namespace crated for its class loader.
+ "/ this allows for multiple versions of the class to be visible in the browser
+
+ | systemLoader extLoader |
+
+ classLoader isNil ifTrue:[ ^ #JAVA ].
+ systemLoader := JavaVM systemClassLoader.
+ systemLoader notNil ifTrue:[
+ classLoader == systemLoader ifTrue:[ ^ #JAVA ].
+ extLoader := systemLoader instVarNamed: #parent.
+ classLoader == extLoader ifTrue:[ ^ #JAVA ].
+ ].
+
+ ^ ('JAVA_' , (classLoader identityHash printStringRadix: 16 padTo: 8)) asSymbol.
+
+ "Created: / 03-09-2013 / 00:38:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
typeOfField:aFieldName
fields do:[:aField |
@@ -874,6 +910,29 @@
"
"Modified: 21.1.1997 / 22:48:28 / cg"
+!
+
+versions
+ "
+ Return all existing versions of this class.
+ A new version is added when a class is
+ updated by runtime code reload and removed when all instances of
+ the version die
+ "
+
+ ^ versions.
+
+ "Created: / 14-04-2013 / 12:10:54 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+!
+
+versions: aWeakArray
+ "
+ set this class' versions. It is expected that all versions of the
+ class will share the same weak array instance.
+ "
+ versions := aWeakArray.
+
+ "Created: / 14-04-2013 / 12:28:09 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaClass methodsFor:'accessing - java'!
@@ -1076,6 +1135,11 @@
"Created: / 18-03-2012 / 14:19:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+handlerForSignal:exceptionHandler context:theContext originator:originator
+ ^nil
+
+!
+
handles: anObject
Transcript showCR:'>>>> JavaClass>>handles: ' , anObject printString.
@@ -1376,6 +1440,8 @@
perform:aMessage onReceiver:receiver from:sender ifNotFound:aBlock
+ <resource: #skipInDebuggersWalkBack>
+
| lo method selector class args|
selector := aMessage selector.
args := aMessage arguments.
@@ -1386,8 +1452,8 @@
method notNil ifTrue:[
method isStatic ifTrue:[
^ method
- valueWithReceiver:self
- arguments:args
+ valueWithReceiver:self arguments:args selector:selector search:self class
+
].
].
].
@@ -1419,7 +1485,7 @@
"Created: / 19-09-2011 / 23:33:06 / Jan Kurs <kursjan@fit.cvut.cz>"
"Modified: / 10-04-2012 / 16:47:31 / kursjan"
- "Modified: / 21-08-2012 / 13:32:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 09-08-2013 / 00:48:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaClass methodsFor:'java initialization'!
@@ -1473,19 +1539,13 @@
classInitInternal
"Called by the JIT-compiled code when a class needs to be initialized"
+ | m |
+
self classInit.
"Force recompilation"
- thisContext sender method flushCode.
-
-!
-
-classInitSpecial
- "Called by the VM when a class needs to be initialized"
-
- self classInit.
-
- "Created: / 08-02-2012 / 23:43:57 / mh <hlopik@gmail.com>"
- "Modified: / 17-07-2012 / 20:54:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ (m := thisContext sender method) isJavaMethod ifTrue:[m flushCode].
+
+
!
initializeStaticFields
@@ -2079,8 +2139,11 @@
"Created: 15.4.1996 / 16:42:52 / cg"
!
-setBinaryFilePath:aPathName
- binaryFilePath := aPathName
+setClassfileBytes: aByteArray
+ self assert: aByteArray isByteArray.
+ classfileBytes := aByteArray
+
+ "Created: / 29-03-2013 / 23:57:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
setFields:f
@@ -2144,12 +2207,13 @@
"Created: / 20-02-2012 / 22:47:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-setSource: aString
- self assert: aString isString.
- sourceString := aString
+setSource: aStringOrNil
+ self assert: (aStringOrNil isNil or:[aStringOrNil isString]).
+ sourceString := aStringOrNil
"Created: / 15-04-1996 / 16:42:52 / cg"
"Created: / 18-02-2012 / 19:10:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 19-04-2013 / 09:30:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
setSourceFile:aFilename
@@ -2267,10 +2331,11 @@
"Classes subclassing from sun.reflect.MagicAccessorImpl are not subject to access rights checks. Another non-documented gem found in openjdk sources :)"
| magicAccessor |
- magicAccessor := Java classNamed: 'sun.reflect.MagicAccessorImpl'.
+ magicAccessor := JavaVM classNamed: 'sun.reflect.MagicAccessorImpl' definedBy: nil.
^ magicAccessor notNil and: [ self includesBehavior: magicAccessor ].
"Created: / 18-11-2012 / 16:11:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 02-05-2013 / 01:23:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
isAnonymous
@@ -2779,23 +2844,76 @@
"Created: / 08-11-2011 / 12:25:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
+!JavaClass methodsFor:'versions'!
+
+mergeVersionsWith: aJavaClass
+ "
+ take both self and aJavaClass and ensure that:
+ 1) both share the same versions array instance
+ 2) versions instance includes both self and aJavaClass.
+ "
+
+ (self versions isNil and: [ aJavaClass versions isNil ]) ifTrue: [
+|versions|
+ versions := WeakArray with: self with: aJavaClass.
+ versions addDependent: JavaClass::JavaClassVersionDiedHandler new.
+ self versions: versions.
+ aJavaClass versions: versions.
+ ^ self.
+ ].
+ self versions isNil ifTrue: [
+ self versions: aJavaClass versions.
+ self versions add: self.
+ ^ self.
+ ].
+ aJavaClass versions isNil ifTrue: [
+ aJavaClass versions: self versions.
+ self versions add: aJavaClass.
+ ^ self.
+ ].
+ self error: 'merge of two classes both of which have multiple versions not supported'.
+
+ "Created: / 14-04-2013 / 13:44:03 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+! !
+
+!JavaClass::JavaClassVersionDiedHandler class methodsFor:'documentation'!
+
+history
+
+ "Created: #update:with:from: / 14-04-2013 / 14:04:20 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+! !
+
+!JavaClass::JavaClassVersionDiedHandler methodsFor:'notification'!
+
+update:aParameter with:anArgument from:source
+
+ aParameter = #ElementExpired ifFalse: [
+ self error: 'only #ElementExpired updates supported'.
+ ].
+ self assert: (source notNil and: [ source size >= 1 ]).
+
+ source size = 1 ifTrue: [
+ "only one version remaining - we can start caching. Let's change the flag"
+ | javaClass |
+ javaClass := (source at: 1).
+ javaClass markCacheable.
+ ].
+
+ "Created: / 14-04-2013 / 14:04:20 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+! !
+
!JavaClass class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libjava/JavaClass.st,v 1.135 2013-04-27 12:31:15 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libjava/JavaClass.st,v 1.136 2013-09-06 00:41:18 vrany Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libjava/JavaClass.st,v 1.135 2013-04-27 12:31:15 cg Exp $'
-!
-
-version_HG
-
- ^ '§Changeset: <not expanded> §'
+ ^ '$Header: /cvs/stx/stx/libjava/JavaClass.st,v 1.136 2013-09-06 00:41:18 vrany Exp $'
!
version_SVN
- ^ '§Id§'
+ ^ 'Id'
! !