JavaVM: Few fixes in native methods jk_new_structure
authorvranyj1
Tue, 18 Oct 2011 21:26:43 +0000
branchjk_new_structure
changeset 1023 6eea44b0da09
parent 1022 38b710d7dfbc
child 1024 e00483588b3d
JavaVM: Few fixes in native methods
src/JavaVM.st
--- a/src/JavaVM.st	Tue Oct 18 15:52:12 2011 +0000
+++ b/src/JavaVM.st	Tue Oct 18 21:26:43 2011 +0000
@@ -4849,7 +4849,6 @@
     | nm  class |
 
     nm := Java as_ST_String: (nativeContext argAt: 1).
-    ((nm findString:'PrivateType') ~= 0) ifTrue:[self halt.].
     class := JavaClassReader 
                 loadClassLazy: nm
                 classpath: Java release classPath
@@ -4858,7 +4857,7 @@
         ifTrue: [ self reflection javaClassObjectForClass: class ]
         ifFalse: [ self throwClassNotFoundException: nm ]
 
-    "Modified: / 08-09-2011 / 08:04:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-10-2011 / 23:13:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_ClassLoader_findLoadedClass0: nativeContext
@@ -6705,15 +6704,17 @@
 _java_security_AccessController_doPrivileged: aJavaContext 
     <javanative: 'java/security/AccessController' name: 'doPrivileged'>
     "we don't care about permissions, we will just allow this. Now it's guaranteed that called code will not perform access permission checks"
-    
-    JavaVM privilegedAccessQuery answer: true
-        do: [
-            (aJavaContext argAt: 1) printString infoPrintCR.
-            ^ (aJavaContext argAt: 1) perform: #'run()Ljava/lang/Object;'.
-        ].
+
+    | retval |
+    
+    JavaVM privilegedAccessQuery answer: true do: [
+        retval := (aJavaContext argAt: 1) perform: #'run()Ljava/lang/Object;'.
+    ].
+    ^retval
 
     "Created: / 20-10-2010 / 12:31:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 09-10-2011 / 23:56:31 / Marcel Hlopko <hlopik@gmail.com>"
+    "Modified: / 18-10-2011 / 23:28:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_security_AccessController_getStackAccessControlContext: nativeContext 
@@ -14461,11 +14462,34 @@
 
 _sun_misc_Unsafe_compareAndSwapLong: aJavaContext
 
-    <javanative: 'sun/misc/Unsafe' name: 'compareAndSwapInt'>
-
-    ^self _sun_misc_Unsafe_compareAndSwapObject: aJavaContext
-
-    "Modified: / 07-08-2011 / 21:50:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    <javanative: 'sun/misc/Unsafe' name: 'compareAndSwapLong'>
+
+        "
+    /**
+     * Atomically update Java variable to <tt>x</tt> if it is currently
+     * holding <tt>expected</tt>.
+     * @return <tt>true</tt> if successful
+     */
+    public final native boolean compareAndSwapInt(Object o, long offset,
+                                                  long expected,
+                                                  long new);
+    "
+    | o offset expected real new ok |
+    o := aJavaContext argAt:1.
+    offset := aJavaContext argAt:2.
+    "offset is long, so aJavaContext at:3 is dummy nil!!!!!!"
+    expected := aJavaContext argAt:4.
+    new := aJavaContext argAt:6.
+
+    OperatingSystem blockInterrupts.
+    real := o instVarAt: offset.
+    (real == expected)
+            ifTrue:[o instVarAt: offset put: new. ok := 1]
+            ifFalse:[ok := 1].
+    OperatingSystem unblockInterrupts.
+    ^ok
+
+    "Modified: / 18-10-2011 / 21:59:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _sun_misc_Unsafe_compareAndSwapObject: aJavaContext
@@ -14589,9 +14613,19 @@
 
 _sun_misc_Unsafe_getInt: nativeContext
 
-    <javanative: 'sun/misc/Unsafe' name: 'getInt(Ljava/lang/Object;J)I'>
-
-    ^ UnimplementedNativeMethodSignal raise
+    <javanative: 'sun/misc/Unsafe' name: 'getInt'>
+    "
+    /**
+    * Fetches a integer value from a given Java variable.
+    */
+    public native int getInt(Object o, long offset);
+    "
+    | o offset |
+    o := nativeContext argAt: 1.
+    offset := nativeContext argAt: 2.
+    ^o instVarAt: offset
+
+    "Modified: / 18-10-2011 / 20:33:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _sun_misc_Unsafe_getLongVolatile: nativeContext
@@ -15184,63 +15218,63 @@
 
     enteredMonitors := self enteredMonitorsOfProcess:thisProcess.
     enteredMonitors size > 0 ifTrue:[
-	MonitorTrace ifTrue:[
-	    ('====> wait - exit ' , enteredMonitors size printString , ' monitors in ' , Processor activeProcess name , ' ...') infoPrintCR.
-	].
-	enteredMonitors do:[:handle | 
-	    |mon|
-
-	    mon := LockTable at:handle ifAbsent:nil.
-	    mon isNil ifTrue:[
-		self halt:'no monitor in wait'.
-	    ] ifFalse:[
-		MonitorTrace ifTrue:[
-		    ('====> wait - exit monitor for ' , handle displayString , ' in ' , Processor activeProcess name , ' ...') infoPrintCR. 
-		].
-		mon exit.
-	    ].
-	].
-	EnteredMonitorsPerProcess removeKey:thisProcess.
+        MonitorTrace ifTrue:[
+            ('====> wait - exit ' , enteredMonitors size printString , ' monitors in ' , Processor activeProcess name , ' ...') infoPrintCR.
+        ].
+        enteredMonitors do:[:handle | 
+            |mon|
+
+            mon := LockTable at:handle ifAbsent:nil.
+            mon isNil ifTrue:[
+                self halt:'no monitor in wait'.
+            ] ifFalse:[
+                MonitorTrace ifTrue:[
+                    ('====> wait - exit monitor for ' , handle displayString , ' in ' , Processor activeProcess name , ' ...') infoPrintCR. 
+                ].
+                mon exit.
+            ].
+        ].
+        EnteredMonitorsPerProcess removeKey:thisProcess.
     ].
 
     wasBlocked ifFalse:[ OperatingSystem unblockInterrupts].
 
     pState notNil ifTrue:[thisProcess state:pState].
     sema isNil ifTrue:[
-	Delay waitForMilliseconds:tmo
+        Delay waitForMilliseconds:tmo
     ] ifFalse:[
-	(tmo isNil or:[tmo = 0]) ifTrue:[
-	    sema wait.
-	] ifFalse:[
-	    sema waitWithTimeout:tmo / 1000.
-	].
+        (tmo isNil or:[tmo = 0]) ifTrue:[
+            sema wait.
+        ] ifFalse:[
+            sema waitWithTimeout:tmo / 1000.
+        ].
     ].
 
     "/ re-enter monitors.
 
     enteredMonitors size > 0 ifTrue:[
-	wasBlocked := OperatingSystem blockInterrupts.
-	self syncMonitorCache.
-
-	MonitorTrace ifTrue:[
-	    ('====> wait - reenter ' , enteredMonitors size printString , ' monitors in ' , Processor activeProcess name , ' ...') infoPrintCR.
-	].
-	enteredMonitors do:[:handle | 
-	    |mon|
-
-	    LockTableAccess critical:[
-		mon := LockTable at:handle ifAbsent:nil.
-		mon isNil ifTrue:[
-		    LockTable at:handle put:(mon := Monitor new)
-		]
-	    ].
-	    MonitorTrace ifTrue:[
-		('====> wait - reenter monitor for ' , handle displayString , ' in ' , Processor activeProcess name , ' ...') infoPrintCR. 
-	    ].
-	    mon enter.
-	].
-	EnteredMonitorsPerProcess at:thisProcess put:enteredMonitors.
-	wasBlocked ifFalse:[ OperatingSystem unblockInterrupts].
+        wasBlocked := OperatingSystem blockInterrupts.
+        self syncMonitorCache.
+
+        MonitorTrace ifTrue:[
+            ('====> wait - reenter ' , enteredMonitors size printString , ' monitors in ' , Processor activeProcess name , ' ...') infoPrintCR.
+        ].
+        enteredMonitors do:[:handle | 
+            |mon|
+
+            LockTableAccess critical:[
+                mon := LockTable at:handle ifAbsent:nil.
+                mon isNil ifTrue:[
+                    LockTable at:handle put:(mon := Monitor new)
+                ]
+            ].
+            MonitorTrace ifTrue:[
+                ('====> wait - reenter monitor for ' , handle displayString , ' in ' , Processor activeProcess name , ' ...') infoPrintCR. 
+            ].
+            mon enter.
+        ].
+        EnteredMonitorsPerProcess at:thisProcess put:enteredMonitors.
+        wasBlocked ifFalse:[ OperatingSystem unblockInterrupts].
     ].
 
     "Created: / 30.12.1998 / 19:19:35 / cg"