--- a/JavaClassRegistry.st Wed Dec 18 12:03:32 2013 +0100
+++ b/JavaClassRegistry.st Wed Dec 18 14:52:11 2013 +0100
@@ -78,7 +78,7 @@
!JavaClassRegistry methodsFor:'accessing'!
-classForName: className loader: classLoader ifAbsent: aBlock
+classForName: className loader: classLoader ifAbsent: aBlock
"Get class loaded by given classLoader from registry or evaluate aBlock if class is not yet registered"
| classes class |
@@ -104,9 +104,9 @@
"Created: / 23-10-2011 / 11:40:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-classForName: className loader: classLoader ifAbsentPut: block
+classForName: className loader: classLoader ifAbsentPut: block
"Get class loaded by classLoader from registry. if absent block is evaluated and resulting class in registered in registry, "
-
+
| class synchronizer |
self assert: (className includes: $.) not.
@@ -117,7 +117,7 @@
"/ we're loading for primordial class loader. If we synchronize
"/ event non-primordial loaders, we risk a deadlock. Very hacky...
- synchronizer := classLoader isNil
+ synchronizer := classLoader isNil
ifTrue:[ [:whatToDo | lock critical: whatToDo ] ]
ifFalse:[ [:whatToDo | whatToDo value ] ].
@@ -125,11 +125,11 @@
"If class is already registered with the same cl, just return it"
class := self classNamed: className loader: classLoader.
"/ This is rubbish...
-"/
+"/
"/ class isNil ifTrue:[
"/ "If java vm is booted, nil class loader means system class loader, lets check it too"
"/ (vm notNil and:[vm booted and: [classLoader isNil]]) ifTrue: [
-"/ class := self classNamed: className loader: vm systemClassLoader.
+"/ class := self classNamed: className loader: vm systemClassLoader.
"/ ].
"/ ].
class isNil ifTrue:[
@@ -148,7 +148,7 @@
classNamed: className
- "Return a class for given classname loaded by 'current classloader' or
+ "Return a class for given classname loaded by 'current classloader' or
nil if not yet loaded"
^self classNamed: className loader: JavaClassReader classLoaderQuerySignal query
@@ -158,7 +158,7 @@
classNamed: className loader: classLoader
- "Return a class for given classname loaded by given classloader or
+ "Return a class for given classname loaded by given classloader or
nil if not yet loaded"
^self classForName: className loader: classLoader ifAbsent:[nil].
@@ -218,9 +218,9 @@
!JavaClassRegistry methodsFor:'class loading'!
-loadFile: aFilename
+loadFile: aFilename
"reads a class from aFilename, installs and returns it."
-
+
| aClass |
self breakPoint: #mh.
@@ -234,19 +234,19 @@
"Modified: / 23-10-2011 / 11:55:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-loadStream: javaClassDataStream loader: aJavaClassLoader
+loadStream: javaClassDataStream loader: aJavaClassLoader
"reads a class from aStream and returns it.
The JavaClass is installed as global.
If new classes are required to be loaded, aClassLoader is
asked to do it."
-
+
| javaClass |
self breakPoint: #mh.
self breakPoint: #jv.
javaClass := JavaClassReader readStream: javaClassDataStream loader: aJavaClassLoader.
javaClass isNil ifTrue: [
- Logger
+ Logger
log: 'JavaClassReader was not able to read given data stream'
severity: #warn
facility: #JVM.
@@ -268,7 +268,7 @@
loaders do:[:classes|
classes do:[:class|
aBlock value: class
- ]
+ ]
]
"Created: / 23-10-2011 / 20:13:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -281,7 +281,7 @@
loaders at: aJavaClassLoader put: Dictionary new.
!
-getClassesDefinedBy:classLoader
+getClassesDefinedBy:classLoader
^loaders at: classLoader ifAbsent: [nil].
! !
@@ -298,7 +298,7 @@
initialize
loaders := WeakIdentityDictionary new.
loaders at: nil put: Dictionary new.
- notifier := BackgroundQueueProcessingJob
+ notifier := BackgroundQueueProcessingJob
named: 'Java class registry notifier'
on:[:typeAndClass|Smalltalk changed: typeAndClass first with: typeAndClass second].
notifier priority: Processor userBackgroundPriority - 1.
@@ -309,7 +309,7 @@
setVM: aJavaVM
- "Now, aJavaVM == JavaVM (i.e, the class JavaVM
+ "Now, aJavaVM == JavaVM (i.e, the class JavaVM
itself, not its instance)"
vm := aJavaVM.
@@ -323,43 +323,42 @@
registerBuiltIn: class
| nm |
- nm := class name.
- nm == #'java/lang/Object' ifTrue:[
- java_lang_Object := class.
+ nm := class binaryName.
+ nm = #'java/lang/Object' ifTrue:[
+ _java_lang_Object_CLASS := class.
^self.
].
- nm == #'java/lang/System' ifTrue:[
- java_lang_System := class.
+ nm = #'java/lang/System' ifTrue:[
+ _java_lang_System_CLASS := class.
^self.
].
- nm == #'java/lang/Class' ifTrue:[
- java_lang_Class := class.
+ nm = #'java/lang/Class' ifTrue:[
+ _java_lang_Class_CLASS := class.
"/ Force load of other reflective classes. This saves us a nil check in
- "/ JavaMirror>>createMethod...
+ "/ JavaMirror>>createMethod...
#(#'java/lang/reflect/Constructor' #'java/lang/reflect/Method' #'java/lang/reflect/Field') do:[:e|
vm classForName: e definedBy: nil.
- ].
+ ].
^self.
].
- nm == #'java/lang/reflect/Constructor' ifTrue:[
- java_lang_reflect_Constructor := class.
+ nm = #'java/lang/reflect/Constructor' ifTrue:[
+ _java_lang_reflect_Constructor_CLASS := class.
].
- nm == #'java/lang/reflect/Method' ifTrue:[
- java_lang_reflect_Method := class.
- ].
- nm == #'java/lang/reflect/Field' ifTrue:[
- java_lang_reflect_Field := class.
+ nm = #'java/lang/reflect/Method' ifTrue:[
+ _java_lang_reflect_Method_CLASS := class.
+ ].
+ nm = #'java/lang/reflect/Field' ifTrue:[
+ _java_lang_reflect_Field_CLASS := class.
].
-
-
"Created: / 22-05-2013 / 20:40:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-12-2013 / 13:03:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
registerClass: newClass
| classes oldClass |
- ((newClass binaryName == #'$do$It$')
+ ((newClass binaryName == #'$do$It$')
and:[newClass superclass binaryName == #'groovy/lang/Script']) ifTrue:[
"/ Mhhh...Groovy do-it. No need to register this!!
^ self
@@ -378,12 +377,12 @@
"/OK, full reload, not just method dictionary update"
reloadedClass ~~ oldClass ifTrue:[
classesPerLoader
- at: newClass binaryName
+ at: newClass binaryName
put: reloadedClass.
self registerClassInSmalltalk: reloadedClass notify: false.
].
Smalltalk changed: #classDefinition with: reloadedClass.
- ^self.
+ ^self.
].
].
].
@@ -397,15 +396,23 @@
"/ There may be classes already loaded with compile errors.
"/ Try to recompile all erroneous classes that depends on this one...
JavaCompiler notNil ifTrue:[
- JavaCompiler recompileErroneousClassesReferringTo: newClass ignoring: newClass.
+ JavaCompiler recompileErroneousClassesReferringTo: newClass ignoring: newClass.
].
newClass isJavaClass ifTrue:[
+ "/ Register class in system dictionary so it can be browsed
+ "/ by system browser
self registerClassInSmalltalk: newClass notify: true.
+
+ "/ Also register builtin classes in JavaVMData
+ newClass isBuiltInClass ifTrue:[
+ self assert: newClass classLoader isNil. "/must be loaded by primordial CL...
+ self registerBuiltIn: newClass.
+ ].
].
"Created: / 23-10-2011 / 11:53:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-11-2011 / 18:40:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 20-11-2013 / 16:05:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-12-2013 / 12:43:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
registerClassInSmalltalk: javaclass notify: doNotify
@@ -435,7 +442,7 @@
"/ This allows java.foo.bar to be visible in ST/X
"/ under the name JAVA::java::foo::bar
- accessor := javaclass"JavaClassAccessor fullName: aString".
+ accessor := javaclass"JavaClassAccessor fullName: aString".
nsName := javaclass nameSpaceName.
nsNameAsSymbol := nsName asSymbolIfInterned.
(nsNameAsSymbol isNil or:[(ns := Smalltalk at: nsNameAsSymbol) isNil]) ifTrue:[
@@ -512,7 +519,7 @@
"/ a race condition occur in stx:libbasic code (something is
"/ nilled menawhile and event handler does not handle this case.
"/ This can happen for example when running tests...
- notifier waitUntilProcessed.
+ notifier waitUntilProcessed.
javaclass isSynthetic ifTrue:[ ^ self ].
nameSpace := javaclass nameSpace.
@@ -534,7 +541,7 @@
"Modified: / 17-10-2013 / 10:50:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-unregisterClassLoader: aJavaClassLoader
+unregisterClassLoader: aJavaClassLoader
| classes |
classes := loaders at: aJavaClassLoader ifAbsent:[ ^ self ].