author | Marcel Hlopko <marcel.hlopko@fit.cvut.cz> |
Tue, 18 Dec 2012 19:02:51 +0100 | |
branch | development |
changeset 1910 | 278ceba64f94 |
parent 1895 | 2d30e588124c |
child 1921 | a395d5c696b9 |
permissions | -rw-r--r-- |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
1 |
" |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
7 |
SWING Research Group, Czech Technical University in Prague |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
8 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
9 |
This software is furnished under a license and may be used |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
10 |
only in accordance with the terms of that license and with the |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
11 |
inclusion of the above copyright notice. This software may not |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
12 |
be provided or otherwise made available to, or used by, any |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
13 |
other person. No title to or ownership of the software is |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
14 |
hereby transferred. |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
15 |
|
1155 | 16 |
[1] Code written at SWING Research Group contains a signature |
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
1152 | 19 |
as of 1.9.2010 |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
20 |
" |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
21 |
"{ Package: 'stx:libjava' }" |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
22 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
23 |
Object subclass:#JavaClassRegistry |
1570 | 24 |
instanceVariableNames:'vm loaders notifier' |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
25 |
classVariableNames:'' |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
26 |
poolDictionaries:'' |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
27 |
category:'Languages-Java-Support' |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
28 |
! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
29 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
30 |
!JavaClassRegistry class methodsFor:'documentation'! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
31 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
32 |
copyright |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
33 |
" |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
1152 | 35 |
|
1155 | 36 |
New code and modifications done at SWING Research Group [1]: |
1152 | 37 |
|
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
39 |
SWING Research Group, Czech Technical University in Prague |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
40 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
41 |
This software is furnished under a license and may be used |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
42 |
only in accordance with the terms of that license and with the |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
43 |
inclusion of the above copyright notice. This software may not |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
44 |
be provided or otherwise made available to, or used by, any |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
45 |
other person. No title to or ownership of the software is |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
46 |
hereby transferred. |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
47 |
|
1155 | 48 |
[1] Code written at SWING Research Group contains a signature |
49 |
of one of the above copright owners. For exact set of such code, |
|
50 |
see the differences between this version and version stx:libjava |
|
1152 | 51 |
as of 1.9.2010 |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
52 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
53 |
" |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
54 |
! ! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
55 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
56 |
!JavaClassRegistry class methodsFor:'instance creation'! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
57 |
|
1059 | 58 |
for: aJavaVM |
59 |
||
60 |
^self new setVM: aJavaVM. |
|
61 |
||
62 |
"Created: / 21-12-2010 / 19:42:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
63 |
! |
|
64 |
||
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
65 |
new |
1059 | 66 |
|
67 |
^ self basicNew initialize. |
|
68 |
||
69 |
"Modified (format): / 30-10-2011 / 12:07:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
70 |
! ! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
71 |
|
1037 | 72 |
!JavaClassRegistry methodsFor:'accessing'! |
73 |
||
74 |
classForName: className loader: classLoader ifAbsent: aBlock |
|
75 |
"Get class loaded by given classLoader from registry or evaluate aBlock if class is not yet registered" |
|
1038 | 76 |
|
1059 | 77 |
| classes class | |
78 |
||
1062
69aac7194016
Fixes in classloaders to make Groovy running (again)
vranyj1
parents:
1060
diff
changeset
|
79 |
self assert: (className includes: $.) not. |
69aac7194016
Fixes in classloaders to make Groovy running (again)
vranyj1
parents:
1060
diff
changeset
|
80 |
|
1059 | 81 |
"Classes loaded by primordial classloader are always |
82 |
used" |
|
1038 | 83 |
|
1059 | 84 |
classLoader notNil ifTrue:[ |
85 |
classes := loaders at: nil ifAbsent: nil. |
|
86 |
class := classes at: className ifAbsent: nil. |
|
87 |
class notNil ifTrue:[ |
|
88 |
^class. |
|
89 |
] |
|
90 |
]. |
|
91 |
||
92 |
"No bootstrap class found, search given classloader" |
|
93 |
classes := loaders at: classLoader ifAbsent: [^aBlock value]. |
|
1038 | 94 |
^classes at: className ifAbsent: aBlock |
1037 | 95 |
|
96 |
"Modified: / 21-10-2011 / 12:39:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
97 |
"Created: / 23-10-2011 / 11:40:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
98 |
! |
|
99 |
||
100 |
classForName: className loader: classLoader ifAbsentPut: block |
|
101 |
"Get class loaded by classLoader from registry. if absent block is evaluated and resulting class in registered in registry, " |
|
102 |
||
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
103 |
| class | |
1062
69aac7194016
Fixes in classloaders to make Groovy running (again)
vranyj1
parents:
1060
diff
changeset
|
104 |
self assert: (className includes: $.) not. |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
105 |
"if class is already registered with the same cl, just return it" |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
106 |
class := self classNamed: className loader: classLoader. |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
107 |
class notNil ifTrue: [ ^ class ]. |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
108 |
"if java vm is booted, nil class loader means system class loader, lets check it too" |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
109 |
(vm booted and: [classLoader isNil]) ifTrue: [class := self classNamed: className loader: vm systemClassLoader. class notNil ifTrue: [^class]]. |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
110 |
"otherwise evaluate block" |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
111 |
class := block value. |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
112 |
class notNil ifTrue: [ |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
113 |
self registerClass: class.]. |
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
114 |
^ class. |
1037 | 115 |
|
116 |
"Created: / 21-10-2011 / 12:00:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
117 |
"Created: / 23-10-2011 / 11:36:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
118 |
"Modified: / 02-11-2011 / 17:29:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1037 | 119 |
! |
120 |
||
121 |
classNamed: className |
|
122 |
||
123 |
"Return a class for given classname loaded by 'current classloader' or |
|
124 |
nil if not yet loaded" |
|
125 |
||
126 |
^self classNamed: className loader: JavaClassReader classLoaderQuerySignal query |
|
127 |
||
128 |
"Created: / 23-10-2011 / 12:23:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
129 |
! |
|
130 |
||
131 |
classNamed: className loader: classLoader |
|
132 |
||
133 |
"Return a class for given classname loaded by given classloader or |
|
134 |
nil if not yet loaded" |
|
135 |
||
136 |
^self classForName: className loader: classLoader ifAbsent:[nil]. |
|
137 |
||
138 |
"Created: / 23-10-2011 / 12:23:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1039 | 139 |
! |
140 |
||
141 |
classes |
|
142 |
||
143 |
^Iterator on:[:whatToDo|self classesDo: whatToDo] |
|
144 |
||
145 |
"Created: / 23-10-2011 / 20:14:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1612 | 146 |
! |
147 |
||
148 |
systemPackage: syspkg |
|
149 |
"Return name (as string) of system package named syspkg or nil if no such package is loaded" |
|
150 |
||
151 |
| classes syspkgSlashed | |
|
152 |
||
153 |
classes := loaders at: nil ifAbsent:[nil]. |
|
154 |
classes isEmptyOrNil ifTrue:[ ^ #() ]. |
|
155 |
syspkgSlashed := syspkg copyReplaceAll: $. with: $/. |
|
156 |
classes keysDo:[:name| |
|
157 |
(name startsWith:syspkgSlashed) ifTrue:[ |
|
158 |
^ syspkg |
|
159 |
] |
|
160 |
]. |
|
161 |
^ nil |
|
162 |
||
163 |
"Created: / 16-08-2012 / 17:40:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
164 |
! |
|
165 |
||
166 |
systemPackages |
|
167 |
"Return a collection system packages (as smalltalk strings) currently loaded" |
|
168 |
||
169 |
| classes syspkgs | |
|
170 |
||
171 |
classes := loaders at: nil ifAbsent:[nil]. |
|
172 |
classes isEmptyOrNil ifTrue:[ ^ #() ]. |
|
173 |
syspkgs := Set new. |
|
174 |
classes keysDo:[:name| |
|
175 |
| slashpos | |
|
176 |
||
177 |
slashpos := name lastIndexOf: $/. |
|
178 |
slashpos ~~ 0 ifTrue:[ |
|
179 |
| syspkg | |
|
180 |
||
181 |
syspkg := name copyTo: slashpos - 1. |
|
182 |
syspkg replaceAll: $/ with: $.. |
|
183 |
syspkgs add: syspkg. |
|
184 |
] |
|
185 |
]. |
|
186 |
^syspkgs |
|
187 |
||
188 |
"Created: / 16-08-2012 / 17:32:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1037 | 189 |
! ! |
190 |
||
191 |
!JavaClassRegistry methodsFor:'class loading'! |
|
192 |
||
193 |
loadFile: aFilename |
|
194 |
"reads a class from aFilename, installs and returns it." |
|
195 |
||
196 |
| aClass | |
|
197 |
||
198 |
self breakPoint: #mh. |
|
199 |
aClass := JavaClassReader readFile: aFilename ignoring: Set new. |
|
200 |
aClass isJavaClass ifFalse:[self breakPoint:#mh]. |
|
201 |
self registerClass: aClass. |
|
202 |
^ aClass. |
|
203 |
||
204 |
"Created: / 15-04-1996 / 14:58:53 / cg" |
|
205 |
"Modified: / 12-05-1998 / 22:06:52 / cg" |
|
206 |
"Modified: / 23-10-2011 / 11:55:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
207 |
! |
|
208 |
||
209 |
loadStream: javaClassDataStream loader: aJavaClassLoader |
|
210 |
"reads a class from aStream and returns it. |
|
211 |
The JavaClass is installed as global. |
|
212 |
If new classes are required to be loaded, aClassLoader is |
|
213 |
asked to do it." |
|
214 |
||
215 |
| javaClass | |
|
216 |
||
217 |
self breakPoint: #mh. |
|
218 |
JavaClassReader classLoaderQuerySignal answer: aJavaClassLoader |
|
219 |
do: [ |
|
220 |
javaClass := JavaClassReader readStream: javaClassDataStream |
|
221 |
ignoring: (Set new). |
|
222 |
javaClass |
|
223 |
ifNil: [ |
|
224 |
Logger |
|
225 |
log: 'JavaClassReader was not able to read given data stream' |
|
226 |
severity: #warn |
|
1059 | 227 |
facility: #JVM. |
1037 | 228 |
self breakPoint: #mh. |
229 |
^ nil. |
|
230 |
]. |
|
231 |
javaClass isJavaClass ifFalse: [ self breakPoint: #mh. ]. |
|
232 |
javaClass classLoader: aJavaClassLoader. |
|
233 |
self registerClass: javaClass. |
|
234 |
]. |
|
235 |
^ javaClass |
|
236 |
||
1059 | 237 |
"Modified: / 30-10-2011 / 12:24:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1037 | 238 |
! ! |
239 |
||
1039 | 240 |
!JavaClassRegistry methodsFor:'enumerating'! |
241 |
||
242 |
classesDo: aBlock |
|
243 |
||
1059 | 244 |
loaders do:[:classes| |
1039 | 245 |
classes do:[:class| |
246 |
aBlock value: class |
|
247 |
] |
|
248 |
] |
|
249 |
||
250 |
"Created: / 23-10-2011 / 20:13:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
251 |
! ! |
|
252 |
||
1037 | 253 |
!JavaClassRegistry methodsFor:'helpers'! |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
254 |
|
1032 | 255 |
addClassLoader: aJavaClassLoader |
1027
43dc608e14aa
another dose of fixes, still not able to boot javavm
hlopkmar
parents:
1026
diff
changeset
|
256 |
|
1059 | 257 |
loaders at: aJavaClassLoader put: Dictionary new. |
1032 | 258 |
! |
259 |
||
260 |
getClassesDefinedBy:classLoader |
|
1059 | 261 |
^loaders at: classLoader ifAbsent: [nil]. |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
262 |
! ! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
263 |
|
1032 | 264 |
!JavaClassRegistry methodsFor:'initialization'! |
265 |
||
266 |
flush |
|
1045
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
267 |
|
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
268 |
self initialize. |
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
269 |
|
1059 | 270 |
"Modified: / 30-10-2011 / 12:06:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1032 | 271 |
! |
272 |
||
273 |
initialize |
|
1059 | 274 |
loaders := WeakIdentityDictionary new. |
275 |
loaders at: nil put: Dictionary new. |
|
1570 | 276 |
notifier := BackgroundQueueProcessingJob |
277 |
named: 'Java class registry notifier' |
|
278 |
on:[:typeAndClass|Smalltalk changed: typeAndClass first with: typeAndClass second]. |
|
279 |
notifier priority: Processor userBackgroundPriority - 1. |
|
1045
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
280 |
|
1612 | 281 |
"Modified: / 16-08-2012 / 17:31:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1059 | 282 |
! |
283 |
||
284 |
setVM: aJavaVM |
|
285 |
||
286 |
"Now, aJavaVM == JavaVM (i.e, the class JavaVM |
|
287 |
itself, not its instance)" |
|
288 |
||
289 |
vm := aJavaVM |
|
290 |
||
291 |
"Created: / 21-12-2010 / 19:44:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1032 | 292 |
! ! |
293 |
||
1037 | 294 |
!JavaClassRegistry methodsFor:'registering'! |
1032 | 295 |
|
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
296 |
registerClass: newClass |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
297 |
| classes oldClass | |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
298 |
|
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
299 |
self assert: (newClass name includes: $.) not. |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
300 |
loaders keysAndValuesDo:[:loader :classesPerLoader| |
1036 | 301 |
|
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
302 |
(classesPerLoader includesKey: newClass name) ifTrue:[ |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
303 |
loader == newClass classLoader ifTrue:[ |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
304 |
(oldClass := classesPerLoader at: newClass name) ~~ newClass ifTrue:[ |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
305 |
"Class already exists, reload & reinstall" |
1453 | 306 |
|
307 |
| reloadedClass | |
|
308 |
reloadedClass := JavaClassReloader reload: oldClass with: newClass. |
|
309 |
"/OK, full reload, not just method dictionary update" |
|
310 |
reloadedClass ~~ oldClass ifTrue:[ |
|
311 |
classesPerLoader |
|
312 |
at: newClass name |
|
313 |
put: reloadedClass. |
|
314 |
self registerClassInSmalltalk: reloadedClass notify: false. |
|
315 |
]. |
|
1478 | 316 |
Smalltalk changed: #classDefinition with: newClass. |
1453 | 317 |
^self. |
1058
1db06119bf3e
Temporary commit (fixing class loaders - classes gets registered twice)
vranyj1
parents:
1057
diff
changeset
|
318 |
]. |
1db06119bf3e
Temporary commit (fixing class loaders - classes gets registered twice)
vranyj1
parents:
1057
diff
changeset
|
319 |
] ifFalse:[ |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
320 |
((newClass name == #Script1) |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
321 |
and:[newClass superclass name == #'groovy/lang/Script']) ifFalse:[ |
1478 | 322 |
"/self breakPoint: #jv. |
1120
b65e199200a4
Fire breakpoint for JV only if class is not artifical Groovy script class (avoids annoying false-positive breakpoint)
vranyj1
parents:
1073
diff
changeset
|
323 |
] |
1057 | 324 |
] |
325 |
] |
|
326 |
]. |
|
327 |
||
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
328 |
classes := loaders at: newClass classLoader ifAbsent: nil. |
1045
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
329 |
classes isNil ifTrue:[ |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
330 |
classes := loaders at: newClass classLoader put: Dictionary new. |
1045
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
331 |
]. |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
332 |
classes at: newClass name put: newClass. |
1453 | 333 |
|
334 |
self registerClassInSmalltalk: newClass notify: true. |
|
1036 | 335 |
|
1037 | 336 |
"Created: / 23-10-2011 / 11:53:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
337 |
"Modified: / 02-11-2011 / 18:40:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1478 | 338 |
"Modified: / 13-04-2012 / 19:04:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1453 | 339 |
! |
340 |
||
341 |
registerClassInSmalltalk: javaclass notify: doNotify |
|
342 |
"Registers class in Smalltalk system dictionary and |
|
343 |
notifies system, so the class become visible by |
|
344 |
Smalltalk" |
|
345 |
||
346 |
| nameComponents accessor ns | |
|
347 |
||
348 |
||
349 |
nameComponents := javaclass name asCollectionOfSubstringsSeparatedBy:$/. |
|
350 |
nameComponents size > 1 ifTrue:[ |
|
351 |
javaclass setCategory:((nameComponents asStringWith:$/ from:1 to:(nameComponents size - 1)) |
|
352 |
replaceAll:$/ with:$. ). |
|
353 |
]. |
|
354 |
||
355 |
nameComponents size > 1 ifTrue:[ |
|
356 |
javaclass setPackage:((nameComponents copyWithoutLast:1) asStringWith:$/) asSymbol |
|
357 |
] ifFalse:[ |
|
358 |
javaclass setPackage:javaclass name asSymbol |
|
359 |
]. |
|
360 |
||
361 |
"/ break up the package and create nameSpaces |
|
362 |
"/ for each package component. |
|
363 |
"/ This allows java.foo.bar to be visible in ST/X |
|
364 |
"/ under the name JAVA::java::foo::bar |
|
365 |
||
366 |
accessor := javaclass"JavaClassAccessor fullName: aString". |
|
367 |
ns := JAVA. |
|
368 |
||
369 |
nameComponents size > 1 ifTrue:[ |
|
370 |
| s | |
|
371 |
||
372 |
s := '' writeStream. |
|
373 |
s nextPutAll:'JAVA'. |
|
374 |
nameComponents from:1 to:(nameComponents size - 1) do:[:aPart | |
|
375 |
s nextPutAll:'::'. |
|
376 |
s nextPutAll:aPart |
|
377 |
]. |
|
378 |
Metaclass confirmationQuerySignal answer:false do:[ |
|
379 |
Class withoutUpdatingChangesDo:[ |
|
380 |
ns := JavaPackage fullName:(s contents). |
|
381 |
] |
|
382 |
] |
|
383 |
]. |
|
384 |
||
385 |
ns isNameSpace ifTrue:[ |
|
386 |
ns at:nameComponents last asSymbol put:accessor. |
|
387 |
]. |
|
388 |
||
389 |
||
390 |
doNotify ifTrue:[ |
|
1570 | 391 |
notifier add:(Array with: #newClass with: javaclass). |
1453 | 392 |
]. |
393 |
||
394 |
"Created: / 04-04-2012 / 10:01:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
395 |
! |
|
396 |
||
397 |
unregisterClass: oldClass |
|
398 |
| classes | |
|
399 |
||
400 |
self assert: (oldClass name includes: $.) not. |
|
401 |
self unregisterClassInSmalltalk: oldClass notify: true. |
|
402 |
classes := loaders at: oldClass classLoader ifAbsent: nil. |
|
403 |
classes notNil ifTrue:[ |
|
404 |
classes removeKey: oldClass name. |
|
405 |
]. |
|
406 |
||
407 |
"Created: / 04-04-2012 / 02:43:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
408 |
! |
|
409 |
||
410 |
unregisterClassInSmalltalk: javaclass notify: doNotify |
|
411 |
"Unregisters given class from Smalltalk system dictionary |
|
412 |
so the class is no longer visible from Smalltalk" |
|
413 |
||
414 |
| nameComponents ns | |
|
415 |
||
416 |
ns := JAVA. |
|
417 |
||
418 |
nameComponents size > 1 ifTrue:[ |
|
419 |
| s | |
|
420 |
||
421 |
s := '' writeStream. |
|
422 |
s nextPutAll:'JAVA'. |
|
423 |
nameComponents from:1 to:(nameComponents size - 1) do:[:aPart | |
|
424 |
s nextPutAll:'::'. |
|
425 |
s nextPutAll:aPart |
|
426 |
]. |
|
427 |
Metaclass confirmationQuerySignal answer:false do:[ |
|
428 |
Class withoutUpdatingChangesDo:[ |
|
429 |
ns := JavaPackage fullName:(s contents). |
|
430 |
] |
|
431 |
] |
|
432 |
]. |
|
433 |
||
434 |
ns isNameSpace ifTrue:[ |
|
435 |
"/Hmmm hmm, how to remove class from a namespace?. |
|
436 |
"/ns at:nameComponents last asSymbol put:nil |
|
437 |
]. |
|
438 |
||
439 |
doNotify ifTrue:[ |
|
1570 | 440 |
notifier add:(Array with: #classRemove with: javaclass). |
1453 | 441 |
]. |
442 |
||
443 |
"Created: / 04-04-2012 / 10:01:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1895
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
444 |
! |
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
445 |
|
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
446 |
unregisterClassLoader: aJavaClassLoader |
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
447 |
loaders removeKey: aJavaClassLoader ifAbsent: nil. |
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
448 |
|
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
449 |
"Created: / 16-12-2012 / 16:39:45 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>" |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
450 |
! ! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
451 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
452 |
!JavaClassRegistry class methodsFor:'documentation'! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
453 |
|
1864 | 454 |
version_HG |
455 |
||
456 |
^ '$Changeset: <not expanded> $' |
|
457 |
! |
|
458 |
||
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
459 |
version_SVN |
1864 | 460 |
^ '§Id§' |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
461 |
! ! |