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