author | vranyj1 |
Tue, 26 Jul 2011 16:31:02 +0000 | |
branch | jk_new_structure |
changeset 877 | f5a5b93e1c78 |
parent 863 | 135fa7c03356 |
child 879 | 8bb82d1ea058 |
permissions | -rw-r--r-- |
752 | 1 |
" |
877 | 2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
3 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
4 |
SWING Research Group, Czech Technical University in Prague |
|
5 |
||
6 |
Parts of the code written by Claus Gittinger are under following |
|
7 |
license: |
|
752 | 8 |
|
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
877 | 15 |
|
16 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
17 |
||
18 |
Permission is hereby granted, free of charge, to any person |
|
19 |
obtaining a copy of this software and associated documentation |
|
20 |
files (the 'Software'), to deal in the Software without |
|
21 |
restriction, including without limitation the rights to use, |
|
22 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
23 |
copies of the Software, and to permit persons to whom the |
|
24 |
Software is furnished to do so, subject to the following |
|
25 |
conditions: |
|
26 |
||
27 |
The above copyright notice and this permission notice shall be |
|
28 |
included in all copies or substantial portions of the Software. |
|
29 |
||
30 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
31 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
32 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
33 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
34 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
35 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
36 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
37 |
OTHER DEALINGS IN THE SOFTWARE. |
|
38 |
||
39 |
[1] Code written at SWING Research Group contain a signature |
|
40 |
of one of the above copright owners. |
|
752 | 41 |
" |
42 |
"{ Package: 'stx:libjava' }" |
|
43 |
||
44 |
Object subclass:#JavaClassReader |
|
45 |
instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots |
|
775 | 46 |
constSlot classBeingLoaded' |
752 | 47 |
classVariableNames:'Verbose AnnotationsVerbose Silent AbsolutelySilent |
48 |
LazyClassLoading InvalidClassFormatSignal ClassLoaderQuerySignal |
|
877 | 49 |
JavaArchiveCache' |
752 | 50 |
poolDictionaries:'' |
51 |
category:'Languages-Java-Support' |
|
52 |
! |
|
53 |
||
54 |
!JavaClassReader class methodsFor:'documentation'! |
|
55 |
||
56 |
copyright |
|
57 |
" |
|
877 | 58 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
59 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
60 |
SWING Research Group, Czech Technical University in Prague |
|
61 |
||
62 |
Parts of the code written by Claus Gittinger are under following |
|
63 |
license: |
|
752 | 64 |
|
65 |
This software is furnished under a license and may be used |
|
66 |
only in accordance with the terms of that license and with the |
|
67 |
inclusion of the above copyright notice. This software may not |
|
68 |
be provided or otherwise made available to, or used by, any |
|
69 |
other person. No title to or ownership of the software is |
|
70 |
hereby transferred. |
|
877 | 71 |
|
72 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
73 |
||
74 |
Permission is hereby granted, free of charge, to any person |
|
75 |
obtaining a copy of this software and associated documentation |
|
76 |
files (the 'Software'), to deal in the Software without |
|
77 |
restriction, including without limitation the rights to use, |
|
78 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
79 |
copies of the Software, and to permit persons to whom the |
|
80 |
Software is furnished to do so, subject to the following |
|
81 |
conditions: |
|
82 |
||
83 |
The above copyright notice and this permission notice shall be |
|
84 |
included in all copies or substantial portions of the Software. |
|
85 |
||
86 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
87 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
88 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
89 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
90 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
91 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
92 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
93 |
OTHER DEALINGS IN THE SOFTWARE. |
|
94 |
||
95 |
[1] Code written at SWING Research Group contain a signature |
|
96 |
of one of the above copright owners. |
|
97 |
||
752 | 98 |
" |
99 |
! ! |
|
100 |
||
101 |
!JavaClassReader class methodsFor:'initialization'! |
|
102 |
||
103 |
initialize |
|
104 |
InvalidClassFormatSignal := Signal new mayProceed: true. |
|
105 |
InvalidClassFormatSignal notifierString: 'class load failure'. |
|
106 |
InvalidClassFormatSignal nameClass: self message: #invalidClassFormatSignal. |
|
107 |
Verbose := false. |
|
108 |
Silent := true. |
|
109 |
AbsolutelySilent := false. |
|
110 |
||
111 |
"/LazyClassLoading := false. |
|
112 |
||
113 |
LazyClassLoading := true. |
|
114 |
ClassLoaderQuerySignal := QuerySignal new. |
|
115 |
JavaArchiveCache := CacheDictionary new: 32. |
|
116 |
AnnotationsVerbose := false. |
|
771 | 117 |
|
752 | 118 |
" |
119 |
JavaClassReader initialize" |
|
120 |
||
121 |
"Modified: / 27-01-1998 / 17:54:23 / cg" |
|
122 |
"Modified: / 17-12-2010 / 17:37:45 / Marcel Hlopko <hlopik@gmail.com>" |
|
772
0f92c23b80ee
testing new project structure + fixing tiny litle bug which caused java not to work at all :)
hlopkmar
parents:
771
diff
changeset
|
123 |
"Modified: / 10-05-2011 / 23:59:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
877 | 124 |
"Modified: / 26-07-2011 / 17:21:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 125 |
! ! |
126 |
||
127 |
!JavaClassReader class methodsFor:'Signal constants'! |
|
128 |
||
129 |
classLoaderQuerySignal |
|
130 |
^ ClassLoaderQuerySignal |
|
131 |
||
132 |
"Created: 14.8.1997 / 19:56:03 / cg" |
|
133 |
! |
|
134 |
||
135 |
invalidClassFormatSignal |
|
136 |
^ InvalidClassFormatSignal |
|
137 |
||
138 |
"Created: 3.8.1997 / 18:17:21 / cg" |
|
139 |
! ! |
|
140 |
||
141 |
!JavaClassReader class methodsFor:'constants'! |
|
142 |
||
143 |
fileMajorVersions |
|
831 | 144 |
^#( |
145 |
46 "Java 1.2" |
|
146 |
49 "Java 5" |
|
147 |
50 "Java 6" |
|
148 |
). |
|
149 |
||
150 |
" |
|
151 |
JSR 202: |
|
152 |
The Java virtual machine implementation of Sun's JDK release 1.0.2 supports |
|
153 |
class file format versions 45.0 through 45.3 inclusive. Sun's JDK releases |
|
154 |
1.1.X can support class file formats of versions in the range 45.0 through |
|
155 |
45.65535 inclusive. For k > 1 implementations of version 1.k of the Java 2 |
|
156 |
platform can support class file formats of versions in the range 45.0 through |
|
157 |
44+k.0 inclusive. |
|
158 |
" |
|
752 | 159 |
|
160 |
"Created: / 19-10-2010 / 21:40:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
830
235c482b462f
- JavaClassReader: do not want about .class file version 50.0
vranyj1
parents:
828
diff
changeset
|
161 |
"Modified: / 01-06-2011 / 21:44:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
831 | 162 |
"Modified: / 02-06-2011 / 22:50:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 163 |
! |
164 |
||
165 |
fileMinorVersions |
|
166 |
^ #( |
|
167 |
3 "Java 1.2" |
|
168 |
0 "Java 6" |
|
169 |
) |
|
170 |
||
171 |
"Created: / 19-10-2010 / 21:41:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
172 |
! |
|
173 |
||
174 |
magic_LSB |
|
175 |
^ 16rBEBAFECA |
|
176 |
||
177 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
178 |
"Created: / 7.5.1998 / 13:15:05 / cg" |
|
179 |
! |
|
180 |
||
181 |
magic_MSB |
|
182 |
^ 16rCAFEBABE |
|
183 |
||
184 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
185 |
! ! |
|
186 |
||
187 |
!JavaClassReader class methodsFor:'debugging'! |
|
188 |
||
189 |
annotationsVerbose:aBoolean |
|
190 |
AnnotationsVerbose := aBoolean |
|
191 |
||
192 |
" |
|
193 |
Java flushClasses. |
|
194 |
JavaClassReader verbose:true |
|
195 |
JavaClassReader verbose:false" |
|
196 |
||
197 |
"Created: / 25-02-2011 / 12:25:23 / Marcel Hlopko <hlopik@gmail.com>" |
|
198 |
! |
|
199 |
||
200 |
verbose:aBoolean |
|
201 |
Verbose := aBoolean |
|
202 |
||
203 |
" |
|
204 |
Java flushClasses. |
|
205 |
JavaClassReader verbose:true |
|
206 |
JavaClassReader verbose:false |
|
207 |
" |
|
208 |
! ! |
|
209 |
||
210 |
!JavaClassReader class methodsFor:'file reading'! |
|
211 |
||
212 |
loadClass:aClassName |
|
213 |
"reads a class, installs and returns it. |
|
214 |
The classes string constants are resolved & <clinit> is called, |
|
215 |
if it implements it." |
|
216 |
||
217 |
|rslt loader| |
|
218 |
||
219 |
loader := ClassLoaderQuerySignal query. |
|
220 |
loader isNil ifTrue:[ |
|
221 |
^ self loadSystemClass:aClassName |
|
222 |
]. |
|
223 |
||
224 |
^ loader loadClass:aClassName |
|
225 |
||
226 |
" |
|
227 |
JavaClassReader loadClass:'awt/Component' |
|
228 |
JavaClassReader loadClass:'awt/Button' |
|
229 |
JavaClassReader loadClass:'browser/AddButton' |
|
230 |
||
231 |
JavaClassReader loadClass:'java/lang/Object' |
|
232 |
JavaClassReader loadClass:'java/lang/AbstractMethodError' |
|
233 |
JavaClassReader loadClass:'java/lang/Thread' |
|
234 |
" |
|
235 |
||
236 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
|
237 |
"Modified: / 20.10.1998 / 17:24:54 / cg" |
|
238 |
! |
|
239 |
||
761 | 240 |
loadClassLazy: internalJavaClassName |
241 |
^ self loadClassLazy: internalJavaClassName ignoring: Set new. |
|
758 | 242 |
|
243 |
"Created: / 08-04-2011 / 18:00:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
761 | 244 |
"Modified: / 11-04-2011 / 19:31:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 245 |
! |
246 |
||
752 | 247 |
loadClassLazy: aClassName ignoring: classesBeingLoaded |
248 |
"private helper: |
|
249 |
reads a class, installs and returns it. |
|
250 |
The class is searched along the ClassPath. |
|
251 |
||
252 |
This is a partial load (to load other classes): |
|
253 |
- The classes stringConstants are not fixed to be JavaStrings |
|
254 |
(i.e they are still ST-Strings). |
|
255 |
- The class is NOT initialized." |
|
256 |
||
257 |
| rslt clsName cls loadedClass | |
|
258 |
||
259 |
clsName := aClassName. |
|
260 |
(clsName endsWith: ';') |
|
261 |
ifTrue: |
|
262 |
[ (clsName startsWith: '[L') |
|
263 |
ifTrue: [ clsName := clsName copyFrom: 3 to: clsName size - 1. ] |
|
264 |
ifFalse: |
|
265 |
[ ('oops - loading of ' , clsName , ' attempted') printNL. |
|
266 |
self halt: 'should not happen'. |
|
267 |
^ nil. ] ]. |
|
268 |
(clsName endsWith: '[]') |
|
269 |
ifTrue: |
|
270 |
[ ('oops - loading of ' , clsName , ' attempted') printNL. |
|
271 |
self halt: 'should not happen'. |
|
272 |
^ nil ]. |
|
273 |
(clsName includes: $.) |
|
274 |
ifTrue: [ clsName := clsName asString copyReplaceAll: $. with: $/ ]. |
|
275 |
(classesBeingLoaded notNil and: [ classesBeingLoaded includes: clsName ]) |
|
276 |
ifTrue: |
|
277 |
[ ('oops - recursive load of ' , clsName , ' attempted') printNL. |
|
278 |
self halt: 'should not happen'. |
|
279 |
^ JavaUnresolvedClassConstant fullName: clsName ]. |
|
280 |
(cls := Java at: clsName) notNil |
|
281 |
ifTrue: |
|
282 |
[ ('oops - ' , clsName , ' is already loaded') printNL. |
|
283 |
||
284 |
"/self halt:clsName , ' is already loaded - should not happen'. |
|
285 |
||
286 |
^ cls ]. |
|
287 |
classesBeingLoaded isNil |
|
288 |
ifTrue: [ loadedClass := Set with: clsName ] |
|
289 |
ifFalse: |
|
290 |
[ loadedClass := Set withAll: classesBeingLoaded. |
|
291 |
loadedClass add: clsName. ]. |
|
292 |
Java effectiveClassPath do: |
|
293 |
[:path | |
|
294 |
| nm p zar entry zipFile read | |
|
295 |
||
296 |
Verbose == true |
|
297 |
ifTrue: [ Transcript showCR: 'trying ' , path asFilename pathName , ' ...'. ]. |
|
298 |
p := path. |
|
299 |
p asFilename isDirectory |
|
300 |
ifTrue: |
|
301 |
[ (p endsWith: Filename separator) |
|
302 |
ifFalse: [ p := p , (Filename separator asString) ]. |
|
303 |
(Array |
|
304 |
with: clsName |
|
305 |
with: clsName asLowercase |
|
306 |
with: clsName asUppercase) do: |
|
307 |
[:tryName | |
|
308 |
nm := p , tryName , '.class'. |
|
309 |
Verbose == true ifTrue: [ Transcript showCR: 'trying ' , nm , ' ...'. ]. |
|
310 |
nm asFilename exists |
|
311 |
ifTrue: |
|
312 |
[ (Java isExcludedFromClassPath: nm) |
|
313 |
ifFalse: |
|
314 |
[ rslt := self loadFileLazy: nm ignoring: loadedClass. |
|
315 |
rslt notNil ifTrue: [ ^ rslt ]. ] ]. ] ] |
|
316 |
ifFalse: |
|
317 |
[ Verbose == true |
|
318 |
ifTrue: |
|
319 |
[ Transcript |
|
320 |
showCR: 'trying ' , (p asFilename withSuffix: 'jar') pathName , ' ...'. |
|
321 |
Transcript |
|
322 |
showCR: 'and ' , (p asFilename withSuffix: 'zip') pathName , ' ...'. ]. |
|
323 |
((zipFile := p asFilename withSuffix: 'jar') exists |
|
324 |
or: [ (zipFile := p asFilename withSuffix: 'zip') exists ]) |
|
325 |
ifTrue: |
|
326 |
[ |
|
327 |
zar := JavaArchiveCache at: zipFile |
|
328 |
ifAbsentPut: [ ZipArchive oldFileNamed: zipFile ]. |
|
329 |
read := |
|
330 |
[ nm := clsName , '.class'. |
|
331 |
entry := zar extract: nm. |
|
332 |
entry notNil |
|
333 |
ifTrue: |
|
334 |
[ (Java isExcludedFromClassPath: nm) |
|
335 |
ifFalse: |
|
336 |
[ rslt := self loadStreamLazy: (entry readStream) ignoring: loadedClass. |
|
337 |
rslt notNil ifTrue: [ ^ rslt ]. ] ] ]. |
|
338 |
JavaClassReader invalidClassFormatSignal handle: |
|
339 |
[ "Kludge, sometimes zar gets corrupted" |
|
340 |
||
341 |
zar := JavaArchiveCache at: zipFile put: (ZipArchive oldFileNamed: zipFile). |
|
342 |
read value ] |
|
343 |
do: [ read value ]. ] ] ]. |
|
344 |
('JAVA [info]: no file found for: ' , clsName) infoPrintCR. |
|
345 |
^ nil |
|
346 |
||
347 |
"Modified: / 14-08-1997 / 11:38:42 / stefan" |
|
348 |
"Modified: / 17-09-1998 / 20:51:25 / cg" |
|
349 |
"Modified: / 18-03-2011 / 16:06:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
350 |
"Modified: / 21-03-2011 / 12:42:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
351 |
! |
|
352 |
||
353 |
loadClassesIn: directory |
|
848
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
354 |
"load all classes (.class files, strictly speaking) found in given directory. |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
355 |
The argument is string containing the name of the directory. |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
356 |
|
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
357 |
Returns a set of loaded classes." |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
358 |
|
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
359 |
^self loadClassesIn: directory matching: '*' |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
360 |
|
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
361 |
"Modified: / 11-06-2011 / 13:35:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
362 |
! |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
363 |
|
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
364 |
loadClassesIn: directory matching: pattern |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
365 |
"load all classes (.class files, strictly speaking) found in given directory. |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
366 |
The arguments are a string containing the name of the directory |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
367 |
and a class name pattern. Only classes matching the pattern are loaded. |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
368 |
class names are matched using String>>matches:. |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
369 |
|
758 | 370 |
Returns a set of loaded classes." |
752 | 371 |
|
758 | 372 |
| dir dirString className loadedClasses | |
373 |
||
848
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
374 |
dir := directory asFilename asAbsoluteFilename. |
752 | 375 |
loadedClasses := Set new. |
376 |
Java addToClassPath: dir pathName. |
|
377 |
dir recursiveDirectoryContentsAsFilenamesDo: |
|
849 | 378 |
[:filename | |
752 | 379 |
(filename isRegularFile and: [ filename suffix = #class ]) |
380 |
ifTrue: |
|
848
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
381 |
[ dirString := dir pathName. |
752 | 382 |
className := filename withoutSuffix pathName. |
383 |
className := className subString: dirString size + 2 to: className size. |
|
848
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
384 |
className := className copyReplaceAll: (Filename separator) with: $.. |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
385 |
(className matches: pattern) ifTrue: |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
386 |
[loadedClasses add: (self loadClass: className)]]]. |
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
387 |
|
761 | 388 |
^ loadedClasses. |
752 | 389 |
|
761 | 390 |
"Modified: / 29-04-2011 / 17:43:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
848
b06ee9c295d9
Utility methods to load relevant subset of Mauve test suite
vranyj1
parents:
831
diff
changeset
|
391 |
"Created: / 11-06-2011 / 13:34:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
849 | 392 |
"Modified: / 11-06-2011 / 16:19:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 393 |
! |
394 |
||
395 |
loadFile:aFilename |
|
396 |
"reads a class from aFilename, installs and returns it. |
|
397 |
The classes strings are fixed and its class-init function is called." |
|
398 |
||
399 |
self loadFileLazy:aFilename ignoring:(Set new). |
|
400 |
self postLoadActions |
|
401 |
! |
|
402 |
||
403 |
loadFileLazy:aFilename ignoring:classesBeingLoaded |
|
404 |
"reads a class from aFilename, installs and returns it. |
|
405 |
Strings are fixed and classrefs are fixed, |
|
406 |
but NO no class-init functions are called." |
|
407 |
||
408 |
|aClass pool| |
|
409 |
||
410 |
aClass := self readFile:aFilename ignoring:classesBeingLoaded. |
|
411 |
aClass notNil ifTrue:[ |
|
412 |
aClass isJavaClass ifTrue:[ |
|
413 |
"/ a java class |
|
414 |
Java at:(aClass fullName asSymbol) put:aClass. |
|
415 |
||
416 |
classesBeingLoaded remove:aClass fullName ifAbsent:nil. |
|
417 |
||
418 |
JavaUnresolvedConstant resolveFor:aClass. |
|
419 |
] ifFalse:[ |
|
420 |
"/ a smalltalk class |
|
421 |
"/ self halt. |
|
422 |
aClass inspect. |
|
423 |
] |
|
424 |
]. |
|
425 |
^ aClass |
|
426 |
||
427 |
" |
|
428 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
429 |
||
430 |
'/phys/ibm3/java/lib/java/lang' asFilename |
|
431 |
directoryContents do:[:nm | |
|
432 |
(nm endsWith:'.class') ifTrue:[ |
|
433 |
('/phys/ibm3/java/lib/java/lang/' , nm) printNL. |
|
434 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/' , nm |
|
435 |
] |
|
436 |
]. |
|
437 |
||
438 |
'/phys/ibm3/java/lib/java/io' asFilename |
|
439 |
directoryContents do:[:nm | |
|
440 |
(nm endsWith:'.class') ifTrue:[ |
|
441 |
('/phys/ibm3/java/lib/java/io/' , nm) printNL. |
|
442 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/io/' , nm |
|
443 |
] |
|
444 |
]. |
|
445 |
||
446 |
'/phys/ibm3/java/lib/java/net' asFilename |
|
447 |
directoryContents do:[:nm | |
|
448 |
(nm endsWith:'.class') ifTrue:[ |
|
449 |
('/phys/ibm3/java/lib/java/net/' , nm) printNL. |
|
450 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/net/' , nm |
|
451 |
] |
|
452 |
]. |
|
453 |
||
454 |
'/phys/ibm3/java/lib/java/util' asFilename |
|
455 |
directoryContents do:[:nm | |
|
456 |
(nm endsWith:'.class') ifTrue:[ |
|
457 |
('/phys/ibm3/java/lib/java/util/' , nm) printNL. |
|
458 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/util/' , nm |
|
459 |
] |
|
460 |
]. |
|
461 |
||
462 |
'/phys/ibm3/java/lib/java/awt' asFilename |
|
463 |
directoryContents do:[:nm | |
|
464 |
(nm endsWith:'.class') ifTrue:[ |
|
465 |
('/phys/ibm3/java/lib/java/awt/' , nm) printNL. |
|
466 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/awt/' , nm |
|
467 |
] |
|
468 |
]. |
|
469 |
||
470 |
'/phys/ibm3/java/lib/java/applet' asFilename |
|
471 |
directoryContents do:[:nm | |
|
472 |
(nm endsWith:'.class') ifTrue:[ |
|
473 |
('/phys/ibm3/java/lib/java/applet/' , nm) printNL. |
|
474 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/applet/' , nm |
|
475 |
] |
|
476 |
]. |
|
477 |
||
478 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/AbstractMethodError.class' |
|
479 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/Thread.class' |
|
480 |
" |
|
481 |
||
482 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
|
483 |
"Modified: / 12.5.1998 / 22:06:52 / cg" |
|
484 |
! |
|
485 |
||
486 |
loadStreamLazy:aStream ignoring:classesBeingLoaded |
|
487 |
"reads a class from aStream, installs and returns it. |
|
488 |
Strings are fixed and classrefs are fixed, |
|
489 |
but NO no class-init functions are called." |
|
490 |
||
491 |
|javaClass pool| |
|
492 |
||
493 |
javaClass := self readStream:aStream ignoring:classesBeingLoaded. |
|
494 |
javaClass notNil ifTrue:[ |
|
495 |
Java at:(javaClass fullName asSymbol) put:javaClass. |
|
496 |
||
497 |
classesBeingLoaded remove:javaClass fullName ifAbsent:nil. |
|
498 |
||
499 |
JavaUnresolvedConstant resolveFor:javaClass. |
|
500 |
]. |
|
501 |
^ javaClass |
|
502 |
||
503 |
"Created: / 30.3.1998 / 17:59:02 / cg" |
|
504 |
! |
|
505 |
||
771 | 506 |
loadSystemClass: aClassName |
752 | 507 |
"reads a class, installs and returns it. |
508 |
The classes string constants are resolved & <clinit> is called, |
|
509 |
if it implements it. |
|
510 |
This only loads local classes (i.e. any Java classReader is not used)" |
|
771 | 511 |
|
512 |
| rslt | |
|
513 |
||
877 | 514 |
rslt := JavaClassReader loadClassLazy: aClassName ignoring: (Set new). |
515 |
rslt notNil ifTrue: [ JavaClassReader postLoadActions ]. |
|
809 | 516 |
self assert: rslt constantPool owner == rslt. |
784 | 517 |
rslt ifNil: [self breakPoint:#mh]. |
752 | 518 |
^ rslt |
519 |
||
520 |
" |
|
521 |
JavaClassReader loadSystemClass:'awt/Component' |
|
522 |
JavaClassReader loadSystemClass:'awt/Button' |
|
523 |
JavaClassReader loadSystemClass:'browser/AddButton' |
|
524 |
||
525 |
JavaClassReader loadSystemClass:'java/lang/Object' |
|
526 |
JavaClassReader loadSystemClass:'java/lang/AbstractMethodError' |
|
771 | 527 |
JavaClassReader loadSystemClass:'java/lang/Thread'" |
528 |
||
529 |
"Created: / 20-10-1998 / 17:24:40 / cg" |
|
784 | 530 |
"Modified: / 13-05-2011 / 17:50:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
877 | 531 |
"Modified: / 26-07-2011 / 17:21:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 532 |
! |
533 |
||
534 |
postLoadActions |
|
535 |
"Resolve all classes' string constants. |
|
536 |
Perform all class initialization functions (of those which are not |
|
537 |
yet initialized)." |
|
538 |
||
539 |
^ self postLoadActions:true |
|
540 |
||
541 |
"Modified: 15.8.1997 / 01:02:17 / cg" |
|
542 |
! |
|
543 |
||
544 |
postLoadActions:loadUnresolved |
|
545 |
"Resolve all classes' string constants. |
|
546 |
Perform all class initialization functions |
|
547 |
(of those which are not yet initialized)." |
|
548 |
||
549 |
|classes prevUnresolved newUnresolved loader| |
|
550 |
||
551 |
"/ need at least java.lang.String, for valid constants |
|
552 |
Java java_lang_String isNil ifTrue:[ |
|
553 |
self loadClassLazy:'java.lang.String' ignoring:(Set new). |
|
554 |
]. |
|
555 |
||
556 |
LazyClassLoading ifFalse:[ |
|
557 |
loader := ClassLoaderQuerySignal query. |
|
558 |
||
559 |
prevUnresolved := nil. |
|
560 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
561 |
loadUnresolved ifTrue:[ |
|
562 |
[prevUnresolved ~= newUnresolved] whileTrue:[ |
|
563 |
newUnresolved do:[:nextUnresolved | |
|
564 |
|classURL| |
|
565 |
||
566 |
(Java at:nextUnresolved) isNil ifTrue:[ "/ could have been loaded in the meantime |
|
567 |
Silent ifFalse:[ |
|
568 |
'loading unresolved: ' print. nextUnresolved printCR. |
|
569 |
]. |
|
570 |
loader isNil ifTrue:[ |
|
571 |
self |
|
572 |
loadClassLazy:nextUnresolved |
|
573 |
ignoring:(Set new). |
|
574 |
] ifFalse:[ |
|
575 |
"/ |
|
576 |
"/ the aquired loader is a javaClassLoader |
|
577 |
"/ which expects an URL as arg. |
|
578 |
"/ |
|
579 |
"/ classURL := Java as_URL:('file:' , nextUnresolved asString , '.class'). |
|
580 |
"/ loader loadClass:classURL |
|
581 |
loader |
|
582 |
perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
583 |
with:(Java as_String:(nextUnresolved asString)). |
|
584 |
] |
|
585 |
] |
|
586 |
]. |
|
587 |
prevUnresolved := newUnresolved. |
|
588 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
589 |
]. |
|
590 |
]. |
|
591 |
false ifTrue:[ |
|
592 |
newUnresolved size == 0 ifTrue:[ |
|
593 |
"/ nothing unresolved |
|
594 |
||
595 |
(classes := Java allClasses) notNil ifTrue:[ |
|
596 |
"/ init all new classes |
|
597 |
"/ fetch again - there could be new ones ... |
|
598 |
||
599 |
classes := Java allClasses. |
|
600 |
classes do:[:aJavaClass | |
|
601 |
aJavaClass isInitialized ifFalse:[ |
|
602 |
Silent ifFalse:[ |
|
603 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
604 |
]. |
|
605 |
aJavaClass classInit |
|
606 |
] |
|
607 |
] |
|
608 |
] |
|
609 |
]. |
|
610 |
]. |
|
611 |
] |
|
612 |
||
613 |
"Created: / 15.8.1997 / 01:01:44 / cg" |
|
614 |
"Modified: / 21.10.1998 / 01:18:35 / cg" |
|
615 |
! |
|
616 |
||
617 |
readFile:aFilename ignoring:classesBeingLoaded |
|
618 |
"reads a class from aFilename and returns it. |
|
619 |
The JavaClass is NOT installed as global and unresolved |
|
620 |
refs are NOT patched." |
|
621 |
||
622 |
|inStream javaClass| |
|
623 |
||
624 |
"Silent"false ifFalse:[ |
|
625 |
'reading ' print. aFilename print. ' ...' printCR. |
|
626 |
]. |
|
627 |
ObjectMemory compressingGarbageCollect. |
|
628 |
||
629 |
[ |
|
630 |
inStream := aFilename asFilename readStream. |
|
631 |
] on:StreamError do:[:ex| |
|
632 |
('JAVA [info]: no file: ' , aFilename asString) printCR. |
|
633 |
self halt. |
|
634 |
^ nil |
|
635 |
]. |
|
636 |
||
637 |
javaClass := self new readStream:inStream ignoring:classesBeingLoaded. |
|
638 |
(javaClass notNil and:[javaClass isJavaClass]) ifTrue:[ |
|
639 |
javaClass setBinaryFilePath:(inStream pathName). |
|
640 |
]. |
|
641 |
inStream close. |
|
642 |
||
643 |
ObjectMemory compressingGarbageCollect. |
|
644 |
AbsolutelySilent ifFalse:[ |
|
645 |
' ... loaded ' print. javaClass displayString printNL. |
|
646 |
]. |
|
647 |
||
648 |
||
649 |
^ javaClass |
|
650 |
||
651 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
|
652 |
"Modified: / 9.5.1998 / 01:44:24 / cg" |
|
653 |
! |
|
654 |
||
655 |
readStream:aStream |
|
656 |
"reads a class from aStream and returns it. |
|
657 |
The JavaClass is installed as global. |
|
658 |
If new classes are required to be loaded, a new standard loader |
|
659 |
is created." |
|
660 |
||
661 |
^ self readStream:aStream loader:nil |
|
662 |
||
663 |
"Modified: 14.8.1997 / 19:51:50 / cg" |
|
664 |
! |
|
665 |
||
771 | 666 |
readStream: aStream ignoring: classesBeingLoaded |
752 | 667 |
"reads a class from aStream and returns it. |
668 |
The JavaClass is not installed as global" |
|
771 | 669 |
|
670 |
| javaClass | |
|
671 |
||
877 | 672 |
javaClass := JavaClassReader new readStream: aStream ignoring: classesBeingLoaded. |
771 | 673 |
AbsolutelySilent |
674 |
ifFalse: |
|
675 |
[ ' ... loaded ' print. |
|
676 |
javaClass displayString printNL. ]. |
|
752 | 677 |
^ javaClass |
678 |
||
771 | 679 |
"Modified: / 30-03-1998 / 18:14:40 / cg" |
680 |
"Modified: / 09-05-2011 / 23:15:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
877 | 681 |
"Modified: / 26-07-2011 / 17:21:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 682 |
! |
683 |
||
684 |
readStream:aStream loader:aClassLoader |
|
685 |
"reads a class from aStream and returns it. |
|
686 |
The JavaClass is installed as global. |
|
687 |
If new classes are required to be loaded, aClassLoader is |
|
688 |
asked to do it. If aClassLoader is nil, a new standard loader |
|
689 |
is created." |
|
690 |
||
691 |
^ self |
|
692 |
readStream:aStream |
|
693 |
loader:aClassLoader |
|
694 |
loadUnresolved:true |
|
695 |
||
696 |
"Modified: 15.8.1997 / 01:00:35 / cg" |
|
697 |
! |
|
698 |
||
771 | 699 |
readStream: aStream loader: aClassLoader loadUnresolved: loadUnresolved |
752 | 700 |
"reads a class from aStream and returns it. |
701 |
The JavaClass is installed as global. |
|
702 |
If new classes are required to be loaded, aClassLoader is |
|
703 |
asked to do it. If aClassLoader is nil, a new standard loader |
|
704 |
is created." |
|
771 | 705 |
|
706 |
| javaClass | |
|
707 |
||
708 |
ClassLoaderQuerySignal answer: aClassLoader |
|
709 |
do: |
|
710 |
[ javaClass := self readStream: aStream ignoring: (Set new). |
|
711 |
javaClass notNil |
|
712 |
ifTrue: |
|
877 | 713 |
[ JavaClassReader postLoadActions: loadUnresolved. |
771 | 714 |
Java at: (javaClass fullName asSymbol) put: javaClass. |
715 |
JavaUnresolvedConstant resolveFor: javaClass. ]. ]. |
|
752 | 716 |
^ javaClass |
717 |
||
771 | 718 |
"Created: / 15-08-1997 / 00:59:24 / cg" |
719 |
"Modified: / 23-01-1998 / 17:14:09 / cg" |
|
720 |
"Modified: / 09-05-2011 / 23:15:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
877 | 721 |
"Modified: / 26-07-2011 / 17:21:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 722 |
! |
723 |
||
724 |
resolveClass:aJavaClass |
|
725 |
"Resolve a particular classes' constants. |
|
726 |
Perform all class initialization functions |
|
727 |
(of those which are not yet initialized)." |
|
728 |
||
729 |
|loader classToLoad| |
|
730 |
||
731 |
LazyClassLoading ifFalse:[ |
|
732 |
loader := (aJavaClass classLoader). "/ ? (ClassLoaderQuerySignal raise). |
|
733 |
||
734 |
[ |
|
735 |
classToLoad := nil. |
|
736 |
aJavaClass constantPool do:[:item | |
|
737 |
|itemClass | |
|
738 |
||
739 |
itemClass := item class. |
|
740 |
itemClass == JavaUnresolvedClassConstant ifTrue:[ |
|
741 |
classToLoad := item className. |
|
742 |
"/ ] ifFalse:[ |
|
743 |
"/ itemClass == JavaUnresolvedMethodrefConstant ifTrue:[ |
|
744 |
"/self halt. |
|
745 |
"/ ] ifFalse:[ |
|
746 |
"/ itemClass == JavaUnresolvedInterfaceMethodrefConstant ifTrue:[ |
|
747 |
"/self halt. |
|
748 |
"/ ] |
|
749 |
"/ ] |
|
750 |
]. |
|
751 |
]. |
|
752 |
||
753 |
classToLoad notNil ifTrue:[ |
|
754 |
loader isNil ifTrue:[ |
|
755 |
self |
|
756 |
loadClassLazy:classToLoad |
|
757 |
ignoring:(Set new). |
|
758 |
] ifFalse:[ |
|
759 |
"/ |
|
760 |
"/ the aquired loader is a javaClassLoader |
|
761 |
"/ which expects an URL as arg. |
|
762 |
"/ |
|
763 |
"/ classURL := Java as_URL:('file:' , nextUnresolved asString , '.class'). |
|
764 |
"/ loader loadClass:classURL |
|
765 |
loader |
|
766 |
perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
767 |
with:(Java as_String:(classToLoad asString)). |
|
768 |
] |
|
769 |
]. |
|
770 |
classToLoad notNil. |
|
771 |
] whileTrue. |
|
772 |
||
773 |
aJavaClass isInitialized ifFalse:[ |
|
774 |
Silent ifFalse:[ |
|
775 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
776 |
]. |
|
777 |
aJavaClass classInit |
|
778 |
]. |
|
779 |
] |
|
780 |
||
781 |
"Created: / 20.10.1998 / 17:53:22 / cg" |
|
782 |
"Modified: / 20.10.1998 / 17:59:09 / cg" |
|
783 |
! ! |
|
784 |
||
771 | 785 |
!JavaClassReader class methodsFor:'mode setting'! |
786 |
||
787 |
useOldClassReader |
|
863
135fa7c03356
Force use JavaClassReader2 since the VM does not actually support
vranyj1
parents:
849
diff
changeset
|
788 |
self error: 'Old class reader should not be used anymore!!'. |
771 | 789 |
UsedJavaClassReaderClass := JavaClassReader. |
790 |
||
791 |
"Created: / 09-05-2011 / 23:11:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
792 |
! ! |
|
793 |
||
794 |
!JavaClassReader methodsFor:'accessing'! |
|
795 |
||
796 |
constants |
|
797 |
^ constants. |
|
798 |
||
799 |
"Created: / 10-05-2011 / 13:48:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
800 |
! |
|
801 |
||
802 |
constants: aJavaConstantPool |
|
803 |
constants := aJavaConstantPool. |
|
804 |
||
805 |
"Created: / 10-05-2011 / 13:48:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
806 |
! |
|
807 |
||
808 |
stream |
|
809 |
^ inStream. |
|
810 |
||
811 |
"Created: / 09-05-2011 / 23:22:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
812 |
! |
|
813 |
||
814 |
stream:aReadStream |
|
815 |
inStream := aReadStream. |
|
816 |
||
817 |
"Created: / 09-05-2011 / 23:23:11 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
818 |
! ! |
|
819 |
||
752 | 820 |
!JavaClassReader methodsFor:'file reading'! |
821 |
||
771 | 822 |
readClassFileIgnoring: classesbeingLoaded |
752 | 823 |
"reads a class from inStream and returns it. |
824 |
The JavaClass is not installed as global and its constants |
|
825 |
(especially strings) may not be fully resolved." |
|
826 |
||
798
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
827 |
| magic access_flags this_class_index super_class super_class_index this_class_ref existingSuperClass fields interfaces staticFields nStatic superClassName thisClassName existing_class thisMetaClass | |
752 | 828 |
|
829 |
"/ |
|
830 |
"/ read magic, determine byte order |
|
831 |
"/ |
|
832 |
msb := true. |
|
771 | 833 |
magic := inStream nextUnsignedLongMSB: true. |
834 |
magic = (self class magic_MSB) |
|
835 |
ifFalse: |
|
836 |
[ magic = (self class magic_LSB) |
|
837 |
ifFalse: |
|
838 |
[ InvalidClassFormatSignal raiseErrorString: 'not a java class file'. |
|
839 |
^ nil ]. |
|
840 |
msb := false. |
|
841 |
Verbose ifTrue: [ Transcript showCR: 'file is lsb' ]. ] |
|
842 |
ifTrue: [ Verbose ifTrue: [ Transcript showCR: 'file is msb' ]. ]. |
|
752 | 843 |
|
844 |
"/ |
|
845 |
"/ get version |
|
846 |
"/ |
|
847 |
||
771 | 848 |
minorVsn := inStream nextUnsignedShortMSB: msb. |
849 |
majorVsn := inStream nextUnsignedShortMSB: msb. |
|
850 |
((self class fileMajorVersions includes: majorVsn) not |
|
851 |
or: [ (self class fileMinorVersions includes: minorVsn) not ]) |
|
852 |
ifTrue: |
|
853 |
[ Transcript |
|
854 |
show: 'warning this file has version '; |
|
855 |
show: majorVsn; |
|
856 |
show: '.'; |
|
857 |
showCR: minorVsn. ]. |
|
858 |
Verbose |
|
859 |
ifTrue: |
|
860 |
[ Transcript |
|
861 |
show: 'version = '; |
|
862 |
show: (majorVsn printString); |
|
863 |
show: '.'; |
|
864 |
showCR: (minorVsn printString). ]. |
|
752 | 865 |
|
866 |
"/ |
|
867 |
"/ get constant pool |
|
868 |
"/ |
|
869 |
||
870 |
self readConstantPool. |
|
871 |
||
872 |
"/ |
|
873 |
"/ access flags |
|
874 |
"/ |
|
875 |
||
771 | 876 |
access_flags := inStream nextUnsignedShortMSB: msb. |
877 |
this_class_index := inStream nextUnsignedShortMSB: msb. |
|
878 |
super_class_index := inStream nextUnsignedShortMSB: msb. |
|
879 |
super_class_index == 0 |
|
880 |
ifTrue: [ super_class := nil ] |
|
881 |
ifFalse: |
|
882 |
[ super_class := constants at: super_class_index. |
|
883 |
superClassName := super_class fullName. |
|
884 |
||
885 |
"/ special for ST-classes |
|
886 |
||
887 |
(superClassName startsWith: 'smalltalk.') |
|
888 |
ifTrue: |
|
889 |
[ "/ a Smalltalk class |
|
890 |
superClassName := superClassName copyFrom: 11. |
|
891 |
existingSuperClass := Smalltalk at: superClassName asSymbol. |
|
892 |
existingSuperClass notNil |
|
893 |
ifTrue: [ super_class := existingSuperClass ] |
|
894 |
ifFalse: |
|
895 |
[ "/ self halt - must load superclass ... |
|
896 |
] ] |
|
897 |
ifFalse: |
|
898 |
[ "/ a JAVA class |
|
798
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
899 |
super_class := Java classNamed: superClassName. |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
900 |
super_class ifNil: |
799 | 901 |
[ super_class := self loadSuperclassIdentifiedBy: (constants at: super_class_index) |
798
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
902 |
ignoring: classesbeingLoaded ]. |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
903 |
super_class ifNil: [ self halt: 'Cannot find super class?!!' ]. ]. ]. |
752 | 904 |
|
905 |
"/ |
|
906 |
"/ get interfaces |
|
907 |
"/ |
|
908 |
||
909 |
interfaces := self readInterfaces. |
|
910 |
||
911 |
"/ |
|
912 |
"/ get fields |
|
913 |
"/ |
|
914 |
||
915 |
fields := self readFieldInfofields. |
|
916 |
||
917 |
"/ |
|
918 |
"/ create the fields as instVars |
|
919 |
"/ static fields are created as class-InstVars |
|
920 |
"/ |
|
798
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
921 |
|
771 | 922 |
staticFields := fields select: [:f | f isStatic ]. |
752 | 923 |
nStatic := staticFields size. |
771 | 924 |
this_class_ref := constants at: this_class_index. |
752 | 925 |
thisClassName := this_class_ref fullName. |
926 |
||
927 |
"/ care for smalltalk classes ... |
|
928 |
||
771 | 929 |
(thisClassName startsWith: 'smalltalk.') |
930 |
ifTrue: |
|
931 |
[ thisClassName := thisClassName copyFrom: 11. |
|
932 |
existing_class := Smalltalk at: thisClassName asSymbol. |
|
933 |
existing_class notNil |
|
934 |
ifTrue: |
|
935 |
[ self halt: ('overloading existing class: ' , thisClassName). |
|
936 |
thisClassName := (thisClassName , '_new') asSymbol. ]. |
|
937 |
thisMetaClass := Metaclass new. |
|
938 |
thisMetaClass setSuperclass: super_class class. |
|
939 |
thisMetaClass instSize: (super_class class instSize + nStatic). |
|
775 | 940 |
classBeingLoaded := thisMetaClass new. |
941 |
classBeingLoaded setSuperclass: super_class. |
|
942 |
classBeingLoaded setName: thisClassName asSymbol. ] |
|
771 | 943 |
ifFalse: |
944 |
[ "/ a java class |
|
775 | 945 |
classBeingLoaded := JavaClass fullName: thisClassName numStatic: nStatic. |
811 | 946 |
|
947 |
fields := fields select: [:f | f isStatic not ]. |
|
948 |
||
949 |
JavaClass setInstanceVariableStringFromFields: staticFields |
|
950 |
in: classBeingLoaded class. |
|
951 |
||
952 |
classBeingLoaded setStaticFields: staticFields. |
|
953 |
classBeingLoaded initializeStaticFields. |
|
775 | 954 |
classBeingLoaded setAccessFlags: access_flags. |
955 |
classBeingLoaded setSuperclass: super_class. |
|
956 |
classBeingLoaded setConstantPool: constants. |
|
957 |
classBeingLoaded setFields: fields. |
|
958 |
classBeingLoaded setInterfaces: interfaces. |
|
809 | 959 |
]. |
752 | 960 |
|
961 |
"/ |
|
962 |
"/ get methods |
|
963 |
"/ |
|
964 |
||
775 | 965 |
self readMethodsFor: classBeingLoaded. |
966 |
self readAttributesFor: classBeingLoaded. |
|
809 | 967 |
"/ classBeingLoaded constantPool |
968 |
"/ do: [:each | self updateOwnerInCPItem: each ]. |
|
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
969 |
classBeingLoaded fields do: [:each | self updateOwnerInField: each ]. |
797
8d4e7c17eadd
fixed JavaClassReader so it always sets staticFields
hlopkmar
parents:
796
diff
changeset
|
970 |
classBeingLoaded staticFields do: [:each | self updateOwnerInField: each ]. |
775 | 971 |
^ classBeingLoaded. |
752 | 972 |
|
973 |
" |
|
974 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
975 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
976 |
JavaClassReader loadFile:'foo.cls' |
|
977 |
||
978 |
JavaClassReader verbose:true. |
|
979 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/java/lang/ArithmeticException.class' |
|
980 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/ArithmeticException.class'" |
|
981 |
||
982 |
"Created: / 15-04-1996 / 15:02:47 / cg" |
|
983 |
"Modified: / 12-11-1998 / 21:14:45 / cg" |
|
984 |
"Modified: / 15-10-2010 / 17:37:38 / Jan Kurs <kurs.jan@post.cz>" |
|
985 |
"Modified: / 28-01-2011 / 15:09:48 / Marcel Hlopko <hlopik@gmail.com>" |
|
800
11f2222f816d
forgotten return and fixed broken class reading (static field were not set up correctly)..
hlopkmar
parents:
799
diff
changeset
|
986 |
"Modified: / 18-05-2011 / 15:30:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
811 | 987 |
"Modified: / 22-05-2011 / 14:23:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 988 |
! |
989 |
||
990 |
readStream:aStream ignoring:classesBeingLoaded |
|
991 |
"reads a class from aStream and returns it. |
|
992 |
The JavaClass is not installed as global" |
|
993 |
||
994 |
inStream := aStream. |
|
995 |
inStream binary. |
|
996 |
||
997 |
^ self readClassFileIgnoring:classesBeingLoaded |
|
998 |
||
999 |
" |
|
1000 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1001 |
" |
|
1002 |
||
1003 |
"Created: 15.4.1996 / 15:00:55 / cg" |
|
1004 |
"Modified: 15.4.1996 / 15:06:18 / cg" |
|
1005 |
! ! |
|
1006 |
||
1007 |
!JavaClassReader methodsFor:'file reading - attributes'! |
|
1008 |
||
1009 |
readAnnotationDefaultAttributeFor:something |
|
1010 |
"/ ('JAVA [info]: unhandled attribute: AnnotationDefault') infoPrintCR. |
|
1011 |
||
1012 |
|len startPos endPos annotationDefault| |
|
1013 |
||
1014 |
self assert:something isJavaMethod |
|
1015 |
description:'AnnotationDefault may only occure for methods!!'. |
|
1016 |
len := inStream nextUnsignedLongMSB:msb. |
|
1017 |
startPos := inStream position. |
|
1018 |
annotationDefault := (something ensureHasAnnotations) |
|
1019 |
default:(JavaAnnotationDefault new |
|
1020 |
value:(self readAnnotationValueFor:something)); |
|
1021 |
default. |
|
1022 |
endPos := inStream position. |
|
1023 |
inStream position:startPos. |
|
1024 |
annotationDefault bytes:(inStream next:len). |
|
1025 |
self assert:inStream position = endPos |
|
1026 |
description:'self readAnnotationValueFor: something is reading what it shouldn'. |
|
1027 |
||
1028 |
"Modified: / 28-02-2011 / 17:08:28 / Marcel Hlopko <hlopik@gmail.com>" |
|
1029 |
"Modified: / 03-03-2011 / 23:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1030 |
! |
|
1031 |
||
1032 |
readAnnotationFor:something |
|
1033 |
| typeIndex type result attrsCount | |
|
1034 |
||
1035 |
typeIndex := inStream nextUnsignedShortMSB:msb. |
|
1036 |
type := something constantPool at:typeIndex. |
|
1037 |
attrsCount := inStream nextUnsignedShortMSB:msb. |
|
1038 |
result := JavaAnnotation for:something. |
|
1039 |
result name:type. |
|
1040 |
attrsCount timesRepeat: |
|
1041 |
[ | nameIndex name valueIndex attr | |
|
1042 |
||
1043 |
nameIndex := inStream nextUnsignedShortMSB:msb. |
|
1044 |
name := something constantPool at:nameIndex. |
|
1045 |
attr := self readAnnotationValueFor:something. |
|
1046 |
attr name:name. |
|
1047 |
result values at:attr name put:attr. |
|
1048 |
AnnotationsVerbose |
|
1049 |
ifTrue:[ ('JAVA [INFO]: Reading annotation attribute: ' , name) infoPrintCR. ]. ]. |
|
1050 |
^ result. |
|
1051 |
||
1052 |
"Created: / 17-12-2010 / 16:21:28 / Marcel Hlopko <hlopik@gmail.com>" |
|
1053 |
"Modified: / 25-02-2011 / 12:25:36 / Marcel Hlopko <hlopik@gmail.com>" |
|
1054 |
! |
|
1055 |
||
1056 |
readAnnotationValueFor:something |
|
1057 |
| tag result | |
|
1058 |
||
1059 |
tag := (inStream nextByte) asCharacter. |
|
1060 |
tag = $e |
|
1061 |
ifTrue: |
|
1062 |
[ result := JavaAnnotationEnumValue for:something. |
|
1063 |
result nameIndex:(inStream nextUnsignedShortMSB:msb). |
|
1064 |
result valueIndex:(inStream nextUnsignedShortMSB:msb). |
|
1065 |
AnnotationsVerbose |
|
1066 |
ifTrue: |
|
1067 |
[ ('JAVA [INFO]: Reading annotation enum value: ' , result name printString, ' -> ' |
|
1068 |
, result value printString) infoPrintCR ]. |
|
1069 |
^ result ]. |
|
1070 |
tag = $c |
|
1071 |
ifTrue: |
|
1072 |
[ result := JavaAnnotationClassValue for:something. |
|
1073 |
result classIndex:(inStream nextUnsignedShortMSB:msb). |
|
1074 |
AnnotationsVerbose |
|
1075 |
ifTrue: |
|
1076 |
[ ('JAVA [INFO]: Reading annotation class value: ' , result name printString, ' -> ' |
|
1077 |
, result value printString) infoPrintCR ]. |
|
1078 |
^ result ]. |
|
1079 |
tag = $@ |
|
1080 |
ifTrue: |
|
1081 |
[ result := JavaAnnotationNestedAnnotationValue for:something. |
|
1082 |
result classIndex:(inStream nextUnsignedShortMSB:msb). |
|
1083 |
AnnotationsVerbose |
|
1084 |
ifTrue: |
|
1085 |
[ ('JAVA [INFO]: Reading annotation nested annotation value: ' , result name printString |
|
1086 |
, ' -> ' , result value printString) |
|
1087 |
infoPrintCR ]. |
|
1088 |
^ result ]. |
|
1089 |
tag = $[ |
|
1090 |
ifTrue: |
|
1091 |
[ result := JavaAnnotationArrayValue for:something. |
|
1092 |
result count:(inStream nextUnsignedShortMSB:msb). |
|
1093 |
AnnotationsVerbose |
|
1094 |
ifTrue:[ ('JAVA [INFO]: Reading annotation array value') infoPrintCR ]. |
|
1095 |
1 to:result count |
|
1096 |
do:[:index | result values at:index put:(self readAnnotationValueFor:something) ]. |
|
1097 |
AnnotationsVerbose |
|
1098 |
ifTrue: |
|
1099 |
[ ('JAVA [INFO]: Finished reading annotation array value: ' |
|
1100 |
, result value printString) infoPrintCR ]. |
|
1101 |
^ result ]. |
|
1102 |
result := JavaAnnotationPrimitiveValue for:something. |
|
1103 |
result valueIndex:(inStream nextUnsignedShortMSB:msb). |
|
1104 |
AnnotationsVerbose |
|
1105 |
ifTrue: |
|
1106 |
[ ('JAVA [INFO]: Finished reading annotation primitive value: ' |
|
1107 |
, result name printString , ' -> ' , result value printString) infoPrintCR ]. |
|
1108 |
^ result. |
|
1109 |
||
1110 |
"Created: / 17-12-2010 / 16:44:14 / Marcel Hlopko <hlopik@gmail.com>" |
|
1111 |
"Modified: / 28-02-2011 / 16:12:09 / Marcel Hlopko <hlopik@gmail.com>" |
|
1112 |
! |
|
1113 |
||
1114 |
readAttribute:attributeName for:something |
|
1115 |
"/ implemented JAVA attributes |
|
1116 |
||
1117 |
(attributeName = 'ConstantValue') |
|
1118 |
ifTrue: |
|
1119 |
[ self readConstantValueAttributeFor:something. |
|
1120 |
^ self. ]. |
|
1121 |
(attributeName = 'Code') |
|
1122 |
ifTrue: |
|
1123 |
[ self readCodeAttributeFor:something. |
|
1124 |
^ self. ]. |
|
1125 |
(attributeName = 'Exceptions') |
|
1126 |
ifTrue: |
|
1127 |
[ self readExceptionsAttributeFor:something. |
|
1128 |
^ self. ]. |
|
1129 |
(attributeName = 'InnerClasses') |
|
1130 |
ifTrue: |
|
1131 |
[ self readInnerClassesAttributeFor:something. |
|
1132 |
^ self. ]. |
|
1133 |
(attributeName = 'EnclosingMethod') |
|
1134 |
ifTrue: |
|
1135 |
[ self readEnclosingMethodAttributeFor:something. |
|
1136 |
^ self. ]. |
|
1137 |
(attributeName = 'LineNumberTable') |
|
1138 |
ifTrue: |
|
1139 |
[ self readLineNumberTableAttributeFor:something. |
|
1140 |
^ self. ]. |
|
1141 |
(attributeName = 'LocalVariableTable') |
|
1142 |
ifTrue: |
|
1143 |
[ self readLocalVariableTableAttributeFor:something. |
|
1144 |
^ self. ]. |
|
1145 |
(attributeName = 'LocalVariableTypeTable') |
|
1146 |
ifTrue: |
|
1147 |
[ self readLocalVariableTypeTableAttributeFor:something. |
|
1148 |
^ self. ]. |
|
1149 |
(attributeName = 'SourceFile') |
|
1150 |
ifTrue: |
|
1151 |
[ self readSourceFileAttributeFor:something. |
|
1152 |
^ self. ]. |
|
1153 |
(attributeName = 'SourceDebugExtension') |
|
1154 |
ifTrue: |
|
1155 |
[ self readSourceDebugExtensionAttributeFor:something. |
|
1156 |
^ self. ]. |
|
1157 |
(attributeName = 'Synthetic') |
|
1158 |
ifTrue: |
|
1159 |
[ self readSyntheticAttributeFor:something. |
|
1160 |
^ self. ]. |
|
1161 |
(attributeName = 'Signature') |
|
1162 |
ifTrue: |
|
1163 |
[ self readSignatureAttributeFor:something. |
|
1164 |
^ self. ]. |
|
1165 |
(attributeName = 'Deprecated') |
|
1166 |
ifTrue: |
|
1167 |
[ self readDeprecatedAttributeFor:something. |
|
1168 |
^ self. ]. |
|
1169 |
(attributeName = 'RuntimeVisibleAnnotations') |
|
1170 |
ifTrue: |
|
1171 |
[ self readRuntimeAnnotationsAttributeFor:something visible:true. |
|
1172 |
^ self. ]. |
|
1173 |
(attributeName = 'RuntimeInvisibleAnnotations') |
|
1174 |
ifTrue: |
|
1175 |
[ self readRuntimeAnnotationsAttributeFor:something visible:false. |
|
1176 |
^ self. ]. |
|
1177 |
(attributeName = 'RuntimeVisibleParameterAnnotations') |
|
1178 |
ifTrue: |
|
1179 |
[ self readRuntimeParameterAnnotationsAttributeFor:something visible:true. |
|
1180 |
^ self. ]. |
|
1181 |
(attributeName = 'RuntimeInvisibleParameterAnnotations') |
|
1182 |
ifTrue: |
|
1183 |
[ self readRuntimeParameterAnnotationsAttributeFor:something visible:false. |
|
1184 |
^ self. ]. |
|
1185 |
(attributeName = 'AnnotationDefault') |
|
1186 |
ifTrue: |
|
1187 |
[ self readAnnotationDefaultAttributeFor:something. |
|
1188 |
^ self. ]. |
|
1189 |
||
1190 |
"/ ignored JAVA attributes |
|
1191 |
||
1192 |
(attributeName = 'FastJavac1.0') |
|
1193 |
ifTrue: |
|
1194 |
[ "/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1195 |
self skipAttribute:attributeName. |
|
1196 |
^ self. ]. |
|
1197 |
(attributeName = 'AbsoluteSourcePath') |
|
1198 |
ifTrue: |
|
1199 |
[ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1200 |
self skipAttribute:attributeName. |
|
1201 |
^ self. ]. |
|
1202 |
(attributeName startsWith:((Character value:13) asString , 'WARNING:')) |
|
1203 |
ifTrue: |
|
1204 |
[ "/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1205 |
self skipAttribute:attributeName. |
|
1206 |
^ self. ]. |
|
1207 |
(attributeName = 'StackMapTable') |
|
1208 |
ifTrue: |
|
1209 |
[ "/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1210 |
self readStackMapTableAttributeFor:something. |
|
1211 |
^ self. ]. |
|
1212 |
||
1213 |
"/ implemented ST attributes |
|
1214 |
||
1215 |
(attributeName = 'STLiterals') |
|
1216 |
ifTrue: |
|
1217 |
[ self readSTLiteralsAttributeFor:something. |
|
1218 |
^ self. ]. |
|
1219 |
(attributeName = 'ClassRevision') |
|
1220 |
ifTrue: |
|
1221 |
[ self readSTClassRevisionAttributeFor:something. |
|
1222 |
^ self. ]. |
|
1223 |
(attributeName = 'ClassPackage') |
|
1224 |
ifTrue: |
|
1225 |
[ self readSTClassPackageAttributeFor:something. |
|
1226 |
^ self. ]. |
|
1227 |
(attributeName = 'ClassCategory') |
|
1228 |
ifTrue: |
|
1229 |
[ self readSTClassCategoryAttributeFor:something. |
|
1230 |
^ self. ]. |
|
1231 |
(attributeName = 'ClassVarNames') |
|
1232 |
ifTrue: |
|
1233 |
[ self readSTClassVarNamesAttributeFor:something. |
|
1234 |
^ self. ]. |
|
1235 |
(attributeName = 'ClassInstVarNames') |
|
1236 |
ifTrue: |
|
1237 |
[ self readSTClassInstVarNamesAttributeFor:something. |
|
1238 |
^ self. ]. |
|
1239 |
(attributeName = 'InstVarNames') |
|
1240 |
ifTrue: |
|
1241 |
[ self readSTInstVarNamesAttributeFor:something. |
|
1242 |
^ self. ]. |
|
1243 |
(attributeName = 'STCode') |
|
1244 |
ifTrue: |
|
1245 |
[ self readSTCodeAttributeFor:something. |
|
1246 |
^ self. ]. |
|
1247 |
(attributeName = 'MethodCategory') |
|
1248 |
ifTrue: |
|
1249 |
[ self readSTMethodCategoryAttributeFor:something. |
|
1250 |
^ self. ]. |
|
1251 |
||
1252 |
"/ unknown attributes |
|
1253 |
||
1254 |
('JAVA [warning]: unrecognized attribute: ' , attributeName) infoPrintCR. |
|
1255 |
self skipAttribute:attributeName. |
|
1256 |
||
1257 |
"Modified: / 03-12-1998 / 13:13:42 / cg" |
|
1258 |
"Modified: / 25-02-2011 / 18:09:21 / Marcel Hlopko <hlopik@gmail.com>" |
|
1259 |
! |
|
1260 |
||
1261 |
readAttributeFor:something |
|
1262 |
|attribute_name_index attribute_name attribute_length attribute_info| |
|
1263 |
||
1264 |
Verbose ifTrue:[Transcript show:'attrib at pos: '; showCR:inStream position]. |
|
1265 |
||
1266 |
attribute_name_index := inStream nextUnsignedShortMSB:msb. |
|
1267 |
attribute_name_index == 0 ifTrue:[ |
|
1268 |
self halt. |
|
1269 |
"/self skipAttribute:'unnamed'. |
|
1270 |
^ self. |
|
1271 |
]. |
|
1272 |
||
1273 |
"/ |
|
1274 |
"/ UNDOC feature ? |
|
1275 |
"/ |
|
1276 |
attribute_name_index > constants size ifTrue:[ |
|
1277 |
attribute_name_index == 16rb700 ifTrue:[ |
|
1278 |
self halt. |
|
1279 |
] |
|
1280 |
]. |
|
1281 |
||
1282 |
attribute_name := constants at:attribute_name_index. |
|
1283 |
||
1284 |
Verbose ifTrue:[Transcript show:'attrib name: '; showCR:attribute_name]. |
|
1285 |
||
1286 |
self readAttribute:attribute_name for:something. |
|
1287 |
||
1288 |
" |
|
1289 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1290 |
" |
|
1291 |
||
1292 |
"Created: / 15-04-1996 / 15:40:17 / cg" |
|
1293 |
"Modified: / 09-04-1998 / 18:13:34 / cg" |
|
1294 |
"Modified: / 19-10-2010 / 21:43:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1295 |
! |
|
1296 |
||
1297 |
readAttributesFor:something |
|
1298 |
|attributes_count| |
|
1299 |
||
1300 |
attributes_count := inStream nextUnsignedShortMSB:msb. |
|
1301 |
||
1302 |
1 to:attributes_count do:[:i | |
|
1303 |
self readAttributeFor:something. |
|
1304 |
]. |
|
1305 |
||
1306 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1307 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1308 |
! |
|
1309 |
||
1310 |
readDeprecatedAttributeFor:aJavaMethodWithHandler |
|
1311 |
||
1312 |
self skipAttribute:'Deprecated'. |
|
1313 |
^self |
|
1314 |
||
1315 |
"Created: / 18-10-2010 / 22:26:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1316 |
! |
|
1317 |
||
1318 |
readEnclosingMethodAttributeFor:something |
|
1319 |
"/ ('JAVA [info]: unhandled attribute: EnclosingMethod') infoPrintCR. |
|
1320 |
self skipAttribute:'EnclosingMethod'. |
|
1321 |
! |
|
1322 |
||
1323 |
readInnerClassesAttributeFor:something |
|
1324 |
"/ ('JAVA [info]: unhandled attribute: InnerClasses') infoPrintCR. |
|
1325 |
self skipAttribute:'InnerClasses'. |
|
1326 |
! |
|
1327 |
||
1328 |
readLocalVariableTypeTableAttributeFor:something |
|
1329 |
"/ ('JAVA [info]: unhandled attribute: LocalVariableTypeTable') infoPrintCR. |
|
1330 |
self skipAttribute:'LocalVariableTypeTable'. |
|
1331 |
! |
|
1332 |
||
1333 |
readRuntimeAnnotationsAttributeFor: something visible: visible |
|
1334 |
| length annotationsCount annotations rawAnnotations startPos endPos | |
|
1335 |
||
1336 |
self assert: inStream isPositionable |
|
1337 |
message: '.class file stream must be positionable'. |
|
1338 |
length := inStream nextUnsignedLongMSB: msb. |
|
1339 |
startPos := inStream position. |
|
1340 |
annotationsCount := inStream nextUnsignedShortMSB: msb. |
|
1341 |
annotationsCount = 0 ifTrue: [ ^ nil ]. |
|
1342 |
annotations := visible ifTrue: [something ensureHasAnnotations ensureRuntimeVisible] ifFalse: [something ensureHasAnnotations ensureRuntimeInvisible]. |
|
1343 |
annotationsCount timesRepeat: |
|
1344 |
[ | currentAnnotation | |
|
1345 |
||
1346 |
currentAnnotation := self readAnnotationFor: something. |
|
1347 |
annotations at: currentAnnotation name put: currentAnnotation. ]. |
|
1348 |
"Cut raw annotations as required by getRawAnnotations()" |
|
1349 |
endPos := inStream position. |
|
1350 |
inStream position: startPos. |
|
1351 |
rawAnnotations := inStream next: length. |
|
1352 |
inStream position ~= endPos |
|
1353 |
ifTrue: [ self halt: 'annotations are probably reading what they shouldnt' ]. |
|
1354 |
annotations rawAnnotations: rawAnnotations. |
|
1355 |
||
1356 |
"Modified: / 07-01-2011 / 22:00:07 / Jan Kurs <kurs.jan@post.cz>" |
|
1357 |
"Modified: / 25-02-2011 / 18:45:58 / Marcel Hlopko <hlopik@gmail.com>" |
|
1358 |
"Modified: / 03-03-2011 / 23:01:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1359 |
"Modified: / 16-03-2011 / 16:57:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1360 |
! |
|
1361 |
||
1362 |
readRuntimeParameterAnnotationsAttributeFor: javaMethod visible: visible |
|
1363 |
| length paramsCount annotationsCount rawAnnotations startPos endPos | |
|
1364 |
||
1365 |
self assert: inStream isPositionable |
|
1366 |
message: '.class file stream must be positionable'. |
|
1367 |
length := inStream nextUnsignedLongMSB: msb. |
|
1368 |
startPos := inStream position. |
|
1369 |
paramsCount := inStream nextByte. |
|
1370 |
paramsCount = 0 ifTrue: [ ^ nil ]. |
|
1371 |
1 to: paramsCount |
|
1372 |
do: |
|
1373 |
[:paramIndex | |
|
1374 |
annotationsCount := inStream nextUnsignedShortMSB: msb. |
|
1375 |
annotationsCount > 0 |
|
1376 |
ifTrue: |
|
1377 |
[ | annotations | |
|
1378 |
annotations := visible |
|
1379 |
ifTrue: |
|
1380 |
[ javaMethod ensureHasAnnotations ensureVisibleParameterAnnotationsAt: paramIndex ] |
|
1381 |
ifFalse: |
|
1382 |
[javaMethod ensureHasAnnotations ensureInvisibleParameterAnnotationsAt: paramIndex ]. |
|
1383 |
annotationsCount timesRepeat: |
|
1384 |
[ | annotation | |
|
1385 |
||
1386 |
annotation := self readAnnotationFor: javaMethod. |
|
1387 |
annotations at: (annotation name) put: annotation. ] ]]. |
|
1388 |
endPos := inStream position. |
|
1389 |
rawAnnotations := inStream position: startPos. |
|
1390 |
rawAnnotations := inStream next: length. |
|
1391 |
inStream position ~= endPos |
|
1392 |
ifTrue: [ self halt: 'annotations are probably reading what they shouldnt' ]. |
|
1393 |
javaMethod annotations rawAnnotations: rawAnnotations. |
|
1394 |
||
1395 |
"Modified: / 28-02-2011 / 17:05:47 / Marcel Hlopko <hlopik@gmail.com>" |
|
1396 |
"Modified: / 16-03-2011 / 17:26:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1397 |
! |
|
1398 |
||
1399 |
readSignatureAttributeFor:something |
|
1400 |
"/ ('JAVA [info]: unhandled attribute: Signature') infoPrintCR. |
|
1401 |
self skipAttribute:'Signature'. |
|
1402 |
! |
|
1403 |
||
1404 |
readSourceDebugExtensionAttributeFor:something |
|
1405 |
"/ ('JAVA [info]: unhandled attribute: SourceDebugExtension') infoPrintCR. |
|
1406 |
self skipAttribute:'SourceDebugExtension'. |
|
1407 |
! |
|
1408 |
||
1409 |
readSourceFileAttributeFor:aClass |
|
1410 |
|attribute_length sourceFile_index sourceFile| |
|
1411 |
||
1412 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1413 |
||
1414 |
sourceFile_index := inStream nextUnsignedShortMSB:msb. |
|
1415 |
sourceFile := constants at:sourceFile_index. |
|
1416 |
||
1417 |
aClass isJavaClass ifTrue:[ |
|
1418 |
aClass setSourceFile:sourceFile. |
|
1419 |
] ifFalse:[ |
|
1420 |
aClass setClassFilename:sourceFile |
|
1421 |
]. |
|
1422 |
||
1423 |
Verbose ifTrue:[Transcript show:'sourceFile: '; showCR:sourceFile]. |
|
1424 |
^ true |
|
1425 |
||
1426 |
" |
|
1427 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1428 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1429 |
JavaClassReader loadFile:'foo.cls' |
|
1430 |
" |
|
1431 |
||
1432 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
|
1433 |
"Modified: / 12.5.1998 / 22:01:07 / cg" |
|
1434 |
! |
|
1435 |
||
1436 |
readStackMapTableAttributeFor:something |
|
1437 |
"/ ('JAVA [info]: unhandled attribute: StackMapTable') infoPrintCR. |
|
1438 |
self skipAttribute:'StackMapTable'. |
|
1439 |
||
1440 |
"Created: / 09-02-2011 / 01:19:20 / Marcel Hlopko <hlopik@gmail.com>" |
|
1441 |
! |
|
1442 |
||
1443 |
readSyntheticAttributeFor:something |
|
1444 |
"/ ('JAVA [info]: unhandled attribute: Synthetic') infoPrintCR. |
|
1445 |
self skipAttribute:'Synthetic'. |
|
1446 |
! |
|
1447 |
||
1448 |
skipAttribute:attributeName |
|
1449 |
"dont know about this attribute - skip it here" |
|
1450 |
||
1451 |
|attribute_length attribute_info| |
|
1452 |
||
1453 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1454 |
attribute_info := ByteArray new:(attribute_length). |
|
1455 |
inStream nextBytes:attribute_length into:attribute_info startingAt:1. |
|
1456 |
||
1457 |
Verbose ifTrue:[Transcript show:'skipped '; show:attributeName; showCR:'-attribute']. |
|
1458 |
||
1459 |
"Created: / 9.4.1998 / 18:12:46 / cg" |
|
1460 |
"Modified: / 9.4.1998 / 18:13:20 / cg" |
|
1461 |
! ! |
|
1462 |
||
1463 |
!JavaClassReader methodsFor:'file reading - attributes-ST'! |
|
1464 |
||
1465 |
readSTClassCategoryAttributeFor:aClass |
|
1466 |
|attribute_length categoryString_index categoryString| |
|
1467 |
||
1468 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1469 |
||
1470 |
categoryString_index := inStream nextUnsignedShortMSB:msb. |
|
1471 |
categoryString := constants at:categoryString_index. |
|
1472 |
||
1473 |
aClass category:categoryString. |
|
1474 |
||
1475 |
Verbose ifTrue:[Transcript show:'categoryString: '; showCR:categoryString]. |
|
1476 |
^ true |
|
1477 |
||
1478 |
" |
|
1479 |
JavaClassReader loadFile:'foo.cls' |
|
1480 |
" |
|
1481 |
||
1482 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1483 |
"Modified: / 9.5.1998 / 02:36:55 / cg" |
|
1484 |
! |
|
1485 |
||
1486 |
readSTClassInstVarNamesAttributeFor:aClass |
|
1487 |
|attribute_length nameString_index nameString| |
|
1488 |
||
1489 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1490 |
||
1491 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1492 |
nameString := constants at:nameString_index. |
|
1493 |
||
1494 |
aClass class instanceVariableString:nameString. |
|
1495 |
||
1496 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1497 |
^ true |
|
1498 |
||
1499 |
" |
|
1500 |
JavaClassReader loadFile:'foo.cls' |
|
1501 |
" |
|
1502 |
||
1503 |
"Modified: / 12.5.1998 / 22:18:03 / cg" |
|
1504 |
"Created: / 12.5.1998 / 22:18:24 / cg" |
|
1505 |
! |
|
1506 |
||
1507 |
readSTClassPackageAttributeFor:aClass |
|
1508 |
|attribute_length packageString_index packageString| |
|
1509 |
||
1510 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1511 |
||
1512 |
packageString_index := inStream nextUnsignedShortMSB:msb. |
|
1513 |
packageString := constants at:packageString_index. |
|
1514 |
||
1515 |
aClass package:packageString asSymbol. |
|
1516 |
||
1517 |
Verbose ifTrue:[Transcript show:'packageString: '; showCR:packageString]. |
|
1518 |
^ true |
|
1519 |
||
1520 |
" |
|
1521 |
JavaClassReader loadFile:'foo.cls' |
|
1522 |
" |
|
1523 |
||
1524 |
"Modified: / 9.5.1998 / 02:32:38 / cg" |
|
1525 |
"Created: / 9.5.1998 / 02:33:44 / cg" |
|
1526 |
! |
|
1527 |
||
1528 |
readSTClassRevisionAttributeFor:aClass |
|
1529 |
|attribute_length revisionString_index revisionString| |
|
1530 |
||
1531 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1532 |
||
1533 |
revisionString_index := inStream nextUnsignedShortMSB:msb. |
|
1534 |
revisionString := constants at:revisionString_index. |
|
1535 |
||
1536 |
aClass setBinaryRevision:revisionString. |
|
1537 |
||
1538 |
Verbose ifTrue:[Transcript show:'revisionString: '; showCR:revisionString]. |
|
1539 |
^ true |
|
1540 |
||
1541 |
" |
|
1542 |
JavaClassReader loadFile:'foo.cls' |
|
1543 |
" |
|
1544 |
||
1545 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1546 |
"Modified: / 9.5.1998 / 02:35:01 / cg" |
|
1547 |
! |
|
1548 |
||
1549 |
readSTClassVarNamesAttributeFor:aClass |
|
1550 |
|attribute_length nameString_index nameString| |
|
1551 |
||
1552 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1553 |
||
1554 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1555 |
nameString := constants at:nameString_index. |
|
1556 |
||
1557 |
aClass classVariableString:nameString. |
|
1558 |
||
1559 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1560 |
^ true |
|
1561 |
||
1562 |
" |
|
1563 |
JavaClassReader loadFile:'foo.cls' |
|
1564 |
" |
|
1565 |
||
1566 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1567 |
"Modified: / 12.5.1998 / 22:18:03 / cg" |
|
1568 |
! |
|
1569 |
||
1570 |
readSTInstVarNamesAttributeFor:aClass |
|
1571 |
|attribute_length nameString_index nameString| |
|
1572 |
||
1573 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1574 |
||
1575 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1576 |
nameString := constants at:nameString_index. |
|
1577 |
||
1578 |
aClass setInstanceVariableString:nameString. |
|
1579 |
||
1580 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1581 |
^ true |
|
1582 |
||
1583 |
" |
|
1584 |
JavaClassReader loadFile:'foo.cls' |
|
1585 |
" |
|
1586 |
||
1587 |
"Created: / 12.5.1998 / 22:18:14 / cg" |
|
1588 |
"Modified: / 12.5.1998 / 22:21:10 / cg" |
|
1589 |
! ! |
|
1590 |
||
1591 |
!JavaClassReader methodsFor:'file reading - constants'! |
|
1592 |
||
1593 |
readConstant |
|
1594 |
|tag constReader const| |
|
1595 |
||
1596 |
||
1597 |
constNeeds2Slots := false. |
|
1598 |
||
1599 |
"/ |
|
1600 |
"/ get tag |
|
1601 |
"/ |
|
1602 |
tag := inStream nextByte. |
|
1603 |
Verbose ifTrue:[Transcript show:'tag = '; showCR:tag]. |
|
1604 |
||
1605 |
tag >= 250 ifTrue:[ |
|
1606 |
constReader := #( |
|
1607 |
"/ ST types |
|
1608 |
readConstant_ST_Large "/ 249 |
|
1609 |
readConstant_ST_Special "/ 250 |
|
1610 |
readConstant_ST_Character "/ 251 |
|
1611 |
readConstant_ST_ByteArray "/ 252 |
|
1612 |
readConstant_ST_Array "/ 253 |
|
1613 |
readConstant_ST_Symbol "/ 254 |
|
1614 |
readConstant_ST_Reserved "/ 255 |
|
1615 |
) at:tag-249+1. |
|
1616 |
] ifFalse:[ |
|
1617 |
constReader := #( |
|
1618 |
"/ JAVA types |
|
1619 |
readConstant_Utf8 "/ 1 - now called Utf8 |
|
1620 |
readConstant_Unicode "/ 2 |
|
1621 |
readConstant_Integer "/ 3 |
|
1622 |
readConstant_Float "/ 4 |
|
1623 |
readConstant_Long "/ 5 |
|
1624 |
readConstant_Double "/ 6 |
|
1625 |
readConstant_Class "/ 7 |
|
1626 |
readConstant_String "/ 8 |
|
1627 |
readConstant_Fieldref "/ 9 |
|
1628 |
readConstant_Methodref "/ 10 |
|
1629 |
readConstant_InterfaceMethodref "/ 11 |
|
1630 |
readConstant_NameAndType "/ 12 |
|
1631 |
) at:tag ifAbsent:[#readConstant_Undef]. |
|
1632 |
]. |
|
1633 |
^ self perform:constReader. |
|
1634 |
||
1635 |
" |
|
1636 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1637 |
" |
|
1638 |
||
1639 |
"Created: / 15.4.1996 / 15:46:32 / cg" |
|
1640 |
"Modified: / 9.5.1998 / 01:26:05 / cg" |
|
1641 |
! |
|
1642 |
||
1643 |
readConstantPool |
|
877 | 1644 |
| constantPoolSize const | |
752 | 1645 |
|
1646 |
"/ |
|
1647 |
"/ get constant pool |
|
1648 |
"/ |
|
877 | 1649 |
constantPoolSize := inStream nextUnsignedShortMSB: msb. |
1650 |
self info: 'constantPoolSize = ' , constantPoolSize printString. |
|
1651 |
constants := JavaConstantPool new: constantPoolSize - 1. |
|
752 | 1652 |
constSlot := 1. |
877 | 1653 |
[ constSlot < constantPoolSize ] whileTrue: [ |
1654 |
self info: 'const slot: ' , constSlot printString. |
|
1655 |
const := self readConstant. |
|
1656 |
constants at: constSlot put: const. |
|
1657 |
||
1658 |
"/ long & double consts take 2 slots |
|
1659 |
"/ (only first is used) |
|
1660 |
||
1661 |
constNeeds2Slots |
|
1662 |
ifTrue: [ constSlot := constSlot + 2. ] |
|
1663 |
ifFalse: [ constSlot := constSlot + 1. ]]. |
|
752 | 1664 |
constSlot := -1. |
877 | 1665 |
|
1666 |
1 to: constantPoolSize - 1 |
|
1667 |
do: |
|
1668 |
[:i | |
|
1669 |
| const value | |
|
1670 |
||
1671 |
const := constants at: i. |
|
1672 |
const ifNotNil: |
|
1673 |
[ "/ kludge for 2-slot constants (which only take 1 slot in ST/X) |
|
1674 |
(const isKindOf: JavaUnresolvedConstant) |
|
1675 |
ifTrue: |
|
1676 |
[ value := const preResolve. |
|
1677 |
value ~~ const ifTrue: [ constants at: i put: value. ] ] ] ]. |
|
752 | 1678 |
|
1679 |
" |
|
1680 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
877 | 1681 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class'" |
1682 |
||
1683 |
"Modified: / 07-05-1998 / 11:44:06 / cg" |
|
1684 |
"Created: / 13-05-2011 / 16:52:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 1685 |
! |
1686 |
||
1687 |
readConstant_Asciz |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1688 |
| len string | |
782 | 1689 |
|
1690 |
||
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1691 |
len := inStream nextUnsignedShortMSB: msb. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1692 |
string := String new: len. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1693 |
inStream |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1694 |
nextBytes: len |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1695 |
into: string |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1696 |
startingAt: 1. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1697 |
Verbose |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1698 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1699 |
[ Transcript |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1700 |
show: 'asciz; string= '; |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1701 |
showCR: string ]. |
752 | 1702 |
^ string |
1703 |
||
1704 |
" |
|
1705 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1706 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class'" |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1707 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1708 |
"Created: / 15-04-1996 / 15:15:35 / cg" |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1709 |
"Modified: / 15-04-1996 / 16:33:45 / cg" |
782 | 1710 |
"Modified: / 13-05-2011 / 17:31:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 1711 |
! |
1712 |
||
1713 |
readConstant_Class |
|
877 | 1714 |
| nameIndex | |
1715 |
||
1716 |
nameIndex := inStream nextUnsignedShortMSB: msb. |
|
1717 |
((constants at: nameIndex) isNil) |
|
1718 |
ifTrue: |
|
1719 |
[ self info: ('reading class; index=' , nameIndex printString , ' name=' |
|
1720 |
, (constants at: nameIndex) printString) ] |
|
1721 |
ifFalse: [ self info: ('reading class; index= ' , nameIndex printString) ]. |
|
1722 |
^ JavaClassRef2 in: constants withNameAt: nameIndex. |
|
1723 |
||
1724 |
"Modified: / 18-05-2011 / 18:21:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 1725 |
! |
1726 |
||
1727 |
readConstant_Double |
|
1728 |
|high low aFloat bytes| |
|
1729 |
||
1730 |
"/ new code - to be tested |
|
1731 |
"/ bytes := ByteArray new:8. |
|
1732 |
"/ |
|
1733 |
"/ inStream nextBytes:8 into:bytes startingAt:1. |
|
1734 |
"/ msb ~~ UninterpretedBytes isBigEndian ifTrue:[ |
|
1735 |
"/ bytes reverse |
|
1736 |
"/ ]. |
|
1737 |
"/ aFloat := bytes doubleAt:1. |
|
1738 |
||
1739 |
"/ old code |
|
1740 |
||
1741 |
high := inStream nextUnsignedLongMSB:msb. |
|
1742 |
low := inStream nextUnsignedLongMSB:msb. |
|
1743 |
||
1744 |
aFloat := Float new. |
|
1745 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
1746 |
aFloat basicAt:1 put:((high bitShift:-24) bitAnd:16rFF). |
|
1747 |
aFloat basicAt:2 put:((high bitShift:-16) bitAnd:16rFF). |
|
1748 |
aFloat basicAt:3 put:((high bitShift:-8) bitAnd:16rFF). |
|
1749 |
aFloat basicAt:4 put:(high bitAnd:16rFF). |
|
1750 |
aFloat basicAt:5 put:((low bitShift:-24) bitAnd:16rFF). |
|
1751 |
aFloat basicAt:6 put:((low bitShift:-16) bitAnd:16rFF). |
|
1752 |
aFloat basicAt:7 put:((low bitShift:-8) bitAnd:16rFF). |
|
1753 |
aFloat basicAt:8 put:(low bitAnd:16rFF). |
|
1754 |
] ifFalse:[ |
|
1755 |
aFloat basicAt:1 put:(low bitAnd:16rFF). |
|
1756 |
aFloat basicAt:2 put:((low bitShift:-8) bitAnd:16rFF). |
|
1757 |
aFloat basicAt:3 put:((low bitShift:-16) bitAnd:16rFF). |
|
1758 |
aFloat basicAt:4 put:((low bitShift:-24) bitAnd:16rFF). |
|
1759 |
aFloat basicAt:5 put:(high bitAnd:16rFF). |
|
1760 |
aFloat basicAt:6 put:((high bitShift:-8) bitAnd:16rFF). |
|
1761 |
aFloat basicAt:7 put:((high bitShift:-16) bitAnd:16rFF). |
|
1762 |
aFloat basicAt:8 put:((high bitShift:-24) bitAnd:16rFF). |
|
1763 |
]. |
|
1764 |
||
1765 |
constNeeds2Slots := true. |
|
1766 |
||
1767 |
Verbose ifTrue:[Transcript show:'double; value= '; showCR:aFloat]. |
|
1768 |
^ aFloat |
|
1769 |
||
1770 |
" |
|
1771 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1772 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1773 |
" |
|
1774 |
||
1775 |
"Created: / 15.4.1996 / 16:34:42 / cg" |
|
1776 |
"Modified: / 8.5.1998 / 22:06:07 / cg" |
|
1777 |
! |
|
1778 |
||
877 | 1779 |
readConstant_Fieldref |
1780 |
"incrementally changing resolving logic, fields will come later" |
|
1781 |
||
1782 |
| classIndex nameAndTypeIndex | |
|
1783 |
||
1784 |
classIndex := inStream nextUnsignedShortMSB: msb. |
|
1785 |
nameAndTypeIndex := inStream nextUnsignedShortMSB: msb. |
|
1786 |
self |
|
1787 |
info: 'reading fieldref; classindex=' , classIndex printString |
|
1788 |
, ' nameAndTypeIndex=' , nameAndTypeIndex printString. |
|
1789 |
^ JavaFieldRef2 |
|
1790 |
in: constants |
|
1791 |
withNameAndTypeAt: nameAndTypeIndex |
|
1792 |
andClassAt: classIndex. |
|
1793 |
||
1794 |
"Modified: / 15-05-2011 / 14:20:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 1795 |
! |
1796 |
||
1797 |
readConstant_Float |
|
1798 |
|b1 b2 b3 b4 aFloat bytes| |
|
1799 |
||
1800 |
"/ new code - to be tested ... |
|
1801 |
"/ |
|
1802 |
"/ bytes := ByteArray new:4. |
|
1803 |
"/ inStream nextBytes:4 into:bytes startingAt:1. |
|
1804 |
"/ msb ~~ UninterpretedBytes isBigEndian ifTrue:[ |
|
1805 |
"/ bytes reverse |
|
1806 |
"/ ]. |
|
1807 |
"/ aFloat := bytes floatAt:1. |
|
1808 |
"/ Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
|
1809 |
"/ ^ aFloat. |
|
1810 |
||
1811 |
"/ old code |
|
1812 |
||
1813 |
aFloat := ShortFloat basicNew. |
|
1814 |
||
1815 |
b1 := inStream nextByte. |
|
1816 |
b2 := inStream nextByte. |
|
1817 |
b3 := inStream nextByte. |
|
1818 |
b4 := inStream nextByte. |
|
1819 |
||
1820 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
1821 |
aFloat basicAt:1 put:b1. |
|
1822 |
aFloat basicAt:2 put:b2. |
|
1823 |
aFloat basicAt:3 put:b3. |
|
1824 |
aFloat basicAt:4 put:b4. |
|
1825 |
] ifFalse:[ |
|
1826 |
aFloat basicAt:4 put:b1. |
|
1827 |
aFloat basicAt:3 put:b2. |
|
1828 |
aFloat basicAt:2 put:b3. |
|
1829 |
aFloat basicAt:1 put:b4. |
|
1830 |
]. |
|
1831 |
Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
|
1832 |
^ aFloat |
|
1833 |
||
1834 |
" |
|
1835 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1836 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1837 |
" |
|
1838 |
||
1839 |
"Created: / 15.4.1996 / 16:34:42 / cg" |
|
1840 |
"Modified: / 10.11.1998 / 22:04:59 / cg" |
|
1841 |
! |
|
1842 |
||
1843 |
readConstant_Integer |
|
1844 |
|value| |
|
1845 |
||
1846 |
value := inStream nextLongMSB:msb. |
|
1847 |
||
1848 |
Verbose ifTrue:[Transcript show:'integer; value= '; showCR:value]. |
|
1849 |
||
1850 |
^ value |
|
1851 |
||
1852 |
" |
|
1853 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1854 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1855 |
" |
|
1856 |
||
1857 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
1858 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
1859 |
! |
|
1860 |
||
1861 |
readConstant_InterfaceMethodref |
|
877 | 1862 |
| classIndex nameAndTypeIndex | |
1863 |
||
1864 |
classIndex := inStream nextUnsignedShortMSB: msb. |
|
1865 |
nameAndTypeIndex := inStream nextUnsignedShortMSB: msb. |
|
1866 |
self |
|
1867 |
info: 'reading interface methodref; classindex=' , classIndex printString |
|
1868 |
, ' nameAndTypeIndex=' , nameAndTypeIndex printString. |
|
1869 |
^ JavaInterfaceMethodRef2 |
|
1870 |
in: constants |
|
1871 |
withNameAndTypeAt: nameAndTypeIndex |
|
1872 |
andClassAt: classIndex. |
|
1873 |
||
1874 |
"Modified: / 12-05-2011 / 18:57:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 1875 |
! |
1876 |
||
1877 |
readConstant_Long |
|
1878 |
|high low value| |
|
1879 |
||
1880 |
high := inStream nextUnsignedLongMSB:msb. |
|
1881 |
low := inStream nextUnsignedLongMSB:msb. |
|
1882 |
||
1883 |
value := (high bitShift:32) bitOr:low. |
|
1884 |
(high bitTest:16r80000000) ifTrue:[ |
|
1885 |
value := value - 16r10000000000000000. |
|
1886 |
]. |
|
1887 |
constNeeds2Slots := true. |
|
1888 |
||
1889 |
Verbose ifTrue:[Transcript show:'long; value= '; showCR:value]. |
|
1890 |
^ value |
|
1891 |
||
1892 |
" |
|
1893 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1894 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1895 |
" |
|
1896 |
||
1897 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
1898 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
1899 |
! |
|
1900 |
||
1901 |
readConstant_Methodref |
|
877 | 1902 |
| classIndex nameAndTypeIndex | |
1903 |
||
1904 |
classIndex := inStream nextUnsignedShortMSB: msb. |
|
1905 |
nameAndTypeIndex := inStream nextUnsignedShortMSB: msb. |
|
1906 |
self |
|
1907 |
info: 'reading methodref; classindex=' , classIndex printString , ' nameAndTypeIndex=' |
|
1908 |
, nameAndTypeIndex printString. |
|
1909 |
^ JavaMethodRef2 |
|
1910 |
in: constants |
|
1911 |
withNameAndTypeAt: nameAndTypeIndex |
|
1912 |
andClassAt: classIndex. |
|
1913 |
||
1914 |
"Modified: / 15-05-2011 / 14:20:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 1915 |
! |
1916 |
||
1917 |
readConstant_NameAndType |
|
877 | 1918 |
| nameIndex descriptorIndex | |
1919 |
||
1920 |
nameIndex := inStream nextUnsignedShortMSB: msb. |
|
1921 |
descriptorIndex := inStream nextUnsignedShortMSB: msb. |
|
1922 |
self |
|
1923 |
info: 'reading nameAndType; nameindex=' , nameIndex printString |
|
1924 |
, ' descriptorIndex= ' , descriptorIndex printString. |
|
1925 |
^JavaNameAndType2 |
|
1926 |
in: constants |
|
1927 |
withNameAt: nameIndex |
|
1928 |
andDescriptorAt: descriptorIndex. |
|
1929 |
||
1930 |
"Modified: / 10-05-2011 / 17:09:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 1931 |
! |
1932 |
||
1933 |
readConstant_String |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1934 |
| tag string_index chars jString | |
782 | 1935 |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1936 |
string_index := inStream nextUnsignedShortMSB: msb. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1937 |
Verbose |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1938 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1939 |
[ Transcript |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1940 |
show: 'string; index= '; |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1941 |
showCR: string_index ]. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1942 |
|
752 | 1943 |
"/ resolve here if possible |
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1944 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1945 |
string_index < constSlot |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1946 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1947 |
[ Java java_lang_String notNil |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1948 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1949 |
[ chars := (constants at: string_index). |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1950 |
chars isString ifFalse: [ self halt: 'should not happen' ]. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1951 |
jString := Java as_String: chars. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1952 |
^ jString. ] ]. |
752 | 1953 |
^ JavaUnresolvedStringConstant |
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1954 |
pool: constants |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1955 |
poolIndex: constSlot |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1956 |
stringIndex: string_index |
752 | 1957 |
|
1958 |
" |
|
1959 |
Verbose := true. |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1960 |
JavaClassReader readFile:'/phys/ibm3/java/lib/java/lang/System.class'" |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1961 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1962 |
"Created: / 15-04-1996 / 15:20:33 / cg" |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1963 |
"Modified: / 07-05-1998 / 11:42:45 / cg" |
782 | 1964 |
"Modified: / 13-05-2011 / 17:31:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 1965 |
! |
1966 |
||
1967 |
readConstant_Unicode |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1968 |
| len string ascii | |
782 | 1969 |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1970 |
len := inStream nextUnsignedShortMSB: msb. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1971 |
string := TwoByteString new: len. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1972 |
1 to: len |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1973 |
do: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1974 |
[:idx | |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1975 |
ascii := inStream nextUnsignedShortMSB: msb. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1976 |
string at: idx put: (Character value: ascii). ]. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1977 |
Verbose |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1978 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1979 |
[ Transcript |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1980 |
show: 'asciz; unicodeString= '; |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1981 |
showCR: string ]. |
752 | 1982 |
^ string |
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1983 |
|
782 | 1984 |
"Modified: / 13-05-2011 / 17:31:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 1985 |
! |
1986 |
||
1987 |
readConstant_Utf8 |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1988 |
| len bytes string | |
782 | 1989 |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1990 |
len := inStream nextUnsignedShortMSB: msb. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1991 |
bytes := ByteArray new: len. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1992 |
inStream |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1993 |
nextBytes: len |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1994 |
into: bytes |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1995 |
startingAt: 1. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1996 |
string := CharacterArray fromJavaUTF8Bytes: bytes. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1997 |
Verbose |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1998 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
1999 |
[ Transcript |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2000 |
show: 'asciz; string= '; |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2001 |
showCR: string ]. |
752 | 2002 |
^ string |
2003 |
||
2004 |
"Modified: / 19-10-2010 / 12:38:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
782 | 2005 |
"Modified: / 13-05-2011 / 17:31:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 2006 |
! ! |
2007 |
||
2008 |
!JavaClassReader methodsFor:'file reading - constants-ST'! |
|
2009 |
||
2010 |
readConstant_ST_Array |
|
2011 |
|aSize arr| |
|
2012 |
||
2013 |
aSize := inStream nextUnsignedShortMSB:msb. |
|
2014 |
arr := Array new:aSize. |
|
2015 |
||
2016 |
1 to:aSize do:[:i | |
|
2017 |
|element_index element| |
|
2018 |
||
2019 |
element_index := inStream nextUnsignedShortMSB:msb. |
|
2020 |
arr at:i put:element_index. |
|
2021 |
]. |
|
2022 |
Verbose ifTrue:[Transcript show:'array; size= '; showCR:aSize]. |
|
2023 |
||
2024 |
^ JavaUnresolvedSTArrayConstant |
|
2025 |
pool:constants |
|
2026 |
poolIndex:constSlot |
|
2027 |
array:arr |
|
2028 |
||
2029 |
"Created: / 7.5.1998 / 11:47:01 / cg" |
|
2030 |
"Modified: / 9.5.1998 / 00:25:34 / cg" |
|
2031 |
! |
|
2032 |
||
2033 |
readConstant_ST_ByteArray |
|
2034 |
|aSize arr| |
|
2035 |
||
2036 |
aSize := inStream nextUnsignedShortMSB:msb. |
|
2037 |
arr := ByteArray new:aSize. |
|
2038 |
||
2039 |
1 to:aSize do:[:i | |
|
2040 |
|element_index| |
|
2041 |
||
2042 |
arr at:i put:(inStream nextByte). |
|
2043 |
]. |
|
2044 |
Verbose ifTrue:[Transcript show:'byteArray; size= '; showCR:aSize]. |
|
2045 |
||
2046 |
^ arr |
|
2047 |
||
2048 |
"Created: / 7.5.1998 / 11:47:12 / cg" |
|
2049 |
! |
|
2050 |
||
2051 |
readConstant_ST_Character |
|
2052 |
|ascii| |
|
2053 |
||
2054 |
ascii := inStream nextUnsignedShortMSB:msb. |
|
2055 |
||
2056 |
Verbose ifTrue:[Transcript show:'char; ascii= '; showCR:ascii]. |
|
2057 |
^ Character value:ascii |
|
2058 |
||
2059 |
"Created: / 7.5.1998 / 11:48:12 / cg" |
|
2060 |
! |
|
2061 |
||
2062 |
readConstant_ST_Special |
|
2063 |
|type| |
|
2064 |
||
2065 |
type := inStream nextUnsignedShortMSB:msb. |
|
2066 |
^ #( |
|
2067 |
nil |
|
2068 |
true |
|
2069 |
false |
|
2070 |
) at:(type + 1) |
|
2071 |
||
2072 |
"Created: / 8.5.1998 / 23:06:56 / cg" |
|
2073 |
"Modified: / 9.5.1998 / 00:40:14 / cg" |
|
2074 |
! |
|
2075 |
||
2076 |
readConstant_ST_String |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2077 |
| tag string_index chars | |
782 | 2078 |
|
2079 |
||
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2080 |
string_index := inStream nextUnsignedShortMSB: msb. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2081 |
Verbose |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2082 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2083 |
[ Transcript |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2084 |
show: 'string; index= '; |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2085 |
showCR: string_index ]. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2086 |
|
752 | 2087 |
"/ resolve here if possible |
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2088 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2089 |
string_index < constSlot |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2090 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2091 |
[ chars := (constants at: string_index). |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2092 |
^ chars ]. |
752 | 2093 |
^ JavaUnresolvedSTStringConstant |
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2094 |
pool: constants |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2095 |
poolIndex: constSlot |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2096 |
stringIndex: string_index |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2097 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2098 |
"Created: / 07-05-1998 / 11:49:55 / cg" |
782 | 2099 |
"Modified: / 13-05-2011 / 17:32:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 2100 |
! |
2101 |
||
2102 |
readConstant_ST_Symbol |
|
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2103 |
| tag string_index chars | |
782 | 2104 |
|
2105 |
||
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2106 |
string_index := inStream nextUnsignedShortMSB: msb. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2107 |
Verbose |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2108 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2109 |
[ Transcript |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2110 |
show: 'symbol; index= '; |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2111 |
showCR: string_index ]. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2112 |
|
752 | 2113 |
"/ resolve here if possible |
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2114 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2115 |
string_index < constSlot |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2116 |
ifTrue: |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2117 |
[ chars := (constants at: string_index). |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2118 |
chars isString ifFalse: [ self halt: 'should not happen' ]. |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2119 |
^ chars asSymbol ]. |
752 | 2120 |
^ JavaUnresolvedSTSymbolConstant |
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2121 |
pool: constants |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2122 |
poolIndex: constSlot |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2123 |
stringIndex: string_index |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2124 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
775
diff
changeset
|
2125 |
"Modified: / 07-05-1998 / 11:48:28 / cg" |
782 | 2126 |
"Modified: / 13-05-2011 / 17:32:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 2127 |
! ! |
2128 |
||
2129 |
!JavaClassReader methodsFor:'file reading - fields'! |
|
2130 |
||
2131 |
readConstantValueAttributeFor:aField |
|
2132 |
|attribute_length constantvalue_index constantValue| |
|
2133 |
||
2134 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2135 |
||
2136 |
constantvalue_index := inStream nextUnsignedShortMSB:msb. |
|
2137 |
constantValue := constants at:constantvalue_index. |
|
2138 |
||
2139 |
aField constantValue:constantValue. |
|
2140 |
||
2141 |
Verbose ifTrue:[Transcript show:'constantValue: '; showCR:constantValue]. |
|
2142 |
^ true |
|
2143 |
||
2144 |
" |
|
2145 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2146 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
2147 |
" |
|
2148 |
||
2149 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2150 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2151 |
! |
|
2152 |
||
2153 |
readFieldInfofield |
|
2154 |
| access_flags name_index signature_index attributes_count field | |
|
797
8d4e7c17eadd
fixed JavaClassReader so it always sets staticFields
hlopkmar
parents:
796
diff
changeset
|
2155 |
|
752 | 2156 |
access_flags := inStream nextUnsignedShortMSB: msb. |
2157 |
name_index := inStream nextUnsignedShortMSB: msb. |
|
2158 |
signature_index := inStream nextUnsignedShortMSB: msb. |
|
2159 |
field := JavaField new. |
|
2160 |
field setAccessFlags: access_flags. |
|
2161 |
field setName: (constants at: name_index) asSymbol. |
|
2162 |
field setSignature: (constants at: signature_index) asSymbol. |
|
2163 |
field constantPool: constants. |
|
2164 |
attributes_count := inStream nextUnsignedShortMSB: msb. |
|
2165 |
Verbose |
|
2166 |
ifTrue: |
|
2167 |
[ Transcript |
|
2168 |
show: ' field name: '; |
|
2169 |
show: (constants at: name_index); |
|
2170 |
show: ' access: '; |
|
2171 |
show: access_flags; |
|
2172 |
show: ' attrib_cnt: '; |
|
2173 |
showCR: attributes_count ]. |
|
2174 |
1 to: attributes_count do: [:i | self readAttributeFor: field. ]. |
|
2175 |
^ field. |
|
2176 |
||
2177 |
" |
|
2178 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class'" |
|
2179 |
||
2180 |
"Created: / 15-04-1996 / 15:38:43 / cg" |
|
2181 |
"Modified: / 15-10-1998 / 10:38:01 / cg" |
|
2182 |
"Modified: / 17-12-2010 / 18:44:30 / Marcel Hlopko <hlopik@gmail.com>" |
|
797
8d4e7c17eadd
fixed JavaClassReader so it always sets staticFields
hlopkmar
parents:
796
diff
changeset
|
2183 |
"Modified: / 18-05-2011 / 14:11:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 2184 |
! |
2185 |
||
2186 |
readFieldInfofields |
|
2187 |
|nFields fields| |
|
2188 |
||
2189 |
"/ |
|
2190 |
"/ get fieldInfos |
|
2191 |
"/ |
|
2192 |
nFields := inStream nextUnsignedShortMSB:msb. |
|
2193 |
Verbose ifTrue:[Transcript show:'fieldsCount = '; showCR:nFields]. |
|
2194 |
||
2195 |
fields := Array new:nFields. |
|
2196 |
||
2197 |
1 to:nFields do:[:i | |
|
2198 |
Verbose ifTrue:[Transcript show:'field: '; showCR:i]. |
|
2199 |
fields at:i put:(self readFieldInfofield) |
|
2200 |
]. |
|
2201 |
^ fields |
|
2202 |
||
2203 |
" |
|
2204 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2205 |
" |
|
2206 |
||
2207 |
"Created: 15.4.1996 / 15:34:41 / cg" |
|
2208 |
"Modified: 15.4.1996 / 15:35:28 / cg" |
|
2209 |
! ! |
|
2210 |
||
2211 |
!JavaClassReader methodsFor:'file reading - interfaces'! |
|
2212 |
||
2213 |
readInterfaces |
|
2214 |
|interfacesCount interface_index interface interfaces| |
|
2215 |
||
2216 |
"/ |
|
2217 |
"/ get interfaces |
|
2218 |
"/ |
|
2219 |
interfacesCount := inStream nextUnsignedShortMSB:msb. |
|
2220 |
Verbose ifTrue:[Transcript show:'interfacesCount = '; showCR:interfacesCount]. |
|
2221 |
||
2222 |
interfaces := Array new:interfacesCount. |
|
2223 |
||
2224 |
1 to:interfacesCount do:[:i | |
|
2225 |
Verbose ifTrue:[Transcript show:'interface: '; showCR:i]. |
|
2226 |
interface_index := inStream nextUnsignedShortMSB:msb. |
|
2227 |
interface := constants at:interface_index. |
|
2228 |
||
2229 |
interfaces at:i put:interface. |
|
2230 |
]. |
|
2231 |
^ interfaces |
|
2232 |
||
2233 |
" |
|
2234 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2235 |
" |
|
2236 |
||
2237 |
"Created: 15.4.1996 / 15:31:59 / cg" |
|
2238 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2239 |
! ! |
|
2240 |
||
2241 |
!JavaClassReader methodsFor:'file reading - methods'! |
|
2242 |
||
2243 |
readCodeAttributeFor:aJavaMethod |
|
2244 |
|attribute_length max_stack max_locals code_length code |
|
2245 |
exception_table_length exception_table unknown1 unknown2| |
|
2246 |
||
2247 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2248 |
||
2249 |
Verbose ifTrue:[Transcript show:'code_attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
|
2250 |
||
2251 |
((minorVsn > 2) or:[majorVsn > 45]) ifTrue:[ |
|
2252 |
"/ should be: |
|
2253 |
max_stack := inStream nextUnsignedShortMSB:msb. |
|
2254 |
max_locals := inStream nextUnsignedShortMSB:msb. |
|
2255 |
code_length := inStream nextUnsignedLongMSB:msb. |
|
2256 |
||
2257 |
"/ unknown1 := inStream nextByte. |
|
2258 |
"/ max_stack := inStream nextByte. |
|
2259 |
"/ max_locals := inStream nextUnsignedShortMSB:msb. |
|
2260 |
"/ unknown2 := inStream nextUnsignedShortMSB:msb. |
|
2261 |
"/ code_length := inStream nextUnsignedShortMSB:msb. |
|
2262 |
"/ Verbose ifTrue:[Transcript show:'?1: '; showCR:unknown1]. |
|
2263 |
"/ Verbose ifTrue:[Transcript show:'?2: '; showCR:unknown2]. |
|
2264 |
] ifFalse:[ |
|
2265 |
max_stack := inStream nextByte. |
|
2266 |
max_locals := inStream nextByte. |
|
2267 |
code_length := inStream nextUnsignedShortMSB:msb. |
|
2268 |
]. |
|
2269 |
||
2270 |
Verbose ifTrue:[ |
|
2271 |
Transcript show:'code_length: '; showCR:(code_length printStringRadix:16). |
|
2272 |
Transcript show:'code at pos: '; showCR:inStream position |
|
2273 |
]. |
|
2274 |
||
2275 |
code_length ~~ 0 ifTrue:[ |
|
2276 |
code := ByteArray new:code_length. |
|
2277 |
inStream nextBytes:code_length into:code startingAt:1. |
|
2278 |
]. |
|
2279 |
Verbose ifTrue:[Transcript show:'method code: '; showCR:code.]. |
|
2280 |
||
2281 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
|
2282 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
|
2283 |
exception_table_length ~~ 0 ifTrue:[ |
|
2284 |
Verbose ifTrue:[Transcript show:'exceptionTable length:'; showCR:exception_table_length.]. |
|
2285 |
||
2286 |
exception_table := Array new:exception_table_length. |
|
2287 |
1 to:exception_table_length do:[:i | |
|
2288 |
|start_pc end_pc handler_pc catch_type| |
|
2289 |
||
2290 |
start_pc := inStream nextUnsignedShortMSB:msb. |
|
2291 |
end_pc := inStream nextUnsignedShortMSB:msb. |
|
2292 |
handler_pc := inStream nextUnsignedShortMSB:msb. |
|
2293 |
catch_type := inStream nextUnsignedShortMSB:msb. |
|
2294 |
catch_type ~= 0 ifTrue:[ |
|
2295 |
catch_type := constants at:catch_type. |
|
2296 |
]. |
|
2297 |
exception_table at:i put:(JavaExceptionTableEntry |
|
2298 |
startPC:start_pc |
|
2299 |
endPC:end_pc |
|
2300 |
handlerPC:handler_pc |
|
2301 |
catchType:catch_type). |
|
2302 |
]. |
|
2303 |
aJavaMethod setExceptionHandlerTable:exception_table. |
|
2304 |
]. |
|
2305 |
||
2306 |
aJavaMethod |
|
2307 |
setCode:code |
|
2308 |
maxStack:max_stack |
|
2309 |
maxLocals:max_locals |
|
2310 |
u1:unknown1 |
|
2311 |
u2:unknown2. |
|
2312 |
||
2313 |
self readAttributesFor:aJavaMethod. |
|
2314 |
^ true |
|
2315 |
||
2316 |
" |
|
2317 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2318 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
2319 |
" |
|
2320 |
||
2321 |
"Created: / 15-04-1996 / 15:40:17 / cg" |
|
2322 |
"Modified: / 16-05-1998 / 01:39:42 / cg" |
|
2323 |
"Modified: / 17-12-2010 / 00:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2324 |
! |
|
2325 |
||
2326 |
readExceptionsAttributeFor:aJavaMethod |
|
2327 |
|attribute_length exception_table_length exception_table| |
|
2328 |
||
2329 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2330 |
||
2331 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
|
2332 |
exception_table_length ~~ 0 ifTrue:[ |
|
2333 |
exception_table := Array new:exception_table_length. |
|
2334 |
1 to:exception_table_length do:[:i | |
|
2335 |
|idx ex| |
|
2336 |
||
2337 |
idx := inStream nextUnsignedShortMSB:msb. |
|
2338 |
ex := constants at:idx. |
|
2339 |
exception_table at:i put:ex. |
|
2340 |
]. |
|
2341 |
]. |
|
2342 |
||
2343 |
Verbose ifTrue:[Transcript showCR:'method has an exceptionTable']. |
|
2344 |
||
2345 |
aJavaMethod setExceptionTable:exception_table. |
|
2346 |
^ true |
|
2347 |
||
2348 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2349 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2350 |
! |
|
2351 |
||
2352 |
readLineNumberTableAttributeFor:aJavaMethod |
|
2353 |
|attribute_length line_number_table_length line_number_table| |
|
2354 |
||
2355 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2356 |
||
2357 |
line_number_table_length := inStream nextUnsignedShortMSB:msb. |
|
2358 |
line_number_table_length ~~ 0 ifTrue:[ |
|
2359 |
line_number_table := Array new:line_number_table_length. |
|
2360 |
1 to:line_number_table_length do:[:i | |
|
2361 |
|start_pc line_number| |
|
2362 |
||
2363 |
start_pc := inStream nextUnsignedShortMSB:msb. |
|
2364 |
line_number := inStream nextUnsignedShortMSB:msb. |
|
2365 |
line_number_table at:i put:(start_pc -> line_number). |
|
2366 |
]. |
|
2367 |
Verbose ifTrue:[Transcript showCR:'method has a lineNumberTable']. |
|
2368 |
||
2369 |
aJavaMethod setLineNumberTable:line_number_table. |
|
2370 |
]. |
|
2371 |
||
2372 |
^ true |
|
2373 |
||
2374 |
" |
|
2375 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2376 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
2377 |
" |
|
2378 |
||
2379 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
|
2380 |
"Modified: / 7.4.1998 / 19:08:42 / cg" |
|
2381 |
! |
|
2382 |
||
2383 |
readLocalVariableTableAttributeFor:aJavaMethod |
|
2384 |
|attribute_length local_variable_table_length local_variable_table| |
|
2385 |
||
2386 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2387 |
||
2388 |
local_variable_table_length := inStream nextUnsignedShortMSB:msb. |
|
2389 |
local_variable_table_length ~~ 0 ifTrue:[ |
|
2390 |
local_variable_table := JavaLocalVariableTable new:local_variable_table_length. |
|
2391 |
1 to:local_variable_table_length do:[:i | |
|
2392 |
|start_pc length name_index sig_index slot name signature| |
|
2393 |
||
2394 |
start_pc := inStream nextUnsignedShortMSB:msb. |
|
2395 |
length := inStream nextUnsignedShortMSB:msb. |
|
2396 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2397 |
name := constants at:name_index. |
|
2398 |
sig_index := inStream nextUnsignedShortMSB:msb. |
|
2399 |
signature := constants at:sig_index. |
|
2400 |
slot := inStream nextUnsignedShortMSB:msb. |
|
2401 |
||
2402 |
local_variable_table at:i put:(JavaLocalVariableTableEntry new |
|
2403 |
startPC:start_pc |
|
2404 |
length:length |
|
2405 |
name:name |
|
2406 |
signature:signature |
|
2407 |
slot:slot) |
|
2408 |
]. |
|
2409 |
]. |
|
2410 |
||
2411 |
Verbose ifTrue:[Transcript showCR:'method has a localvariableTable']. |
|
2412 |
||
2413 |
aJavaMethod setLocalVariableTable:local_variable_table. |
|
2414 |
^ true |
|
2415 |
||
2416 |
" |
|
2417 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2418 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
2419 |
" |
|
2420 |
||
2421 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2422 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2423 |
! |
|
2424 |
||
2425 |
readMethodFor:aClass |
|
2426 |
|m access_flags name_index name signature_index signature |
|
2427 |
tooManyArgs| |
|
2428 |
||
2429 |
"/ |
|
2430 |
"/ get a method |
|
2431 |
"/ |
|
2432 |
access_flags := inStream nextUnsignedShortMSB:msb. |
|
2433 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2434 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
2435 |
||
2436 |
name := constants at:name_index. |
|
2437 |
signature := constants at:signature_index. |
|
2438 |
||
2439 |
Verbose ifTrue:[ |
|
2440 |
Transcript show:'method name:'; showCR:name. |
|
2441 |
Transcript show:'signature:'; showCR:signature. |
|
2442 |
]. |
|
2443 |
||
2444 |
aClass isJavaClass ifTrue:[ |
|
2445 |
(access_flags bitAnd:JavaMethod A_NATIVE) ~~ 0 ifTrue:[ |
|
2446 |
m := JavaNativeMethod new. |
|
2447 |
] ifFalse:[ |
|
2448 |
m := JavaMethodWithHandler new. |
|
2449 |
]. |
|
2450 |
m setAccessFlags:access_flags. |
|
2451 |
tooManyArgs := false. |
|
2452 |
ArgumentError handle:[:ex | |
|
2453 |
'JAVA: ***** java method has too many arguments - will fail to execute' infoPrintCR. |
|
2454 |
tooManyArgs := true. |
|
2455 |
ex proceed. |
|
2456 |
] do:[ |
|
2457 |
m setName:name signature:signature. |
|
2458 |
]. |
|
2459 |
m setJavaClass:aClass. |
|
2460 |
||
2461 |
self readAttributesFor:m. |
|
2462 |
||
2463 |
tooManyArgs ifTrue:[ |
|
2464 |
m code:nil. |
|
2465 |
m byteCode:nil. |
|
2466 |
]. |
|
2467 |
(m exceptionHandlerTable isNil) ifTrue:[ |
|
2468 |
m isNative ifFalse:[ |
|
2469 |
m getExceptionTable isNil ifTrue:[ |
|
2470 |
m := JavaMethod fromMethod:m |
|
2471 |
] ifFalse:[ |
|
2472 |
m := JavaMethodWithException fromMethod:m |
|
2473 |
] |
|
2474 |
] |
|
2475 |
] ifFalse:[ |
|
2476 |
m setAccessFlags:(m accessFlags bitOr:JavaMethod A_HASHANDLER) |
|
2477 |
]. |
|
2478 |
aClass addMethod:m name:name signature:signature. |
|
2479 |
] ifFalse:[ |
|
2480 |
m := Method new. |
|
2481 |
self readAttributesFor:m. |
|
2482 |
(access_flags bitTest:JavaMethod A_STATIC) ifTrue:[ |
|
2483 |
aClass class primAddSelector:name asSymbol withMethod:m. |
|
2484 |
] ifFalse:[ |
|
2485 |
aClass primAddSelector:name asSymbol withMethod:m. |
|
2486 |
] |
|
2487 |
]. |
|
2488 |
||
2489 |
" |
|
2490 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2491 |
" |
|
2492 |
||
2493 |
"Created: / 15-04-1996 / 16:48:49 / cg" |
|
2494 |
"Modified: / 25-09-1999 / 23:16:25 / cg" |
|
2495 |
"Modified: / 04-02-2011 / 23:07:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2496 |
! |
|
2497 |
||
2498 |
readMethodsFor:aJavaClass |
|
2499 |
|methodsCount method| |
|
2500 |
||
2501 |
"/ |
|
2502 |
"/ get methods |
|
2503 |
"/ |
|
2504 |
methodsCount := inStream nextUnsignedShortMSB:msb. |
|
2505 |
Verbose ifTrue:[Transcript show:'methodsCount = '; showCR:methodsCount]. |
|
2506 |
||
2507 |
1 to:methodsCount do:[:i | |
|
2508 |
Verbose ifTrue:[Transcript show:'method: '; showCR:i]. |
|
2509 |
method := self readMethodFor:aJavaClass |
|
2510 |
]. |
|
2511 |
||
2512 |
" |
|
2513 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2514 |
" |
|
2515 |
||
2516 |
"Created: / 15.4.1996 / 16:46:30 / cg" |
|
2517 |
"Modified: / 8.5.1998 / 21:20:59 / cg" |
|
2518 |
! ! |
|
2519 |
||
2520 |
!JavaClassReader methodsFor:'file reading - methods-ST'! |
|
2521 |
||
2522 |
readSTCodeAttributeFor:aSmalltalkMethod |
|
2523 |
|attribute_length max_stack max_locals code_length code |
|
2524 |
exception_table_length unknown1 unknown2| |
|
2525 |
||
2526 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2527 |
||
2528 |
Verbose ifTrue:[Transcript show:'attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
|
2529 |
||
2530 |
max_stack := inStream nextUnsignedShortMSB:msb. |
|
2531 |
max_locals := inStream nextUnsignedShortMSB:msb. |
|
2532 |
||
2533 |
code_length := inStream nextUnsignedLongMSB:msb. |
|
2534 |
Verbose ifTrue:[Transcript show:'code_length: '; showCR:(code_length printStringRadix:16)]. |
|
2535 |
Verbose ifTrue:[Transcript show:'code at pos: '; showCR:inStream position]. |
|
2536 |
||
2537 |
code_length ~~ 0 ifTrue:[ |
|
2538 |
code := ByteArray new:code_length. |
|
2539 |
inStream nextBytes:code_length into:code startingAt:1. |
|
2540 |
]. |
|
2541 |
Verbose ifTrue:[Transcript show:'method code: '; showCR:code.]. |
|
2542 |
||
2543 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
|
2544 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
|
2545 |
exception_table_length ~~ 0 ifTrue:[ |
|
2546 |
self error:'unexpected exceptionTable length'. |
|
2547 |
"/ skip it. |
|
2548 |
1 to:exception_table_length do:[:i | |
|
2549 |
"start_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2550 |
"end_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2551 |
"handler_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2552 |
"catch_type :=" inStream nextUnsignedShortMSB:msb. |
|
2553 |
]. |
|
2554 |
]. |
|
2555 |
||
2556 |
aSmalltalkMethod byteCode:code. |
|
2557 |
aSmalltalkMethod stackSize:max_stack . |
|
2558 |
aSmalltalkMethod numberOfVars:max_locals. |
|
2559 |
||
2560 |
self readAttributesFor:aSmalltalkMethod. |
|
2561 |
^ true |
|
2562 |
||
2563 |
"Modified: / 16.5.1998 / 01:39:30 / cg" |
|
2564 |
! |
|
2565 |
||
2566 |
readSTLiteralsAttributeFor:aSmalltalkMethod |
|
2567 |
|attribute_length literal_table_length literal_table litIndex literal| |
|
2568 |
||
2569 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2570 |
||
2571 |
literal_table_length := inStream nextUnsignedShortMSB:msb. |
|
2572 |
literal_table_length ~~ 0 ifTrue:[ |
|
2573 |
literal_table := Array new:literal_table_length. |
|
2574 |
1 to:literal_table_length do:[:i | |
|
2575 |
litIndex := inStream nextUnsignedShortMSB:msb. |
|
2576 |
literal := (constants at:litIndex). |
|
2577 |
literal_table at:i put:literal. |
|
2578 |
]. |
|
2579 |
]. |
|
2580 |
Verbose ifTrue:[Transcript show:'literals: '; showCR:literal_table storeString.]. |
|
2581 |
||
2582 |
"Created: / 7.5.1998 / 11:52:28 / cg" |
|
2583 |
"Modified: / 16.5.1998 / 01:52:27 / cg" |
|
2584 |
! |
|
2585 |
||
2586 |
readSTMethodCategoryAttributeFor:aSmalltalkMethod |
|
2587 |
|attribute_length name_index name| |
|
2588 |
||
2589 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2590 |
||
2591 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2592 |
name := (constants at:name_index). |
|
2593 |
||
2594 |
aSmalltalkMethod category:name. |
|
2595 |
||
2596 |
"Modified: / 8.5.1998 / 20:39:59 / cg" |
|
2597 |
"Created: / 16.5.1998 / 01:04:19 / cg" |
|
2598 |
! ! |
|
2599 |
||
775 | 2600 |
!JavaClassReader methodsFor:'helpers'! |
2601 |
||
798
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
2602 |
loadSuperclassIdentifiedBy: something ignoring: classesBeingLoaded |
877 | 2603 |
"overriding method, here we expect something to be new JavaClassRef2" |
2604 |
||
2605 |
self assert: something isJavaRef |
|
2606 |
message: 'class identifier is not a java reference'. |
|
2607 |
||
2608 |
self assert: something isJavaClassRef |
|
2609 |
message: 'class identifier is not a java class reference'. |
|
2610 |
||
2611 |
(classesBeingLoaded includes: something fullName) ifTrue: |
|
2612 |
[self error: 'class we want to load is being loaded and that means something went wrong. tell mh']. |
|
2613 |
||
2614 |
"Do NOT use >>something resolve<< here, since something |
|
2615 |
has no owner set and therefore access check will cause DNU. |
|
2616 |
Ask JV for details." |
|
2617 |
||
2618 |
^Java classForName: something javaClassName. |
|
2619 |
||
2620 |
"Created: / 18-05-2011 / 14:55:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2621 |
"Modified: / 22-05-2011 / 13:58:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
798
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
2622 |
! |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
797
diff
changeset
|
2623 |
|
775 | 2624 |
updateOwnerInCPItem: each |
2625 |
((each isJavaRef and: [ each isNewJavaRef ]) |
|
2626 |
or: [ each isJavaNameAndType and: [ each isNewJavaNameAndType ] ]) |
|
2627 |
ifTrue: [ each owner: classBeingLoaded ]. |
|
2628 |
||
2629 |
"Created: / 12-05-2011 / 17:40:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
2630 |
! |
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
2631 |
|
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
2632 |
updateOwnerInField: each |
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
2633 |
|
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
2634 |
each setClass: classBeingLoaded. |
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
2635 |
|
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
2636 |
"Created: / 18-05-2011 / 13:57:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
775 | 2637 |
! ! |
2638 |
||
799 | 2639 |
!JavaClassReader methodsFor:'logging'! |
2640 |
||
2641 |
info: message |
|
2642 |
Verbose ifTrue: [ Transcript showCR: message printString ]. |
|
2643 |
||
2644 |
"Created: / 18-05-2011 / 15:06:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2645 |
! ! |
|
2646 |
||
752 | 2647 |
!JavaClassReader class methodsFor:'documentation'! |
2648 |
||
2649 |
version |
|
877 | 2650 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaClassReader.st,v 1.92 2009/10/09 14:21:53 cg Exp $' |
752 | 2651 |
! |
2652 |
||
2653 |
version_CVS |
|
2654 |
^ '§Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaClassReader.st,v 1.92 2009/10/09 14:21:53 cg Exp §' |
|
2655 |
! |
|
2656 |
||
2657 |
version_SVN |
|
2658 |
^ '$Id$' |
|
2659 |
! ! |
|
2660 |
||
2661 |
JavaClassReader initialize! |