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 |
Context variableSubclass:#JavaContext
|
1093
|
45 |
instanceVariableNames:'exArg exPC byteCode constPool acqrMonitors'
|
752
|
46 |
classVariableNames:''
|
|
47 |
poolDictionaries:''
|
|
48 |
category:'Languages-Java-Support'
|
|
49 |
!
|
|
50 |
|
|
51 |
!JavaContext class methodsFor:'documentation'!
|
|
52 |
|
|
53 |
copyright
|
|
54 |
"
|
877
|
55 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
56 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
57 |
SWING Research Group, Czech Technical University in Prague
|
|
58 |
|
|
59 |
Parts of the code written by Claus Gittinger are under following
|
|
60 |
license:
|
752
|
61 |
|
|
62 |
This software is furnished under a license and may be used
|
|
63 |
only in accordance with the terms of that license and with the
|
|
64 |
inclusion of the above copyright notice. This software may not
|
|
65 |
be provided or otherwise made available to, or used by, any
|
|
66 |
other person. No title to or ownership of the software is
|
|
67 |
hereby transferred.
|
877
|
68 |
|
|
69 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
|
|
70 |
|
|
71 |
Permission is hereby granted, free of charge, to any person
|
|
72 |
obtaining a copy of this software and associated documentation
|
|
73 |
files (the 'Software'), to deal in the Software without
|
|
74 |
restriction, including without limitation the rights to use,
|
|
75 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
76 |
copies of the Software, and to permit persons to whom the
|
|
77 |
Software is furnished to do so, subject to the following
|
|
78 |
conditions:
|
752
|
79 |
|
877
|
80 |
The above copyright notice and this permission notice shall be
|
|
81 |
included in all copies or substantial portions of the Software.
|
752
|
82 |
|
877
|
83 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
84 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
85 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
86 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
87 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
88 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
89 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
90 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
91 |
|
|
92 |
[1] Code written at SWING Research Group contain a signature
|
|
93 |
of one of the above copright owners.
|
|
94 |
|
|
95 |
"
|
752
|
96 |
! !
|
|
97 |
|
|
98 |
!JavaContext methodsFor:'* As yet uncategorized *'!
|
|
99 |
|
|
100 |
markForException
|
|
101 |
"set the exception handler flag in the receiver.
|
|
102 |
The JVM needs this to enter an exception handler instead of restarting
|
|
103 |
from the beginning (when the context is restarted).
|
|
104 |
- a highly internal mechanism and not for public use."
|
|
105 |
"
|
|
106 |
%{ /* NOCONTEXT */
|
|
107 |
#ifdef __JAVA_EX_PEND
|
|
108 |
/* actually no longer - only a non-nil exPC is now used as marker */
|
|
109 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__JAVA_EX_PEND));
|
|
110 |
#endif
|
|
111 |
%}
|
|
112 |
"
|
|
113 |
|
|
114 |
"Modified: / 13-12-1995 / 19:05:22 / cg"
|
|
115 |
"Modified: / 25-10-2010 / 17:19:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
116 |
! !
|
|
117 |
|
|
118 |
!JavaContext methodsFor:'ST context mimicri'!
|
|
119 |
|
|
120 |
arg1Index
|
|
121 |
"the java stack contains the receiver in a non-static
|
|
122 |
method, as slot 0. Therefore, the first arg is found at slot2
|
|
123 |
if this is for a non-static method"
|
|
124 |
|
|
125 |
self method isStatic ifTrue:[
|
|
126 |
^ 1
|
|
127 |
].
|
|
128 |
^ 2
|
|
129 |
!
|
|
130 |
|
|
131 |
argAt:n
|
|
132 |
"return the i'th argument (1..nArgs)"
|
|
133 |
|
|
134 |
^ self at:(self arg1Index - 1 + n)
|
|
135 |
|
|
136 |
"Created: / 2.1.1998 / 17:54:13 / cg"
|
|
137 |
"Modified: / 2.1.1998 / 21:39:30 / cg"
|
|
138 |
!
|
|
139 |
|
|
140 |
argAt:n put:value
|
|
141 |
"change the i'th argument (1..nArgs)"
|
|
142 |
|
|
143 |
^ super argAt:(self arg1Index - 1 + n) put:value
|
|
144 |
|
|
145 |
"Created: / 2.1.1998 / 17:54:34 / cg"
|
|
146 |
"Modified: / 2.1.1998 / 21:35:19 / cg"
|
|
147 |
!
|
|
148 |
|
|
149 |
args
|
|
150 |
"return an array filled with the arguments of this context"
|
|
151 |
|
|
152 |
|n|
|
|
153 |
|
|
154 |
n := self numArgs.
|
|
155 |
n == 0 ifTrue:[
|
|
156 |
"/ little optimization here - avoid creating empty containers
|
|
157 |
^ #()
|
|
158 |
].
|
|
159 |
|
|
160 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:(self arg1Index).
|
|
161 |
|
|
162 |
"Created: / 2.1.1998 / 17:54:57 / cg"
|
|
163 |
"Modified: / 2.1.1998 / 21:34:44 / cg"
|
|
164 |
!
|
|
165 |
|
|
166 |
argsAndVars
|
|
167 |
"return an array filled with the arguments and variables of this context"
|
|
168 |
|
|
169 |
|n|
|
|
170 |
|
|
171 |
n := self numArgs + self numVars.
|
|
172 |
n == 0 ifTrue:[
|
|
173 |
"/ little optimization here - avoid creating empty containers
|
|
174 |
^ #()
|
|
175 |
].
|
|
176 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:(self arg1Index).
|
|
177 |
|
|
178 |
"Created: / 2.1.1998 / 17:55:14 / cg"
|
|
179 |
"Modified: / 13.1.1998 / 15:44:56 / cg"
|
|
180 |
!
|
|
181 |
|
|
182 |
lineNumber
|
|
183 |
|nr pc|
|
|
184 |
|
|
185 |
pc := self pc.
|
|
186 |
|
|
187 |
"/ 'ask line for pc:' print. pc printCR.
|
|
188 |
pc isNil ifTrue:[
|
|
189 |
nr := self lineNumberFromMethod.
|
|
190 |
nr notNil ifTrue:[
|
|
191 |
^ nr
|
|
192 |
].
|
|
193 |
" '-> 0 [a]' printCR. "
|
|
194 |
^0
|
|
195 |
].
|
|
196 |
|
|
197 |
nr := self method lineNumberForPC:pc.
|
|
198 |
nr isNil ifTrue:[
|
|
199 |
nr := self lineNumberFromMethod.
|
|
200 |
nr notNil ifTrue:[
|
|
201 |
^ nr
|
|
202 |
].
|
|
203 |
" '-> 0 [b]' printCR. "
|
|
204 |
^ 0
|
|
205 |
].
|
|
206 |
"/ '-> ' print. nr printCR.
|
|
207 |
^ nr.
|
|
208 |
|
|
209 |
"Created: / 1.5.1996 / 15:05:47 / cg"
|
|
210 |
"Modified: / 15.1.1998 / 15:25:29 / cg"
|
|
211 |
!
|
|
212 |
|
|
213 |
lineNumberFromMethod
|
|
214 |
|m|
|
|
215 |
|
|
216 |
m := self method.
|
|
217 |
m notNil ifTrue:[
|
|
218 |
^ m lineNumber
|
|
219 |
].
|
|
220 |
^ nil
|
|
221 |
|
|
222 |
"Created: / 4.1.1998 / 23:34:45 / cg"
|
|
223 |
"Modified: / 4.1.1998 / 23:35:55 / cg"
|
|
224 |
!
|
|
225 |
|
|
226 |
method
|
|
227 |
"the method may be found in the interpreter temps ..."
|
|
228 |
|
|
229 |
method isJavaMethod ifTrue:[^ method].
|
|
230 |
^ super method
|
|
231 |
|
|
232 |
"Created: / 1.5.1996 / 15:03:43 / cg"
|
|
233 |
"Modified: / 25.9.1999 / 23:26:40 / cg"
|
|
234 |
!
|
|
235 |
|
|
236 |
numArgs
|
|
237 |
"return the number of args.
|
|
238 |
Redefined since Java keeps the receiver of a non-static method
|
|
239 |
at local slot 1."
|
|
240 |
|
|
241 |
|n|
|
|
242 |
|
|
243 |
n := super numArgs.
|
|
244 |
self method isStatic ifFalse:[
|
|
245 |
n := n - 1
|
|
246 |
].
|
|
247 |
^ n
|
|
248 |
|
|
249 |
"Created: / 2.1.1998 / 22:21:24 / cg"
|
|
250 |
!
|
|
251 |
|
|
252 |
numTemps
|
|
253 |
"return the number of temporary variables of the Method.
|
|
254 |
Redefined since Java keeps the receiver of a non-static method
|
|
255 |
at local slot 1."
|
|
256 |
|
|
257 |
|n|
|
|
258 |
|
|
259 |
n := self size - super numVars - super numArgs.
|
|
260 |
^ n
|
|
261 |
|
|
262 |
"Created: / 13.1.1998 / 16:52:32 / cg"
|
|
263 |
"Modified: / 13.1.1998 / 17:23:27 / cg"
|
|
264 |
!
|
|
265 |
|
|
266 |
numVars
|
|
267 |
"return the number of locals.
|
|
268 |
Redefined since Java keeps the receiver of a non-static method
|
|
269 |
at local slot 0 and holds the args as locals."
|
|
270 |
|
|
271 |
|n|
|
|
272 |
|
|
273 |
n := super numVars.
|
|
274 |
^ (n - self numArgs) max:0
|
|
275 |
|
|
276 |
"Created: / 13.1.1998 / 17:03:08 / cg"
|
|
277 |
"Modified: / 13.1.1998 / 17:25:16 / cg"
|
|
278 |
!
|
|
279 |
|
|
280 |
pc
|
|
281 |
lineNr isNil ifTrue:[^ nil].
|
|
282 |
^ lineNr bitAnd:16rFFFF
|
|
283 |
|
|
284 |
"Created: / 4.1.1998 / 23:33:48 / cg"
|
|
285 |
"Modified: / 10.11.1998 / 13:20:12 / cg"
|
|
286 |
!
|
|
287 |
|
|
288 |
quickLineNumber
|
|
289 |
"the lineNumber - without decompiling"
|
|
290 |
|
|
291 |
^ self method quickLineNumberForPC:self pc
|
|
292 |
|
|
293 |
"Created: / 10.11.1998 / 14:20:30 / cg"
|
|
294 |
!
|
|
295 |
|
|
296 |
selector
|
|
297 |
"the selector can be extracted from the method.
|
|
298 |
the method may be found in the interpreter temps ..."
|
|
299 |
|
|
300 |
|s m|
|
|
301 |
|
|
302 |
selector isNil ifTrue:[
|
|
303 |
m := self method.
|
|
304 |
m notNil ifTrue:[
|
|
305 |
^ m name
|
|
306 |
]
|
|
307 |
].
|
|
308 |
^ super selector
|
|
309 |
|
|
310 |
"Modified: / 30.12.1997 / 17:22:06 / cg"
|
|
311 |
"Created: / 30.12.1997 / 17:23:47 / cg"
|
|
312 |
!
|
|
313 |
|
|
314 |
setPC:newPC
|
|
315 |
lineNr := newPC
|
|
316 |
|
|
317 |
"Created: / 5.1.1998 / 00:09:02 / cg"
|
|
318 |
!
|
|
319 |
|
|
320 |
temporaries
|
|
321 |
"return an array filled with the arguments and variables of this context"
|
|
322 |
|
|
323 |
|n nSkipped|
|
|
324 |
|
|
325 |
"/ the flas-numVars includes the receiver and args
|
|
326 |
nSkipped := super numVars "self numArgs + self numVars".
|
|
327 |
"/ but my context setup is args+numvars.
|
|
328 |
nSkipped := super numArgs + super numVars.
|
|
329 |
|
|
330 |
n := self size - nSkipped.
|
|
331 |
n == 0 ifTrue:[
|
|
332 |
"/ little optimization here - avaoid creating empty containers
|
|
333 |
^ #()
|
|
334 |
].
|
|
335 |
|
|
336 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:nSkipped+1.
|
|
337 |
|
|
338 |
"Created: / 13.1.1998 / 15:44:12 / cg"
|
|
339 |
"Modified: / 13.1.1998 / 17:22:54 / cg"
|
|
340 |
!
|
|
341 |
|
|
342 |
vars
|
|
343 |
"return an array filled with the local variables of this context"
|
|
344 |
|
|
345 |
|nonVars mySize|
|
|
346 |
|
|
347 |
mySize := self numVars.
|
|
348 |
mySize == 0 ifTrue:[
|
|
349 |
"/ little optimization here - avaoid creating empty containers
|
|
350 |
^ #()
|
|
351 |
].
|
|
352 |
nonVars := (self arg1Index-1) + self numArgs.
|
|
353 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1
|
|
354 |
|
|
355 |
"Created: / 13.1.1998 / 16:48:16 / cg"
|
|
356 |
! !
|
|
357 |
|
|
358 |
!JavaContext methodsFor:'accessing'!
|
|
359 |
|
1093
|
360 |
acquiredMonitors
|
|
361 |
^acqrMonitors
|
|
362 |
|
|
363 |
"Created: / 08-11-2011 / 12:23:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
364 |
!
|
|
365 |
|
|
366 |
addMonitor: mon
|
|
367 |
acqrMonitors ifNil: [acqrMonitors := OrderedCollection new].
|
|
368 |
acqrMonitors add: mon.
|
|
369 |
|
|
370 |
"Created: / 08-11-2011 / 14:19:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
371 |
!
|
|
372 |
|
752
|
373 |
programmingLanguage
|
|
374 |
|
|
375 |
^JavaLanguage instance
|
|
376 |
|
|
377 |
"Created: / 17-03-2011 / 10:17:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1093
|
378 |
!
|
|
379 |
|
|
380 |
removeMonitor: mon
|
|
381 |
acqrMonitors ifNil: [ self halt: 'removing non existing monitor' ].
|
|
382 |
acqrMonitors remove: mon.
|
|
383 |
|
|
384 |
"Created: / 08-11-2011 / 14:19:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
752
|
385 |
! !
|
|
386 |
|
|
387 |
!JavaContext methodsFor:'exception handler support'!
|
|
388 |
|
|
389 |
exceptionArg:aJavaException
|
|
390 |
exArg := aJavaException.
|
|
391 |
|
|
392 |
"Created: / 7.1.1998 / 21:36:56 / cg"
|
|
393 |
!
|
|
394 |
|
|
395 |
exceptionArg:aJavaException pc:newPc
|
|
396 |
exArg := aJavaException.
|
|
397 |
exPC := newPc.
|
|
398 |
|
|
399 |
"Created: / 7.1.1998 / 21:36:56 / cg"
|
|
400 |
! !
|
|
401 |
|
|
402 |
!JavaContext methodsFor:'printing & storing'!
|
|
403 |
|
|
404 |
receiverPrintString
|
|
405 |
"return a string describing the receiver of the context"
|
|
406 |
|
|
407 |
|receiverClass receiverClassName newString implementorClass searchClass|
|
|
408 |
|
|
409 |
"/ %{
|
|
410 |
"/ /*
|
|
411 |
"/ * special handling for (invalid) free objects.
|
|
412 |
"/ * these only appear if some primitiveCode does not correctly use SEND macros,
|
|
413 |
"/ * which may lead to sends to free objects. In normal operation, this 'cannot' happen.
|
|
414 |
"/ */
|
|
415 |
"/ if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) {
|
|
416 |
"/ receiverClassName = __MKSTRING("FreeObject");
|
|
417 |
"/ }
|
|
418 |
"/ %}.
|
|
419 |
"/ receiverClassName notNil ifTrue:[^ receiverClassName].
|
|
420 |
|
|
421 |
receiverClass := receiver class.
|
|
422 |
"/ java has no class-methods ...
|
|
423 |
receiverClass := receiverClass theNonMetaclass.
|
|
424 |
|
|
425 |
receiverClassName := receiverClass nameInBrowser.
|
|
426 |
(receiverClass == SmallInteger) ifTrue:[
|
|
427 |
newString := '(' , receiver printString , ') ' , receiverClassName
|
|
428 |
] ifFalse:[
|
|
429 |
newString := receiverClassName
|
|
430 |
].
|
|
431 |
|
|
432 |
"
|
|
433 |
kludge to avoid slow search for containing class
|
|
434 |
"
|
|
435 |
(selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
|
|
436 |
implementorClass := self methodClass.
|
|
437 |
].
|
|
438 |
implementorClass notNil ifTrue: [
|
|
439 |
(implementorClass ~~ receiverClass) ifTrue: [
|
|
440 |
newString := newString , '>>>',
|
|
441 |
implementorClass nameInBrowser printString
|
|
442 |
]
|
|
443 |
] ifFalse:[
|
|
444 |
searchClass := self searchClass.
|
|
445 |
searchClass ~~ receiverClass ifTrue:[
|
|
446 |
newString := newString , '>>>' , searchClass nameInBrowser
|
|
447 |
].
|
|
448 |
"/ "
|
|
449 |
"/ kludge for doIt - these unbound methods are not
|
|
450 |
"/ found in the classes methodDictionary
|
|
451 |
"/ "
|
|
452 |
"/ (selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
|
|
453 |
"/ newString := newString , '>>>**NONE**'
|
|
454 |
"/ ]
|
|
455 |
].
|
|
456 |
|
|
457 |
^ newString
|
|
458 |
! !
|
|
459 |
|
|
460 |
!JavaContext methodsFor:'queries'!
|
|
461 |
|
|
462 |
hasStackToShow
|
|
463 |
"private interface to the debugger.
|
|
464 |
Smalltalk contexts return false here - other language frames
|
|
465 |
(i.e. Java frames) may want to show the evaluation stack"
|
|
466 |
|
|
467 |
^ true
|
|
468 |
|
|
469 |
"Modified: / 13.5.1997 / 16:31:12 / cg"
|
|
470 |
"Created: / 7.5.1998 / 01:23:57 / cg"
|
|
471 |
!
|
|
472 |
|
|
473 |
isJavaContext
|
|
474 |
"return true, if this is a javaContext."
|
|
475 |
|
|
476 |
^ true
|
|
477 |
|
|
478 |
"Created: / 8.5.1998 / 21:23:47 / cg"
|
|
479 |
!
|
|
480 |
|
|
481 |
stackFrame
|
|
482 |
"private interface to the debugger."
|
|
483 |
|
|
484 |
^ (1 to:self size) collect:[:i | self at:i]
|
|
485 |
|
|
486 |
"Created: / 7.5.1998 / 01:26:19 / cg"
|
|
487 |
! !
|
|
488 |
|
|
489 |
!JavaContext class methodsFor:'documentation'!
|
|
490 |
|
|
491 |
version
|
1022
|
492 |
^ '$Id$'
|
752
|
493 |
!
|
|
494 |
|
|
495 |
version_SVN
|
1022
|
496 |
^ '$Id$'
|
1093
|
497 |
! !
|