Another pass over java.io.* natives. Fixes for OpenJDK 7. development
authorJan Vrany <jan.vrany@fit.cvut.cz>
Wed, 13 Nov 2013 11:13:40 +0000
branchdevelopment
changeset 2917 e634189c444e
parent 2916 3d8a63dbf6dd
child 2918 e2fc5ead5542
child 2921 85ccd41f883c
Another pass over java.io.* natives. Fixes for OpenJDK 7.
JavaNativeMethodImpl_OpenJDK6.st
JavaNativeMethodImpl_OpenJDK7.st
TestletTestCaseProxy.st
--- a/JavaNativeMethodImpl_OpenJDK6.st	Tue Nov 12 11:17:13 2013 +0000
+++ b/JavaNativeMethodImpl_OpenJDK6.st	Wed Nov 13 11:13:40 2013 +0000
@@ -8467,9 +8467,9 @@
     FileIOTrace ifTrue:[
         ('JAVA: getFilePointer on ' , file pathName) infoPrintCR.
     ].
-    ^file position
-
-    "Modified: / 06-07-2012 / 12:40:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    ^file position0Based
+
+    "Modified: / 13-11-2013 / 11:10:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_RandomAccessFile_initIDs: this
@@ -8485,7 +8485,7 @@
 
     <javanative: 'java/io/RandomAccessFile' name: 'length()J'>
 
-        |file sz|
+    | file sz |
 
     file := self validateFile:this.
 
@@ -8493,10 +8493,12 @@
         ('JAVA: length of ' , file pathName) infoPrintCR.
     ].
 
-    sz := file size.
+    file flush.
+    sz := file fileSize.
     ^ sz.
 
-    "Created: / 4.2.1998 / 13:27:58 / cg"
+    "Created: / 04-02-1998 / 13:27:58 / cg"
+    "Modified (format): / 13-11-2013 / 10:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_RandomAccessFile_open: this _:a1 _: a2
@@ -8533,6 +8535,11 @@
 
     dir := (filename := nm utf8Encoded asFilename) directory pathName.
 
+    filename isDirectory ifTrue:[
+        JavaVM throwFileNotFoundException: nm , ' is directory, not file'.
+        ^ nil.
+    ].
+
     (PermittedDirectories notNil
     and:[PermittedDirectories includes:dir]) ifFalse:[
         FileOpenConfirmation ifTrue:[
@@ -8561,7 +8568,8 @@
     ].
 
     (filename exists not and:[readonly]) ifTrue:[
-        JavaVM throwIOExceptionWithMessage:'File ' , nm , ' does not exist'
+        JavaVM throwIOExceptionWithMessage:'File ' , nm , ' does not exist'.
+        ^ nil.
     ].
 
     readonly ifTrue:[
@@ -8572,6 +8580,7 @@
             JavaVM throwIOExceptionWithMessage:('cannot open ' , nm , ' for writing').
         ].
     ].
+    stream binary.
 
 
     fileNo := self addOpenFile:stream.
@@ -8586,7 +8595,7 @@
 
     "Created: / 04-02-1998 / 00:14:48 / cg"
     "Modified: / 12-11-1998 / 21:29:46 / cg"
-    "Modified: / 23-07-2012 / 19:37:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 13-11-2013 / 11:07:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_RandomAccessFile_read: this
@@ -8639,18 +8648,57 @@
     "Modified (comment): / 06-07-2012 / 12:39:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-_java_io_RandomAccessFile_setLength: this _: a1 _: a2
+_java_io_RandomAccessFile_setLength: this _: newLength _: ignored
 
     <javanative: 'java/io/RandomAccessFile' name: 'setLength(J)V'>
-
-    ^ JavaVM unimplementedNativeMethodSignal raise
+    "
+    /**
+     * Sets the length of this file.
+     *
+     * <p> If the present length of the file as returned by the
+     * <code>length</code> method is greater than the <code>newLength</code>
+     * argument then the file will be truncated.  In this case, if the file
+     * offset as returned by the <code>getFilePointer</code> method is greater
+     * than <code>newLength</code> then after this method returns the offset
+     * will be equal to <code>newLength</code>.
+     *
+     * <p> If the present length of the file as returned by the
+     * <code>length</code> method is smaller than the <code>newLength</code>
+     * argument then the file will be extended.  In this case, the contents of
+     * the extended portion of the file are not defined.
+     *
+     * @param      newLength    The desired length of the file
+     * @exception  IOException  If an I/O error occurs
+     * @since      1.2
+     */
+    "
+
+    | file sz |
+
+    file := self validateFile:this.
+
+    FileIOTrace ifTrue:[
+        ('JAVA: length of ' , file pathName) infoPrintCR.
+    ].
+
+    file flush.
+    sz := file fileSize.
+    file truncateTo: newLength .
+    sz > newLength ifTrue:[
+        file position0Based: newLength.
+    ].
+    ^ sz.
+
+    "Modified: / 13-11-2013 / 11:10:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_RandomAccessFile_write: this _: a1
 
     <javanative: 'java/io/RandomAccessFile' name: 'write(I)V'>
 
-    ^ JavaVM unimplementedNativeMethodSignal raise
+    ^ self _java_io_FileOutputStream_write: this _:a1
+
+    "Modified: / 13-11-2013 / 11:03:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_RandomAccessFile_writeBytes: this _:bytes _: offset _: count
@@ -8730,15 +8778,15 @@
 
     path := Java as_ST_String: name.
     [
-        file := FileStream basicNew open: path withMode: #(CREATE_NEW GENERIC_READ_WRITE).
-        file closeFile.
-        result := 1.
+        file := FileStream basicNew.
+        result := (file openFile: path withMode: #(CREATE_NEW GENERIC_READ_WRITE) attributes: nil) notNil ifTrue:[1] ifFalse:[0].
+        file close.
     ] on: OpenError do:[
-        result = 0.
+        result := 0.
     ].
     ^ result.
 
-    "Modified: / 11-11-2013 / 21:53:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-11-2013 / 23:52:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_UnixFileSystem_createFileExclusively: this _:a1 _: a2
@@ -9072,16 +9120,16 @@
 
     path := Java as_ST_String: name.
     [
-        file := FileStream basicNew open: path withMode: #(GENERIC_READ_WRITE FILE_SHARE_READ FILE_SHARE_WRITE  CREATE_NEW).
-        file closeFile.
-        result := 1.
+        file := FileStream basicNew.
+        result := (file openFile: path withMode: #(GENERIC_READ_WRITE FILE_SHARE_READ FILE_SHARE_WRITE  CREATE_NEW) attributes: nil)  notNil ifTrue:[1] ifFalse:[0]. 
+        file close.
     ] on: OpenError do:[
-        result = 0.
+        result := 0.
     ].
     ^ result.
 
     "Modified: / 18-08-2011 / 17:26:11 / jv"
-    "Modified: / 11-11-2013 / 22:00:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-11-2013 / 23:52:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_WinNTFileSystem_delete0: this _:a1
--- a/JavaNativeMethodImpl_OpenJDK7.st	Tue Nov 12 11:17:13 2013 +0000
+++ b/JavaNativeMethodImpl_OpenJDK7.st	Wed Nov 13 11:13:40 2013 +0000
@@ -40,14 +40,38 @@
 
     <javanative: 'java/io/FileOutputStream' name: 'open(Ljava/lang/String;Z)V'>
 
-    ^ JavaVM unimplementedNativeMethodSignal raise
+    ^ self commonOpen: this path: a1 forAppend: a2 == 1
+
+    "Modified: / 12-11-2013 / 22:48:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-_java_io_FileOutputStream_write: this _: a1 _: a2 
+_java_io_FileOutputStream_write: this _: byte _: append 
 
     <javanative: 'java/io/FileOutputStream' name: 'write(IZ)V'>
+    "
+    /**
+     * Writes the specified byte to this file output stream.
+     *
+     * @param   b   the byte to be written.
+     * @param   append   {@code true} if the write operation first
+     *     advances the position to the end of file
+     */
+    "
+    | fdobj fd stream b |
 
-    ^ JavaVM unimplementedNativeMethodSignal raise
+    "/Java byte is signed, make it integer in 0-255"
+    b := byte < 0 ifTrue:[ byte + 256] ifFalse:[byte ].
+    fdobj := (this instVarNamed: #fd).
+    fd    := fdobj instVarNamed: #fd.
+    stream := self getOpenFileAt:fd.
+    [
+        append == 1 ifTrue:[ stream setToEnd ].
+        stream nextPut: b.
+    ] on: Error do:[:ex|
+        JavaVM throwIOExceptionWithMessage:ex description
+    ]
+
+    "Modified: / 13-11-2013 / 09:34:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_io_FileOutputStream_writeBytes: this _:bytes _: offset _: count _: append
@@ -334,6 +358,13 @@
     ^ nil.
 
     "Modified: / 08-02-2013 / 01:28:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+_java_lang_UNIXProcess_forkAndExec: this _: a1 _: a2 _: a3 _: a4 _: a5 _: a6 _: a7 _: a8 
+
+    <javanative: 'java/lang/UNIXProcess' name: 'forkAndExec([B[BI[BI[B[IZ)I'>
+
+    ^ JavaVM unimplementedNativeMethodSignal raise
 ! !
 
 !JavaNativeMethodImpl_OpenJDK7 class methodsFor:'native - java.util.zip'!
--- a/TestletTestCaseProxy.st	Tue Nov 12 11:17:13 2013 +0000
+++ b/TestletTestCaseProxy.st	Wed Nov 13 11:13:40 2013 +0000
@@ -179,28 +179,32 @@
 !
 
 performTest
-    | handlerBlock |
-    handlerBlock := [:ex | TestResult failure sunitSignalWith: ex description ].
+
+    <resource: #skipInDebuggersWalkBack>
+
     self createHarness.
-    [
-        JavaVM unimplementedNativeMethodSignal handle: handlerBlock
-            do: [
-"/                Stdout nextPutLine: self javaClass name.
-"/                ObjectMemory checkConsistency.
+"/    [
+"/        JavaVM unimplementedNativeMethodSignal handle: [:ex | 
+"/            TestResult failure sunitSignalWith: ex description 
+"/        ] do: [
+"/"/                Stdout nextPutLine: self javaClass name.
+"/"/                ObjectMemory checkConsistency.
                 self javaClass new 
                     perform: 'test(Lgnu/testlet/TestHarness;)V' sunitAsSymbol
                     with: harness.
 "/                ObjectMemory garbageCollect.
 "/                JavaVM dumpOpenExternalStreamsOn: Stdout. 
 "/                ObjectMemory checkConsistency.            
-            ].
-    ] on: JavaError do: handlerBlock
+"/            ].
+"/    ] on: JavaError do: [:ex | 
+"/        TestResult failure sunitSignalWith: ex description 
+"/    ]
 
     "/((harness instVarNamed: 'passed') = 0 ) ifTrue: [ TestResult failure sunitSignalWith: 'Test failed' ].
 
     "Created: / 01-03-2011 / 14:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 05-12-2011 / 21:15:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-    "Modified: / 23-07-2012 / 16:50:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-11-2013 / 22:57:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !TestletTestCaseProxy methodsFor:'private - Proxy interface'!
@@ -216,7 +220,8 @@
     type == 1 ifTrue:[
         ^Filename newTemporaryDirectory.  
     ] ifFalse:[type == 2 ifTrue:[
-        ^JavaTestsResource classpathForMauve anyOne asFilename directory / 'bin'
+"/        ^JavaTestsResource classpathForMauve anyOne asFilename directory / 'bin'
+        ^JavaTestsResource classpathForMauve anyOne asFilename directory / 'src'
     ] ifFalse:[type == 3 ifTrue:[
         ^(JavaTestsResource classpathForMauve anyOne asFilename directory / 'src') asString , Filename separator
     ] ifFalse:[type == 4 ifTrue:[
@@ -226,6 +231,7 @@
     ]]]].
 
     "Created: / 10-08-2011 / 15:03:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 13-11-2013 / 09:55:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 message:msg type: type