src/JavaVM.st
branchjk_new_structure
changeset 1183 4db27693ce84
parent 1179 26fa6829e4d7
child 1185 f13a7d1c7385
--- a/src/JavaVM.st	Tue Nov 29 15:41:03 2011 +0000
+++ b/src/JavaVM.st	Wed Nov 30 10:15:49 2011 +0000
@@ -3027,10 +3027,7 @@
     
     | jThread  jName  name  stProcess  helper |
     jThread := nativeContext receiver.
-    (jThread instVarNamed: 'priority') < 1 ifTrue: [
-        self halt.
-        jThread instVarNamed: 'priority' put: 1.
-    ].
+    self assert: (jThread instVarNamed: 'priority') > 0.
     stProcess := JavaProcess for: (helper := JavaProcess newHelper)
                 priority: (Processor activePriority).
     helper javaThreadObject: jThread.
@@ -3049,14 +3046,10 @@
             ].
         ]
     ].
-    
-"/name = 'UserDialogShowThread' ifTrue:[
-"/self halt
-"/].
     "/ when that process terminates, wakup any waiters
     "/mh 29.11.11 this makes join work
-    stProcess addExitAction:[self acquireMonitorAndNotifyAll:jThread].
-    
+    
+    stProcess addExitAction: [ self acquireMonitorAndNotifyAll: jThread ].
     stProcess name: 'JAVA-' , name.
     stProcess restartable: true.
     stProcess resume.
@@ -3066,7 +3059,7 @@
     "Modified: / 24-12-1999 / 03:14:33 / cg"
     "Created: / 14-12-2010 / 21:31:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 15-12-2010 / 11:19:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 29-11-2011 / 14:24:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 30-11-2011 / 11:05:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaVM class methodsFor:'helpers - awt'!
@@ -6690,15 +6683,13 @@
     | jThread  stProcess |
     jThread := nativeContext receiver.
     stProcess := self stProcessForJavaThread: jThread.
-    stProcess isNil ifTrue: [
-        self halt.
-        ^ 0
-    ].
-    stProcess interruptWith: [].
+    self assert: stProcess notNil.
+
+    stProcess setInterrupted.
 
     "Modified: / 02-01-1998 / 21:49:06 / cg"
     "Created: / 10-04-1998 / 15:21:43 / cg"
-    "Modified: / 28-11-2011 / 15:32:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 30-11-2011 / 11:03:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
 _java_lang_Thread_isAlive: nativeContext
@@ -6724,29 +6715,24 @@
     "Modified: / 6.2.1998 / 02:15:01 / cg"
 !
 
-_java_lang_Thread_isInterrupted: nativeContext
-
+_java_lang_Thread_isInterrupted: nativeContext 
     <javanative: 'java/lang/Thread' name: 'isInterrupted'>
-
-        "ask if a thread is interrupted (clear interruptState if arg is true)"
-
-    |jThread stProcess clearInterrupt rslt|
-
+    "ask if a thread is interrupted (clear interruptState if arg is true)"
+    
+    | jThread  stProcess  clearInterrupt  wasInterrupted |
     jThread := nativeContext receiver.
-    stProcess := self stProcessForJavaThread:jThread.
-    stProcess isNil ifTrue:[
-        self halt.
-        ^ 0
-    ].
-
-    clearInterrupt := nativeContext argAt:1.
-    rslt := "stProcess isInterrupted"false ifTrue:[1] ifFalse:[0].
-    "clearInterrupt ~~ 0 ifTrue:[stProcess clearInterruptActions]."
-    ^ rslt
+    stProcess := self stProcessForJavaThread: jThread.
+    self assert: stProcess notNil.
+    clearInterrupt := nativeContext argAt: 1.
+    wasInterrupted := stProcess isInterrupted.
+    clearInterrupt ~~ 0 ifTrue: [ stProcess clearInterrupted ].
+    stProcess isDead ifTrue: [ ^ 0 ].
+    ^ wasInterrupted.
 
     "Modified: / 02-01-1998 / 21:49:06 / cg"
     "Created: / 07-01-1998 / 18:50:26 / cg"
     "Modified: / 05-08-2011 / 22:21:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 30-11-2011 / 10:49:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
 _java_lang_Thread_registerNatives: aJavaContext
@@ -6786,14 +6772,11 @@
     | millis |
     millis := nativeContext argAt: 1.
     self 
-  
-
-        waitOn: nil
-        forTimeout: millis
+        sleepForTimeout: millis
         state: #javaSleep.
 
     "Modified: / 08-01-1999 / 16:42:52 / cg"
-    "Modified: / 22-11-2011 / 13:18:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 30-11-2011 / 11:04:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
 _java_lang_Thread_start0: nativeContext
@@ -16652,6 +16635,24 @@
     "Modified: / 17-11-2011 / 21:29:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
+sleepForTimeout: tmo state: state 
+    "wait"
+    
+    | thisProcess |
+    thisProcess := Processor activeProcess.
+    state notNil ifTrue: [ thisProcess state: state ].
+    Delay waitForMilliseconds: tmo.
+    thisProcess isInterrupted ifTrue: [
+        thisProcess clearInterrupted.
+        self 
+            throwInterruptedException: 'process was interrupted before/during sleep !!?'
+    ].
+
+    "Created: / 30-12-1998 / 19:19:35 / cg"
+    "Modified: / 08-01-1999 / 17:29:24 / cg"
+    "Created: / 30-11-2011 / 11:04:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
 unwindHandlerForJavaContext: aJavaContext 
     "given a context which has been marked for unwind,
      retrieve the handler block. This method is called when ST
@@ -16687,10 +16688,19 @@
     thisProcess := Processor activeProcess.
     wasBlocked := OperatingSystem blockInterrupts.
     mon := self monitorFor: handle.
-    (mon isOwnedBy:thisProcess) ifFalse: [self throwIllegalMonitorStateException: 'monitor was not owned on wait by ' , thisProcess printString].
+    (mon isOwnedBy: thisProcess) ifFalse: [
+        self 
+            throwIllegalMonitorStateException: 'monitor was not owned on wait by ' 
+                    , thisProcess printString
+    ].
     state notNil ifTrue: [ thisProcess state: state ].
     mon waitForMilliseconds: tmo.
     wasBlocked ifFalse: [ OperatingSystem unblockInterrupts ].
+    thisProcess isInterrupted ifTrue: [
+        thisProcess clearInterrupted.
+        self 
+            throwInterruptedException: 'process was interrupted before/during wait !!?'
+    ].
 
     "Created: / 30-12-1998 / 19:19:35 / cg"
     "Modified: / 08-01-1999 / 17:29:24 / cg"