JavaProcess.st
changeset 2151 c0b6570c6f9b
parent 2107 f4509f6767fa
child 2200 e7ece7115203
--- a/JavaProcess.st	Tue Apr 13 13:26:06 2010 +0200
+++ b/JavaProcess.st	Thu Aug 18 20:42:48 2011 +0200
@@ -1,6 +1,10 @@
 "
- COPYRIGHT (c) 1997 by eXept Software AG
-              All Rights Reserved
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -8,9 +12,33 @@
  be provided or otherwise made available to, or used by, any
  other person.  No title to or ownership of the software is
  hereby transferred.
-"
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
 
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+"
 "{ Package: 'stx:libjava' }"
 
 Process subclass:#JavaProcess
@@ -20,12 +48,23 @@
 	category:'Languages-Java-Classes'
 !
 
+Object subclass:#Helper
+	instanceVariableNames:'javaThreadObject javaProcess'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:JavaProcess
+!
+
 !JavaProcess class methodsFor:'documentation'!
 
 copyright
 "
- COPYRIGHT (c) 1997 by eXept Software AG
-              All Rights Reserved
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -33,8 +72,43 @@
  be provided or otherwise made available to, or used by, any
  other person.  No title to or ownership of the software is
  hereby transferred.
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+
 "
+! !
 
+!JavaProcess class methodsFor:'instance creation'!
+
+newHelper
+
+    ^Helper new
+
+    "Created: / 15-12-2010 / 11:11:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaProcess methodsFor:'accessing'!
@@ -84,8 +158,147 @@
     "Created: / 10.4.1998 / 15:21:15 / cg"
 ! !
 
+!JavaProcess methodsFor:'suspend & resume'!
+
+terminateNoSignal
+
+    | jThread |
+    jThread := Java threads keyAtValue: self.
+    JavaVM wakeup: jThread.
+
+    super terminateNoSignal
+
+    "Created: / 15-12-2010 / 00:18:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-12-2010 / 11:19:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaProcess::Helper methodsFor:'initialization'!
+
+javaProcess:something
+    javaProcess := something.
+!
+
+javaThreadObject:something
+    javaThreadObject := something.
+! !
+
+!JavaProcess::Helper methodsFor:'support'!
+
+value
+    |procName|
+
+    Object abortSignal 
+        handle:[:ex | 
+            procName := javaProcess name.
+            (procName startsWith:'JAVA-AWT-EventQueue') ifTrue:[
+                ('JAVA [info]: thread ' , procName , ' aborted - restarting process.') 
+                    infoPrintCR.
+                ex restart.
+            ] ifFalse:[
+                (javaProcess == (Smalltalk at:#'JavaVM:JavaScreenUpdaterThread') 
+                    or:[javaProcess == (Smalltalk at:#'JavaVM:JavaEventQueueThread')]) 
+                        ifTrue:[
+                            ('JAVA [info]: thread ' , procName , ' aborted - restarting process.') 
+                                infoPrintCR.
+                            ex restart
+                        ]
+                        ifFalse:[('JAVA [info]: thread ' , procName , ' aborted.') infoPrintCR.]
+            ].
+        ]
+        do:[
+            [
+                JavaVM javaExceptionSignal 
+                    handle:[:ex | 
+                        |exClass|
+
+                        procName := javaProcess name.
+                        exClass := ex parameter class.
+                        exClass == (Java at:'java.lang.ThreadDeath') ifTrue:[
+                            ('JAVA: thread ' , procName , ' terminated') infoPrintCR.
+                        ] ifFalse:[
+                            Transcript 
+                                showCR:('JAVA: thread ''' , procName , ''' terminated with exception: ' 
+                                        , exClass name).
+                        ].
+                        ex return.
+                    ]
+                    do:[
+                        Object messageNotUnderstoodSignal 
+                            handle:[:ex | 
+                                |
+                                "/ remap doesNotUnderstand with nil-receiver to
+                                "/ a nullPointerException ...
+                                 con m|
+
+                                con := ex suspendedContext.
+                                con receiver isNil ifTrue:[
+                                    ((m := con sender method) notNil and:[m isJavaMethod]) ifTrue:[
+                                        JavaVM throwNullPointerException.
+                                        AbortSignal raise.
+                                        
+                                        "/ ex proceed.
+                                    ]
+                                ].
+                                ex reject.
+                            ]
+                            do:[
+                                "/ Transcript showCR:(Timestamp now printString , 'start thread: ', stProcess name).
+                                javaThreadObject perform:#'run()V'.
+                                (Smalltalk at:#'JavaVM:ThreadTrace') == true ifTrue:[
+                                    ('JAVA: thread ' , javaProcess name , ' terminated') infoPrintCR.
+                                ].
+                                javaThreadObject perform:#'exit()V'.
+                                (Smalltalk at:#'JavaVM:ThreadTrace') == true ifTrue:[
+                                    ('JAVA: after exit of thread ' , javaProcess name) infoPrintCR.
+                                ]
+                            ]
+                    ]
+            ] ensure:[
+                |monitors|
+
+                monitors := (Smalltalk at:#'JavaVM:EnteredMonitorsPerProcess') 
+                            at:javaProcess
+                            ifAbsent:nil.
+                monitors notNil ifTrue:[
+                    monitors do:[:obj | 
+                        |mon|
+
+                        mon := JavaVM monitorFor:obj.
+                        mon notNil ifTrue:[
+                            mon owningProcess == javaProcess ifTrue:[
+                                ('JAVA: release monitor owned by dying thread: ' , javaProcess name) 
+                                    infoPrintCR.
+                                self breakPoint: #jv.
+                                mon exit
+                            ].
+                        ].
+                    ].
+                    (Smalltalk at:#'JavaVM:EnteredMonitorsPerProcess') removeKey:javaProcess.
+                    javaProcess == (Smalltalk at:#'JavaVM:JavaScreenUpdaterThread') ifTrue:[
+                        Smalltalk at:#'JavaVM:JavaScreenUpdaterThread' put:nil.
+                    ].
+                    javaProcess == (Smalltalk at:#'JavaVM:JavaEventQueueThread') ifTrue:[
+                        Smalltalk at:#'JavaVM:JavaEventQueueThread' put:nil.
+                    ].
+                    
+"/                                    screenUpdaterClass := Java at:'sun.awt.ScreenUpdater'.    
+"/                                    screenUpdaterClass notNil ifTrue:[
+"/                                        screenUpdaterClass instVarNamed:'updater' put:nil.
+"/                                    ].
+                ].
+                Java threads removeKey:javaThreadObject ifAbsent:[].
+            ]
+        ]
+
+    "Created: / 15-12-2010 / 11:06:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaProcess class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libjava/JavaProcess.st,v 1.14 2002-11-22 20:09:21 cg Exp $'
+    ^ '$Id: JavaProcess.st,v 1.15 2011-08-18 18:42:48 vrany Exp $'
+!
+
+version_SVN
+    ^ '$Id: JavaProcess.st,v 1.15 2011-08-18 18:42:48 vrany Exp $'
 ! !