author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 25 Jan 2013 00:15:51 +0000 | |
branch | refactoring-classpath |
changeset 2000 | 13a10b73aa83 |
parent 1995 | b129fd0a81e4 |
child 2037 | 6b93bf17087a |
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" |
1995
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
109 |
(vm booted and: [classLoader isNil]) ifTrue: [ |
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
110 |
class := self classNamed: className loader: vm systemClassLoader. |
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
111 |
class notNil ifTrue: [^class] |
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
112 |
]. |
1073
e842ab17fe16
quite big class loaders rewrite.. javavm/groovy boots, almost all tests pass.. hope you will like it..
hlopkmar
parents:
1062
diff
changeset
|
113 |
"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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
^ class. |
1037 | 118 |
|
119 |
"Created: / 21-10-2011 / 12:00:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
120 |
"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
|
121 |
"Modified: / 02-11-2011 / 17:29:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1995
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
122 |
"Modified (format): / 24-01-2013 / 11:19:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1037 | 123 |
! |
124 |
||
125 |
classNamed: className |
|
126 |
||
127 |
"Return a class for given classname loaded by 'current classloader' or |
|
128 |
nil if not yet loaded" |
|
129 |
||
130 |
^self classNamed: className loader: JavaClassReader classLoaderQuerySignal query |
|
131 |
||
132 |
"Created: / 23-10-2011 / 12:23:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
133 |
! |
|
134 |
||
135 |
classNamed: className loader: classLoader |
|
136 |
||
137 |
"Return a class for given classname loaded by given classloader or |
|
138 |
nil if not yet loaded" |
|
139 |
||
140 |
^self classForName: className loader: classLoader ifAbsent:[nil]. |
|
141 |
||
142 |
"Created: / 23-10-2011 / 12:23:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1039 | 143 |
! |
144 |
||
145 |
classes |
|
146 |
||
147 |
^Iterator on:[:whatToDo|self classesDo: whatToDo] |
|
148 |
||
149 |
"Created: / 23-10-2011 / 20:14:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1612 | 150 |
! |
151 |
||
152 |
systemPackage: syspkg |
|
153 |
"Return name (as string) of system package named syspkg or nil if no such package is loaded" |
|
154 |
||
155 |
| classes syspkgSlashed | |
|
156 |
||
157 |
classes := loaders at: nil ifAbsent:[nil]. |
|
158 |
classes isEmptyOrNil ifTrue:[ ^ #() ]. |
|
159 |
syspkgSlashed := syspkg copyReplaceAll: $. with: $/. |
|
160 |
classes keysDo:[:name| |
|
161 |
(name startsWith:syspkgSlashed) ifTrue:[ |
|
162 |
^ syspkg |
|
163 |
] |
|
164 |
]. |
|
165 |
^ nil |
|
166 |
||
167 |
"Created: / 16-08-2012 / 17:40:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
168 |
! |
|
169 |
||
170 |
systemPackages |
|
171 |
"Return a collection system packages (as smalltalk strings) currently loaded" |
|
172 |
||
173 |
| classes syspkgs | |
|
174 |
||
175 |
classes := loaders at: nil ifAbsent:[nil]. |
|
176 |
classes isEmptyOrNil ifTrue:[ ^ #() ]. |
|
177 |
syspkgs := Set new. |
|
178 |
classes keysDo:[:name| |
|
179 |
| slashpos | |
|
180 |
||
181 |
slashpos := name lastIndexOf: $/. |
|
182 |
slashpos ~~ 0 ifTrue:[ |
|
183 |
| syspkg | |
|
184 |
||
185 |
syspkg := name copyTo: slashpos - 1. |
|
186 |
syspkg replaceAll: $/ with: $.. |
|
187 |
syspkgs add: syspkg. |
|
188 |
] |
|
189 |
]. |
|
190 |
^syspkgs |
|
191 |
||
192 |
"Created: / 16-08-2012 / 17:32:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1037 | 193 |
! ! |
194 |
||
195 |
!JavaClassRegistry methodsFor:'class loading'! |
|
196 |
||
197 |
loadFile: aFilename |
|
198 |
"reads a class from aFilename, installs and returns it." |
|
199 |
||
200 |
| aClass | |
|
201 |
||
202 |
self breakPoint: #mh. |
|
203 |
aClass := JavaClassReader readFile: aFilename ignoring: Set new. |
|
204 |
aClass isJavaClass ifFalse:[self breakPoint:#mh]. |
|
205 |
self registerClass: aClass. |
|
206 |
^ aClass. |
|
207 |
||
208 |
"Created: / 15-04-1996 / 14:58:53 / cg" |
|
209 |
"Modified: / 12-05-1998 / 22:06:52 / cg" |
|
210 |
"Modified: / 23-10-2011 / 11:55:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
211 |
! |
|
212 |
||
213 |
loadStream: javaClassDataStream loader: aJavaClassLoader |
|
214 |
"reads a class from aStream and returns it. |
|
215 |
The JavaClass is installed as global. |
|
216 |
If new classes are required to be loaded, aClassLoader is |
|
217 |
asked to do it." |
|
218 |
||
219 |
| javaClass | |
|
220 |
||
221 |
self breakPoint: #mh. |
|
222 |
JavaClassReader classLoaderQuerySignal answer: aJavaClassLoader |
|
223 |
do: [ |
|
224 |
javaClass := JavaClassReader readStream: javaClassDataStream |
|
225 |
ignoring: (Set new). |
|
226 |
javaClass |
|
227 |
ifNil: [ |
|
228 |
Logger |
|
229 |
log: 'JavaClassReader was not able to read given data stream' |
|
230 |
severity: #warn |
|
1059 | 231 |
facility: #JVM. |
1037 | 232 |
self breakPoint: #mh. |
233 |
^ nil. |
|
234 |
]. |
|
235 |
javaClass isJavaClass ifFalse: [ self breakPoint: #mh. ]. |
|
236 |
javaClass classLoader: aJavaClassLoader. |
|
237 |
self registerClass: javaClass. |
|
238 |
]. |
|
239 |
^ javaClass |
|
240 |
||
1059 | 241 |
"Modified: / 30-10-2011 / 12:24:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1037 | 242 |
! ! |
243 |
||
1039 | 244 |
!JavaClassRegistry methodsFor:'enumerating'! |
245 |
||
246 |
classesDo: aBlock |
|
247 |
||
1059 | 248 |
loaders do:[:classes| |
1039 | 249 |
classes do:[:class| |
250 |
aBlock value: class |
|
251 |
] |
|
252 |
] |
|
253 |
||
254 |
"Created: / 23-10-2011 / 20:13:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
255 |
! ! |
|
256 |
||
1037 | 257 |
!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
|
258 |
|
1032 | 259 |
addClassLoader: aJavaClassLoader |
1027
43dc608e14aa
another dose of fixes, still not able to boot javavm
hlopkmar
parents:
1026
diff
changeset
|
260 |
|
1059 | 261 |
loaders at: aJavaClassLoader put: Dictionary new. |
1032 | 262 |
! |
263 |
||
264 |
getClassesDefinedBy:classLoader |
|
1059 | 265 |
^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
|
266 |
! ! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
267 |
|
1032 | 268 |
!JavaClassRegistry methodsFor:'initialization'! |
269 |
||
270 |
flush |
|
1045
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
271 |
|
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
272 |
self initialize. |
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
273 |
|
1059 | 274 |
"Modified: / 30-10-2011 / 12:06:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1032 | 275 |
! |
276 |
||
277 |
initialize |
|
1059 | 278 |
loaders := WeakIdentityDictionary new. |
279 |
loaders at: nil put: Dictionary new. |
|
1570 | 280 |
notifier := BackgroundQueueProcessingJob |
281 |
named: 'Java class registry notifier' |
|
282 |
on:[:typeAndClass|Smalltalk changed: typeAndClass first with: typeAndClass second]. |
|
283 |
notifier priority: Processor userBackgroundPriority - 1. |
|
1045
6b11c34520f2
JavaClassRegistry: keep classloaders in WeakIdentityDictionary to allow classloaders to be GCd
vranyj1
parents:
1039
diff
changeset
|
284 |
|
1612 | 285 |
"Modified: / 16-08-2012 / 17:31:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1059 | 286 |
! |
287 |
||
288 |
setVM: aJavaVM |
|
289 |
||
290 |
"Now, aJavaVM == JavaVM (i.e, the class JavaVM |
|
291 |
itself, not its instance)" |
|
292 |
||
293 |
vm := aJavaVM |
|
294 |
||
295 |
"Created: / 21-12-2010 / 19:44:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1032 | 296 |
! ! |
297 |
||
1037 | 298 |
!JavaClassRegistry methodsFor:'registering'! |
1032 | 299 |
|
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
300 |
registerClass: newClass |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
301 |
| classes oldClass | |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
302 |
|
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
303 |
self assert: (newClass name includes: $.) not. |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
304 |
loaders keysAndValuesDo:[:loader :classesPerLoader| |
1036 | 305 |
|
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
306 |
(classesPerLoader includesKey: newClass name) ifTrue:[ |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
307 |
loader == newClass classLoader ifTrue:[ |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
308 |
(oldClass := classesPerLoader at: newClass name) ~~ newClass ifTrue:[ |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
309 |
"Class already exists, reload & reinstall" |
1453 | 310 |
|
311 |
| reloadedClass | |
|
312 |
reloadedClass := JavaClassReloader reload: oldClass with: newClass. |
|
313 |
"/OK, full reload, not just method dictionary update" |
|
314 |
reloadedClass ~~ oldClass ifTrue:[ |
|
315 |
classesPerLoader |
|
316 |
at: newClass name |
|
317 |
put: reloadedClass. |
|
318 |
self registerClassInSmalltalk: reloadedClass notify: false. |
|
319 |
]. |
|
1478 | 320 |
Smalltalk changed: #classDefinition with: newClass. |
1453 | 321 |
^self. |
1058
1db06119bf3e
Temporary commit (fixing class loaders - classes gets registered twice)
vranyj1
parents:
1057
diff
changeset
|
322 |
]. |
1db06119bf3e
Temporary commit (fixing class loaders - classes gets registered twice)
vranyj1
parents:
1057
diff
changeset
|
323 |
] ifFalse:[ |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
324 |
((newClass name == #Script1) |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
325 |
and:[newClass superclass name == #'groovy/lang/Script']) ifFalse:[ |
1478 | 326 |
"/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
|
327 |
] |
1057 | 328 |
] |
329 |
] |
|
330 |
]. |
|
331 |
||
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
332 |
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
|
333 |
classes isNil ifTrue:[ |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
334 |
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
|
335 |
]. |
1995
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
336 |
classes at: newClass name put: newClass. |
1453 | 337 |
self registerClassInSmalltalk: newClass notify: true. |
1036 | 338 |
|
1037 | 339 |
"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
|
340 |
"Modified: / 02-11-2011 / 18:40:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1995
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
341 |
"Modified: / 24-01-2013 / 11:31:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1453 | 342 |
! |
343 |
||
344 |
registerClassInSmalltalk: javaclass notify: doNotify |
|
345 |
"Registers class in Smalltalk system dictionary and |
|
346 |
notifies system, so the class become visible by |
|
347 |
Smalltalk" |
|
348 |
||
349 |
| nameComponents accessor ns | |
|
350 |
||
351 |
||
352 |
nameComponents := javaclass name asCollectionOfSubstringsSeparatedBy:$/. |
|
353 |
nameComponents size > 1 ifTrue:[ |
|
354 |
javaclass setCategory:((nameComponents asStringWith:$/ from:1 to:(nameComponents size - 1)) |
|
355 |
replaceAll:$/ with:$. ). |
|
356 |
]. |
|
357 |
||
358 |
nameComponents size > 1 ifTrue:[ |
|
359 |
javaclass setPackage:((nameComponents copyWithoutLast:1) asStringWith:$/) asSymbol |
|
360 |
] ifFalse:[ |
|
361 |
javaclass setPackage:javaclass name asSymbol |
|
362 |
]. |
|
363 |
||
364 |
"/ break up the package and create nameSpaces |
|
365 |
"/ for each package component. |
|
366 |
"/ This allows java.foo.bar to be visible in ST/X |
|
367 |
"/ under the name JAVA::java::foo::bar |
|
368 |
||
369 |
accessor := javaclass"JavaClassAccessor fullName: aString". |
|
370 |
ns := JAVA. |
|
371 |
||
372 |
nameComponents size > 1 ifTrue:[ |
|
373 |
| s | |
|
374 |
||
375 |
s := '' writeStream. |
|
376 |
s nextPutAll:'JAVA'. |
|
377 |
nameComponents from:1 to:(nameComponents size - 1) do:[:aPart | |
|
378 |
s nextPutAll:'::'. |
|
379 |
s nextPutAll:aPart |
|
380 |
]. |
|
381 |
Metaclass confirmationQuerySignal answer:false do:[ |
|
382 |
Class withoutUpdatingChangesDo:[ |
|
383 |
ns := JavaPackage fullName:(s contents). |
|
384 |
] |
|
385 |
] |
|
386 |
]. |
|
387 |
||
388 |
ns isNameSpace ifTrue:[ |
|
389 |
ns at:nameComponents last asSymbol put:accessor. |
|
390 |
]. |
|
391 |
||
392 |
||
393 |
doNotify ifTrue:[ |
|
1570 | 394 |
notifier add:(Array with: #newClass with: javaclass). |
1453 | 395 |
]. |
396 |
||
397 |
"Created: / 04-04-2012 / 10:01:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
398 |
! |
|
399 |
||
1921
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
400 |
registerClasses: classes |
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
401 |
classes do:[:cls|self registerClass: cls]. |
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
402 |
|
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
403 |
"Created: / 02-01-2013 / 17:01:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
404 |
! |
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
405 |
|
1453 | 406 |
unregisterClass: oldClass |
407 |
| classes | |
|
408 |
||
409 |
self assert: (oldClass name includes: $.) not. |
|
410 |
self unregisterClassInSmalltalk: oldClass notify: true. |
|
411 |
classes := loaders at: oldClass classLoader ifAbsent: nil. |
|
412 |
classes notNil ifTrue:[ |
|
413 |
classes removeKey: oldClass name. |
|
414 |
]. |
|
415 |
||
416 |
"Created: / 04-04-2012 / 02:43:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
417 |
! |
|
418 |
||
419 |
unregisterClassInSmalltalk: javaclass notify: doNotify |
|
420 |
"Unregisters given class from Smalltalk system dictionary |
|
421 |
so the class is no longer visible from Smalltalk" |
|
422 |
||
423 |
| nameComponents ns | |
|
424 |
||
425 |
ns := JAVA. |
|
426 |
||
427 |
nameComponents size > 1 ifTrue:[ |
|
428 |
| s | |
|
429 |
||
430 |
s := '' writeStream. |
|
431 |
s nextPutAll:'JAVA'. |
|
432 |
nameComponents from:1 to:(nameComponents size - 1) do:[:aPart | |
|
433 |
s nextPutAll:'::'. |
|
434 |
s nextPutAll:aPart |
|
435 |
]. |
|
436 |
Metaclass confirmationQuerySignal answer:false do:[ |
|
437 |
Class withoutUpdatingChangesDo:[ |
|
438 |
ns := JavaPackage fullName:(s contents). |
|
439 |
] |
|
440 |
] |
|
441 |
]. |
|
442 |
||
443 |
ns isNameSpace ifTrue:[ |
|
444 |
"/Hmmm hmm, how to remove class from a namespace?. |
|
445 |
"/ns at:nameComponents last asSymbol put:nil |
|
446 |
]. |
|
447 |
||
448 |
doNotify ifTrue:[ |
|
1570 | 449 |
notifier add:(Array with: #classRemove with: javaclass). |
1453 | 450 |
]. |
451 |
||
452 |
"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
|
453 |
! |
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
454 |
|
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
455 |
unregisterClassLoader: aJavaClassLoader |
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
456 |
loaders removeKey: aJavaClassLoader ifAbsent: nil. |
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
457 |
|
2d30e588124c
added reloading tests and naive implementation
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
1864
diff
changeset
|
458 |
"Created: / 16-12-2012 / 16:39:45 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>" |
1921
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
459 |
! |
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
460 |
|
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
461 |
unregisterClasses: classes |
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
462 |
classes do:[:cls|self unregisterClass: cls]. |
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
463 |
|
a395d5c696b9
JavaCompiler refactored to compile completely in memory.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1895
diff
changeset
|
464 |
"Created: / 02-01-2013 / 17:01:26 / 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
|
465 |
! ! |
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
466 |
|
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
467 |
!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
|
468 |
|
1864 | 469 |
version_HG |
470 |
||
471 |
^ '$Changeset: <not expanded> $' |
|
472 |
! |
|
473 |
||
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
diff
changeset
|
474 |
version_SVN |
1864 | 475 |
^ '§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
|
476 |
! ! |
1995
b129fd0a81e4
Fixes for boot class path index.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1921
diff
changeset
|
477 |