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