454
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG
|
511
|
3 |
All Rights Reserved
|
454
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
|
|
14 |
|
427
|
15 |
Context variableSubclass:#JavaContext
|
511
|
16 |
instanceVariableNames:'exArg exPC byteCode constPool method'
|
28
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Java-Support'
|
|
20 |
!
|
|
21 |
|
454
|
22 |
!JavaContext class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1997 by eXept Software AG
|
511
|
27 |
All Rights Reserved
|
454
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
|
|
37 |
|
|
38 |
! !
|
28
|
39 |
|
|
40 |
!JavaContext methodsFor:'ST context mimicri'!
|
|
41 |
|
261
|
42 |
arg1Index
|
|
43 |
"the java stack contains the receiver in a non-static
|
|
44 |
method, as slot 0. Therefore, the first arg is found at slot2
|
|
45 |
if this is for a non-static method"
|
252
|
46 |
|
|
47 |
self method isStatic ifTrue:[
|
261
|
48 |
^ 1
|
252
|
49 |
].
|
261
|
50 |
^ 2
|
|
51 |
!
|
|
52 |
|
|
53 |
argAt:n
|
|
54 |
"return the i'th argument (1..nArgs)"
|
|
55 |
|
|
56 |
^ self at:(self arg1Index - 1 + n)
|
252
|
57 |
|
|
58 |
"Created: / 2.1.1998 / 17:54:13 / cg"
|
|
59 |
"Modified: / 2.1.1998 / 21:39:30 / cg"
|
|
60 |
!
|
117
|
61 |
|
252
|
62 |
argAt:n put:value
|
261
|
63 |
"change the i'th argument (1..nArgs)"
|
216
|
64 |
|
261
|
65 |
^ super argAt:(self arg1Index - 1 + n) put:value
|
252
|
66 |
|
|
67 |
"Created: / 2.1.1998 / 17:54:34 / cg"
|
|
68 |
"Modified: / 2.1.1998 / 21:35:19 / cg"
|
|
69 |
!
|
|
70 |
|
|
71 |
args
|
|
72 |
"return an array filled with the arguments of this context"
|
|
73 |
|
261
|
74 |
|n|
|
28
|
75 |
|
252
|
76 |
n := self numArgs.
|
|
77 |
n == 0 ifTrue:[
|
261
|
78 |
"/ little optimization here - avoid creating empty containers
|
255
|
79 |
^ #()
|
252
|
80 |
].
|
|
81 |
|
261
|
82 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:(self arg1Index).
|
252
|
83 |
|
|
84 |
"Created: / 2.1.1998 / 17:54:57 / cg"
|
|
85 |
"Modified: / 2.1.1998 / 21:34:44 / cg"
|
|
86 |
!
|
|
87 |
|
|
88 |
argsAndVars
|
|
89 |
"return an array filled with the arguments and variables of this context"
|
|
90 |
|
261
|
91 |
|n|
|
28
|
92 |
|
252
|
93 |
n := self numArgs + self numVars.
|
|
94 |
n == 0 ifTrue:[
|
363
|
95 |
"/ little optimization here - avoid creating empty containers
|
|
96 |
^ #()
|
252
|
97 |
].
|
261
|
98 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:(self arg1Index).
|
252
|
99 |
|
|
100 |
"Created: / 2.1.1998 / 17:55:14 / cg"
|
261
|
101 |
"Modified: / 13.1.1998 / 15:44:56 / cg"
|
28
|
102 |
!
|
|
103 |
|
252
|
104 |
lineNumber
|
|
105 |
|nr pc|
|
156
|
106 |
|
252
|
107 |
pc := self pc.
|
43
|
108 |
|
211
|
109 |
"/ 'ask line for pc:' print. pc printCR.
|
255
|
110 |
pc isNil ifTrue:[
|
363
|
111 |
nr := self lineNumberFromMethod.
|
|
112 |
nr notNil ifTrue:[
|
|
113 |
^ nr
|
|
114 |
].
|
|
115 |
" '-> 0 [a]' printCR. "
|
|
116 |
^0
|
255
|
117 |
].
|
43
|
118 |
|
252
|
119 |
nr := self method lineNumberForPC:pc.
|
255
|
120 |
nr isNil ifTrue:[
|
363
|
121 |
nr := self lineNumberFromMethod.
|
|
122 |
nr notNil ifTrue:[
|
|
123 |
^ nr
|
|
124 |
].
|
|
125 |
" '-> 0 [b]' printCR. "
|
|
126 |
^ 0
|
255
|
127 |
].
|
211
|
128 |
"/ '-> ' print. nr printCR.
|
210
|
129 |
^ nr.
|
28
|
130 |
|
252
|
131 |
"Created: / 1.5.1996 / 15:05:47 / cg"
|
261
|
132 |
"Modified: / 15.1.1998 / 15:25:29 / cg"
|
28
|
133 |
!
|
|
134 |
|
252
|
135 |
lineNumberFromMethod
|
|
136 |
|m|
|
|
137 |
|
|
138 |
m := self method.
|
|
139 |
m notNil ifTrue:[
|
255
|
140 |
^ m lineNumber
|
252
|
141 |
].
|
|
142 |
^ nil
|
28
|
143 |
|
252
|
144 |
"Created: / 4.1.1998 / 23:34:45 / cg"
|
|
145 |
"Modified: / 4.1.1998 / 23:35:55 / cg"
|
|
146 |
!
|
|
147 |
|
|
148 |
method
|
|
149 |
"the method may be found in the interpreter temps ..."
|
|
150 |
|
382
|
151 |
(method isKindOf:JavaMethod) ifTrue:[^ method].
|
252
|
152 |
^ super method
|
|
153 |
|
|
154 |
"Created: / 1.5.1996 / 15:03:43 / cg"
|
382
|
155 |
"Modified: / 16.10.1998 / 01:22:12 / cg"
|
28
|
156 |
!
|
|
157 |
|
|
158 |
methodHome
|
|
159 |
^ self
|
|
160 |
!
|
|
161 |
|
|
162 |
numArgs
|
252
|
163 |
"return the number of args.
|
|
164 |
Redefined since Java keeps the receiver of a non-static method
|
261
|
165 |
at local slot 1."
|
28
|
166 |
|
252
|
167 |
|n|
|
198
|
168 |
|
252
|
169 |
n := super numArgs.
|
|
170 |
self method isStatic ifFalse:[
|
255
|
171 |
n := n - 1
|
252
|
172 |
].
|
|
173 |
^ n
|
28
|
174 |
|
252
|
175 |
"Created: / 2.1.1998 / 22:21:24 / cg"
|
28
|
176 |
!
|
|
177 |
|
261
|
178 |
numTemps
|
|
179 |
"return the number of temporary variables of the Method.
|
|
180 |
Redefined since Java keeps the receiver of a non-static method
|
|
181 |
at local slot 1."
|
|
182 |
|
|
183 |
|n|
|
|
184 |
|
|
185 |
n := self size - super numVars - super numArgs.
|
|
186 |
^ n
|
|
187 |
|
|
188 |
"Created: / 13.1.1998 / 16:52:32 / cg"
|
|
189 |
"Modified: / 13.1.1998 / 17:23:27 / cg"
|
|
190 |
!
|
|
191 |
|
|
192 |
numVars
|
|
193 |
"return the number of locals.
|
|
194 |
Redefined since Java keeps the receiver of a non-static method
|
|
195 |
at local slot 0 and holds the args as locals."
|
|
196 |
|
|
197 |
|n|
|
|
198 |
|
|
199 |
n := super numVars.
|
|
200 |
^ n - self numArgs
|
|
201 |
|
|
202 |
"Created: / 13.1.1998 / 17:03:08 / cg"
|
|
203 |
"Modified: / 13.1.1998 / 17:25:16 / cg"
|
|
204 |
!
|
|
205 |
|
32
|
206 |
pc
|
252
|
207 |
lineNr isNil ifTrue:[^ nil].
|
429
|
208 |
^ lineNr bitAnd:16rFFFF
|
28
|
209 |
|
252
|
210 |
"Created: / 4.1.1998 / 23:33:48 / cg"
|
429
|
211 |
"Modified: / 10.11.1998 / 13:20:12 / cg"
|
|
212 |
!
|
|
213 |
|
|
214 |
quickLineNumber
|
|
215 |
"the lineNumber - without decompiling"
|
|
216 |
|
|
217 |
^ self method quickLineNumberForPC:self pc
|
|
218 |
|
|
219 |
"Created: / 10.11.1998 / 14:20:30 / cg"
|
117
|
220 |
!
|
|
221 |
|
252
|
222 |
selector
|
|
223 |
"the selector can be extracted from the method.
|
|
224 |
the method may be found in the interpreter temps ..."
|
|
225 |
|
|
226 |
|s m|
|
|
227 |
|
|
228 |
selector isNil ifTrue:[
|
|
229 |
m := self method.
|
|
230 |
m notNil ifTrue:[
|
|
231 |
^ m name
|
|
232 |
]
|
|
233 |
].
|
|
234 |
^ super selector
|
|
235 |
|
|
236 |
"Modified: / 30.12.1997 / 17:22:06 / cg"
|
|
237 |
"Created: / 30.12.1997 / 17:23:47 / cg"
|
125
|
238 |
!
|
|
239 |
|
252
|
240 |
setPC:newPC
|
|
241 |
lineNr := newPC
|
|
242 |
|
|
243 |
"Created: / 5.1.1998 / 00:09:02 / cg"
|
261
|
244 |
!
|
|
245 |
|
|
246 |
temporaries
|
|
247 |
"return an array filled with the arguments and variables of this context"
|
|
248 |
|
|
249 |
|n nSkipped|
|
|
250 |
|
|
251 |
"/ the flas-numVars includes the receiver and args
|
|
252 |
nSkipped := super numVars "self numArgs + self numVars".
|
|
253 |
"/ but my context setup is args+numvars.
|
|
254 |
nSkipped := super numArgs + super numVars.
|
|
255 |
|
|
256 |
n := self size - nSkipped.
|
|
257 |
n == 0 ifTrue:[
|
363
|
258 |
"/ little optimization here - avaoid creating empty containers
|
|
259 |
^ #()
|
261
|
260 |
].
|
|
261 |
|
|
262 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:nSkipped+1.
|
|
263 |
|
|
264 |
"Created: / 13.1.1998 / 15:44:12 / cg"
|
|
265 |
"Modified: / 13.1.1998 / 17:22:54 / cg"
|
|
266 |
!
|
|
267 |
|
|
268 |
vars
|
|
269 |
"return an array filled with the local variables of this context"
|
|
270 |
|
|
271 |
|nonVars mySize|
|
|
272 |
|
|
273 |
mySize := self numVars.
|
|
274 |
mySize == 0 ifTrue:[
|
363
|
275 |
"/ little optimization here - avaoid creating empty containers
|
|
276 |
^ #()
|
261
|
277 |
].
|
|
278 |
nonVars := (self arg1Index-1) + self numArgs.
|
|
279 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1
|
|
280 |
|
|
281 |
"Created: / 13.1.1998 / 16:48:16 / cg"
|
252
|
282 |
! !
|
|
283 |
|
|
284 |
!JavaContext methodsFor:'exception handler support'!
|
117
|
285 |
|
255
|
286 |
exceptionArg:aJavaException
|
511
|
287 |
exArg := aJavaException.
|
|
288 |
|
|
289 |
"Created: / 7.1.1998 / 21:36:56 / cg"
|
|
290 |
!
|
|
291 |
|
|
292 |
exceptionArg:aJavaException pc:newPc
|
|
293 |
exArg := aJavaException.
|
|
294 |
exPC := newPc.
|
255
|
295 |
|
|
296 |
"Created: / 7.1.1998 / 21:36:56 / cg"
|
|
297 |
!
|
|
298 |
|
252
|
299 |
markForException
|
|
300 |
"set the exception handler flag in the receiver.
|
|
301 |
The JVM needs this to enter an exception handler instead of restarting
|
|
302 |
from the beginning (when the context is restarted).
|
|
303 |
- a highly internal mechanism and not for public use."
|
117
|
304 |
|
363
|
305 |
flags := flags bitOr:16r08000000.
|
|
306 |
|
|
307 |
"/ %{ /* NOCONTEXT */
|
|
308 |
"/ __INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__JAVA_EX_PEND));
|
|
309 |
"/ %}
|
252
|
310 |
|
|
311 |
"Modified: 13.12.1995 / 19:05:22 / cg"
|
28
|
312 |
! !
|
|
313 |
|
|
314 |
!JavaContext methodsFor:'printing & storing'!
|
|
315 |
|
252
|
316 |
receiverPrintString
|
|
317 |
"return a string describing the receiver of the context"
|
52
|
318 |
|
252
|
319 |
|receiverClass receiverClassName newString implementorClass|
|
28
|
320 |
|
363
|
321 |
"/ %{
|
|
322 |
"/ /*
|
|
323 |
"/ * special handling for (invalid) free objects.
|
|
324 |
"/ * these only appear if some primitiveCode does not correctly use SEND macros,
|
|
325 |
"/ * which may lead to sends to free objects. In normal operation, this 'cannot' happen.
|
|
326 |
"/ */
|
|
327 |
"/ if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) {
|
|
328 |
"/ receiverClassName = __MKSTRING("FreeObject");
|
|
329 |
"/ }
|
|
330 |
"/ %}.
|
252
|
331 |
receiverClassName notNil ifTrue:[^ receiverClassName].
|
228
|
332 |
|
252
|
333 |
receiverClass := receiver class.
|
|
334 |
receiverClassName := receiverClass name.
|
|
335 |
(receiverClass == SmallInteger) ifTrue:[
|
|
336 |
newString := '(' , receiver printString , ') ' , receiverClassName
|
228
|
337 |
] ifFalse:[
|
252
|
338 |
newString := receiverClassName
|
228
|
339 |
].
|
|
340 |
|
252
|
341 |
"
|
|
342 |
kludge to avoid slow search for containing class
|
|
343 |
"
|
|
344 |
(selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
|
|
345 |
implementorClass := self methodClass.
|
|
346 |
].
|
|
347 |
implementorClass notNil ifTrue: [
|
|
348 |
(implementorClass ~~ receiverClass) ifTrue: [
|
|
349 |
newString := newString , '>>>',
|
|
350 |
implementorClass name printString
|
|
351 |
]
|
|
352 |
] ifFalse:[
|
|
353 |
self searchClass ~~ receiverClass ifTrue:[
|
|
354 |
newString := newString , '>>>' , self searchClass name
|
|
355 |
].
|
|
356 |
"/ "
|
|
357 |
"/ kludge for doIt - these unbound methods are not
|
|
358 |
"/ found in the classes methodDictionary
|
|
359 |
"/ "
|
|
360 |
"/ (selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
|
|
361 |
"/ newString := newString , '>>>**NONE**'
|
|
362 |
"/ ]
|
28
|
363 |
].
|
|
364 |
|
252
|
365 |
^ newString
|
28
|
366 |
|
|
367 |
! !
|
|
368 |
|
343
|
369 |
!JavaContext methodsFor:'queries'!
|
|
370 |
|
|
371 |
hasStackToShow
|
|
372 |
"private interface to the debugger.
|
|
373 |
Smalltalk contexts return false here - other language frames
|
|
374 |
(i.e. Java frames) may want to show the evaluation stack"
|
|
375 |
|
|
376 |
^ true
|
|
377 |
|
|
378 |
"Modified: / 13.5.1997 / 16:31:12 / cg"
|
|
379 |
"Created: / 7.5.1998 / 01:23:57 / cg"
|
|
380 |
!
|
|
381 |
|
346
|
382 |
isJavaContext
|
|
383 |
"return true, if this is a javaContext."
|
|
384 |
|
|
385 |
^ true
|
|
386 |
|
|
387 |
"Created: / 8.5.1998 / 21:23:47 / cg"
|
|
388 |
!
|
|
389 |
|
343
|
390 |
stackFrame
|
|
391 |
"private interface to the debugger."
|
|
392 |
|
|
393 |
^ (1 to:self size) collect:[:i | self at:i]
|
|
394 |
|
|
395 |
"Created: / 7.5.1998 / 01:26:19 / cg"
|
|
396 |
! !
|
|
397 |
|
129
|
398 |
!JavaContext class methodsFor:'documentation'!
|
28
|
399 |
|
|
400 |
version
|
511
|
401 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaContext.st,v 1.29 1999/01/04 16:01:50 cg Exp $'
|
28
|
402 |
! !
|