752
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
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 |
"{ Package: 'stx:libjava' }"
|
|
13 |
|
|
14 |
Process subclass:#JavaProcess
|
|
15 |
instanceVariableNames:'suspendedContext'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Languages-Java-Classes'
|
|
19 |
!
|
|
20 |
|
|
21 |
Object subclass:#Helper
|
|
22 |
instanceVariableNames:'javaThreadObject javaProcess'
|
|
23 |
classVariableNames:''
|
|
24 |
poolDictionaries:''
|
|
25 |
privateIn:JavaProcess
|
|
26 |
!
|
|
27 |
|
|
28 |
!JavaProcess class methodsFor:'documentation'!
|
|
29 |
|
|
30 |
copyright
|
|
31 |
"
|
|
32 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
33 |
All Rights Reserved
|
|
34 |
|
|
35 |
This software is furnished under a license and may be used
|
|
36 |
only in accordance with the terms of that license and with the
|
|
37 |
inclusion of the above copyright notice. This software may not
|
|
38 |
be provided or otherwise made available to, or used by, any
|
|
39 |
other person. No title to or ownership of the software is
|
|
40 |
hereby transferred.
|
|
41 |
"
|
|
42 |
|
|
43 |
! !
|
|
44 |
|
|
45 |
!JavaProcess class methodsFor:'instance creation'!
|
|
46 |
|
|
47 |
newHelper
|
|
48 |
|
|
49 |
^Helper new
|
|
50 |
|
|
51 |
"Created: / 15-12-2010 / 11:11:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
52 |
! !
|
|
53 |
|
|
54 |
!JavaProcess methodsFor:'accessing'!
|
|
55 |
|
|
56 |
suspendedContext
|
|
57 |
|con|
|
|
58 |
|
|
59 |
"/ suspendedContext notNil ifTrue:[^ suspendedContext].
|
|
60 |
"/ state ~~ #debug ifTrue:[
|
|
61 |
"/ "/ hide non-JAVA contexts ...
|
|
62 |
"/ con := super suspendedContext.
|
|
63 |
"/ [con notNil] whileTrue:[
|
|
64 |
"/ (con isMemberOf:JavaContext) ifTrue:[^ con].
|
|
65 |
"/ con := con sender.
|
|
66 |
"/ ].
|
|
67 |
"/ ].
|
|
68 |
^ super suspendedContext
|
|
69 |
|
|
70 |
"Created: / 7.5.1996 / 09:02:03 / cg"
|
|
71 |
"Modified: / 4.2.1998 / 20:44:31 / cg"
|
|
72 |
!
|
|
73 |
|
|
74 |
suspendedContext:aContext
|
|
75 |
suspendedContext := aContext
|
|
76 |
|
|
77 |
"Created: 7.5.1996 / 09:02:12 / cg"
|
|
78 |
! !
|
|
79 |
|
|
80 |
!JavaProcess methodsFor:'interrupts'!
|
|
81 |
|
|
82 |
clearInterruptActions
|
|
83 |
interruptActions := nil
|
|
84 |
|
|
85 |
"Created: 14.8.1997 / 17:27:22 / cg"
|
|
86 |
!
|
|
87 |
|
|
88 |
isInterrupted
|
|
89 |
^ interruptActions notNil
|
|
90 |
|
|
91 |
"Created: 14.8.1997 / 17:26:40 / cg"
|
|
92 |
!
|
|
93 |
|
|
94 |
markInterrupted
|
|
95 |
super interruptWith:[]
|
|
96 |
|
|
97 |
"Modified: / 10.4.1998 / 15:20:58 / cg"
|
|
98 |
"Created: / 10.4.1998 / 15:21:15 / cg"
|
|
99 |
! !
|
|
100 |
|
|
101 |
!JavaProcess methodsFor:'suspend & resume'!
|
|
102 |
|
|
103 |
terminateNoSignal
|
|
104 |
|
|
105 |
| jThread |
|
|
106 |
jThread := Java threads keyAtValue: self.
|
|
107 |
JavaVM wakeup: jThread.
|
|
108 |
|
|
109 |
super terminateNoSignal
|
|
110 |
|
|
111 |
"Created: / 15-12-2010 / 00:18:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
112 |
"Modified: / 15-12-2010 / 11:19:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
113 |
! !
|
|
114 |
|
|
115 |
!JavaProcess::Helper methodsFor:'initialization'!
|
|
116 |
|
|
117 |
javaProcess:something
|
|
118 |
javaProcess := something.
|
|
119 |
!
|
|
120 |
|
|
121 |
javaThreadObject:something
|
|
122 |
javaThreadObject := something.
|
|
123 |
! !
|
|
124 |
|
|
125 |
!JavaProcess::Helper methodsFor:'support'!
|
|
126 |
|
|
127 |
value
|
|
128 |
|procName|
|
|
129 |
|
|
130 |
Object abortSignal handle:
|
|
131 |
[:ex |
|
|
132 |
procName := javaProcess name.
|
|
133 |
(procName startsWith:'JAVA-AWT-EventQueue')
|
|
134 |
ifTrue:
|
|
135 |
[ ('JAVA [info]: thread ' , procName , ' aborted - restarting process.')
|
|
136 |
infoPrintCR.
|
|
137 |
ex restart. ]
|
|
138 |
ifFalse:
|
|
139 |
[ (javaProcess == (Smalltalk at:#'JavaVM:JavaScreenUpdaterThread')
|
|
140 |
or:[ javaProcess == (Smalltalk at:#'JavaVM:JavaEventQueueThread') ])
|
|
141 |
ifTrue:
|
|
142 |
[ ('JAVA [info]: thread ' , procName , ' aborted - restarting process.')
|
|
143 |
infoPrintCR.
|
|
144 |
ex restart ]
|
|
145 |
ifFalse:[ ('JAVA [info]: thread ' , procName , ' aborted.') infoPrintCR. ] ]. ]
|
|
146 |
do:
|
|
147 |
[
|
|
148 |
[ JavaVM javaExceptionSignal handle:
|
|
149 |
[:ex |
|
|
150 |
|exClass|
|
|
151 |
|
|
152 |
procName := javaProcess name.
|
|
153 |
exClass := ex parameter class.
|
|
154 |
exClass == (Java at:'java.lang.ThreadDeath')
|
|
155 |
ifTrue:[ ('JAVA: thread ' , procName , ' terminated') infoPrintCR. ]
|
|
156 |
ifFalse:
|
|
157 |
[ Transcript
|
|
158 |
showCR:('JAVA: thread ''' , procName , ''' terminated with exception: '
|
|
159 |
, exClass name). ].
|
|
160 |
ex return. ]
|
|
161 |
do:
|
|
162 |
[ Object messageNotUnderstoodSignal handle:
|
|
163 |
[:ex |
|
|
164 |
|
|
|
165 |
"/ remap doesNotUnderstand with nil-receiver to
|
|
166 |
"/ a nullPointerException ...
|
|
167 |
con m|
|
|
168 |
|
|
169 |
con := ex suspendedContext.
|
|
170 |
con receiver isNil
|
|
171 |
ifTrue:
|
|
172 |
[ ((m := con sender method) notNil and:[ m isJavaMethod ])
|
|
173 |
ifTrue:
|
|
174 |
[ JavaVM throwNullPointerException.
|
|
175 |
AbortSignal raise.
|
|
176 |
"/ ex proceed.
|
|
177 |
] ].
|
|
178 |
ex reject. ]
|
|
179 |
do:
|
|
180 |
[ "/ Transcript showCR:(Timestamp now printString , 'start thread: ', stProcess name).
|
|
181 |
javaThreadObject perform:#'run()V'.
|
|
182 |
(Smalltalk at:#'JavaVM:ThreadTrace') == true
|
|
183 |
ifTrue:[ ('JAVA: thread ' , javaProcess name , ' terminated') infoPrintCR. ].
|
|
184 |
javaThreadObject perform:#'exit()V'.
|
|
185 |
(Smalltalk at:#'JavaVM:ThreadTrace') == true
|
|
186 |
ifTrue:[ ('JAVA: after exit of thread ' , javaProcess name) infoPrintCR. ] ] ] ] ensure:
|
|
187 |
[ |monitors|
|
|
188 |
|
|
189 |
monitors := (Smalltalk at:#'JavaVM:EnteredMonitorsPerProcess')
|
|
190 |
at:javaProcess
|
|
191 |
ifAbsent:nil.
|
|
192 |
monitors notNil
|
|
193 |
ifTrue:
|
|
194 |
[ monitors do:
|
|
195 |
[:obj |
|
|
196 |
|mon|
|
|
197 |
|
|
198 |
mon := JavaVM monitorFor:obj.
|
|
199 |
mon notNil
|
|
200 |
ifTrue:
|
|
201 |
[ mon owningProcess == javaProcess
|
|
202 |
ifTrue:
|
|
203 |
[ ('JAVA: release monitor owned by dying thread: ' , javaProcess name)
|
|
204 |
infoPrintCR.
|
|
205 |
mon exit ]. ]. ].
|
|
206 |
(Smalltalk at:#'JavaVM:EnteredMonitorsPerProcess') removeKey:javaProcess.
|
|
207 |
javaProcess == (Smalltalk at:#'JavaVM:JavaScreenUpdaterThread')
|
|
208 |
ifTrue:[ Smalltalk at:#'JavaVM:JavaScreenUpdaterThread' put:nil. ].
|
|
209 |
javaProcess == (Smalltalk at:#'JavaVM:JavaEventQueueThread')
|
|
210 |
ifTrue:[ Smalltalk at:#'JavaVM:JavaEventQueueThread' put:nil. ].
|
|
211 |
|
|
212 |
"/ screenUpdaterClass := Java at:'sun.awt.ScreenUpdater'.
|
|
213 |
"/ screenUpdaterClass notNil ifTrue:[
|
|
214 |
"/ screenUpdaterClass instVarNamed:'updater' put:nil.
|
|
215 |
"/ ].
|
|
216 |
].
|
|
217 |
Java threads removeKey:javaThreadObject ifAbsent:[]. ] ]
|
|
218 |
|
|
219 |
"Created: / 15-12-2010 / 11:06:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
220 |
! !
|
|
221 |
|
|
222 |
!JavaProcess class methodsFor:'documentation'!
|
|
223 |
|
|
224 |
version
|
|
225 |
^ '$Id$'
|
|
226 |
!
|
|
227 |
|
|
228 |
version_SVN
|
|
229 |
^ '$Id$'
|
|
230 |
! !
|