author | Claus Gittinger <cg@exept.de> |
Fri, 09 Oct 2009 16:21:53 +0200 | |
changeset 2148 | b51eb5830f48 |
parent 2142 | 4836ff0780cd |
child 2151 | c0b6570c6f9b |
permissions | -rw-r--r-- |
454 | 1 |
" |
2089 | 2 |
COPYRIGHT (c) 1997 by eXept Software AG |
3 |
All Rights Reserved |
|
454 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
695 | 12 |
"{ Package: 'stx:libjava' }" |
13 |
||
1 | 14 |
Object subclass:#JavaClassReader |
91 | 15 |
instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots |
2089 | 16 |
constSlot' |
17 |
classVariableNames:'Verbose Silent AbsolutelySilent LazyClassLoading |
|
18 |
InvalidClassFormatSignal ClassLoaderQuerySignal' |
|
1 | 19 |
poolDictionaries:'' |
2108 | 20 |
category:'Languages-Java-Support' |
1 | 21 |
! |
22 |
||
454 | 23 |
!JavaClassReader class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
2089 | 27 |
COPYRIGHT (c) 1997 by eXept Software AG |
28 |
All Rights Reserved |
|
454 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
2089 | 37 |
|
38 |
||
454 | 39 |
! ! |
1 | 40 |
|
135 | 41 |
!JavaClassReader class methodsFor:'initialization'! |
1 | 42 |
|
43 |
initialize |
|
2089 | 44 |
InvalidClassFormatSignal := Signal new mayProceed:true. |
45 |
InvalidClassFormatSignal notifierString:'class load failure'. |
|
46 |
InvalidClassFormatSignal nameClass:self message:#invalidClassFormatSignal. |
|
47 |
||
48 |
Verbose := false. |
|
91 | 49 |
Silent := true. |
50 |
AbsolutelySilent := false. |
|
2089 | 51 |
|
52 |
LazyClassLoading := false. "/ true. |
|
53 |
ClassLoaderQuerySignal := QuerySignal new |
|
29 | 54 |
|
55 |
" |
|
2089 | 56 |
JavaClassReader initialize |
57 |
" |
|
58 |
||
59 |
"Modified: / 27.1.1998 / 17:54:23 / cg" |
|
198 | 60 |
! ! |
61 |
||
62 |
!JavaClassReader class methodsFor:'Signal constants'! |
|
63 |
||
223 | 64 |
classLoaderQuerySignal |
65 |
^ ClassLoaderQuerySignal |
|
66 |
||
67 |
"Created: 14.8.1997 / 19:56:03 / cg" |
|
68 |
! |
|
69 |
||
198 | 70 |
invalidClassFormatSignal |
71 |
^ InvalidClassFormatSignal |
|
72 |
||
73 |
"Created: 3.8.1997 / 18:17:21 / cg" |
|
1 | 74 |
! ! |
75 |
||
344 | 76 |
!JavaClassReader class methodsFor:'constants'! |
77 |
||
2089 | 78 |
fileMajorVersion |
79 |
^ 45 |
|
80 |
||
81 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
82 |
"Created: / 7.5.1998 / 13:16:35 / cg" |
|
344 | 83 |
! |
84 |
||
2089 | 85 |
fileMinorVersion |
86 |
^ 3 |
|
87 |
||
88 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
89 |
"Created: / 7.5.1998 / 13:16:40 / cg" |
|
344 | 90 |
! |
91 |
||
92 |
magic_LSB |
|
93 |
^ 16rBEBAFECA |
|
94 |
||
95 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
96 |
"Created: / 7.5.1998 / 13:15:05 / cg" |
|
97 |
! |
|
98 |
||
99 |
magic_MSB |
|
100 |
^ 16rCAFEBABE |
|
101 |
||
102 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
103 |
! ! |
|
104 |
||
135 | 105 |
!JavaClassReader class methodsFor:'debugging'! |
1 | 106 |
|
107 |
verbose:aBoolean |
|
108 |
Verbose := aBoolean |
|
109 |
||
110 |
" |
|
67 | 111 |
Java flushClasses. |
1 | 112 |
JavaClassReader verbose:true |
113 |
JavaClassReader verbose:false |
|
114 |
" |
|
115 |
! ! |
|
116 |
||
135 | 117 |
!JavaClassReader class methodsFor:'file reading'! |
1 | 118 |
|
21 | 119 |
loadClass:aClassName |
43 | 120 |
"reads a class, installs and returns it. |
121 |
The classes string constants are resolved & <clinit> is called, |
|
122 |
if it implements it." |
|
21 | 123 |
|
223 | 124 |
|rslt loader| |
21 | 125 |
|
548 | 126 |
loader := ClassLoaderQuerySignal query. |
223 | 127 |
loader isNil ifTrue:[ |
399 | 128 |
^ self loadSystemClass:aClassName |
223 | 129 |
]. |
130 |
||
131 |
^ loader loadClass:aClassName |
|
21 | 132 |
|
133 |
" |
|
134 |
JavaClassReader loadClass:'awt/Component' |
|
135 |
JavaClassReader loadClass:'awt/Button' |
|
136 |
JavaClassReader loadClass:'browser/AddButton' |
|
137 |
||
138 |
JavaClassReader loadClass:'java/lang/Object' |
|
139 |
JavaClassReader loadClass:'java/lang/AbstractMethodError' |
|
140 |
JavaClassReader loadClass:'java/lang/Thread' |
|
141 |
" |
|
142 |
||
252 | 143 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
399 | 144 |
"Modified: / 20.10.1998 / 17:24:54 / cg" |
21 | 145 |
! |
146 |
||
2089 | 147 |
loadClassLazy:aClassName ignoring:classesBeingLoaded |
38 | 148 |
"private helper: |
149 |
reads a class, installs and returns it. |
|
150 |
The class is searched along the ClassPath. |
|
43 | 151 |
|
152 |
This is a partial load (to load other classes): |
|
2089 | 153 |
- The classes stringConstants are not fixed to be JavaStrings |
43 | 154 |
(i.e they are still ST-Strings). |
252 | 155 |
- The class is NOT initialized." |
2089 | 156 |
|
157 |
|rslt clsName cls loadedClass| |
|
158 |
||
159 |
(aClassName endsWith:';') ifTrue:[ |
|
160 |
('oops - loading of ' , aClassName , ' attempted') printNL. |
|
161 |
self halt:'should not happen'. |
|
162 |
^ nil |
|
163 |
]. |
|
164 |
(aClassName endsWith:'[]') ifTrue:[ |
|
165 |
('oops - loading of ' , aClassName , ' attempted') printNL. |
|
166 |
self halt:'should not happen'. |
|
167 |
^ nil |
|
168 |
]. |
|
169 |
||
170 |
clsName := aClassName. |
|
171 |
(clsName includes:$.) ifTrue:[ |
|
172 |
clsName := clsName asString copyReplaceAll:$. with:$/ |
|
173 |
]. |
|
174 |
||
175 |
(classesBeingLoaded notNil and:[classesBeingLoaded includes:clsName]) ifTrue:[ |
|
176 |
('oops - recursive load of ' , clsName , ' attempted') printNL. |
|
177 |
self halt:'should not happen'. |
|
178 |
^ JavaUnresolvedClassConstant fullName:clsName |
|
179 |
]. |
|
180 |
||
181 |
(cls := Java at:clsName) notNil ifTrue:[ |
|
182 |
('oops - ' , clsName , ' is already loaded') printNL. |
|
183 |
self halt:clsName , ' is already loaded - should not happen'. |
|
184 |
^ cls |
|
185 |
]. |
|
186 |
||
187 |
classesBeingLoaded isNil ifTrue:[ |
|
188 |
loadedClass := Set with:clsName |
|
189 |
] ifFalse:[ |
|
190 |
loadedClass := Set withAll:classesBeingLoaded. |
|
191 |
loadedClass add:clsName. |
|
91 | 192 |
]. |
2089 | 193 |
|
194 |
Java classPath do:[:path | |
|
195 |
|nm p zar entry zipFile| |
|
196 |
||
197 |
Verbose == true ifTrue:[ |
|
198 |
Transcript showCR:'trying ' , path asFilename pathName, ' ...'. |
|
199 |
]. |
|
200 |
||
201 |
p := path. |
|
202 |
p asFilename isDirectory ifTrue:[ |
|
203 |
(p endsWith:Filename separator) ifFalse:[ |
|
204 |
p := p , (Filename separator asString) |
|
205 |
]. |
|
206 |
(Array |
|
207 |
with:clsName |
|
208 |
with:clsName asLowercase |
|
209 |
with:clsName asUppercase) |
|
210 |
do:[:tryName | |
|
211 |
nm := p , tryName , '.class'. |
|
212 |
Verbose == true ifTrue:[ |
|
213 |
Transcript showCR:'trying ' , nm, ' ...'. |
|
214 |
]. |
|
215 |
nm asFilename exists ifTrue:[ |
|
216 |
(Java isExcludedFromClassPath:nm) ifFalse:[ |
|
217 |
rslt := self loadFileLazy:nm ignoring:loadedClass. |
|
218 |
rslt notNil ifTrue:[^ rslt]. |
|
219 |
] |
|
220 |
]. |
|
221 |
] |
|
222 |
] ifFalse:[ |
|
223 |
Verbose == true ifTrue:[ |
|
224 |
Transcript showCR:'trying ' , (p asFilename withSuffix:'jar') pathName, ' ...'. |
|
225 |
Transcript showCR:'and ' , (p asFilename withSuffix:'zip') pathName, ' ...'. |
|
226 |
]. |
|
227 |
((zipFile := p asFilename withSuffix:'jar') exists |
|
228 |
or:[(zipFile := p asFilename withSuffix:'zip') exists]) ifTrue:[ |
|
229 |
zar := ZipArchive oldFileNamed:zipFile. |
|
230 |
(Array |
|
231 |
with:clsName |
|
232 |
with:clsName asLowercase |
|
233 |
with:clsName asUppercase) |
|
234 |
do:[:tryName | |
|
235 |
nm := tryName , '.class'. |
|
236 |
entry := zar extract:nm. |
|
237 |
entry notNil ifTrue:[ |
|
238 |
(Java isExcludedFromClassPath:nm) ifFalse:[ |
|
239 |
rslt := self loadStreamLazy:(entry readStream) ignoring:loadedClass. |
|
240 |
rslt notNil ifTrue:[^ rslt]. |
|
241 |
] |
|
242 |
] |
|
243 |
] |
|
244 |
] |
|
245 |
] |
|
246 |
]. |
|
247 |
||
248 |
('JAVA [info]: no file found for: ' , clsName) infoPrintCR. |
|
249 |
^ nil |
|
250 |
||
251 |
"Modified: / 14.8.1997 / 11:38:42 / stefan" |
|
252 |
"Modified: / 17.9.1998 / 20:51:25 / cg" |
|
38 | 253 |
! |
254 |
||
7 | 255 |
loadFile:aFilename |
43 | 256 |
"reads a class from aFilename, installs and returns it. |
257 |
The classes strings are fixed and its class-init function is called." |
|
258 |
||
54 | 259 |
self loadFileLazy:aFilename ignoring:(Set new). |
43 | 260 |
self postLoadActions |
261 |
! |
|
262 |
||
54 | 263 |
loadFileLazy:aFilename ignoring:classesBeingLoaded |
43 | 264 |
"reads a class from aFilename, installs and returns it. |
91 | 265 |
Strings are fixed and classrefs are fixed, |
266 |
but NO no class-init functions are called." |
|
7 | 267 |
|
353 | 268 |
|aClass pool| |
7 | 269 |
|
353 | 270 |
aClass := self readFile:aFilename ignoring:classesBeingLoaded. |
271 |
aClass notNil ifTrue:[ |
|
272 |
aClass isJavaClass ifTrue:[ |
|
350 | 273 |
"/ a java class |
353 | 274 |
Java at:(aClass fullName asSymbol) put:aClass. |
350 | 275 |
|
353 | 276 |
classesBeingLoaded remove:aClass fullName ifAbsent:nil. |
21 | 277 |
|
353 | 278 |
JavaUnresolvedConstant resolveFor:aClass. |
350 | 279 |
] ifFalse:[ |
280 |
"/ a smalltalk class |
|
353 | 281 |
"/ self halt. |
282 |
aClass inspect. |
|
350 | 283 |
] |
7 | 284 |
]. |
353 | 285 |
^ aClass |
7 | 286 |
|
287 |
" |
|
288 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
9 | 289 |
|
290 |
'/phys/ibm3/java/lib/java/lang' asFilename |
|
350 | 291 |
directoryContents do:[:nm | |
292 |
(nm endsWith:'.class') ifTrue:[ |
|
293 |
('/phys/ibm3/java/lib/java/lang/' , nm) printNL. |
|
294 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/' , nm |
|
295 |
] |
|
296 |
]. |
|
9 | 297 |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
298 |
'/phys/ibm3/java/lib/java/io' asFilename |
350 | 299 |
directoryContents do:[:nm | |
300 |
(nm endsWith:'.class') ifTrue:[ |
|
301 |
('/phys/ibm3/java/lib/java/io/' , nm) printNL. |
|
302 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/io/' , nm |
|
303 |
] |
|
304 |
]. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
305 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
306 |
'/phys/ibm3/java/lib/java/net' asFilename |
350 | 307 |
directoryContents do:[:nm | |
308 |
(nm endsWith:'.class') ifTrue:[ |
|
309 |
('/phys/ibm3/java/lib/java/net/' , nm) printNL. |
|
310 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/net/' , nm |
|
311 |
] |
|
312 |
]. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
313 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
314 |
'/phys/ibm3/java/lib/java/util' asFilename |
350 | 315 |
directoryContents do:[:nm | |
316 |
(nm endsWith:'.class') ifTrue:[ |
|
317 |
('/phys/ibm3/java/lib/java/util/' , nm) printNL. |
|
318 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/util/' , nm |
|
319 |
] |
|
320 |
]. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
321 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
322 |
'/phys/ibm3/java/lib/java/awt' asFilename |
350 | 323 |
directoryContents do:[:nm | |
324 |
(nm endsWith:'.class') ifTrue:[ |
|
325 |
('/phys/ibm3/java/lib/java/awt/' , nm) printNL. |
|
326 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/awt/' , nm |
|
327 |
] |
|
328 |
]. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
329 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
330 |
'/phys/ibm3/java/lib/java/applet' asFilename |
350 | 331 |
directoryContents do:[:nm | |
332 |
(nm endsWith:'.class') ifTrue:[ |
|
333 |
('/phys/ibm3/java/lib/java/applet/' , nm) printNL. |
|
334 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/applet/' , nm |
|
335 |
] |
|
336 |
]. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
337 |
|
9 | 338 |
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
|
339 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/Thread.class' |
7 | 340 |
" |
341 |
||
350 | 342 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
353 | 343 |
"Modified: / 12.5.1998 / 22:06:52 / cg" |
7 | 344 |
! |
345 |
||
327 | 346 |
loadStreamLazy:aStream ignoring:classesBeingLoaded |
347 |
"reads a class from aStream, installs and returns it. |
|
348 |
Strings are fixed and classrefs are fixed, |
|
349 |
but NO no class-init functions are called." |
|
350 |
||
351 |
|javaClass pool| |
|
352 |
||
353 |
javaClass := self readStream:aStream ignoring:classesBeingLoaded. |
|
354 |
javaClass notNil ifTrue:[ |
|
355 |
Java at:(javaClass fullName asSymbol) put:javaClass. |
|
356 |
||
357 |
classesBeingLoaded remove:javaClass fullName ifAbsent:nil. |
|
358 |
||
359 |
JavaUnresolvedConstant resolveFor:javaClass. |
|
360 |
]. |
|
361 |
^ javaClass |
|
362 |
||
363 |
"Created: / 30.3.1998 / 17:59:02 / cg" |
|
364 |
! |
|
365 |
||
2089 | 366 |
loadSystemClass:aClassName |
399 | 367 |
"reads a class, installs and returns it. |
368 |
The classes string constants are resolved & <clinit> is called, |
|
369 |
if it implements it. |
|
370 |
This only loads local classes (i.e. any Java classReader is not used)" |
|
2089 | 371 |
|
372 |
|rslt| |
|
373 |
||
374 |
rslt := self loadClassLazy:aClassName ignoring:(Set new). |
|
375 |
rslt notNil ifTrue:[self postLoadActions]. |
|
376 |
||
377 |
^ rslt |
|
399 | 378 |
|
379 |
" |
|
380 |
JavaClassReader loadSystemClass:'awt/Component' |
|
381 |
JavaClassReader loadSystemClass:'awt/Button' |
|
382 |
JavaClassReader loadSystemClass:'browser/AddButton' |
|
383 |
||
384 |
JavaClassReader loadSystemClass:'java/lang/Object' |
|
385 |
JavaClassReader loadSystemClass:'java/lang/AbstractMethodError' |
|
2089 | 386 |
JavaClassReader loadSystemClass:'java/lang/Thread' |
399 | 387 |
" |
2089 | 388 |
|
389 |
"Modified: / 3.1.1998 / 22:36:13 / cg" |
|
390 |
"Created: / 20.10.1998 / 17:24:40 / cg" |
|
399 | 391 |
! |
392 |
||
43 | 393 |
postLoadActions |
394 |
"Resolve all classes' string constants. |
|
395 |
Perform all class initialization functions (of those which are not |
|
396 |
yet initialized)." |
|
397 |
||
225 | 398 |
^ self postLoadActions:true |
399 |
||
400 |
"Modified: 15.8.1997 / 01:02:17 / cg" |
|
401 |
! |
|
402 |
||
403 |
postLoadActions:loadUnresolved |
|
404 |
"Resolve all classes' string constants. |
|
252 | 405 |
Perform all class initialization functions |
406 |
(of those which are not yet initialized)." |
|
225 | 407 |
|
223 | 408 |
|classes prevUnresolved newUnresolved loader| |
43 | 409 |
|
91 | 410 |
"/ need at least java.lang.String, for valid constants |
167 | 411 |
Java java_lang_String isNil ifTrue:[ |
255 | 412 |
self loadClassLazy:'java.lang.String' ignoring:(Set new). |
54 | 413 |
]. |
414 |
||
91 | 415 |
LazyClassLoading ifFalse:[ |
547 | 416 |
loader := ClassLoaderQuerySignal query. |
255 | 417 |
|
418 |
prevUnresolved := nil. |
|
419 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
420 |
loadUnresolved ifTrue:[ |
|
421 |
[prevUnresolved ~= newUnresolved] whileTrue:[ |
|
422 |
newUnresolved do:[:nextUnresolved | |
|
423 |
|classURL| |
|
223 | 424 |
|
255 | 425 |
(Java at:nextUnresolved) isNil ifTrue:[ "/ could have been loaded in the meantime |
426 |
Silent ifFalse:[ |
|
427 |
'loading unresolved: ' print. nextUnresolved printCR. |
|
428 |
]. |
|
429 |
loader isNil ifTrue:[ |
|
430 |
self |
|
431 |
loadClassLazy:nextUnresolved |
|
432 |
ignoring:(Set new). |
|
433 |
] ifFalse:[ |
|
434 |
"/ |
|
435 |
"/ the aquired loader is a javaClassLoader |
|
436 |
"/ which expects an URL as arg. |
|
437 |
"/ |
|
438 |
"/ classURL := Java as_URL:('file:' , nextUnresolved asString , '.class'). |
|
439 |
"/ loader loadClass:classURL |
|
440 |
loader |
|
441 |
perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
442 |
with:(Java as_String:(nextUnresolved asString)). |
|
443 |
] |
|
444 |
] |
|
445 |
]. |
|
446 |
prevUnresolved := newUnresolved. |
|
447 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
448 |
]. |
|
449 |
]. |
|
407 | 450 |
false ifTrue:[ |
255 | 451 |
newUnresolved size == 0 ifTrue:[ |
452 |
"/ nothing unresolved |
|
91 | 453 |
|
255 | 454 |
(classes := Java allClasses) notNil ifTrue:[ |
455 |
"/ init all new classes |
|
456 |
"/ fetch again - there could be new ones ... |
|
91 | 457 |
|
255 | 458 |
classes := Java allClasses. |
459 |
classes do:[:aJavaClass | |
|
460 |
aJavaClass isInitialized ifFalse:[ |
|
461 |
Silent ifFalse:[ |
|
462 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
463 |
]. |
|
464 |
aJavaClass classInit |
|
465 |
] |
|
466 |
] |
|
467 |
] |
|
468 |
]. |
|
407 | 469 |
]. |
43 | 470 |
] |
167 | 471 |
|
252 | 472 |
"Created: / 15.8.1997 / 01:01:44 / cg" |
407 | 473 |
"Modified: / 21.10.1998 / 01:18:35 / cg" |
43 | 474 |
! |
475 |
||
54 | 476 |
readFile:aFilename ignoring:classesBeingLoaded |
7 | 477 |
"reads a class from aFilename and returns it. |
91 | 478 |
The JavaClass is NOT installed as global and unresolved |
479 |
refs are NOT patched." |
|
7 | 480 |
|
73 | 481 |
|inStream javaClass| |
1 | 482 |
|
2089 | 483 |
Silent ifFalse:[ |
2115 | 484 |
'reading ' print. aFilename print. ' ...' printCR. |
43 | 485 |
]. |
21 | 486 |
|
2115 | 487 |
[ |
488 |
inStream := aFilename asFilename readStream. |
|
489 |
] on:StreamError do:[:ex| |
|
490 |
('JAVA [info]: no file: ' , aFilename asString) printCR. |
|
318 | 491 |
self halt. |
492 |
^ nil |
|
91 | 493 |
]. |
494 |
||
495 |
javaClass := self new readStream:inStream ignoring:classesBeingLoaded. |
|
350 | 496 |
(javaClass notNil and:[javaClass isJavaClass]) ifTrue:[ |
318 | 497 |
javaClass setBinaryFilePath:(inStream pathName). |
73 | 498 |
]. |
1 | 499 |
inStream close. |
27 | 500 |
|
91 | 501 |
AbsolutelySilent ifFalse:[ |
318 | 502 |
' ... loaded ' print. javaClass displayString printNL. |
43 | 503 |
]. |
27 | 504 |
|
73 | 505 |
^ javaClass |
1 | 506 |
|
2089 | 507 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
508 |
"Modified: / 9.5.1998 / 01:44:24 / cg" |
|
1 | 509 |
! |
510 |
||
198 | 511 |
readStream:aStream |
512 |
"reads a class from aStream and returns it. |
|
223 | 513 |
The JavaClass is installed as global. |
514 |
If new classes are required to be loaded, a new standard loader |
|
515 |
is created." |
|
198 | 516 |
|
223 | 517 |
^ self readStream:aStream loader:nil |
198 | 518 |
|
223 | 519 |
"Modified: 14.8.1997 / 19:51:50 / cg" |
198 | 520 |
! |
521 |
||
2089 | 522 |
readStream:aStream ignoring:classesBeingLoaded |
7 | 523 |
"reads a class from aStream and returns it. |
524 |
The JavaClass is not installed as global" |
|
2089 | 525 |
|
526 |
|javaClass| |
|
527 |
||
528 |
javaClass := self new readStream:aStream ignoring:classesBeingLoaded. |
|
529 |
||
530 |
AbsolutelySilent ifFalse:[ |
|
531 |
' ... loaded ' print. javaClass displayString printNL. |
|
532 |
]. |
|
533 |
||
327 | 534 |
^ javaClass |
535 |
||
2089 | 536 |
"Modified: / 30.3.1998 / 18:14:40 / cg" |
223 | 537 |
! |
538 |
||
539 |
readStream:aStream loader:aClassLoader |
|
540 |
"reads a class from aStream and returns it. |
|
541 |
The JavaClass is installed as global. |
|
542 |
If new classes are required to be loaded, aClassLoader is |
|
543 |
asked to do it. If aClassLoader is nil, a new standard loader |
|
544 |
is created." |
|
545 |
||
225 | 546 |
^ self |
252 | 547 |
readStream:aStream |
548 |
loader:aClassLoader |
|
549 |
loadUnresolved:true |
|
225 | 550 |
|
551 |
"Modified: 15.8.1997 / 01:00:35 / cg" |
|
552 |
! |
|
553 |
||
2089 | 554 |
readStream:aStream loader:aClassLoader loadUnresolved:loadUnresolved |
225 | 555 |
"reads a class from aStream and returns it. |
556 |
The JavaClass is installed as global. |
|
557 |
If new classes are required to be loaded, aClassLoader is |
|
558 |
asked to do it. If aClassLoader is nil, a new standard loader |
|
559 |
is created." |
|
2089 | 560 |
|
561 |
|javaClass| |
|
562 |
||
563 |
ClassLoaderQuerySignal answer:aClassLoader |
|
564 |
do:[ |
|
565 |
javaClass := self readStream:aStream ignoring:(Set new). |
|
566 |
javaClass notNil ifTrue:[ |
|
567 |
self postLoadActions:loadUnresolved. |
|
568 |
Java at:(javaClass fullName asSymbol) put:javaClass. |
|
569 |
JavaUnresolvedConstant resolveFor:javaClass. |
|
570 |
]. |
|
571 |
]. |
|
223 | 572 |
^ javaClass |
573 |
||
2089 | 574 |
"Created: / 15.8.1997 / 00:59:24 / cg" |
575 |
"Modified: / 23.1.1998 / 17:14:09 / cg" |
|
399 | 576 |
! |
577 |
||
578 |
resolveClass:aJavaClass |
|
579 |
"Resolve a particular classes' constants. |
|
580 |
Perform all class initialization functions |
|
581 |
(of those which are not yet initialized)." |
|
582 |
||
583 |
|loader classToLoad| |
|
584 |
||
585 |
LazyClassLoading ifFalse:[ |
|
586 |
loader := (aJavaClass classLoader). "/ ? (ClassLoaderQuerySignal raise). |
|
587 |
||
588 |
[ |
|
589 |
classToLoad := nil. |
|
590 |
aJavaClass constantPool do:[:item | |
|
591 |
|itemClass | |
|
592 |
||
593 |
itemClass := item class. |
|
594 |
itemClass == JavaUnresolvedClassConstant ifTrue:[ |
|
595 |
classToLoad := item className. |
|
596 |
"/ ] ifFalse:[ |
|
597 |
"/ itemClass == JavaUnresolvedMethodrefConstant ifTrue:[ |
|
598 |
"/self halt. |
|
599 |
"/ ] ifFalse:[ |
|
600 |
"/ itemClass == JavaUnresolvedInterfaceMethodrefConstant ifTrue:[ |
|
601 |
"/self halt. |
|
602 |
"/ ] |
|
603 |
"/ ] |
|
604 |
]. |
|
605 |
]. |
|
606 |
||
607 |
classToLoad notNil ifTrue:[ |
|
608 |
loader isNil ifTrue:[ |
|
609 |
self |
|
610 |
loadClassLazy:classToLoad |
|
611 |
ignoring:(Set new). |
|
612 |
] ifFalse:[ |
|
613 |
"/ |
|
614 |
"/ the aquired loader is a javaClassLoader |
|
615 |
"/ which expects an URL as arg. |
|
616 |
"/ |
|
617 |
"/ classURL := Java as_URL:('file:' , nextUnresolved asString , '.class'). |
|
618 |
"/ loader loadClass:classURL |
|
619 |
loader |
|
620 |
perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
621 |
with:(Java as_String:(classToLoad asString)). |
|
622 |
] |
|
623 |
]. |
|
624 |
classToLoad notNil. |
|
625 |
] whileTrue. |
|
626 |
||
627 |
aJavaClass isInitialized ifFalse:[ |
|
628 |
Silent ifFalse:[ |
|
629 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
630 |
]. |
|
631 |
aJavaClass classInit |
|
632 |
]. |
|
633 |
] |
|
634 |
||
635 |
"Created: / 20.10.1998 / 17:53:22 / cg" |
|
636 |
"Modified: / 20.10.1998 / 17:59:09 / cg" |
|
1 | 637 |
! ! |
638 |
||
639 |
!JavaClassReader methodsFor:'file reading'! |
|
640 |
||
2089 | 641 |
readClassFileIgnoring:classesbeingLoaded |
7 | 642 |
"reads a class from inStream and returns it. |
38 | 643 |
The JavaClass is not installed as global and its constants |
644 |
(especially strings) may not be fully resolved." |
|
2089 | 645 |
|
646 |
|magic |
|
647 |
access_flags this_class this_class_index super_class super_class_index |
|
648 |
realSuperClass this_class_ref existingSuperClass |
|
649 |
fields interfaces staticFields nStatic |
|
650 |
jSuperClass loader superClassName thisClassName existing_class |
|
651 |
thisMetaClass| |
|
1 | 652 |
|
653 |
"/ |
|
654 |
"/ read magic, determine byte order |
|
655 |
"/ |
|
656 |
msb := true. |
|
2089 | 657 |
magic := inStream nextUnsignedLongMSB:true. |
658 |
magic = (self class magic_MSB) ifFalse:[ |
|
659 |
magic = (self class magic_LSB) ifFalse:[ |
|
660 |
InvalidClassFormatSignal raiseErrorString:'not a java class file'. |
|
661 |
^ nil |
|
662 |
]. |
|
663 |
msb := false. |
|
664 |
Verbose ifTrue:[Transcript showCR:'file is lsb']. |
|
665 |
] ifTrue:[ |
|
666 |
Verbose ifTrue:[Transcript showCR:'file is msb']. |
|
667 |
]. |
|
668 |
||
1 | 669 |
"/ |
670 |
"/ get version |
|
671 |
"/ |
|
2089 | 672 |
minorVsn := inStream nextUnsignedShortMSB:msb. |
673 |
majorVsn := inStream nextUnsignedShortMSB:msb. |
|
674 |
||
675 |
(majorVsn ~~ (self class fileMajorVersion) |
|
676 |
or:[minorVsn ~~ (self class fileMinorVersion)]) ifTrue:[ |
|
677 |
Transcript show:'warning this file has version '; show:majorVsn; show:'.'; showCR:minorVsn. |
|
678 |
]. |
|
679 |
||
680 |
Verbose ifTrue:[ |
|
681 |
Transcript show:'version = '; |
|
682 |
show:(majorVsn printString); |
|
683 |
show:'.'; |
|
684 |
showCR:(minorVsn printString). |
|
685 |
]. |
|
686 |
||
1 | 687 |
"/ |
688 |
"/ get constant pool |
|
689 |
"/ |
|
690 |
self readConstantPool. |
|
2089 | 691 |
|
1 | 692 |
"/ |
693 |
"/ access flags |
|
694 |
"/ |
|
2089 | 695 |
access_flags := inStream nextUnsignedShortMSB:msb. |
696 |
this_class_index := inStream nextUnsignedShortMSB:msb. |
|
697 |
super_class_index := inStream nextUnsignedShortMSB:msb. |
|
698 |
||
699 |
super_class_index == 0 ifTrue:[ |
|
700 |
super_class := nil |
|
701 |
] ifFalse:[ |
|
702 |
super_class := constants at:super_class_index. |
|
703 |
superClassName := super_class fullName. |
|
704 |
||
705 |
"/ special for ST-classes |
|
706 |
(superClassName startsWith:'smalltalk.') ifTrue:[ |
|
707 |
"/ a Smalltalk class |
|
708 |
superClassName := superClassName copyFrom:11. |
|
709 |
existingSuperClass := Smalltalk at:superClassName asSymbol. |
|
710 |
existingSuperClass notNil ifTrue:[ |
|
711 |
super_class := existingSuperClass |
|
712 |
] ifFalse:[ |
|
713 |
"/ self halt - must load superclass ... |
|
714 |
] |
|
715 |
] ifFalse:[ |
|
716 |
"/ a JAVA class |
|
717 |
existingSuperClass := Java classNamed:superClassName. |
|
718 |
existingSuperClass notNil ifTrue:[ |
|
719 |
super_class := existingSuperClass |
|
720 |
] ifFalse:[ |
|
721 |
(super_class isMemberOf:JavaUnresolvedClassConstant) ifTrue:[ |
|
722 |
Silent ifFalse:[ |
|
723 |
'load superClass: ' print. superClassName printCR. |
|
724 |
]. |
|
725 |
loader := ClassLoaderQuerySignal query. |
|
726 |
loader isNil ifTrue:[ |
|
727 |
existingSuperClass := self class |
|
728 |
loadClassLazy:superClassName |
|
729 |
ignoring:classesbeingLoaded. |
|
730 |
] ifFalse:[ |
|
731 |
jSuperClass := loader |
|
732 |
perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
733 |
with:(Java as_String:superClassName). |
|
734 |
existingSuperClass := JavaVM classForJavaClassObject:jSuperClass. |
|
735 |
]. |
|
736 |
existingSuperClass isNil ifTrue:[ |
|
737 |
('JAVA: cannot find superclass: ' , superClassName) infoPrintCR. |
|
738 |
"/ self halt:('cannot find superclass: ' , superClassName). |
|
739 |
^ nil. |
|
740 |
]. |
|
741 |
super_class := existingSuperClass |
|
742 |
] ifFalse:[ |
|
743 |
self halt:'oops - superclass ?' |
|
744 |
] |
|
745 |
]. |
|
746 |
]. |
|
747 |
]. |
|
748 |
||
1 | 749 |
"/ |
750 |
"/ get interfaces |
|
751 |
"/ |
|
38 | 752 |
interfaces := self readInterfaces. |
2089 | 753 |
|
1 | 754 |
"/ |
755 |
"/ get fields |
|
756 |
"/ |
|
38 | 757 |
fields := self readFieldInfofields. |
2089 | 758 |
|
40 | 759 |
"/ |
760 |
"/ create the fields as instVars |
|
761 |
"/ static fields are created as class-InstVars |
|
762 |
"/ |
|
2089 | 763 |
staticFields := fields select:[:f | f isStatic]. |
40 | 764 |
nStatic := staticFields size. |
2089 | 765 |
|
766 |
this_class_ref := constants at:this_class_index. |
|
350 | 767 |
thisClassName := this_class_ref fullName. |
2089 | 768 |
|
350 | 769 |
"/ care for smalltalk classes ... |
2089 | 770 |
(thisClassName startsWith:'smalltalk.') ifTrue:[ |
771 |
thisClassName := thisClassName copyFrom:11. |
|
772 |
||
773 |
existing_class := Smalltalk at:thisClassName asSymbol. |
|
774 |
existing_class notNil ifTrue:[ |
|
775 |
self halt:('overloading existing class: ', thisClassName). |
|
776 |
thisClassName := (thisClassName , '_new') asSymbol. |
|
777 |
]. |
|
778 |
thisMetaClass := Metaclass new. |
|
779 |
thisMetaClass setSuperclass:super_class class. |
|
780 |
thisMetaClass instSize:(super_class class instSize + nStatic). |
|
781 |
||
782 |
this_class := thisMetaClass new. |
|
783 |
this_class setSuperclass:super_class. |
|
784 |
this_class setName:thisClassName asSymbol. |
|
785 |
] ifFalse:[ |
|
786 |
"/ a java class |
|
787 |
||
788 |
this_class := JavaClass fullName:thisClassName numStatic:nStatic. |
|
789 |
||
790 |
nStatic ~~ 0 ifTrue:[ |
|
791 |
fields := fields select:[:f | f isStatic not]. |
|
792 |
||
793 |
JavaClass setInstanceVariableStringFromFields:staticFields in:this_class class. |
|
794 |
this_class setStaticFields:staticFields. |
|
795 |
this_class initializeStaticFields. |
|
796 |
]. |
|
797 |
||
798 |
this_class setAccessFlags:access_flags. |
|
799 |
this_class setSuperclass:super_class. |
|
800 |
this_class setConstantPool:constants. |
|
801 |
||
802 |
this_class setFields:fields. |
|
803 |
this_class setInterfaces:interfaces. |
|
804 |
||
805 |
constants owner:this_class. |
|
806 |
]. |
|
807 |
||
1 | 808 |
"/ |
809 |
"/ get methods |
|
810 |
"/ |
|
2089 | 811 |
self readMethodsFor:this_class. |
812 |
||
813 |
self readAttributesFor:this_class. |
|
814 |
||
815 |
^ this_class |
|
5 | 816 |
|
1 | 817 |
" |
355 | 818 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
819 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
820 |
JavaClassReader loadFile:'foo.cls' |
|
9 | 821 |
|
822 |
JavaClassReader verbose:true. |
|
355 | 823 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/java/lang/ArithmeticException.class' |
2089 | 824 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/ArithmeticException.class' |
825 |
" |
|
826 |
||
827 |
"Created: / 15.4.1996 / 15:02:47 / cg" |
|
828 |
"Modified: / 12.11.1998 / 21:14:45 / cg" |
|
5 | 829 |
! |
830 |
||
54 | 831 |
readStream:aStream ignoring:classesBeingLoaded |
7 | 832 |
"reads a class from aStream and returns it. |
833 |
The JavaClass is not installed as global" |
|
834 |
||
5 | 835 |
inStream := aStream. |
836 |
inStream binary. |
|
38 | 837 |
|
54 | 838 |
^ self readClassFileIgnoring:classesBeingLoaded |
5 | 839 |
|
840 |
" |
|
841 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
842 |
" |
|
843 |
||
844 |
"Created: 15.4.1996 / 15:00:55 / cg" |
|
845 |
"Modified: 15.4.1996 / 15:06:18 / cg" |
|
846 |
! ! |
|
847 |
||
848 |
!JavaClassReader methodsFor:'file reading - attributes'! |
|
849 |
||
2148 | 850 |
readAnnotationDefaultAttributeFor:something |
851 |
"/ ('JAVA [info]: unhandled attribute: AnnotationDefault') infoPrintCR. |
|
852 |
self skipAttribute:'AnnotationDefault'. |
|
853 |
! |
|
854 |
||
2089 | 855 |
readAttribute:attributeName for:something |
2148 | 856 |
"/ implemented JAVA attributes |
857 |
(attributeName = 'ConstantValue') ifTrue:[ |
|
858 |
self readConstantValueAttributeFor:something. |
|
859 |
^ self. |
|
860 |
]. |
|
861 |
(attributeName = 'Code') ifTrue:[ |
|
862 |
self readCodeAttributeFor:something. |
|
863 |
^ self. |
|
864 |
]. |
|
865 |
(attributeName = 'Exceptions') ifTrue:[ |
|
866 |
self readExceptionsAttributeFor:something. |
|
867 |
^ self. |
|
868 |
]. |
|
869 |
(attributeName = 'InnerClasses') ifTrue:[ |
|
870 |
self readInnerClassesAttributeFor:something. |
|
871 |
^ self. |
|
872 |
]. |
|
873 |
(attributeName = 'EnclosingMethod') ifTrue:[ |
|
874 |
self readEnclosingMethodAttributeFor:something. |
|
875 |
^ self. |
|
876 |
]. |
|
877 |
(attributeName = 'LineNumberTable') ifTrue:[ |
|
878 |
self readLineNumberTableAttributeFor:something. |
|
879 |
^ self. |
|
880 |
]. |
|
881 |
(attributeName = 'LocalVariableTable') ifTrue:[ |
|
882 |
self readLocalVariableTableAttributeFor:something. |
|
883 |
^ self. |
|
884 |
]. |
|
885 |
(attributeName = 'LocalVariableTypeTable') ifTrue:[ |
|
886 |
self readLocalVariableTypeTableAttributeFor:something. |
|
887 |
^ self. |
|
888 |
]. |
|
889 |
(attributeName = 'SourceFile') ifTrue:[ |
|
890 |
self readSourceFileAttributeFor:something. |
|
891 |
^ self. |
|
892 |
]. |
|
893 |
(attributeName = 'SourceDebugExtension') ifTrue:[ |
|
894 |
self readSourceDebugExtensionAttributeFor:something. |
|
895 |
^ self. |
|
896 |
]. |
|
897 |
(attributeName = 'Synthetic') ifTrue:[ |
|
898 |
self readSyntheticAttributeFor:something. |
|
899 |
^ self. |
|
900 |
]. |
|
901 |
(attributeName = 'Signature') ifTrue:[ |
|
902 |
self readSignatureAttributeFor:something. |
|
903 |
^ self. |
|
904 |
]. |
|
905 |
(attributeName = 'Deprecated') ifTrue:[ |
|
906 |
self readDeprecatedAttributeFor:something. |
|
907 |
^ self. |
|
908 |
]. |
|
909 |
(attributeName = 'RuntimeVisibleAnnotations') ifTrue:[ |
|
910 |
self readRuntimeVisibleAnnotationsAttributeFor:something. |
|
911 |
^ self. |
|
912 |
]. |
|
913 |
(attributeName = 'RuntimeInvisibleAnnotations') ifTrue:[ |
|
914 |
self readRuntimeInvisibleAnnotationsAttributeFor:something. |
|
915 |
^ self. |
|
916 |
]. |
|
917 |
(attributeName = 'RuntimeVisibleParameterAnnotations') ifTrue:[ |
|
918 |
self readRuntimeVisibleParameterAnnotationsAttributeFor:something. |
|
919 |
^ self. |
|
920 |
]. |
|
921 |
(attributeName = 'RuntimeInvisibleParameterAnnotations') ifTrue:[ |
|
922 |
self readRuntimeInvisibleParameterAnnotationsAttributeFor:something. |
|
923 |
^ self. |
|
924 |
]. |
|
925 |
(attributeName = 'AnnotationDefault') ifTrue:[ |
|
926 |
self readAnnotationDefaultAttributeFor:something. |
|
927 |
^ self. |
|
928 |
]. |
|
929 |
||
930 |
"/ ignored JAVA attributes |
|
931 |
(attributeName = 'FastJavac1.0') ifTrue:[ |
|
932 |
"/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
933 |
self skipAttribute:attributeName. |
|
934 |
^ self. |
|
935 |
]. |
|
936 |
(attributeName = 'AbsoluteSourcePath') ifTrue:[ |
|
937 |
('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
938 |
self skipAttribute:attributeName. |
|
939 |
^ self. |
|
940 |
]. |
|
941 |
||
942 |
(attributeName startsWith:((Character value:13) asString , 'WARNING:')) ifTrue:[ |
|
943 |
"/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
944 |
self skipAttribute:attributeName. |
|
945 |
^ self. |
|
946 |
]. |
|
947 |
||
948 |
||
2089 | 949 |
"/ implemented ST attributes |
950 |
(attributeName = 'STLiterals') ifTrue:[ |
|
951 |
self readSTLiteralsAttributeFor:something. |
|
952 |
^ self. |
|
953 |
]. |
|
954 |
(attributeName = 'ClassRevision') ifTrue:[ |
|
955 |
self readSTClassRevisionAttributeFor:something. |
|
956 |
^ self. |
|
957 |
]. |
|
958 |
(attributeName = 'ClassPackage') ifTrue:[ |
|
959 |
self readSTClassPackageAttributeFor:something. |
|
960 |
^ self. |
|
961 |
]. |
|
962 |
(attributeName = 'ClassCategory') ifTrue:[ |
|
963 |
self readSTClassCategoryAttributeFor:something. |
|
964 |
^ self. |
|
965 |
]. |
|
966 |
(attributeName = 'ClassVarNames') ifTrue:[ |
|
967 |
self readSTClassVarNamesAttributeFor:something. |
|
968 |
^ self. |
|
969 |
]. |
|
970 |
(attributeName = 'ClassInstVarNames') ifTrue:[ |
|
971 |
self readSTClassInstVarNamesAttributeFor:something. |
|
972 |
^ self. |
|
973 |
]. |
|
974 |
(attributeName = 'InstVarNames') ifTrue:[ |
|
975 |
self readSTInstVarNamesAttributeFor:something. |
|
976 |
^ self. |
|
977 |
]. |
|
978 |
(attributeName = 'STCode') ifTrue:[ |
|
979 |
self readSTCodeAttributeFor:something. |
|
980 |
^ self. |
|
981 |
]. |
|
982 |
(attributeName = 'MethodCategory') ifTrue:[ |
|
983 |
self readSTMethodCategoryAttributeFor:something. |
|
984 |
^ self. |
|
985 |
]. |
|
986 |
||
355 | 987 |
"/ unknown attributes |
335 | 988 |
('JAVA [warning]: unrecognized attribute: ' , attributeName) infoPrintCR. |
333 | 989 |
self skipAttribute:attributeName. |
5 | 990 |
|
2089 | 991 |
"Modified: / 3.12.1998 / 13:13:42 / cg" |
5 | 992 |
! |
993 |
||
994 |
readAttributeFor:something |
|
995 |
|attribute_name_index attribute_name attribute_length attribute_info| |
|
996 |
||
61 | 997 |
Verbose ifTrue:[Transcript show:'attrib at pos: '; showCR:inStream position]. |
9 | 998 |
|
128 | 999 |
attribute_name_index := inStream nextUnsignedShortMSB:msb. |
2142 | 1000 |
attribute_name_index == 0 ifTrue:[ |
1001 |
self halt. |
|
1002 |
"/ self skipAttribute:'unnamed'. |
|
1003 |
^ self. |
|
1004 |
]. |
|
9 | 1005 |
|
1006 |
"/ |
|
1007 |
"/ UNDOC feature ? |
|
1008 |
"/ |
|
1009 |
attribute_name_index > constants size ifTrue:[ |
|
333 | 1010 |
attribute_name_index == 16rb700 ifTrue:[ |
1011 |
self halt. |
|
1012 |
] |
|
9 | 1013 |
]. |
1014 |
||
5 | 1015 |
attribute_name := constants at:attribute_name_index. |
9 | 1016 |
|
61 | 1017 |
Verbose ifTrue:[Transcript show:'attrib name: '; showCR:attribute_name]. |
9 | 1018 |
|
333 | 1019 |
self readAttribute:attribute_name for:something. |
5 | 1020 |
|
1021 |
" |
|
1022 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1023 |
" |
|
1024 |
||
2089 | 1025 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
1026 |
"Modified: / 9.4.1998 / 18:13:34 / cg" |
|
5 | 1027 |
! |
1028 |
||
1029 |
readAttributesFor:something |
|
1030 |
|attributes_count| |
|
1031 |
||
128 | 1032 |
attributes_count := inStream nextUnsignedShortMSB:msb. |
5 | 1033 |
|
1034 |
1 to:attributes_count do:[:i | |
|
252 | 1035 |
self readAttributeFor:something. |
5 | 1036 |
]. |
1037 |
||
1038 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1039 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
333 | 1040 |
! |
1041 |
||
2148 | 1042 |
readEnclosingMethodAttributeFor:something |
1043 |
"/ ('JAVA [info]: unhandled attribute: EnclosingMethod') infoPrintCR. |
|
1044 |
self skipAttribute:'EnclosingMethod'. |
|
1045 |
! |
|
1046 |
||
1047 |
readInnerClassesAttributeFor:something |
|
1048 |
"/ ('JAVA [info]: unhandled attribute: InnerClasses') infoPrintCR. |
|
1049 |
self skipAttribute:'InnerClasses'. |
|
1050 |
! |
|
1051 |
||
1052 |
readLocalVariableTypeTableAttributeFor:something |
|
1053 |
"/ ('JAVA [info]: unhandled attribute: LocalVariableTypeTable') infoPrintCR. |
|
1054 |
self skipAttribute:'LocalVariableTypeTable'. |
|
1055 |
! |
|
1056 |
||
1057 |
readRuntimeInvisibleAnnotationsAttributeFor:something |
|
1058 |
"/ ('JAVA [info]: unhandled attribute: RuntimeInvisibleAnnotationsAttributeFor') infoPrintCR. |
|
1059 |
self skipAttribute:'RuntimeInvisibleAnnotationsAttributeFor'. |
|
1060 |
! |
|
1061 |
||
1062 |
readRuntimeInvisibleParameterAnnotationsAttributeFor:something |
|
1063 |
"/ ('JAVA [info]: unhandled attribute: RuntimeInvisibleParameterAnnotations') infoPrintCR. |
|
1064 |
self skipAttribute:'RuntimeInvisibleParameterAnnotations'. |
|
1065 |
! |
|
1066 |
||
1067 |
readRuntimeVisibleAnnotationsAttributeFor:something |
|
1068 |
"/ ('JAVA [info]: unhandled attribute: RuntimeVisibleAnnotations') infoPrintCR. |
|
1069 |
self skipAttribute:'RuntimeVisibleAnnotations'. |
|
1070 |
! |
|
1071 |
||
1072 |
readRuntimeVisibleParameterAnnotationsAttributeFor:something |
|
1073 |
"/ ('JAVA [info]: unhandled attribute: RuntimeVisibleParameterAnnotations') infoPrintCR. |
|
1074 |
self skipAttribute:'RuntimeVisibleParameterAnnotations'. |
|
1075 |
! |
|
1076 |
||
1077 |
readSignatureAttributeFor:something |
|
1078 |
"/ ('JAVA [info]: unhandled attribute: Signature') infoPrintCR. |
|
1079 |
self skipAttribute:'Signature'. |
|
1080 |
! |
|
1081 |
||
1082 |
readSourceDebugExtensionAttributeFor:something |
|
1083 |
"/ ('JAVA [info]: unhandled attribute: SourceDebugExtension') infoPrintCR. |
|
1084 |
self skipAttribute:'SourceDebugExtension'. |
|
1085 |
! |
|
1086 |
||
353 | 1087 |
readSourceFileAttributeFor:aClass |
350 | 1088 |
|attribute_length sourceFile_index sourceFile| |
1089 |
||
1090 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1091 |
||
1092 |
sourceFile_index := inStream nextUnsignedShortMSB:msb. |
|
1093 |
sourceFile := constants at:sourceFile_index. |
|
1094 |
||
353 | 1095 |
aClass isJavaClass ifTrue:[ |
1096 |
aClass setSourceFile:sourceFile. |
|
1097 |
] ifFalse:[ |
|
1098 |
aClass setClassFilename:sourceFile |
|
1099 |
]. |
|
350 | 1100 |
|
1101 |
Verbose ifTrue:[Transcript show:'sourceFile: '; showCR:sourceFile]. |
|
1102 |
^ true |
|
1103 |
||
1104 |
" |
|
1105 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1106 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1107 |
JavaClassReader loadFile:'foo.cls' |
|
1108 |
" |
|
1109 |
||
1110 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
|
353 | 1111 |
"Modified: / 12.5.1998 / 22:01:07 / cg" |
350 | 1112 |
! |
1113 |
||
2148 | 1114 |
readSyntheticAttributeFor:something |
1115 |
"/ ('JAVA [info]: unhandled attribute: Synthetic') infoPrintCR. |
|
1116 |
self skipAttribute:'Synthetic'. |
|
1117 |
! |
|
1118 |
||
333 | 1119 |
skipAttribute:attributeName |
1120 |
"dont know about this attribute - skip it here" |
|
1121 |
||
1122 |
|attribute_length attribute_info| |
|
1123 |
||
1124 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1125 |
attribute_info := ByteArray new:(attribute_length). |
|
1126 |
inStream nextBytes:attribute_length into:attribute_info startingAt:1. |
|
1127 |
||
1128 |
Verbose ifTrue:[Transcript show:'skipped '; show:attributeName; showCR:'-attribute']. |
|
1129 |
||
1130 |
"Created: / 9.4.1998 / 18:12:46 / cg" |
|
1131 |
"Modified: / 9.4.1998 / 18:13:20 / cg" |
|
5 | 1132 |
! ! |
1133 |
||
350 | 1134 |
!JavaClassReader methodsFor:'file reading - attributes-ST'! |
1135 |
||
1136 |
readSTClassCategoryAttributeFor:aClass |
|
1137 |
|attribute_length categoryString_index categoryString| |
|
1138 |
||
1139 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1140 |
||
1141 |
categoryString_index := inStream nextUnsignedShortMSB:msb. |
|
1142 |
categoryString := constants at:categoryString_index. |
|
1143 |
||
1144 |
aClass category:categoryString. |
|
1145 |
||
1146 |
Verbose ifTrue:[Transcript show:'categoryString: '; showCR:categoryString]. |
|
1147 |
^ true |
|
1148 |
||
1149 |
" |
|
1150 |
JavaClassReader loadFile:'foo.cls' |
|
1151 |
" |
|
1152 |
||
1153 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1154 |
"Modified: / 9.5.1998 / 02:36:55 / cg" |
|
1155 |
! |
|
1156 |
||
353 | 1157 |
readSTClassInstVarNamesAttributeFor:aClass |
1158 |
|attribute_length nameString_index nameString| |
|
1159 |
||
1160 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1161 |
||
1162 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1163 |
nameString := constants at:nameString_index. |
|
1164 |
||
1165 |
aClass class instanceVariableString:nameString. |
|
1166 |
||
1167 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1168 |
^ true |
|
1169 |
||
1170 |
" |
|
1171 |
JavaClassReader loadFile:'foo.cls' |
|
1172 |
" |
|
1173 |
||
1174 |
"Modified: / 12.5.1998 / 22:18:03 / cg" |
|
1175 |
"Created: / 12.5.1998 / 22:18:24 / cg" |
|
1176 |
! |
|
1177 |
||
350 | 1178 |
readSTClassPackageAttributeFor:aClass |
1179 |
|attribute_length packageString_index packageString| |
|
1180 |
||
1181 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1182 |
||
1183 |
packageString_index := inStream nextUnsignedShortMSB:msb. |
|
1184 |
packageString := constants at:packageString_index. |
|
1185 |
||
1186 |
aClass package:packageString asSymbol. |
|
1187 |
||
1188 |
Verbose ifTrue:[Transcript show:'packageString: '; showCR:packageString]. |
|
1189 |
^ true |
|
1190 |
||
1191 |
" |
|
1192 |
JavaClassReader loadFile:'foo.cls' |
|
1193 |
" |
|
1194 |
||
1195 |
"Modified: / 9.5.1998 / 02:32:38 / cg" |
|
1196 |
"Created: / 9.5.1998 / 02:33:44 / cg" |
|
1197 |
! |
|
1198 |
||
1199 |
readSTClassRevisionAttributeFor:aClass |
|
1200 |
|attribute_length revisionString_index revisionString| |
|
1201 |
||
1202 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1203 |
||
1204 |
revisionString_index := inStream nextUnsignedShortMSB:msb. |
|
1205 |
revisionString := constants at:revisionString_index. |
|
1206 |
||
1207 |
aClass setBinaryRevision:revisionString. |
|
1208 |
||
1209 |
Verbose ifTrue:[Transcript show:'revisionString: '; showCR:revisionString]. |
|
1210 |
^ true |
|
1211 |
||
1212 |
" |
|
1213 |
JavaClassReader loadFile:'foo.cls' |
|
1214 |
" |
|
1215 |
||
1216 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1217 |
"Modified: / 9.5.1998 / 02:35:01 / cg" |
|
353 | 1218 |
! |
1219 |
||
1220 |
readSTClassVarNamesAttributeFor:aClass |
|
1221 |
|attribute_length nameString_index nameString| |
|
1222 |
||
1223 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1224 |
||
1225 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1226 |
nameString := constants at:nameString_index. |
|
1227 |
||
1228 |
aClass classVariableString:nameString. |
|
1229 |
||
1230 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1231 |
^ true |
|
1232 |
||
1233 |
" |
|
1234 |
JavaClassReader loadFile:'foo.cls' |
|
1235 |
" |
|
1236 |
||
1237 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1238 |
"Modified: / 12.5.1998 / 22:18:03 / cg" |
|
1239 |
! |
|
1240 |
||
1241 |
readSTInstVarNamesAttributeFor:aClass |
|
1242 |
|attribute_length nameString_index nameString| |
|
1243 |
||
1244 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1245 |
||
1246 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1247 |
nameString := constants at:nameString_index. |
|
1248 |
||
1249 |
aClass setInstanceVariableString:nameString. |
|
1250 |
||
1251 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1252 |
^ true |
|
1253 |
||
1254 |
" |
|
1255 |
JavaClassReader loadFile:'foo.cls' |
|
1256 |
" |
|
1257 |
||
1258 |
"Created: / 12.5.1998 / 22:18:14 / cg" |
|
1259 |
"Modified: / 12.5.1998 / 22:21:10 / cg" |
|
350 | 1260 |
! ! |
1261 |
||
5 | 1262 |
!JavaClassReader methodsFor:'file reading - constants'! |
1263 |
||
1 | 1264 |
readConstant |
1265 |
|tag constReader const| |
|
1266 |
||
1267 |
||
11 | 1268 |
constNeeds2Slots := false. |
1269 |
||
1 | 1270 |
"/ |
1271 |
"/ get tag |
|
1272 |
"/ |
|
128 | 1273 |
tag := inStream nextByte. |
61 | 1274 |
Verbose ifTrue:[Transcript show:'tag = '; showCR:tag]. |
1 | 1275 |
|
350 | 1276 |
tag >= 250 ifTrue:[ |
1277 |
constReader := #( |
|
1278 |
"/ ST types |
|
1279 |
readConstant_ST_Large "/ 249 |
|
1280 |
readConstant_ST_Special "/ 250 |
|
1281 |
readConstant_ST_Character "/ 251 |
|
1282 |
readConstant_ST_ByteArray "/ 252 |
|
1283 |
readConstant_ST_Array "/ 253 |
|
1284 |
readConstant_ST_Symbol "/ 254 |
|
1285 |
readConstant_ST_Reserved "/ 255 |
|
1286 |
) at:tag-249+1. |
|
1287 |
] ifFalse:[ |
|
1288 |
constReader := #( |
|
344 | 1289 |
"/ JAVA types |
695 | 1290 |
readConstant_Utf8 "/ 1 - now called Utf8 |
344 | 1291 |
readConstant_Unicode "/ 2 |
1292 |
readConstant_Integer "/ 3 |
|
1293 |
readConstant_Float "/ 4 |
|
1294 |
readConstant_Long "/ 5 |
|
1295 |
readConstant_Double "/ 6 |
|
1296 |
readConstant_Class "/ 7 |
|
1297 |
readConstant_String "/ 8 |
|
1298 |
readConstant_Fieldref "/ 9 |
|
1299 |
readConstant_Methodref "/ 10 |
|
1300 |
readConstant_InterfaceMethodref "/ 11 |
|
1301 |
readConstant_NameAndType "/ 12 |
|
1302 |
) at:tag ifAbsent:[#readConstant_Undef]. |
|
350 | 1303 |
]. |
1 | 1304 |
^ self perform:constReader. |
1305 |
||
1306 |
" |
|
1307 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1308 |
" |
|
1309 |
||
344 | 1310 |
"Created: / 15.4.1996 / 15:46:32 / cg" |
350 | 1311 |
"Modified: / 9.5.1998 / 01:26:05 / cg" |
1 | 1312 |
! |
1313 |
||
1314 |
readConstantPool |
|
2089 | 1315 |
|constantPoolCount const i| |
1 | 1316 |
|
1317 |
"/ |
|
1318 |
"/ get constant pool |
|
1319 |
"/ |
|
2089 | 1320 |
constantPoolCount := inStream nextUnsignedShortMSB:msb. |
1321 |
Verbose ifTrue:[Transcript show:'constantPoolCount = '; showCR:constantPoolCount]. |
|
1322 |
||
1323 |
constants := JavaConstantPool "Array" new:constantPoolCount-1. |
|
1324 |
||
21 | 1325 |
constSlot := 1. |
2089 | 1326 |
[constSlot < constantPoolCount] whileTrue:[ |
1327 |
Verbose ifTrue:[Transcript show:'const: '; showCR:constSlot]. |
|
1328 |
const := self readConstant. |
|
1329 |
constants at:constSlot put:const. |
|
1330 |
||
1331 |
"/ long & double consts take 2 slots |
|
1332 |
"/ (only first is used) |
|
1333 |
constNeeds2Slots ifTrue:[ |
|
1334 |
constSlot := constSlot + 2. |
|
1335 |
] ifFalse:[ |
|
1336 |
constSlot := constSlot + 1. |
|
1337 |
] |
|
1338 |
]. |
|
1339 |
||
52 | 1340 |
constSlot := -1. |
2089 | 1341 |
|
1342 |
"/ preresolve what can be (especially, strings are resolved here) |
|
1343 |
||
1344 |
1 to:constantPoolCount-1 do:[:i | |
|
1345 |
|const value| |
|
1346 |
||
1347 |
const := constants at:i. |
|
1348 |
const notNil ifTrue:[ "/ kludge for 2-slot constants (which only take 1 slot in ST/X) |
|
1349 |
(const isKindOf:JavaUnresolvedConstant) ifTrue:[ |
|
1350 |
value := const preResolve. |
|
1351 |
value ~~ const ifTrue:[ |
|
1352 |
constants at:i put:value. |
|
1353 |
] |
|
1354 |
] |
|
1355 |
] |
|
1356 |
]. |
|
1 | 1357 |
|
1358 |
" |
|
1359 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2089 | 1360 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
1361 |
" |
|
1362 |
||
1363 |
"Created: / 15.4.1996 / 15:14:11 / cg" |
|
1364 |
"Modified: / 7.5.1998 / 11:44:06 / cg" |
|
1 | 1365 |
! |
1366 |
||
1367 |
readConstant_Asciz |
|
2089 | 1368 |
|len string| |
1369 |
||
1370 |
len := inStream nextUnsignedShortMSB:msb. |
|
1371 |
string := String new:len. |
|
1372 |
inStream nextBytes:len into:string startingAt:1. |
|
1373 |
||
1374 |
Verbose ifTrue:[Transcript show:'asciz; string= '; showCR:string]. |
|
1375 |
||
1 | 1376 |
^ string |
1377 |
||
1378 |
" |
|
1379 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2089 | 1380 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
1381 |
" |
|
1382 |
||
1383 |
"Created: 15.4.1996 / 15:15:35 / cg" |
|
1384 |
"Modified: 15.4.1996 / 16:33:45 / cg" |
|
1 | 1385 |
! |
1386 |
||
1387 |
readConstant_Class |
|
2089 | 1388 |
|name_index name| |
1389 |
||
1390 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
1391 |
||
1392 |
Verbose ifTrue:[Transcript show:'class; index= '; showCR:name_index]. |
|
1393 |
||
1394 |
name := constants at:name_index. |
|
1395 |
name notNil ifTrue:[ |
|
1396 |
Verbose ifTrue:[Transcript showCR:'name in constant_class already resolved']. |
|
1397 |
"/ self halt |
|
1398 |
]. |
|
1399 |
||
1400 |
^ JavaUnresolvedClassConstant |
|
1401 |
pool:constants |
|
1402 |
poolIndex:constSlot |
|
1403 |
nameIndex:name_index |
|
1404 |
||
1405 |
" |
|
1406 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1407 |
" |
|
1408 |
||
1409 |
"Created: / 15.4.1996 / 15:21:13 / cg" |
|
1410 |
"Modified: / 8.5.1998 / 21:53:16 / cg" |
|
1 | 1411 |
! |
1412 |
||
11 | 1413 |
readConstant_Double |
350 | 1414 |
|high low aFloat bytes| |
1415 |
||
1416 |
"/ new code - to be tested |
|
1417 |
"/ bytes := ByteArray new:8. |
|
1418 |
"/ |
|
1419 |
"/ inStream nextBytes:8 into:bytes startingAt:1. |
|
1420 |
"/ msb ~~ UninterpretedBytes isBigEndian ifTrue:[ |
|
1421 |
"/ bytes reverse |
|
1422 |
"/ ]. |
|
1423 |
"/ aFloat := bytes doubleAt:1. |
|
1424 |
||
1425 |
"/ old code |
|
11 | 1426 |
|
128 | 1427 |
high := inStream nextUnsignedLongMSB:msb. |
1428 |
low := inStream nextUnsignedLongMSB:msb. |
|
11 | 1429 |
|
1430 |
aFloat := Float new. |
|
1431 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
350 | 1432 |
aFloat basicAt:1 put:((high bitShift:-24) bitAnd:16rFF). |
1433 |
aFloat basicAt:2 put:((high bitShift:-16) bitAnd:16rFF). |
|
1434 |
aFloat basicAt:3 put:((high bitShift:-8) bitAnd:16rFF). |
|
1435 |
aFloat basicAt:4 put:(high bitAnd:16rFF). |
|
1436 |
aFloat basicAt:5 put:((low bitShift:-24) bitAnd:16rFF). |
|
1437 |
aFloat basicAt:6 put:((low bitShift:-16) bitAnd:16rFF). |
|
1438 |
aFloat basicAt:7 put:((low bitShift:-8) bitAnd:16rFF). |
|
1439 |
aFloat basicAt:8 put:(low bitAnd:16rFF). |
|
11 | 1440 |
] ifFalse:[ |
350 | 1441 |
aFloat basicAt:1 put:(low bitAnd:16rFF). |
1442 |
aFloat basicAt:2 put:((low bitShift:-8) bitAnd:16rFF). |
|
1443 |
aFloat basicAt:3 put:((low bitShift:-16) bitAnd:16rFF). |
|
1444 |
aFloat basicAt:4 put:((low bitShift:-24) bitAnd:16rFF). |
|
1445 |
aFloat basicAt:5 put:(high bitAnd:16rFF). |
|
1446 |
aFloat basicAt:6 put:((high bitShift:-8) bitAnd:16rFF). |
|
1447 |
aFloat basicAt:7 put:((high bitShift:-16) bitAnd:16rFF). |
|
1448 |
aFloat basicAt:8 put:((high bitShift:-24) bitAnd:16rFF). |
|
11 | 1449 |
]. |
1450 |
||
1451 |
constNeeds2Slots := true. |
|
1452 |
||
61 | 1453 |
Verbose ifTrue:[Transcript show:'double; value= '; showCR:aFloat]. |
11 | 1454 |
^ aFloat |
1455 |
||
1456 |
" |
|
1457 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1458 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1459 |
" |
|
1460 |
||
350 | 1461 |
"Created: / 15.4.1996 / 16:34:42 / cg" |
1462 |
"Modified: / 8.5.1998 / 22:06:07 / cg" |
|
11 | 1463 |
! |
1464 |
||
2089 | 1465 |
readConstant_Fieldref |
1466 |
|class_index name_and_type_index| |
|
1467 |
||
1468 |
class_index := inStream nextUnsignedShortMSB:msb. |
|
1469 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1470 |
||
1471 |
Verbose ifTrue:[Transcript show:'fieldref; classindex= '; showCR:class_index]. |
|
1472 |
Verbose ifTrue:[Transcript show:'fieldref; name&typeindex= '; showCR:name_and_type_index]. |
|
1473 |
||
1474 |
^ JavaUnresolvedFieldrefConstant |
|
1475 |
pool:constants |
|
1476 |
poolIndex:constSlot |
|
1477 |
classIndex:class_index |
|
1478 |
nameandTypeIndex:name_and_type_index |
|
1479 |
||
1480 |
" |
|
1481 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1482 |
" |
|
1483 |
||
1484 |
"Created: 15.4.1996 / 15:22:18 / cg" |
|
1485 |
"Modified: 15.4.1996 / 16:07:01 / cg" |
|
1 | 1486 |
! |
1487 |
||
11 | 1488 |
readConstant_Float |
433 | 1489 |
|b1 b2 b3 b4 aFloat bytes| |
350 | 1490 |
|
1491 |
"/ new code - to be tested ... |
|
352 | 1492 |
"/ |
1493 |
"/ bytes := ByteArray new:4. |
|
1494 |
"/ inStream nextBytes:4 into:bytes startingAt:1. |
|
1495 |
"/ msb ~~ UninterpretedBytes isBigEndian ifTrue:[ |
|
1496 |
"/ bytes reverse |
|
1497 |
"/ ]. |
|
1498 |
"/ aFloat := bytes floatAt:1. |
|
1499 |
"/ Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
|
1500 |
"/ ^ aFloat. |
|
350 | 1501 |
|
1502 |
"/ old code |
|
11 | 1503 |
|
1504 |
aFloat := ShortFloat basicNew. |
|
433 | 1505 |
|
1506 |
b1 := inStream nextByte. |
|
1507 |
b2 := inStream nextByte. |
|
1508 |
b3 := inStream nextByte. |
|
1509 |
b4 := inStream nextByte. |
|
1510 |
||
11 | 1511 |
UninterpretedBytes isBigEndian ifTrue:[ |
433 | 1512 |
aFloat basicAt:1 put:b1. |
1513 |
aFloat basicAt:2 put:b2. |
|
1514 |
aFloat basicAt:3 put:b3. |
|
1515 |
aFloat basicAt:4 put:b4. |
|
11 | 1516 |
] ifFalse:[ |
433 | 1517 |
aFloat basicAt:4 put:b1. |
1518 |
aFloat basicAt:3 put:b2. |
|
1519 |
aFloat basicAt:2 put:b3. |
|
1520 |
aFloat basicAt:1 put:b4. |
|
11 | 1521 |
]. |
61 | 1522 |
Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
11 | 1523 |
^ aFloat |
1524 |
||
1525 |
" |
|
1526 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1527 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1528 |
" |
|
1529 |
||
350 | 1530 |
"Created: / 15.4.1996 / 16:34:42 / cg" |
433 | 1531 |
"Modified: / 10.11.1998 / 22:04:59 / cg" |
11 | 1532 |
! |
1533 |
||
1 | 1534 |
readConstant_Integer |
1535 |
|value| |
|
1536 |
||
128 | 1537 |
value := inStream nextLongMSB:msb. |
1 | 1538 |
|
61 | 1539 |
Verbose ifTrue:[Transcript show:'integer; value= '; showCR:value]. |
1 | 1540 |
|
1541 |
^ value |
|
1542 |
||
1543 |
" |
|
1544 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1545 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1546 |
" |
|
1547 |
||
1548 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
1549 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
1550 |
! |
|
1551 |
||
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
1552 |
readConstant_InterfaceMethodref |
2089 | 1553 |
|class_index name_and_type_index| |
1554 |
||
1555 |
class_index := inStream nextUnsignedShortMSB:msb. |
|
1556 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1557 |
||
1558 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
|
1559 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
1560 |
||
1561 |
^ JavaUnresolvedInterfaceMethodrefConstant |
|
1562 |
pool:constants |
|
1563 |
poolIndex:constSlot |
|
1564 |
classIndex:class_index |
|
1565 |
nameandTypeIndex:name_and_type_index |
|
1566 |
||
1567 |
" |
|
1568 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1569 |
" |
|
1570 |
||
1571 |
"Created: 15.4.1996 / 15:22:37 / cg" |
|
1572 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
1573 |
! |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
1574 |
|
11 | 1575 |
readConstant_Long |
1576 |
|high low value| |
|
1577 |
||
128 | 1578 |
high := inStream nextUnsignedLongMSB:msb. |
1579 |
low := inStream nextUnsignedLongMSB:msb. |
|
11 | 1580 |
|
1581 |
value := (high bitShift:32) bitOr:low. |
|
60 | 1582 |
(high bitTest:16r80000000) ifTrue:[ |
252 | 1583 |
value := value - 16r10000000000000000. |
60 | 1584 |
]. |
11 | 1585 |
constNeeds2Slots := true. |
1586 |
||
61 | 1587 |
Verbose ifTrue:[Transcript show:'long; value= '; showCR:value]. |
11 | 1588 |
^ value |
1589 |
||
1590 |
" |
|
1591 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1592 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1593 |
" |
|
1594 |
||
1595 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
1596 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
1597 |
! |
|
1598 |
||
1 | 1599 |
readConstant_Methodref |
2089 | 1600 |
|class_index name_and_type_index| |
1601 |
||
1602 |
class_index := inStream nextUnsignedShortMSB:msb. |
|
1603 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1604 |
||
1605 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
|
1606 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
1607 |
||
1608 |
^ JavaUnresolvedMethodrefConstant |
|
1609 |
pool:constants |
|
1610 |
poolIndex:constSlot |
|
1611 |
classIndex:class_index |
|
1612 |
nameandTypeIndex:name_and_type_index |
|
1613 |
||
1614 |
" |
|
1615 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1616 |
" |
|
1617 |
||
1618 |
"Created: 15.4.1996 / 15:22:37 / cg" |
|
1619 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
|
1 | 1620 |
! |
1621 |
||
91 | 1622 |
readConstant_NameAndType |
2089 | 1623 |
|name_index signature_index| |
1624 |
||
1625 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
1626 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
1627 |
||
1628 |
Verbose ifTrue:[Transcript show:'methodref; nameindex= '; showCR:name_index]. |
|
1629 |
Verbose ifTrue:[Transcript show:'methodref; signatureindex= '; showCR:signature_index]. |
|
1630 |
||
1631 |
^ JavaUnresolvedNameandTypeConstant |
|
1632 |
pool:constants |
|
1633 |
poolIndex:constSlot |
|
1634 |
nameIndex:name_index |
|
1635 |
signatureIndex:signature_index |
|
1636 |
||
1637 |
" |
|
1638 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1639 |
" |
|
1640 |
||
1641 |
"Created: 15.4.1996 / 15:23:43 / cg" |
|
1642 |
"Modified: 15.4.1996 / 16:17:16 / cg" |
|
1 | 1643 |
! |
1644 |
||
1645 |
readConstant_String |
|
2089 | 1646 |
|tag string_index chars jString| |
1647 |
||
1648 |
string_index := inStream nextUnsignedShortMSB:msb. |
|
1649 |
||
1650 |
Verbose ifTrue:[Transcript show:'string; index= '; showCR:string_index]. |
|
1651 |
||
344 | 1652 |
"/ resolve here if possible |
2089 | 1653 |
string_index < constSlot ifTrue:[ |
1654 |
Java java_lang_String notNil ifTrue:[ |
|
1655 |
chars := (constants at:string_index). |
|
1656 |
chars isString ifFalse:[ |
|
1657 |
self halt:'should not happen' |
|
1658 |
]. |
|
1659 |
jString := Java as_String:chars. |
|
1660 |
^ jString. |
|
1661 |
] |
|
1662 |
]. |
|
1663 |
||
91 | 1664 |
^ JavaUnresolvedStringConstant |
2089 | 1665 |
pool:constants |
1666 |
poolIndex:constSlot |
|
1667 |
stringIndex:string_index |
|
1 | 1668 |
|
1669 |
" |
|
43 | 1670 |
Verbose := true. |
2089 | 1671 |
JavaClassReader readFile:'/phys/ibm3/java/lib/java/lang/System.class' |
1672 |
" |
|
1673 |
||
1674 |
"Created: / 15.4.1996 / 15:20:33 / cg" |
|
1675 |
"Modified: / 7.5.1998 / 11:42:45 / cg" |
|
695 | 1676 |
! |
1677 |
||
1678 |
readConstant_Unicode |
|
2089 | 1679 |
|len string ascii| |
1680 |
||
1681 |
len := inStream nextUnsignedShortMSB:msb. |
|
1682 |
string := TwoByteString new:len. |
|
1683 |
1 to:len do:[:idx | |
|
1684 |
ascii := inStream nextUnsignedShortMSB:msb. |
|
1685 |
string at:idx put:(Character value:ascii). |
|
1686 |
]. |
|
1687 |
||
1688 |
Verbose ifTrue:[Transcript show:'asciz; unicodeString= '; showCR:string]. |
|
1689 |
||
695 | 1690 |
^ string |
1691 |
! |
|
1692 |
||
1693 |
readConstant_Utf8 |
|
2089 | 1694 |
|len bytes string| |
1695 |
||
1696 |
len := inStream nextUnsignedShortMSB:msb. |
|
1697 |
bytes := ByteArray new:len. |
|
1698 |
inStream nextBytes:len into:bytes startingAt:1. |
|
1699 |
string := CharacterArray fromUTF8Bytes:bytes. |
|
1700 |
||
1701 |
Verbose ifTrue:[Transcript show:'asciz; string= '; showCR:string]. |
|
1702 |
||
695 | 1703 |
^ string |
344 | 1704 |
! ! |
1705 |
||
1706 |
!JavaClassReader methodsFor:'file reading - constants-ST'! |
|
1707 |
||
1708 |
readConstant_ST_Array |
|
1709 |
|aSize arr| |
|
1710 |
||
1711 |
aSize := inStream nextUnsignedShortMSB:msb. |
|
1712 |
arr := Array new:aSize. |
|
1713 |
||
1714 |
1 to:aSize do:[:i | |
|
350 | 1715 |
|element_index element| |
344 | 1716 |
|
1717 |
element_index := inStream nextUnsignedShortMSB:msb. |
|
1718 |
arr at:i put:element_index. |
|
1719 |
]. |
|
1720 |
Verbose ifTrue:[Transcript show:'array; size= '; showCR:aSize]. |
|
1721 |
||
1722 |
^ JavaUnresolvedSTArrayConstant |
|
1723 |
pool:constants |
|
1724 |
poolIndex:constSlot |
|
1725 |
array:arr |
|
1726 |
||
1727 |
"Created: / 7.5.1998 / 11:47:01 / cg" |
|
350 | 1728 |
"Modified: / 9.5.1998 / 00:25:34 / cg" |
344 | 1729 |
! |
1730 |
||
1731 |
readConstant_ST_ByteArray |
|
1732 |
|aSize arr| |
|
1733 |
||
1734 |
aSize := inStream nextUnsignedShortMSB:msb. |
|
1735 |
arr := ByteArray new:aSize. |
|
1736 |
||
1737 |
1 to:aSize do:[:i | |
|
1738 |
|element_index| |
|
1739 |
||
1740 |
arr at:i put:(inStream nextByte). |
|
1741 |
]. |
|
1742 |
Verbose ifTrue:[Transcript show:'byteArray; size= '; showCR:aSize]. |
|
1743 |
||
1744 |
^ arr |
|
1745 |
||
1746 |
"Created: / 7.5.1998 / 11:47:12 / cg" |
|
1747 |
! |
|
1748 |
||
1749 |
readConstant_ST_Character |
|
1750 |
|ascii| |
|
1751 |
||
1752 |
ascii := inStream nextUnsignedShortMSB:msb. |
|
1753 |
||
1754 |
Verbose ifTrue:[Transcript show:'char; ascii= '; showCR:ascii]. |
|
1755 |
^ Character value:ascii |
|
1756 |
||
1757 |
"Created: / 7.5.1998 / 11:48:12 / cg" |
|
1758 |
! |
|
1759 |
||
350 | 1760 |
readConstant_ST_Special |
1761 |
|type| |
|
1762 |
||
1763 |
type := inStream nextUnsignedShortMSB:msb. |
|
1764 |
^ #( |
|
1765 |
nil |
|
1766 |
true |
|
1767 |
false |
|
1768 |
) at:(type + 1) |
|
1769 |
||
1770 |
"Created: / 8.5.1998 / 23:06:56 / cg" |
|
1771 |
"Modified: / 9.5.1998 / 00:40:14 / cg" |
|
1772 |
! |
|
1773 |
||
344 | 1774 |
readConstant_ST_String |
2089 | 1775 |
|tag string_index chars| |
1776 |
||
1777 |
string_index := inStream nextUnsignedShortMSB:msb. |
|
1778 |
||
1779 |
Verbose ifTrue:[Transcript show:'string; index= '; showCR:string_index]. |
|
1780 |
||
344 | 1781 |
"/ resolve here if possible |
2089 | 1782 |
string_index < constSlot ifTrue:[ |
1783 |
chars := (constants at:string_index). |
|
1784 |
^ chars |
|
1785 |
]. |
|
1786 |
||
344 | 1787 |
^ JavaUnresolvedSTStringConstant |
2089 | 1788 |
pool:constants |
1789 |
poolIndex:constSlot |
|
1790 |
stringIndex:string_index |
|
1791 |
||
1792 |
"Modified: / 7.5.1998 / 11:48:28 / cg" |
|
1793 |
"Created: / 7.5.1998 / 11:49:55 / cg" |
|
344 | 1794 |
! |
1795 |
||
1796 |
readConstant_ST_Symbol |
|
2089 | 1797 |
|tag string_index chars| |
1798 |
||
1799 |
string_index := inStream nextUnsignedShortMSB:msb. |
|
1800 |
||
1801 |
Verbose ifTrue:[Transcript show:'symbol; index= '; showCR:string_index]. |
|
1802 |
||
344 | 1803 |
"/ resolve here if possible |
2089 | 1804 |
string_index < constSlot ifTrue:[ |
1805 |
chars := (constants at:string_index). |
|
1806 |
chars isString ifFalse:[ |
|
1807 |
self halt:'should not happen' |
|
1808 |
]. |
|
1809 |
^ chars asSymbol |
|
1810 |
]. |
|
1811 |
||
344 | 1812 |
^ JavaUnresolvedSTSymbolConstant |
2089 | 1813 |
pool:constants |
1814 |
poolIndex:constSlot |
|
1815 |
stringIndex:string_index |
|
1816 |
||
1817 |
"Modified: / 7.5.1998 / 11:48:28 / cg" |
|
5 | 1818 |
! ! |
1819 |
||
1820 |
!JavaClassReader methodsFor:'file reading - fields'! |
|
1821 |
||
1822 |
readConstantValueAttributeFor:aField |
|
1823 |
|attribute_length constantvalue_index constantValue| |
|
1824 |
||
128 | 1825 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
5 | 1826 |
|
128 | 1827 |
constantvalue_index := inStream nextUnsignedShortMSB:msb. |
5 | 1828 |
constantValue := constants at:constantvalue_index. |
1829 |
||
59 | 1830 |
aField constantValue:constantValue. |
1831 |
||
61 | 1832 |
Verbose ifTrue:[Transcript show:'constantValue: '; showCR:constantValue]. |
5 | 1833 |
^ true |
1834 |
||
1835 |
" |
|
1836 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1837 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1838 |
" |
|
1839 |
||
1840 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1841 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1 | 1842 |
! |
1843 |
||
1844 |
readFieldInfofield |
|
2089 | 1845 |
|access_flags name_index signature_index attributes_count field| |
1846 |
||
1847 |
access_flags := inStream nextUnsignedShortMSB:msb. |
|
1848 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
1849 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
1850 |
||
5 | 1851 |
field := JavaField new. |
2089 | 1852 |
field setAccessFlags:access_flags. |
1853 |
field setName:(constants at:name_index) asSymbol. |
|
1854 |
field setSignature:(constants at:signature_index) asSymbol. |
|
1855 |
||
1856 |
attributes_count := inStream nextUnsignedShortMSB:msb. |
|
1857 |
||
1858 |
Verbose ifTrue:[Transcript show:' field name: '; show:(constants at:name_index); |
|
1859 |
show:' access: '; show:access_flags; |
|
1860 |
show:' attrib_cnt: '; showCR:attributes_count]. |
|
1861 |
||
1862 |
1 to:attributes_count do:[:i | |
|
1863 |
self readAttributeFor:field. |
|
1864 |
]. |
|
1865 |
||
1866 |
^ field |
|
27 | 1867 |
|
1 | 1868 |
" |
2089 | 1869 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
1870 |
" |
|
1871 |
||
1872 |
"Created: / 15.4.1996 / 15:38:43 / cg" |
|
1873 |
"Modified: / 15.10.1998 / 10:38:01 / cg" |
|
1 | 1874 |
! |
1875 |
||
1876 |
readFieldInfofields |
|
38 | 1877 |
|nFields fields| |
1 | 1878 |
|
1879 |
"/ |
|
38 | 1880 |
"/ get fieldInfos |
1 | 1881 |
"/ |
128 | 1882 |
nFields := inStream nextUnsignedShortMSB:msb. |
61 | 1883 |
Verbose ifTrue:[Transcript show:'fieldsCount = '; showCR:nFields]. |
1 | 1884 |
|
27 | 1885 |
fields := Array new:nFields. |
1886 |
||
1887 |
1 to:nFields do:[:i | |
|
252 | 1888 |
Verbose ifTrue:[Transcript show:'field: '; showCR:i]. |
1889 |
fields at:i put:(self readFieldInfofield) |
|
1 | 1890 |
]. |
38 | 1891 |
^ fields |
1 | 1892 |
|
1893 |
" |
|
1894 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1895 |
" |
|
1896 |
||
1897 |
"Created: 15.4.1996 / 15:34:41 / cg" |
|
1898 |
"Modified: 15.4.1996 / 15:35:28 / cg" |
|
5 | 1899 |
! ! |
1900 |
||
38 | 1901 |
!JavaClassReader methodsFor:'file reading - interfaces'! |
1902 |
||
1903 |
readInterfaces |
|
110 | 1904 |
|interfacesCount interface_index interface interfaces| |
38 | 1905 |
|
1906 |
"/ |
|
1907 |
"/ get interfaces |
|
1908 |
"/ |
|
128 | 1909 |
interfacesCount := inStream nextUnsignedShortMSB:msb. |
61 | 1910 |
Verbose ifTrue:[Transcript show:'interfacesCount = '; showCR:interfacesCount]. |
38 | 1911 |
|
1912 |
interfaces := Array new:interfacesCount. |
|
1913 |
||
1914 |
1 to:interfacesCount do:[:i | |
|
252 | 1915 |
Verbose ifTrue:[Transcript show:'interface: '; showCR:i]. |
1916 |
interface_index := inStream nextUnsignedShortMSB:msb. |
|
1917 |
interface := constants at:interface_index. |
|
38 | 1918 |
|
252 | 1919 |
interfaces at:i put:interface. |
38 | 1920 |
]. |
1921 |
^ interfaces |
|
1922 |
||
1923 |
" |
|
1924 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1925 |
" |
|
1926 |
||
1927 |
"Created: 15.4.1996 / 15:31:59 / cg" |
|
1928 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1929 |
! ! |
|
1930 |
||
5 | 1931 |
!JavaClassReader methodsFor:'file reading - methods'! |
1932 |
||
1933 |
readCodeAttributeFor:aJavaMethod |
|
1934 |
|attribute_length max_stack max_locals code_length code |
|
9 | 1935 |
exception_table_length exception_table unknown1 unknown2| |
1 | 1936 |
|
128 | 1937 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
1 | 1938 |
|
357 | 1939 |
Verbose ifTrue:[Transcript show:'code_attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
9 | 1940 |
|
2089 | 1941 |
minorVsn > 2 ifTrue:[ |
348 | 1942 |
"/ should be: |
1943 |
max_stack := inStream nextUnsignedShortMSB:msb. |
|
1944 |
max_locals := inStream nextUnsignedShortMSB:msb. |
|
1945 |
code_length := inStream nextUnsignedLongMSB:msb. |
|
1946 |
||
1947 |
"/ unknown1 := inStream nextByte. |
|
1948 |
"/ max_stack := inStream nextByte. |
|
1949 |
"/ max_locals := inStream nextUnsignedShortMSB:msb. |
|
1950 |
"/ unknown2 := inStream nextUnsignedShortMSB:msb. |
|
1951 |
"/ code_length := inStream nextUnsignedShortMSB:msb. |
|
1952 |
"/ Verbose ifTrue:[Transcript show:'?1: '; showCR:unknown1]. |
|
1953 |
"/ Verbose ifTrue:[Transcript show:'?2: '; showCR:unknown2]. |
|
39 | 1954 |
] ifFalse:[ |
348 | 1955 |
max_stack := inStream nextByte. |
1956 |
max_locals := inStream nextByte. |
|
1957 |
code_length := inStream nextUnsignedShortMSB:msb. |
|
9 | 1958 |
]. |
1959 |
||
357 | 1960 |
Verbose ifTrue:[ |
1961 |
Transcript show:'code_length: '; showCR:(code_length printStringRadix:16). |
|
1962 |
Transcript show:'code at pos: '; showCR:inStream position |
|
1963 |
]. |
|
38 | 1964 |
|
357 | 1965 |
code_length ~~ 0 ifTrue:[ |
1966 |
code := ByteArray new:code_length. |
|
1967 |
inStream nextBytes:code_length into:code startingAt:1. |
|
1968 |
]. |
|
1969 |
Verbose ifTrue:[Transcript show:'method code: '; showCR:code.]. |
|
9 | 1970 |
|
128 | 1971 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
61 | 1972 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
5 | 1973 |
exception_table_length ~~ 0 ifTrue:[ |
348 | 1974 |
Verbose ifTrue:[Transcript show:'exceptionTable length:'; showCR:exception_table_length.]. |
9 | 1975 |
|
348 | 1976 |
exception_table := Array new:exception_table_length. |
1977 |
1 to:exception_table_length do:[:i | |
|
1978 |
|start_pc end_pc handler_pc catch_type| |
|
1 | 1979 |
|
348 | 1980 |
start_pc := inStream nextUnsignedShortMSB:msb. |
1981 |
end_pc := inStream nextUnsignedShortMSB:msb. |
|
1982 |
handler_pc := inStream nextUnsignedShortMSB:msb. |
|
583 | 1983 |
catch_type := inStream nextUnsignedShortMSB:msb. |
1984 |
catch_type ~= 0 ifTrue:[ |
|
1985 |
catch_type := constants at:catch_type. |
|
1986 |
]. |
|
348 | 1987 |
exception_table at:i put:(JavaExceptionTableEntry |
1988 |
startPC:start_pc |
|
1989 |
endPC:end_pc |
|
1990 |
handlerPC:handler_pc |
|
1991 |
catchType:catch_type). |
|
1992 |
]. |
|
1993 |
aJavaMethod setExceptionHandlerTable:exception_table. |
|
1 | 1994 |
]. |
1995 |
||
29 | 1996 |
aJavaMethod |
348 | 1997 |
setCode:code |
1998 |
maxStack:max_stack |
|
1999 |
maxLocals:max_locals |
|
2000 |
u1:unknown1 |
|
2001 |
u2:unknown2. |
|
5 | 2002 |
|
2003 |
self readAttributesFor:aJavaMethod. |
|
2004 |
^ true |
|
2005 |
||
1 | 2006 |
" |
2007 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
5 | 2008 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
1 | 2009 |
" |
2010 |
||
2089 | 2011 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
2012 |
"Modified: / 16.5.1998 / 01:39:42 / cg" |
|
5 | 2013 |
! |
2014 |
||
83 | 2015 |
readExceptionsAttributeFor:aJavaMethod |
2016 |
|attribute_length exception_table_length exception_table| |
|
2017 |
||
128 | 2018 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
83 | 2019 |
|
128 | 2020 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
83 | 2021 |
exception_table_length ~~ 0 ifTrue:[ |
252 | 2022 |
exception_table := Array new:exception_table_length. |
2023 |
1 to:exception_table_length do:[:i | |
|
2024 |
|idx ex| |
|
83 | 2025 |
|
252 | 2026 |
idx := inStream nextUnsignedShortMSB:msb. |
2027 |
ex := constants at:idx. |
|
2028 |
exception_table at:i put:ex. |
|
2029 |
]. |
|
83 | 2030 |
]. |
2031 |
||
2032 |
Verbose ifTrue:[Transcript showCR:'method has an exceptionTable']. |
|
2033 |
||
2034 |
aJavaMethod setExceptionTable:exception_table. |
|
2035 |
^ true |
|
2036 |
||
2037 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2038 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2039 |
! |
|
2040 |
||
5 | 2041 |
readLineNumberTableAttributeFor:aJavaMethod |
2042 |
|attribute_length line_number_table_length line_number_table| |
|
2043 |
||
128 | 2044 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
5 | 2045 |
|
128 | 2046 |
line_number_table_length := inStream nextUnsignedShortMSB:msb. |
5 | 2047 |
line_number_table_length ~~ 0 ifTrue:[ |
330 | 2048 |
line_number_table := Array new:line_number_table_length. |
2049 |
1 to:line_number_table_length do:[:i | |
|
2050 |
|start_pc line_number| |
|
5 | 2051 |
|
330 | 2052 |
start_pc := inStream nextUnsignedShortMSB:msb. |
2053 |
line_number := inStream nextUnsignedShortMSB:msb. |
|
2054 |
line_number_table at:i put:(start_pc -> line_number). |
|
2055 |
]. |
|
2056 |
Verbose ifTrue:[Transcript showCR:'method has a lineNumberTable']. |
|
2057 |
||
2058 |
aJavaMethod setLineNumberTable:line_number_table. |
|
5 | 2059 |
]. |
2060 |
||
2061 |
^ true |
|
2062 |
||
2063 |
" |
|
2064 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2065 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
2066 |
" |
|
2067 |
||
330 | 2068 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
2069 |
"Modified: / 7.4.1998 / 19:08:42 / cg" |
|
1 | 2070 |
! |
2071 |
||
50 | 2072 |
readLocalVariableTableAttributeFor:aJavaMethod |
2073 |
|attribute_length local_variable_table_length local_variable_table| |
|
2074 |
||
128 | 2075 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
50 | 2076 |
|
128 | 2077 |
local_variable_table_length := inStream nextUnsignedShortMSB:msb. |
50 | 2078 |
local_variable_table_length ~~ 0 ifTrue:[ |
252 | 2079 |
local_variable_table := JavaLocalVariableTable new:local_variable_table_length. |
2080 |
1 to:local_variable_table_length do:[:i | |
|
2081 |
|start_pc length name_index sig_index slot name signature| |
|
50 | 2082 |
|
252 | 2083 |
start_pc := inStream nextUnsignedShortMSB:msb. |
2084 |
length := inStream nextUnsignedShortMSB:msb. |
|
2085 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2086 |
name := constants at:name_index. |
|
2087 |
sig_index := inStream nextUnsignedShortMSB:msb. |
|
2088 |
signature := constants at:sig_index. |
|
2089 |
slot := inStream nextUnsignedShortMSB:msb. |
|
50 | 2090 |
|
252 | 2091 |
local_variable_table at:i put:(JavaLocalVariableTableEntry new |
2092 |
startPC:start_pc |
|
2093 |
length:length |
|
2094 |
name:name |
|
2095 |
signature:signature |
|
2096 |
slot:slot) |
|
2097 |
]. |
|
50 | 2098 |
]. |
2099 |
||
61 | 2100 |
Verbose ifTrue:[Transcript showCR:'method has a localvariableTable']. |
50 | 2101 |
|
2102 |
aJavaMethod setLocalVariableTable:local_variable_table. |
|
2103 |
^ true |
|
2104 |
||
2105 |
" |
|
2106 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2107 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
2108 |
" |
|
2109 |
||
2110 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2111 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2112 |
! |
|
2113 |
||
357 | 2114 |
readMethodFor:aClass |
2089 | 2115 |
|m access_flags name_index name signature_index signature |
273 | 2116 |
tooManyArgs| |
1 | 2117 |
|
2118 |
"/ |
|
2119 |
"/ get a method |
|
2120 |
"/ |
|
128 | 2121 |
access_flags := inStream nextUnsignedShortMSB:msb. |
2122 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2089 | 2123 |
signature_index := inStream nextUnsignedShortMSB:msb. |
1 | 2124 |
|
5 | 2125 |
name := constants at:name_index. |
2089 | 2126 |
signature := constants at:signature_index. |
9 | 2127 |
|
357 | 2128 |
Verbose ifTrue:[ |
2129 |
Transcript show:'method name:'; showCR:name. |
|
2089 | 2130 |
Transcript show:'signature:'; showCR:signature. |
357 | 2131 |
]. |
9 | 2132 |
|
357 | 2133 |
aClass isJavaClass ifTrue:[ |
612 | 2134 |
(access_flags bitAnd:JavaMethod A_NATIVE) ~~ 0 ifTrue:[ |
2135 |
m := JavaNativeMethod new. |
|
2136 |
] ifFalse:[ |
|
2137 |
m := JavaMethodWithHandler new. |
|
2138 |
]. |
|
357 | 2139 |
m setAccessFlags:access_flags. |
2140 |
tooManyArgs := false. |
|
2142 | 2141 |
ArgumentError handle:[:ex | |
357 | 2142 |
'JAVA: ***** java method has too many arguments - will fail to execute' infoPrintCR. |
2143 |
tooManyArgs := true. |
|
2144 |
ex proceed. |
|
2145 |
] do:[ |
|
2089 | 2146 |
m setName:name signature:signature. |
357 | 2147 |
]. |
2148 |
m setJavaClass:aClass. |
|
2149 |
||
2150 |
self readAttributesFor:m. |
|
2151 |
||
2152 |
tooManyArgs ifTrue:[ |
|
2153 |
m code:nil. |
|
2154 |
m byteCode:nil. |
|
2155 |
]. |
|
423 | 2156 |
(m exceptionHandlerTable isNil) ifTrue:[ |
612 | 2157 |
m isNative ifFalse:[ |
2089 | 2158 |
m exceptionTable isNil ifTrue:[ |
612 | 2159 |
m := JavaMethod fromMethod:m |
2160 |
] ifFalse:[ |
|
2161 |
m := JavaMethodWithException fromMethod:m |
|
2162 |
] |
|
423 | 2163 |
] |
468 | 2164 |
] ifFalse:[ |
470 | 2165 |
m setAccessFlags:(m accessFlags bitOr:JavaMethod A_HASHANDLER) |
386 | 2166 |
]. |
2089 | 2167 |
aClass addMethod:m name:name signature:signature. |
357 | 2168 |
] ifFalse:[ |
2169 |
m := Method new. |
|
2170 |
self readAttributesFor:m. |
|
2171 |
(access_flags bitTest:JavaMethod A_STATIC) ifTrue:[ |
|
2172 |
aClass class primAddSelector:name asSymbol withMethod:m. |
|
2173 |
] ifFalse:[ |
|
2174 |
aClass primAddSelector:name asSymbol withMethod:m. |
|
2175 |
] |
|
273 | 2176 |
]. |
1 | 2177 |
|
2178 |
" |
|
2179 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2180 |
" |
|
2181 |
||
2089 | 2182 |
"Created: / 15.4.1996 / 16:48:49 / cg" |
2183 |
"Modified: / 25.9.1999 / 23:16:25 / cg" |
|
1 | 2184 |
! |
2185 |
||
38 | 2186 |
readMethodsFor:aJavaClass |
1 | 2187 |
|methodsCount method| |
2188 |
||
2189 |
"/ |
|
2190 |
"/ get methods |
|
2191 |
"/ |
|
128 | 2192 |
methodsCount := inStream nextUnsignedShortMSB:msb. |
61 | 2193 |
Verbose ifTrue:[Transcript show:'methodsCount = '; showCR:methodsCount]. |
1 | 2194 |
|
2195 |
1 to:methodsCount do:[:i | |
|
348 | 2196 |
Verbose ifTrue:[Transcript show:'method: '; showCR:i]. |
2197 |
method := self readMethodFor:aJavaClass |
|
1 | 2198 |
]. |
2199 |
||
2200 |
" |
|
2201 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2202 |
" |
|
2203 |
||
348 | 2204 |
"Created: / 15.4.1996 / 16:46:30 / cg" |
2205 |
"Modified: / 8.5.1998 / 21:20:59 / cg" |
|
1 | 2206 |
! ! |
2207 |
||
344 | 2208 |
!JavaClassReader methodsFor:'file reading - methods-ST'! |
2209 |
||
348 | 2210 |
readSTCodeAttributeFor:aSmalltalkMethod |
2211 |
|attribute_length max_stack max_locals code_length code |
|
2212 |
exception_table_length unknown1 unknown2| |
|
2213 |
||
2214 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2215 |
||
2216 |
Verbose ifTrue:[Transcript show:'attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
|
2217 |
||
2218 |
max_stack := inStream nextUnsignedShortMSB:msb. |
|
2219 |
max_locals := inStream nextUnsignedShortMSB:msb. |
|
2220 |
||
2221 |
code_length := inStream nextUnsignedLongMSB:msb. |
|
2222 |
Verbose ifTrue:[Transcript show:'code_length: '; showCR:(code_length printStringRadix:16)]. |
|
2223 |
Verbose ifTrue:[Transcript show:'code at pos: '; showCR:inStream position]. |
|
2224 |
||
357 | 2225 |
code_length ~~ 0 ifTrue:[ |
2226 |
code := ByteArray new:code_length. |
|
2227 |
inStream nextBytes:code_length into:code startingAt:1. |
|
2228 |
]. |
|
2229 |
Verbose ifTrue:[Transcript show:'method code: '; showCR:code.]. |
|
348 | 2230 |
|
2231 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
|
2232 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
|
2233 |
exception_table_length ~~ 0 ifTrue:[ |
|
2234 |
self error:'unexpected exceptionTable length'. |
|
2235 |
"/ skip it. |
|
2236 |
1 to:exception_table_length do:[:i | |
|
2237 |
"start_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2238 |
"end_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2239 |
"handler_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2240 |
"catch_type :=" inStream nextUnsignedShortMSB:msb. |
|
2241 |
]. |
|
2242 |
]. |
|
2243 |
||
357 | 2244 |
aSmalltalkMethod byteCode:code. |
2245 |
aSmalltalkMethod stackSize:max_stack . |
|
2246 |
aSmalltalkMethod numberOfVars:max_locals. |
|
348 | 2247 |
|
2248 |
self readAttributesFor:aSmalltalkMethod. |
|
2249 |
^ true |
|
2250 |
||
357 | 2251 |
"Modified: / 16.5.1998 / 01:39:30 / cg" |
348 | 2252 |
! |
2253 |
||
344 | 2254 |
readSTLiteralsAttributeFor:aSmalltalkMethod |
348 | 2255 |
|attribute_length literal_table_length literal_table litIndex literal| |
2256 |
||
2257 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2258 |
||
2259 |
literal_table_length := inStream nextUnsignedShortMSB:msb. |
|
2260 |
literal_table_length ~~ 0 ifTrue:[ |
|
2261 |
literal_table := Array new:literal_table_length. |
|
2262 |
1 to:literal_table_length do:[:i | |
|
2263 |
litIndex := inStream nextUnsignedShortMSB:msb. |
|
2264 |
literal := (constants at:litIndex). |
|
2265 |
literal_table at:i put:literal. |
|
2266 |
]. |
|
2267 |
]. |
|
357 | 2268 |
Verbose ifTrue:[Transcript show:'literals: '; showCR:literal_table storeString.]. |
344 | 2269 |
|
2270 |
"Created: / 7.5.1998 / 11:52:28 / cg" |
|
357 | 2271 |
"Modified: / 16.5.1998 / 01:52:27 / cg" |
2272 |
! |
|
2273 |
||
2274 |
readSTMethodCategoryAttributeFor:aSmalltalkMethod |
|
2275 |
|attribute_length name_index name| |
|
2276 |
||
2277 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2278 |
||
2279 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2280 |
name := (constants at:name_index). |
|
2281 |
||
2282 |
aSmalltalkMethod category:name. |
|
2283 |
||
348 | 2284 |
"Modified: / 8.5.1998 / 20:39:59 / cg" |
357 | 2285 |
"Created: / 16.5.1998 / 01:04:19 / cg" |
344 | 2286 |
! ! |
2287 |
||
135 | 2288 |
!JavaClassReader class methodsFor:'documentation'! |
1 | 2289 |
|
2290 |
version |
|
2148 | 2291 |
^ '$Header: /cvs/stx/stx/libjava/JavaClassReader.st,v 1.92 2009-10-09 14:21:53 cg Exp $' |
2292 |
! |
|
2293 |
||
2294 |
version_CVS |
|
2295 |
^ '$Header: /cvs/stx/stx/libjava/JavaClassReader.st,v 1.92 2009-10-09 14:21:53 cg Exp $' |
|
1 | 2296 |
! ! |
2108 | 2297 |
|
2089 | 2298 |
JavaClassReader initialize! |