author | cg |
Fri, 07 Feb 1997 20:37:59 +0000 | |
changeset 135 | 098936234135 |
parent 128 | acc4e8e77092 |
child 167 | 77dcbc4b2201 |
permissions | -rw-r--r-- |
1 | 1 |
Object subclass:#JavaClassReader |
91 | 2 |
instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots |
38 | 3 |
constSlot' |
135 | 4 |
classVariableNames:'Verbose Silent AbsolutelySilent LazyClassLoading' |
1 | 5 |
poolDictionaries:'' |
6 |
category:'Java-Support' |
|
7 |
! |
|
8 |
||
9 |
||
135 | 10 |
!JavaClassReader class methodsFor:'initialization'! |
1 | 11 |
|
12 |
initialize |
|
91 | 13 |
Verbose := false. |
14 |
Silent := true. |
|
15 |
AbsolutelySilent := false. |
|
16 |
||
17 |
LazyClassLoading := false. "/ true. |
|
29 | 18 |
|
19 |
" |
|
20 |
JavaClassReader initialize |
|
21 |
" |
|
22 |
||
135 | 23 |
"Modified: 7.2.1997 / 19:25:23 / cg" |
1 | 24 |
! ! |
25 |
||
135 | 26 |
!JavaClassReader class methodsFor:'debugging'! |
1 | 27 |
|
28 |
verbose:aBoolean |
|
29 |
Verbose := aBoolean |
|
30 |
||
31 |
" |
|
67 | 32 |
Java flushClasses. |
1 | 33 |
JavaClassReader verbose:true |
34 |
JavaClassReader verbose:false |
|
35 |
" |
|
36 |
! ! |
|
37 |
||
135 | 38 |
!JavaClassReader class methodsFor:'file reading'! |
1 | 39 |
|
21 | 40 |
loadClass:aClassName |
43 | 41 |
"reads a class, installs and returns it. |
42 |
The classes string constants are resolved & <clinit> is called, |
|
43 |
if it implements it." |
|
21 | 44 |
|
45 |
|rslt| |
|
46 |
||
54 | 47 |
rslt := self loadClassLazy:aClassName ignoring:Set new. |
91 | 48 |
rslt notNil ifTrue:[self postLoadActions]. |
40 | 49 |
|
38 | 50 |
^ rslt |
21 | 51 |
|
52 |
" |
|
53 |
JavaClassReader loadClass:'awt/Component' |
|
54 |
JavaClassReader loadClass:'awt/Button' |
|
55 |
JavaClassReader loadClass:'browser/AddButton' |
|
56 |
||
57 |
JavaClassReader loadClass:'java/lang/Object' |
|
58 |
JavaClassReader loadClass:'java/lang/AbstractMethodError' |
|
59 |
JavaClassReader loadClass:'java/lang/Thread' |
|
60 |
" |
|
61 |
||
62 |
"Created: 15.4.1996 / 14:58:53 / cg" |
|
63 |
! |
|
64 |
||
54 | 65 |
loadClassLazy:aClassName ignoring:classesBeingLoaded |
38 | 66 |
"private helper: |
67 |
reads a class, installs and returns it. |
|
68 |
The class is searched along the ClassPath. |
|
43 | 69 |
|
70 |
This is a partial load (to load other classes): |
|
71 |
- The classes stringConstants are not fixed to be JavaStrings |
|
72 |
(i.e they are still ST-Strings). |
|
73 |
- The class is not initialized." |
|
38 | 74 |
|
91 | 75 |
|rslt clsName cls loadedClass| |
50 | 76 |
|
52 | 77 |
(aClassName endsWith:';') ifTrue:[ |
78 |
('oops - loading of ' , aClassName , ' attempted') printNL. |
|
91 | 79 |
self halt:'should not happen'. |
80 |
^ nil |
|
81 |
]. |
|
82 |
(aClassName endsWith:'[]') ifTrue:[ |
|
83 |
('oops - loading of ' , aClassName , ' attempted') printNL. |
|
84 |
self halt:'should not happen'. |
|
52 | 85 |
^ nil |
86 |
]. |
|
87 |
||
50 | 88 |
clsName := aClassName. |
89 |
(clsName includes:$.) ifTrue:[ |
|
90 |
clsName := clsName copy replaceAll:$. by:$/ |
|
91 |
]. |
|
38 | 92 |
|
91 | 93 |
(classesBeingLoaded notNil and:[classesBeingLoaded includes:clsName]) ifTrue:[ |
54 | 94 |
('oops - recursive load of ' , clsName , ' attempted') printNL. |
91 | 95 |
self halt:'should not happen'. |
54 | 96 |
^ JavaUnresolvedClassConstant fullName:clsName |
97 |
]. |
|
98 |
||
91 | 99 |
(cls := Java at:clsName) notNil ifTrue:[ |
100 |
('oops - ' , clsName , ' is already loaded') printNL. |
|
101 |
self halt:'should not happen'. |
|
102 |
^ cls |
|
103 |
]. |
|
104 |
||
105 |
classesBeingLoaded isNil ifTrue:[ |
|
106 |
loadedClass := Set with:clsName |
|
107 |
] ifFalse:[ |
|
108 |
loadedClass := Set withAll:classesBeingLoaded. |
|
109 |
loadedClass add:clsName. |
|
110 |
]. |
|
54 | 111 |
|
135 | 112 |
Java classPath do:[:path | |
113 |
|nm p| |
|
91 | 114 |
|
135 | 115 |
p := path. |
116 |
(p endsWith:Filename separator) ifFalse:[ |
|
117 |
p := p , (Filename separator asString) |
|
118 |
]. |
|
119 |
(nm := p , clsName , '.class') asFilename exists ifTrue:[ |
|
120 |
rslt := self loadFileLazy:nm ignoring:loadedClass. |
|
121 |
rslt notNil ifTrue:[^ rslt]. |
|
91 | 122 |
] |
38 | 123 |
]. |
124 |
||
91 | 125 |
('JAVA: no file found for: ' , clsName) infoPrintCR. |
126 |
^ nil |
|
135 | 127 |
|
128 |
"Modified: 7.2.1997 / 19:30:08 / cg" |
|
38 | 129 |
! |
130 |
||
7 | 131 |
loadFile:aFilename |
43 | 132 |
"reads a class from aFilename, installs and returns it. |
133 |
The classes strings are fixed and its class-init function is called." |
|
134 |
||
54 | 135 |
self loadFileLazy:aFilename ignoring:(Set new). |
43 | 136 |
self postLoadActions |
137 |
! |
|
138 |
||
54 | 139 |
loadFileLazy:aFilename ignoring:classesBeingLoaded |
43 | 140 |
"reads a class from aFilename, installs and returns it. |
91 | 141 |
Strings are fixed and classrefs are fixed, |
142 |
but NO no class-init functions are called." |
|
7 | 143 |
|
21 | 144 |
|javaClass pool| |
7 | 145 |
|
54 | 146 |
javaClass := self readFile:aFilename ignoring:classesBeingLoaded. |
7 | 147 |
javaClass notNil ifTrue:[ |
32 | 148 |
Java at:(javaClass fullName asSymbol) put:javaClass. |
21 | 149 |
|
54 | 150 |
classesBeingLoaded remove:javaClass fullName ifAbsent:nil. |
21 | 151 |
|
91 | 152 |
JavaUnresolvedConstant resolveFor:javaClass. |
7 | 153 |
]. |
9 | 154 |
^ javaClass |
7 | 155 |
|
156 |
" |
|
157 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
9 | 158 |
|
159 |
'/phys/ibm3/java/lib/java/lang' asFilename |
|
160 |
directoryContents do:[:nm | |
|
161 |
(nm endsWith:'.class') ifTrue:[ |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
162 |
('/phys/ibm3/java/lib/java/lang/' , nm) printNL. |
9 | 163 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/' , nm |
164 |
] |
|
21 | 165 |
]. |
9 | 166 |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
167 |
'/phys/ibm3/java/lib/java/io' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
168 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
169 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
170 |
('/phys/ibm3/java/lib/java/io/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
171 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/io/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
172 |
] |
21 | 173 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
174 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
175 |
'/phys/ibm3/java/lib/java/net' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
176 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
177 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
178 |
('/phys/ibm3/java/lib/java/net/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
179 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/net/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
180 |
] |
21 | 181 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
182 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
183 |
'/phys/ibm3/java/lib/java/util' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
184 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
185 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
186 |
('/phys/ibm3/java/lib/java/util/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
187 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/util/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
188 |
] |
21 | 189 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
190 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
191 |
'/phys/ibm3/java/lib/java/awt' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
192 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
193 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
194 |
('/phys/ibm3/java/lib/java/awt/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
195 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/awt/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
196 |
] |
21 | 197 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
198 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
199 |
'/phys/ibm3/java/lib/java/applet' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
200 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
201 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
202 |
('/phys/ibm3/java/lib/java/applet/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
203 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/applet/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
204 |
] |
21 | 205 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
206 |
|
9 | 207 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/AbstractMethodError.class' |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
208 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/Thread.class' |
7 | 209 |
" |
210 |
||
211 |
"Created: 15.4.1996 / 14:58:53 / cg" |
|
212 |
! |
|
213 |
||
43 | 214 |
postLoadActions |
215 |
"Resolve all classes' string constants. |
|
216 |
Perform all class initialization functions (of those which are not |
|
217 |
yet initialized)." |
|
218 |
||
91 | 219 |
|classes prevUnresolved newUnresolved| |
43 | 220 |
|
91 | 221 |
"/ need at least java.lang.String, for valid constants |
222 |
Java javaString isNil ifTrue:[ |
|
223 |
self loadClassLazy:'java.lang.String' ignoring:Set new. |
|
54 | 224 |
]. |
225 |
||
91 | 226 |
LazyClassLoading ifFalse:[ |
227 |
prevUnresolved := nil. |
|
228 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
229 |
[prevUnresolved ~= newUnresolved] whileTrue:[ |
|
230 |
newUnresolved do:[:nextUnresolved | |
|
231 |
(Java at:nextUnresolved) isNil ifTrue:[ "/ could have been loaded in the meantime |
|
232 |
Silent ifFalse:[ |
|
233 |
'loading unresolved: ' print. nextUnresolved printCR. |
|
234 |
]. |
|
235 |
||
236 |
self |
|
237 |
loadClassLazy:nextUnresolved |
|
238 |
ignoring:Set new. |
|
239 |
] |
|
240 |
]. |
|
241 |
prevUnresolved := newUnresolved. |
|
242 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
243 |
]. |
|
244 |
||
245 |
newUnresolved size == 0 ifTrue:[ |
|
246 |
"/ nothing unresolved |
|
247 |
||
248 |
(classes := Java allClasses) notNil ifTrue:[ |
|
249 |
"/ init all new classes |
|
250 |
"/ fetch again - there could be new ones ... |
|
251 |
||
252 |
classes := Java allClasses. |
|
253 |
classes do:[:aJavaClass | |
|
254 |
aJavaClass isInitialized ifFalse:[ |
|
255 |
Silent ifFalse:[ |
|
256 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
257 |
]. |
|
258 |
aJavaClass classInit |
|
259 |
] |
|
260 |
] |
|
261 |
] |
|
262 |
]. |
|
43 | 263 |
] |
264 |
! |
|
265 |
||
54 | 266 |
readFile:aFilename ignoring:classesBeingLoaded |
7 | 267 |
"reads a class from aFilename and returns it. |
91 | 268 |
The JavaClass is NOT installed as global and unresolved |
269 |
refs are NOT patched." |
|
7 | 270 |
|
73 | 271 |
|inStream javaClass| |
1 | 272 |
|
43 | 273 |
Silent ifFalse:[ |
274 |
'reading ' print. aFilename print. ' ...' printNL. |
|
275 |
]. |
|
21 | 276 |
|
1 | 277 |
inStream := aFilename asFilename readStream. |
91 | 278 |
inStream isNil ifTrue:[ |
279 |
('no file: ' , aFilename) printCR. |
|
280 |
self halt. |
|
281 |
^ nil |
|
282 |
]. |
|
283 |
||
284 |
javaClass := self new readStream:inStream ignoring:classesBeingLoaded. |
|
73 | 285 |
javaClass notNil ifTrue:[ |
286 |
javaClass setBinaryFilePath:(inStream pathName). |
|
287 |
]. |
|
1 | 288 |
inStream close. |
27 | 289 |
|
91 | 290 |
AbsolutelySilent ifFalse:[ |
73 | 291 |
' ... loaded ' print. javaClass displayString printNL. |
43 | 292 |
]. |
27 | 293 |
|
73 | 294 |
^ javaClass |
1 | 295 |
|
296 |
"Created: 15.4.1996 / 14:58:53 / cg" |
|
297 |
! |
|
298 |
||
54 | 299 |
readStream:aStream ignoring:classesBeingLoaded |
7 | 300 |
"reads a class from aStream and returns it. |
301 |
The JavaClass is not installed as global" |
|
302 |
||
54 | 303 |
^ self new readStream:aStream ignoring:classesBeingLoaded |
1 | 304 |
|
305 |
" |
|
306 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
307 |
" |
|
308 |
||
309 |
"Modified: 15.4.1996 / 15:01:30 / cg" |
|
310 |
! ! |
|
311 |
||
312 |
!JavaClassReader methodsFor:'file reading'! |
|
313 |
||
54 | 314 |
readClassFileIgnoring:classesbeingLoaded |
7 | 315 |
"reads a class from inStream and returns it. |
38 | 316 |
The JavaClass is not installed as global and its constants |
317 |
(especially strings) may not be fully resolved." |
|
7 | 318 |
|
9 | 319 |
|magic |
38 | 320 |
access_flags this_class this_class_index super_class super_class_index |
321 |
realSuperClass this_class_ref existingSuperClass |
|
40 | 322 |
fields interfaces staticFields nStatic| |
1 | 323 |
|
324 |
"/ |
|
325 |
"/ read magic, determine byte order |
|
326 |
"/ |
|
327 |
msb := true. |
|
128 | 328 |
magic := inStream nextUnsignedLongMSB:msb. |
1 | 329 |
magic = 16rCAFEBABE ifFalse:[ |
330 |
magic = 16rBEBAFECA ifFalse:[ |
|
331 |
self error:'not a java class file'. |
|
332 |
^ nil |
|
333 |
]. |
|
334 |
msb := false. |
|
61 | 335 |
Verbose ifTrue:[Transcript showCR:'file is lsb']. |
1 | 336 |
] ifTrue:[ |
61 | 337 |
Verbose ifTrue:[Transcript showCR:'file is msb']. |
1 | 338 |
]. |
339 |
||
340 |
"/ |
|
341 |
"/ get version |
|
342 |
"/ |
|
128 | 343 |
minorVsn := inStream nextUnsignedShortMSB:msb. |
344 |
majorVsn := inStream nextUnsignedShortMSB:msb. |
|
9 | 345 |
|
99 | 346 |
(majorVsn ~~ 45 or:[minorVsn ~~ 3]) ifTrue:[ |
347 |
Transcript show:'warning this file has version '; show:majorVsn; show:'.'; showCR:minorVsn. |
|
348 |
]. |
|
349 |
||
350 |
Verbose ifTrue:[ |
|
351 |
Transcript show:'version = '; |
|
352 |
show:(majorVsn printString); |
|
353 |
show:'.'; |
|
354 |
showCR:(minorVsn printString). |
|
355 |
]. |
|
1 | 356 |
|
357 |
"/ |
|
358 |
"/ get constant pool |
|
359 |
"/ |
|
360 |
self readConstantPool. |
|
361 |
||
362 |
"/ |
|
363 |
"/ access flags |
|
364 |
"/ |
|
128 | 365 |
access_flags := inStream nextUnsignedShortMSB:msb. |
366 |
this_class_index := inStream nextUnsignedShortMSB:msb. |
|
367 |
super_class_index := inStream nextUnsignedShortMSB:msb. |
|
1 | 368 |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
369 |
super_class_index == 0 ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
370 |
super_class := nil |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
371 |
] ifFalse:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
372 |
super_class := constants at:super_class_index. |
32 | 373 |
existingSuperClass := Java classNamed:super_class fullName. |
21 | 374 |
existingSuperClass notNil ifTrue:[ |
375 |
super_class := existingSuperClass |
|
54 | 376 |
] ifFalse:[ |
377 |
(super_class isMemberOf:JavaUnresolvedClassConstant) ifTrue:[ |
|
91 | 378 |
Silent ifFalse:[ |
379 |
'load superClass: ' print. super_class fullName printCR. |
|
54 | 380 |
]. |
91 | 381 |
|
382 |
existingSuperClass := self class |
|
383 |
loadClassLazy:(super_class fullName) |
|
384 |
ignoring:classesbeingLoaded. |
|
385 |
||
72 | 386 |
existingSuperClass isNil ifTrue:[ |
54 | 387 |
self halt:('cannot find superclass: ' , super_class fullName). |
72 | 388 |
]. |
389 |
super_class := existingSuperClass |
|
91 | 390 |
] ifFalse:[ |
391 |
self halt:'oops - superclass ?' |
|
392 |
] |
|
29 | 393 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
394 |
]. |
1 | 395 |
|
396 |
"/ |
|
397 |
"/ get interfaces |
|
398 |
"/ |
|
38 | 399 |
interfaces := self readInterfaces. |
1 | 400 |
|
401 |
"/ |
|
402 |
"/ get fields |
|
403 |
"/ |
|
38 | 404 |
fields := self readFieldInfofields. |
40 | 405 |
|
406 |
"/ |
|
407 |
"/ create the fields as instVars |
|
408 |
"/ static fields are created as class-InstVars |
|
409 |
"/ |
|
410 |
staticFields := fields select:[:f | f isStatic]. |
|
411 |
nStatic := staticFields size. |
|
412 |
||
413 |
this_class_ref := constants at:this_class_index. |
|
414 |
nStatic ~~ 0 ifTrue:[ |
|
415 |
fields := fields select:[:f | f isStatic not]. |
|
416 |
||
417 |
this_class := JavaClass fullName:(this_class_ref fullName) numStatic:nStatic. |
|
91 | 418 |
|
40 | 419 |
JavaClass setInstanceVariableStringFromFields:staticFields in:this_class class. |
59 | 420 |
this_class setStaticFields:staticFields. |
60 | 421 |
this_class initializeStaticFields. |
40 | 422 |
] ifFalse:[ |
91 | 423 |
this_class := JavaClass fullName:(this_class_ref fullName) numStatic:0. |
40 | 424 |
]. |
425 |
||
426 |
this_class setAccessFlags:access_flags. |
|
427 |
this_class setSuperclass:super_class. |
|
428 |
this_class setConstantPool:constants. |
|
429 |
||
52 | 430 |
this_class setFields:fields. |
110 | 431 |
this_class setInterfaces:interfaces. |
1 | 432 |
|
433 |
"/ |
|
434 |
"/ get methods |
|
435 |
"/ |
|
38 | 436 |
self readMethodsFor:this_class. |
1 | 437 |
|
5 | 438 |
self readAttributesFor:this_class. |
439 |
||
91 | 440 |
constants owner:this_class. |
441 |
||
5 | 442 |
^ this_class |
443 |
||
1 | 444 |
" |
445 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
446 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
9 | 447 |
|
448 |
JavaClassReader verbose:true. |
|
449 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/ArithmeticException.class' |
|
450 |
JavaClassReader readFile:'/phys/ibm3/java/lib/java/lang/ArithmeticException.class' |
|
1 | 451 |
" |
452 |
||
453 |
"Created: 15.4.1996 / 15:02:47 / cg" |
|
454 |
"Modified: 15.4.1996 / 16:51:48 / cg" |
|
455 |
! |
|
456 |
||
5 | 457 |
readSourceFileAttributeFor:aJavaClass |
458 |
|attribute_length sourceFile_index sourceFile| |
|
459 |
||
128 | 460 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
5 | 461 |
|
128 | 462 |
sourceFile_index := inStream nextUnsignedShortMSB:msb. |
5 | 463 |
sourceFile := constants at:sourceFile_index. |
464 |
||
465 |
aJavaClass setSourceFile:sourceFile. |
|
466 |
||
61 | 467 |
Verbose ifTrue:[Transcript show:'sourceFile: '; showCR:sourceFile]. |
5 | 468 |
^ true |
469 |
||
470 |
" |
|
471 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
472 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
473 |
" |
|
474 |
||
475 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
476 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
477 |
! |
|
478 |
||
54 | 479 |
readStream:aStream ignoring:classesBeingLoaded |
7 | 480 |
"reads a class from aStream and returns it. |
481 |
The JavaClass is not installed as global" |
|
482 |
||
5 | 483 |
inStream := aStream. |
484 |
inStream binary. |
|
38 | 485 |
|
54 | 486 |
^ self readClassFileIgnoring:classesBeingLoaded |
5 | 487 |
|
488 |
" |
|
489 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
490 |
" |
|
491 |
||
492 |
"Created: 15.4.1996 / 15:00:55 / cg" |
|
493 |
"Modified: 15.4.1996 / 15:06:18 / cg" |
|
494 |
! ! |
|
495 |
||
496 |
!JavaClassReader methodsFor:'file reading - attributes'! |
|
497 |
||
498 |
readAttribute:attributeName for:something |
|
83 | 499 |
|
5 | 500 |
(attributeName = 'Code') ifTrue:[ |
501 |
self readCodeAttributeFor:something. |
|
502 |
^ true. |
|
503 |
]. |
|
83 | 504 |
(attributeName = 'Exceptions') ifTrue:[ |
505 |
self readExceptionsAttributeFor:something. |
|
506 |
^ true. |
|
507 |
]. |
|
5 | 508 |
(attributeName = 'LineNumberTable') ifTrue:[ |
509 |
self readLineNumberTableAttributeFor:something. |
|
510 |
^ true. |
|
511 |
]. |
|
512 |
(attributeName = 'LocalVariableTable') ifTrue:[ |
|
513 |
self readLocalVariableTableAttributeFor:something. |
|
514 |
^ true. |
|
515 |
]. |
|
516 |
(attributeName = 'ConstantValue') ifTrue:[ |
|
517 |
self readConstantValueAttributeFor:something. |
|
518 |
^ true. |
|
519 |
]. |
|
520 |
(attributeName = 'SourceFile') ifTrue:[ |
|
521 |
self readSourceFileAttributeFor:something. |
|
522 |
^ true. |
|
523 |
]. |
|
83 | 524 |
|
525 |
('JAVA: unrecognized attribute: ' , attributeName) infoPrintCR. |
|
5 | 526 |
^ false |
527 |
||
528 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
529 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
530 |
! |
|
531 |
||
532 |
readAttributeFor:something |
|
533 |
|attribute_name_index attribute_name attribute_length attribute_info| |
|
534 |
||
61 | 535 |
Verbose ifTrue:[Transcript show:'attrib at pos: '; showCR:inStream position]. |
9 | 536 |
|
128 | 537 |
attribute_name_index := inStream nextUnsignedShortMSB:msb. |
9 | 538 |
|
539 |
"/ |
|
540 |
"/ UNDOC feature ? |
|
541 |
"/ |
|
542 |
attribute_name_index > constants size ifTrue:[ |
|
543 |
attribute_name_index == 16rb700 ifTrue:[ |
|
544 |
self halt. |
|
545 |
] |
|
546 |
]. |
|
547 |
||
5 | 548 |
attribute_name := constants at:attribute_name_index. |
9 | 549 |
|
61 | 550 |
Verbose ifTrue:[Transcript show:'attrib name: '; showCR:attribute_name]. |
9 | 551 |
|
5 | 552 |
(self readAttribute:attribute_name for:something) ifFalse:[ |
128 | 553 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
5 | 554 |
attribute_info := ByteArray new:(attribute_length). |
555 |
inStream nextBytes:attribute_length into:attribute_info startingAt:1. |
|
556 |
||
61 | 557 |
Verbose ifTrue:[Transcript show:'skipped '; show:attribute_name; showCR:'-attribute']. |
5 | 558 |
]. |
559 |
||
560 |
" |
|
561 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
562 |
" |
|
563 |
||
564 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
565 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
566 |
! |
|
567 |
||
568 |
readAttributesFor:something |
|
569 |
|attributes_count| |
|
570 |
||
128 | 571 |
attributes_count := inStream nextUnsignedShortMSB:msb. |
5 | 572 |
|
573 |
1 to:attributes_count do:[:i | |
|
574 |
self readAttributeFor:something. |
|
575 |
]. |
|
576 |
||
577 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
578 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
579 |
! ! |
|
580 |
||
581 |
!JavaClassReader methodsFor:'file reading - constants'! |
|
582 |
||
1 | 583 |
readConstant |
584 |
|tag constReader const| |
|
585 |
||
586 |
||
11 | 587 |
constNeeds2Slots := false. |
588 |
||
1 | 589 |
"/ |
590 |
"/ get tag |
|
591 |
"/ |
|
128 | 592 |
tag := inStream nextByte. |
61 | 593 |
Verbose ifTrue:[Transcript show:'tag = '; showCR:tag]. |
1 | 594 |
|
595 |
constReader := #( |
|
91 | 596 |
readConstant_Asciz "/ 1 - now called Utf8 |
597 |
readConstant_Unicode "/ 2 |
|
1 | 598 |
readConstant_Integer "/ 3 |
599 |
readConstant_Float "/ 4 |
|
600 |
readConstant_Long "/ 5 |
|
601 |
readConstant_Double "/ 6 |
|
602 |
readConstant_Class "/ 7 |
|
603 |
readConstant_String "/ 8 |
|
604 |
readConstant_Fieldref "/ 9 |
|
605 |
readConstant_Methodref "/ 10 |
|
606 |
readConstant_InterfaceMethodref "/ 11 |
|
91 | 607 |
readConstant_NameAndType "/ 12 |
1 | 608 |
) at:tag ifAbsent:[#readConstant_Undef]. |
609 |
||
610 |
^ self perform:constReader. |
|
611 |
||
612 |
" |
|
613 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
614 |
" |
|
615 |
||
616 |
"Created: 15.4.1996 / 15:46:32 / cg" |
|
617 |
"Modified: 15.4.1996 / 15:47:00 / cg" |
|
618 |
! |
|
619 |
||
620 |
readConstantPool |
|
11 | 621 |
|constantPoolCount const i| |
1 | 622 |
|
623 |
"/ |
|
624 |
"/ get constant pool |
|
625 |
"/ |
|
128 | 626 |
constantPoolCount := inStream nextUnsignedShortMSB:msb. |
61 | 627 |
Verbose ifTrue:[Transcript show:'constantPoolCount = '; showCR:constantPoolCount]. |
1 | 628 |
|
91 | 629 |
constants := JavaConstantPool "Array" new:constantPoolCount-1. |
1 | 630 |
|
21 | 631 |
constSlot := 1. |
632 |
[constSlot < constantPoolCount] whileTrue:[ |
|
61 | 633 |
Verbose ifTrue:[Transcript show:'const: '; showCR:constSlot]. |
1 | 634 |
const := self readConstant. |
21 | 635 |
constants at:constSlot put:const. |
11 | 636 |
constNeeds2Slots ifTrue:[ |
21 | 637 |
constSlot := constSlot + 1. |
11 | 638 |
]. |
21 | 639 |
constSlot := constSlot + 1. |
1 | 640 |
]. |
641 |
||
52 | 642 |
constSlot := -1. |
643 |
||
91 | 644 |
"/ preresolve what can be (especially, strings are resolved here) |
645 |
||
1 | 646 |
1 to:constantPoolCount-1 do:[:i | |
67 | 647 |
|const value| |
1 | 648 |
|
649 |
const := constants at:i. |
|
38 | 650 |
const notNil ifTrue:[ "/ kludge for 2-slot constants (which only take 1 slot in ST/X) |
91 | 651 |
(const isKindOf:JavaUnresolvedConstant) ifTrue:[ |
652 |
value := const preResolve. |
|
653 |
value ~~ const ifTrue:[ |
|
654 |
constants at:i put:value. |
|
655 |
] |
|
656 |
] |
|
11 | 657 |
] |
1 | 658 |
]. |
659 |
||
660 |
" |
|
661 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
662 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
663 |
" |
|
664 |
||
665 |
"Created: 15.4.1996 / 15:14:11 / cg" |
|
666 |
"Modified: 15.4.1996 / 16:41:57 / cg" |
|
667 |
! |
|
668 |
||
669 |
readConstant_Asciz |
|
670 |
|len string| |
|
671 |
||
128 | 672 |
len := inStream nextUnsignedShortMSB:msb. |
1 | 673 |
string := String new:len. |
674 |
inStream nextBytes:len into:string startingAt:1. |
|
675 |
||
61 | 676 |
Verbose ifTrue:[Transcript show:'asciz; string= '; showCR:string]. |
1 | 677 |
|
678 |
^ string |
|
679 |
||
680 |
" |
|
681 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
682 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
683 |
" |
|
684 |
||
685 |
"Created: 15.4.1996 / 15:15:35 / cg" |
|
686 |
"Modified: 15.4.1996 / 16:33:45 / cg" |
|
687 |
! |
|
688 |
||
689 |
readConstant_Class |
|
52 | 690 |
|name_index name| |
1 | 691 |
|
128 | 692 |
name_index := inStream nextUnsignedShortMSB:msb. |
1 | 693 |
|
61 | 694 |
Verbose ifTrue:[Transcript show:'class; index= '; showCR:name_index]. |
1 | 695 |
|
52 | 696 |
name := constants at:name_index. |
697 |
name notNil ifTrue:[ |
|
698 |
self halt |
|
699 |
]. |
|
700 |
||
21 | 701 |
^ JavaUnresolvedClassConstant |
91 | 702 |
pool:constants |
703 |
poolIndex:constSlot |
|
21 | 704 |
nameIndex:name_index |
91 | 705 |
|
1 | 706 |
" |
707 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
708 |
" |
|
709 |
||
710 |
"Created: 15.4.1996 / 15:21:13 / cg" |
|
711 |
"Modified: 15.4.1996 / 15:49:32 / cg" |
|
712 |
! |
|
713 |
||
11 | 714 |
readConstant_Double |
715 |
|high low aFloat| |
|
716 |
||
128 | 717 |
high := inStream nextUnsignedLongMSB:msb. |
718 |
low := inStream nextUnsignedLongMSB:msb. |
|
11 | 719 |
|
720 |
aFloat := Float new. |
|
721 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
722 |
aFloat basicAt:1 put:((high bitShift:-24) bitAnd:16rFF). |
|
723 |
aFloat basicAt:2 put:((high bitShift:-16) bitAnd:16rFF). |
|
724 |
aFloat basicAt:3 put:((high bitShift:-8) bitAnd:16rFF). |
|
725 |
aFloat basicAt:4 put:(high bitAnd:16rFF). |
|
726 |
aFloat basicAt:5 put:((low bitShift:-24) bitAnd:16rFF). |
|
727 |
aFloat basicAt:6 put:((low bitShift:-16) bitAnd:16rFF). |
|
728 |
aFloat basicAt:7 put:((low bitShift:-8) bitAnd:16rFF). |
|
729 |
aFloat basicAt:8 put:(low bitAnd:16rFF). |
|
730 |
] ifFalse:[ |
|
731 |
aFloat basicAt:1 put:(low bitAnd:16rFF). |
|
732 |
aFloat basicAt:2 put:((low bitShift:-8) bitAnd:16rFF). |
|
733 |
aFloat basicAt:3 put:((low bitShift:-16) bitAnd:16rFF). |
|
734 |
aFloat basicAt:4 put:((low bitShift:-24) bitAnd:16rFF). |
|
735 |
aFloat basicAt:5 put:(high bitAnd:16rFF). |
|
736 |
aFloat basicAt:6 put:((high bitShift:-8) bitAnd:16rFF). |
|
737 |
aFloat basicAt:7 put:((high bitShift:-16) bitAnd:16rFF). |
|
738 |
aFloat basicAt:8 put:((high bitShift:-24) bitAnd:16rFF). |
|
739 |
]. |
|
740 |
||
741 |
constNeeds2Slots := true. |
|
742 |
||
61 | 743 |
Verbose ifTrue:[Transcript show:'double; value= '; showCR:aFloat]. |
11 | 744 |
^ aFloat |
745 |
||
746 |
" |
|
747 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
748 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
749 |
" |
|
750 |
||
751 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
752 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
753 |
! |
|
754 |
||
1 | 755 |
readConstant_Fieldref |
756 |
|class_index name_and_type_index| |
|
757 |
||
128 | 758 |
class_index := inStream nextUnsignedShortMSB:msb. |
759 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1 | 760 |
|
61 | 761 |
Verbose ifTrue:[Transcript show:'fieldref; classindex= '; showCR:class_index]. |
762 |
Verbose ifTrue:[Transcript show:'fieldref; name&typeindex= '; showCR:name_and_type_index]. |
|
1 | 763 |
|
91 | 764 |
^ JavaUnresolvedFieldrefConstant |
765 |
pool:constants |
|
766 |
poolIndex:constSlot |
|
1 | 767 |
classIndex:class_index |
768 |
nameandTypeIndex:name_and_type_index |
|
769 |
||
770 |
" |
|
771 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
772 |
" |
|
773 |
||
774 |
"Created: 15.4.1996 / 15:22:18 / cg" |
|
775 |
"Modified: 15.4.1996 / 16:07:01 / cg" |
|
776 |
! |
|
777 |
||
11 | 778 |
readConstant_Float |
779 |
|high aFloat| |
|
780 |
||
128 | 781 |
high := inStream nextUnsignedLongMSB:msb. |
11 | 782 |
|
783 |
aFloat := ShortFloat basicNew. |
|
784 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
785 |
aFloat basicAt:1 put:((high bitShift:-24) bitAnd:16rFF). |
|
786 |
aFloat basicAt:2 put:((high bitShift:-16) bitAnd:16rFF). |
|
787 |
aFloat basicAt:3 put:((high bitShift:-8) bitAnd:16rFF). |
|
788 |
aFloat basicAt:4 put:(high bitAnd:16rFF). |
|
789 |
] ifFalse:[ |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
790 |
aFloat basicAt:1 put:(high bitAnd:16rFF). |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
791 |
aFloat basicAt:2 put:((high bitShift:-8) bitAnd:16rFF). |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
792 |
aFloat basicAt:3 put:((high bitShift:-16) bitAnd:16rFF). |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
793 |
aFloat basicAt:4 put:((high bitShift:-24) bitAnd:16rFF). |
11 | 794 |
]. |
795 |
||
61 | 796 |
Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
11 | 797 |
^ aFloat |
798 |
||
799 |
" |
|
800 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
801 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
802 |
" |
|
803 |
||
804 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
805 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
806 |
! |
|
807 |
||
1 | 808 |
readConstant_Integer |
809 |
|value| |
|
810 |
||
128 | 811 |
value := inStream nextLongMSB:msb. |
1 | 812 |
|
61 | 813 |
Verbose ifTrue:[Transcript show:'integer; value= '; showCR:value]. |
1 | 814 |
|
815 |
^ value |
|
816 |
||
817 |
" |
|
818 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
819 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
820 |
" |
|
821 |
||
822 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
823 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
824 |
! |
|
825 |
||
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
826 |
readConstant_InterfaceMethodref |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
827 |
|class_index name_and_type_index| |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
828 |
|
128 | 829 |
class_index := inStream nextUnsignedShortMSB:msb. |
830 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
831 |
|
61 | 832 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
833 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
834 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
835 |
^ JavaUnresolvedInterfaceMethodrefConstant |
91 | 836 |
pool:constants |
837 |
poolIndex:constSlot |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
838 |
classIndex:class_index |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
839 |
nameandTypeIndex:name_and_type_index |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
840 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
841 |
" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
842 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
843 |
" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
844 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
845 |
"Created: 15.4.1996 / 15:22:37 / cg" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
846 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
847 |
! |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
848 |
|
11 | 849 |
readConstant_Long |
850 |
|high low value| |
|
851 |
||
128 | 852 |
high := inStream nextUnsignedLongMSB:msb. |
853 |
low := inStream nextUnsignedLongMSB:msb. |
|
11 | 854 |
|
855 |
value := (high bitShift:32) bitOr:low. |
|
60 | 856 |
(high bitTest:16r80000000) ifTrue:[ |
857 |
value := value - 16r10000000000000000. |
|
858 |
]. |
|
11 | 859 |
constNeeds2Slots := true. |
860 |
||
61 | 861 |
Verbose ifTrue:[Transcript show:'long; value= '; showCR:value]. |
11 | 862 |
^ value |
863 |
||
864 |
" |
|
865 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
866 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
867 |
" |
|
868 |
||
869 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
870 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
871 |
! |
|
872 |
||
1 | 873 |
readConstant_Methodref |
874 |
|class_index name_and_type_index| |
|
875 |
||
128 | 876 |
class_index := inStream nextUnsignedShortMSB:msb. |
877 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1 | 878 |
|
61 | 879 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
880 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
1 | 881 |
|
882 |
^ JavaUnresolvedMethodrefConstant |
|
91 | 883 |
pool:constants |
884 |
poolIndex:constSlot |
|
1 | 885 |
classIndex:class_index |
886 |
nameandTypeIndex:name_and_type_index |
|
887 |
||
888 |
" |
|
889 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
890 |
" |
|
891 |
||
892 |
"Created: 15.4.1996 / 15:22:37 / cg" |
|
893 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
|
894 |
! |
|
895 |
||
91 | 896 |
readConstant_NameAndType |
1 | 897 |
|name_index signature_index| |
898 |
||
128 | 899 |
name_index := inStream nextUnsignedShortMSB:msb. |
900 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
1 | 901 |
|
61 | 902 |
Verbose ifTrue:[Transcript show:'methodref; nameindex= '; showCR:name_index]. |
903 |
Verbose ifTrue:[Transcript show:'methodref; signatureindex= '; showCR:signature_index]. |
|
1 | 904 |
|
905 |
^ JavaUnresolvedNameandTypeConstant |
|
91 | 906 |
pool:constants |
907 |
poolIndex:constSlot |
|
1 | 908 |
nameIndex:name_index |
91 | 909 |
signatureIndex:signature_index |
1 | 910 |
|
911 |
" |
|
912 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
913 |
" |
|
914 |
||
915 |
"Created: 15.4.1996 / 15:23:43 / cg" |
|
916 |
"Modified: 15.4.1996 / 16:17:16 / cg" |
|
917 |
! |
|
918 |
||
919 |
readConstant_String |
|
920 |
|tag string_index| |
|
921 |
||
128 | 922 |
string_index := inStream nextUnsignedShortMSB:msb. |
1 | 923 |
|
61 | 924 |
Verbose ifTrue:[Transcript show:'string; index= '; showCR:string_index]. |
1 | 925 |
|
91 | 926 |
^ JavaUnresolvedStringConstant |
927 |
pool:constants |
|
928 |
poolIndex:constSlot |
|
929 |
stringIndex:string_index |
|
1 | 930 |
|
931 |
" |
|
43 | 932 |
Verbose := true. |
933 |
JavaClassReader readFile:'/phys/ibm3/java/lib/java/lang/System.class' |
|
1 | 934 |
" |
935 |
||
936 |
"Created: 15.4.1996 / 15:20:33 / cg" |
|
937 |
"Modified: 15.4.1996 / 16:01:37 / cg" |
|
5 | 938 |
! ! |
939 |
||
940 |
!JavaClassReader methodsFor:'file reading - fields'! |
|
941 |
||
942 |
readConstantValueAttributeFor:aField |
|
943 |
|attribute_length constantvalue_index constantValue| |
|
944 |
||
128 | 945 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
5 | 946 |
|
128 | 947 |
constantvalue_index := inStream nextUnsignedShortMSB:msb. |
5 | 948 |
constantValue := constants at:constantvalue_index. |
949 |
||
59 | 950 |
aField constantValue:constantValue. |
951 |
||
61 | 952 |
Verbose ifTrue:[Transcript show:'constantValue: '; showCR:constantValue]. |
5 | 953 |
^ true |
954 |
||
955 |
" |
|
956 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
957 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
958 |
" |
|
959 |
||
960 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
961 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1 | 962 |
! |
963 |
||
964 |
readFieldInfofield |
|
5 | 965 |
|access_flags name_index signature_index attributes_count field| |
1 | 966 |
|
128 | 967 |
access_flags := inStream nextUnsignedShortMSB:msb. |
968 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
969 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
5 | 970 |
|
971 |
field := JavaField new. |
|
972 |
field setAccessFlags:access_flags. |
|
973 |
field setName:(constants at:name_index). |
|
974 |
field setSignature:(constants at:signature_index). |
|
975 |
||
128 | 976 |
attributes_count := inStream nextUnsignedShortMSB:msb. |
1 | 977 |
|
99 | 978 |
Verbose ifTrue:[Transcript show:' field name: '; show:(constants at:name_index); |
979 |
show:' access: '; show:access_flags; |
|
980 |
show:' attrib_cnt: '; showCR:attributes_count]. |
|
981 |
||
1 | 982 |
1 to:attributes_count do:[:i | |
5 | 983 |
self readAttributeFor:field. |
1 | 984 |
]. |
985 |
||
27 | 986 |
^ field |
987 |
||
1 | 988 |
" |
989 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
990 |
" |
|
991 |
||
992 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
993 |
"Created: 15.4.1996 / 15:38:43 / cg" |
|
994 |
! |
|
995 |
||
996 |
readFieldInfofields |
|
38 | 997 |
|nFields fields| |
1 | 998 |
|
999 |
"/ |
|
38 | 1000 |
"/ get fieldInfos |
1 | 1001 |
"/ |
128 | 1002 |
nFields := inStream nextUnsignedShortMSB:msb. |
61 | 1003 |
Verbose ifTrue:[Transcript show:'fieldsCount = '; showCR:nFields]. |
1 | 1004 |
|
27 | 1005 |
fields := Array new:nFields. |
1006 |
||
1007 |
1 to:nFields do:[:i | |
|
61 | 1008 |
Verbose ifTrue:[Transcript show:'field: '; showCR:i]. |
27 | 1009 |
fields at:i put:(self readFieldInfofield) |
1 | 1010 |
]. |
38 | 1011 |
^ fields |
1 | 1012 |
|
1013 |
" |
|
1014 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1015 |
" |
|
1016 |
||
1017 |
"Created: 15.4.1996 / 15:34:41 / cg" |
|
1018 |
"Modified: 15.4.1996 / 15:35:28 / cg" |
|
5 | 1019 |
! ! |
1020 |
||
38 | 1021 |
!JavaClassReader methodsFor:'file reading - interfaces'! |
1022 |
||
1023 |
readInterfaces |
|
110 | 1024 |
|interfacesCount interface_index interface interfaces| |
38 | 1025 |
|
1026 |
"/ |
|
1027 |
"/ get interfaces |
|
1028 |
"/ |
|
128 | 1029 |
interfacesCount := inStream nextUnsignedShortMSB:msb. |
61 | 1030 |
Verbose ifTrue:[Transcript show:'interfacesCount = '; showCR:interfacesCount]. |
38 | 1031 |
|
1032 |
interfaces := Array new:interfacesCount. |
|
1033 |
||
1034 |
1 to:interfacesCount do:[:i | |
|
61 | 1035 |
Verbose ifTrue:[Transcript show:'interface: '; showCR:i]. |
128 | 1036 |
interface_index := inStream nextUnsignedShortMSB:msb. |
110 | 1037 |
interface := constants at:interface_index. |
38 | 1038 |
|
1039 |
interfaces at:i put:interface. |
|
1040 |
]. |
|
1041 |
^ interfaces |
|
1042 |
||
1043 |
" |
|
1044 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1045 |
" |
|
1046 |
||
1047 |
"Created: 15.4.1996 / 15:31:59 / cg" |
|
1048 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1049 |
! ! |
|
1050 |
||
5 | 1051 |
!JavaClassReader methodsFor:'file reading - methods'! |
1052 |
||
1053 |
readCodeAttributeFor:aJavaMethod |
|
1054 |
|attribute_length max_stack max_locals code_length code |
|
9 | 1055 |
exception_table_length exception_table unknown1 unknown2| |
1 | 1056 |
|
128 | 1057 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
1 | 1058 |
|
9 | 1059 |
|
61 | 1060 |
Verbose ifTrue:[Transcript show:'attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
9 | 1061 |
|
99 | 1062 |
minorVsn > 2 ifTrue:[ |
128 | 1063 |
unknown1 := inStream nextByte. |
1064 |
max_stack := inStream nextByte. |
|
1065 |
max_locals := inStream nextUnsignedShortMSB:msb. |
|
1066 |
unknown2 := inStream nextUnsignedShortMSB:msb. |
|
61 | 1067 |
Verbose ifTrue:[Transcript show:'?1: '; showCR:unknown1]. |
1068 |
Verbose ifTrue:[Transcript show:'?2: '; showCR:unknown2]. |
|
39 | 1069 |
] ifFalse:[ |
128 | 1070 |
max_stack := inStream nextByte. |
1071 |
max_locals := inStream nextByte. |
|
9 | 1072 |
]. |
1073 |
||
128 | 1074 |
code_length := inStream nextUnsignedShortMSB:msb. |
61 | 1075 |
Verbose ifTrue:[Transcript show:'code_length: '; showCR:(code_length printStringRadix:16)]. |
1076 |
Verbose ifTrue:[Transcript show:'code at pos: '; showCR:inStream position]. |
|
38 | 1077 |
|
5 | 1078 |
code := ByteArray new:code_length. |
1079 |
inStream nextBytes:code_length into:code startingAt:1. |
|
1 | 1080 |
|
61 | 1081 |
Verbose ifTrue:[Transcript show:'method code:'; showCR:code.]. |
9 | 1082 |
|
128 | 1083 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
61 | 1084 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
5 | 1085 |
exception_table_length ~~ 0 ifTrue:[ |
61 | 1086 |
Verbose ifTrue:[Transcript show:'exceptionTable length:'; showCR:exception_table_length.]. |
9 | 1087 |
|
5 | 1088 |
exception_table := Array new:exception_table_length. |
1089 |
1 to:exception_table_length do:[:i | |
|
1090 |
|start_pc end_pc handler_pc catch_type| |
|
1 | 1091 |
|
128 | 1092 |
start_pc := inStream nextUnsignedShortMSB:msb. |
1093 |
end_pc := inStream nextUnsignedShortMSB:msb. |
|
1094 |
handler_pc := inStream nextUnsignedShortMSB:msb. |
|
1095 |
catch_type := constants at:(inStream nextUnsignedShortMSB:msb). |
|
5 | 1096 |
exception_table at:i put:(JavaExceptionTableEntry |
1097 |
startPC:start_pc |
|
1098 |
endPC:end_pc |
|
1099 |
handlerPC:handler_pc |
|
1100 |
catchType:catch_type). |
|
1101 |
]. |
|
83 | 1102 |
aJavaMethod setExceptionHandlerTable:exception_table. |
1 | 1103 |
]. |
1104 |
||
29 | 1105 |
aJavaMethod |
1106 |
setCode:code |
|
1107 |
maxStack:max_stack |
|
1108 |
maxLocals:max_locals |
|
1109 |
u1:unknown1 |
|
1110 |
u2:unknown2. |
|
5 | 1111 |
|
1112 |
self readAttributesFor:aJavaMethod. |
|
1113 |
^ true |
|
1114 |
||
1 | 1115 |
" |
1116 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
5 | 1117 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
1 | 1118 |
" |
1119 |
||
1120 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
5 | 1121 |
"Created: 15.4.1996 / 15:40:17 / cg" |
1122 |
! |
|
1123 |
||
83 | 1124 |
readExceptionsAttributeFor:aJavaMethod |
1125 |
|attribute_length exception_table_length exception_table| |
|
1126 |
||
128 | 1127 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
83 | 1128 |
|
128 | 1129 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
83 | 1130 |
exception_table_length ~~ 0 ifTrue:[ |
1131 |
exception_table := Array new:exception_table_length. |
|
1132 |
1 to:exception_table_length do:[:i | |
|
1133 |
|idx ex| |
|
1134 |
||
128 | 1135 |
idx := inStream nextUnsignedShortMSB:msb. |
83 | 1136 |
ex := constants at:idx. |
1137 |
exception_table at:i put:ex. |
|
1138 |
]. |
|
1139 |
]. |
|
1140 |
||
1141 |
Verbose ifTrue:[Transcript showCR:'method has an exceptionTable']. |
|
1142 |
||
1143 |
aJavaMethod setExceptionTable:exception_table. |
|
1144 |
^ true |
|
1145 |
||
1146 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1147 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1148 |
! |
|
1149 |
||
5 | 1150 |
readLineNumberTableAttributeFor:aJavaMethod |
1151 |
|attribute_length line_number_table_length line_number_table| |
|
1152 |
||
128 | 1153 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
5 | 1154 |
|
128 | 1155 |
line_number_table_length := inStream nextUnsignedShortMSB:msb. |
5 | 1156 |
line_number_table_length ~~ 0 ifTrue:[ |
1157 |
line_number_table := Array new:line_number_table_length. |
|
1158 |
1 to:line_number_table_length do:[:i | |
|
1159 |
|start_pc line_number| |
|
1160 |
||
128 | 1161 |
start_pc := inStream nextUnsignedShortMSB:msb. |
1162 |
line_number := inStream nextUnsignedShortMSB:msb. |
|
5 | 1163 |
line_number_table at:i put:(start_pc -> line_number). |
1164 |
]. |
|
1165 |
]. |
|
1166 |
||
61 | 1167 |
Verbose ifTrue:[Transcript showCR:'method has a lineNumberTable']. |
9 | 1168 |
|
5 | 1169 |
aJavaMethod setLineNumberTable:line_number_table. |
1170 |
^ true |
|
1171 |
||
1172 |
" |
|
1173 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1174 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
1175 |
" |
|
1176 |
||
1177 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1178 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1 | 1179 |
! |
1180 |
||
50 | 1181 |
readLocalVariableTableAttributeFor:aJavaMethod |
1182 |
|attribute_length local_variable_table_length local_variable_table| |
|
1183 |
||
128 | 1184 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
50 | 1185 |
|
128 | 1186 |
local_variable_table_length := inStream nextUnsignedShortMSB:msb. |
50 | 1187 |
local_variable_table_length ~~ 0 ifTrue:[ |
104 | 1188 |
local_variable_table := JavaLocalVariableTable new:local_variable_table_length. |
50 | 1189 |
1 to:local_variable_table_length do:[:i | |
1190 |
|start_pc length name_index sig_index slot name signature| |
|
1191 |
||
128 | 1192 |
start_pc := inStream nextUnsignedShortMSB:msb. |
1193 |
length := inStream nextUnsignedShortMSB:msb. |
|
1194 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
86 | 1195 |
name := constants at:name_index. |
128 | 1196 |
sig_index := inStream nextUnsignedShortMSB:msb. |
86 | 1197 |
signature := constants at:sig_index. |
128 | 1198 |
slot := inStream nextUnsignedShortMSB:msb. |
50 | 1199 |
|
1200 |
local_variable_table at:i put:(JavaLocalVariableTableEntry new |
|
1201 |
startPC:start_pc |
|
1202 |
length:length |
|
1203 |
name:name |
|
1204 |
signature:signature |
|
1205 |
slot:slot) |
|
1206 |
]. |
|
1207 |
]. |
|
1208 |
||
61 | 1209 |
Verbose ifTrue:[Transcript showCR:'method has a localvariableTable']. |
50 | 1210 |
|
1211 |
aJavaMethod setLocalVariableTable:local_variable_table. |
|
1212 |
^ true |
|
1213 |
||
1214 |
" |
|
1215 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1216 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
1217 |
" |
|
1218 |
||
1219 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1220 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1221 |
! |
|
1222 |
||
38 | 1223 |
readMethodFor:aJavaClass |
9 | 1224 |
|m access_flags name_index name signature_index signature| |
1 | 1225 |
|
1226 |
"/ |
|
1227 |
"/ get a method |
|
1228 |
"/ |
|
128 | 1229 |
access_flags := inStream nextUnsignedShortMSB:msb. |
1230 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
1231 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
1 | 1232 |
|
5 | 1233 |
name := constants at:name_index. |
1234 |
signature := constants at:signature_index. |
|
9 | 1235 |
|
61 | 1236 |
Verbose ifTrue:[Transcript show:'method name:'; showCR:name. |
1237 |
Transcript show:'signature:'; showCR:signature.]. |
|
9 | 1238 |
|
5 | 1239 |
m := JavaMethod new. |
1240 |
m setAccessFlags:access_flags. |
|
1241 |
m setSignature:signature. |
|
1242 |
m setName:name. |
|
38 | 1243 |
m setJavaClass:aJavaClass. |
5 | 1244 |
|
1245 |
self readAttributesFor:m. |
|
1246 |
||
38 | 1247 |
aJavaClass addMethod:m name:name signature:signature. |
1 | 1248 |
|
1249 |
" |
|
1250 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1251 |
" |
|
1252 |
||
1253 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1254 |
"Created: 15.4.1996 / 16:48:49 / cg" |
|
1255 |
! |
|
1256 |
||
38 | 1257 |
readMethodsFor:aJavaClass |
1 | 1258 |
|methodsCount method| |
1259 |
||
1260 |
||
1261 |
"/ |
|
1262 |
"/ get methods |
|
1263 |
"/ |
|
128 | 1264 |
methodsCount := inStream nextUnsignedShortMSB:msb. |
61 | 1265 |
Verbose ifTrue:[Transcript show:'methodsCount = '; showCR:methodsCount]. |
1 | 1266 |
|
1267 |
1 to:methodsCount do:[:i | |
|
61 | 1268 |
Verbose ifTrue:[Transcript show:'method: '; showCR:i]. |
38 | 1269 |
method := self readMethodFor:aJavaClass |
1 | 1270 |
]. |
1271 |
||
1272 |
" |
|
1273 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1274 |
" |
|
1275 |
||
1276 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1277 |
"Created: 15.4.1996 / 16:46:30 / cg" |
|
1278 |
! ! |
|
1279 |
||
135 | 1280 |
!JavaClassReader class methodsFor:'documentation'! |
1 | 1281 |
|
1282 |
version |
|
135 | 1283 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaClassReader.st,v 1.38 1997/02/07 20:37:08 cg Exp $' |
1 | 1284 |
! ! |
1285 |
JavaClassReader initialize! |