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