# HG changeset patch # User vranyj1 # Date 1306834344 0 # Node ID 26e719a7e88c1a59d0669378347db0b11333f0ca # Parent 8d12f019746bbb5451c39b2701cf46ee9297e9dd Few fixes and native methods diff -r 8d12f019746b -r 26e719a7e88c src/JavaClass.st --- a/src/JavaClass.st Tue May 31 09:28:43 2011 +0000 +++ b/src/JavaClass.st Tue May 31 09:32:24 2011 +0000 @@ -688,13 +688,11 @@ interfaces notNil ifTrue: [ interfaces := interfaces collect: - [:clsRef | - clsRef isUnresolved - ifTrue:[ clsRef javaClass ] - ifFalse:[ clsRef ]]]. + [:clsRef | clsRef javaClass ] ]. + ^ interfaces ? #() - "Modified: / 05-02-2011 / 23:53:03 / Jan Vrany " + "Modified: / 31-05-2011 / 09:40:42 / Jan Vrany " ! javaClass diff -r 8d12f019746b -r 26e719a7e88c src/JavaExceptionTableEntry.st --- a/src/JavaExceptionTableEntry.st Tue May 31 09:28:43 2011 +0000 +++ b/src/JavaExceptionTableEntry.st Tue May 31 09:32:24 2011 +0000 @@ -125,9 +125,8 @@ (catchType == 0) ifTrue:[^ handlerPC]. (catchType isNil) ifTrue:[^ handlerPC]. cls := aMethod javaClass. - catchType isUnresolved ifTrue:[ - catchType := catchType javaClass. - ]. + catchType := catchType javaClass. + (catchType isKindOf:JavaClass) ifFalse:[ self halt. ^ nil @@ -140,7 +139,7 @@ ^ nil "Modified: / 07-01-1998 / 15:30:14 / cg" - "Modified: / 25-02-2011 / 11:52:48 / Jan Vrany " + "Modified: / 31-05-2011 / 09:53:46 / Jan Vrany " ! startPC:start_pc endPC:end_pc handlerPC:handler_pc catchType:catch_type diff -r 8d12f019746b -r 26e719a7e88c src/JavaVM.st --- a/src/JavaVM.st Tue May 31 09:28:43 2011 +0000 +++ b/src/JavaVM.st Tue May 31 09:32:24 2011 +0000 @@ -3384,16 +3384,16 @@ fs := nativeContext receiver. fd := fs instVarNamed:'fd'. (fd instVarNamed:'fd') ~~ 0 ifTrue:[ - self halt:'file already open'. - self internalError:'file already open'. - ^ self. + "/self halt:'file already open'. + self internalError:'file already open'. + ^ self. ]. name := nativeContext argAt:1. name := Java as_ST_String:name. FileOpenTrace ifTrue:[ - ('JAVA: opening ' , name) infoPrintCR. + ('JAVA: opening ' , name) infoPrintCR. ]. fn := name asFilename. @@ -3402,53 +3402,54 @@ readonly := false. (PermittedDirectories notNil and:[PermittedDirectories includes:dir]) ifFalse:[ - FileOpenConfirmation ifTrue:[ - answer := Dialog - confirmWithCancel:('JAVA Security check\\Opening ''' , name , ''' for read/write.\Grant permission ?') withCRs - labels:#('no' 'grant' 'readonly') - values:#(false true #readonly) - default:3. - answer == false ifTrue:[ - self throwIOExceptionWithMessage:('no permission to open ' , name , ' for writing'). - ^ self - ]. - readonly := (answer == #readonly). - - readonly ifFalse:[ - (self confirm:('JAVA Security check\\Always permit writes in this directory (''' , dir , ''') ?') withCRs) - ifTrue:[ - PermittedDirectories isNil ifTrue:[ - PermittedDirectories := Set new - ]. - PermittedDirectories add:dir. - ] - ] - ] + FileOpenConfirmation ifTrue:[ + answer := Dialog + confirmWithCancel:('JAVA Security check\\Opening ''' , name , ''' for read/write.\Grant permission ?') withCRs + labels:#('no' 'grant' 'readonly') + values:#(false true #readonly) + default:3. + answer == false ifTrue:[ + self throwIOExceptionWithMessage:('no permission to open ' , name , ' for writing'). + ^ self + ]. + readonly := (answer == #readonly). + + readonly ifFalse:[ + (self confirm:('JAVA Security check\\Always permit writes in this directory (''' , dir , ''') ?') withCRs) + ifTrue:[ + PermittedDirectories isNil ifTrue:[ + PermittedDirectories := Set new + ]. + PermittedDirectories add:dir. + ] + ] + ] ]. readonly ifTrue:[ - stream := fn readStream. + stream := fn readStream. ] ifFalse:[ - forAppend ifTrue:[ - stream := fn appendingWriteStream. - ] ifFalse:[ - stream := fn writeStream. - ] + forAppend ifTrue:[ + stream := fn appendingWriteStream. + ] ifFalse:[ + stream := fn writeStream. + ] ]. stream isNil ifTrue:[ - self throwIOExceptionWithMessage:('cannot open ' , name , ' for writing'). + self throwIOExceptionWithMessage:('cannot open ' , name , ' for writing'). ]. fileNo := self addOpenFile:stream. FileOpenTrace ifTrue:[ - ('JAVA: opened ' , name , ' as FD ' , fileNo printString , ' for writing') infoPrintCR. + ('JAVA: opened ' , name , ' as FD ' , fileNo printString , ' for writing') infoPrintCR. ]. fd instVarNamed:'fd' put:fileNo. - "Created: / 7.4.1998 / 19:14:09 / cg" - "Modified: / 4.1.1999 / 14:34:42 / cg" + "Created: / 07-04-1998 / 19:14:09 / cg" + "Modified: / 04-01-1999 / 14:34:42 / cg" + "Modified: / 31-05-2011 / 09:54:01 / Jan Vrany " ! fileStreamForReading:name @@ -3686,6 +3687,63 @@ "Created: / 27.1.1998 / 18:15:51 / cg" ! +_java_io_FileInputStream_open: nativeContext + + + + |fs fd fn name stream fileNo| + + fs := nativeContext receiver. + fd := fs instVarNamed:'fd'. + (fileNo := fd instVarNamed:'fd') ~~ 0 ifTrue:[ + fileNo ~~ -1 ifTrue:[ + self halt:'file already open'. + self internalError:'file already open'. + ^ self. + ] + ]. + + name := nativeContext argAt:1. + name := Java as_ST_String:name. + + name := self fixFilename:name. + + FileOpenTrace ifTrue:[ + ('JAVA: opening ' , name) infoPrintCR. + ]. + + stream := self fileStreamForReading:name. + stream isNil ifTrue:[ + FileOpenTrace ifTrue:[ + ('JAVA: failed to open ''' , name , ''' for reading.') infoPrintCR. + ]. + + self throwIOExceptionWithMessage:('cannot open ' , name , ' for reading'). + + ^ self. + ]. + stream buffered:false. + +"/ FileOpenConfirmation ifTrue:[ +"/ (self confirm:('JAVA Security check\\Opening ''' , name , ''' for reading.\Grant permission ?') withCRs) +"/ ifFalse:[ +"/ self throwIOExceptionWithMessage:('no permission to open ' , name , ' for reading'). +"/ ^ self +"/ ] +"/ ]. + + fileNo := self addOpenFile:stream. + + FileOpenTrace ifTrue:[ + ('JAVA: opened ' , name , ' as FD ' , fileNo printString) infoPrintCR. + ]. + + fd instVarNamed:'fd' put:fileNo. + + "Created: / 4.1.1998 / 16:47:12 / cg" + "Modified: / 28.1.1999 / 17:24:07 / cg" +! + _java_io_FileOutputStream_initIDs: nativeContext @@ -3695,6 +3753,15 @@ "Created: / 27.1.1998 / 18:16:40 / cg" ! +_java_io_FileOutputStream_open: nativeContext + + + + ^ self commonOpen:nativeContext forAppend:false + + "Modified: / 7.4.1998 / 19:14:31 / cg" +! + _java_io_FileOutputStream_writeBytes: nativeContext @@ -3721,6 +3788,20 @@ "Modified: / 01-04-2011 / 18:09:32 / Jan Vrany " ! +_java_io_ObjectInputStream_latestUserDefinedLoader: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_io_ObjectStreamClass_hasStaticInitializer: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_io_ObjectStreamClass_initNative: aJavaContext @@ -3736,6 +3817,13 @@ "Created: / 20-12-2010 / 17:43:55 / Jan Vrany " ! +_java_io_RandomAccessFile_initIDs: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_io_UnixFileSystem_canonicalize0: aJavaContext @@ -3749,6 +3837,34 @@ "Created: / 10-12-2010 / 14:40:49 / Jan Vrany " ! +_java_io_UnixFileSystem_checkAccess: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_io_UnixFileSystem_createDirectory: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_io_UnixFileSystem_createFileExclusively: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_io_UnixFileSystem_delete0: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_io_UnixFileSystem_getBooleanAttributes0: aJavaContext @@ -3860,6 +3976,20 @@ "Created: / 10-12-2010 / 15:11:33 / Jan Vrany " ! +_java_lang_ClassLoader_defineClass1: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_lang_ClassLoader_findLoadedClass0: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_lang_ClassLoader_registerNatives: aJavaContext @@ -3956,6 +4086,13 @@ "Modified: / 28-02-2011 / 18:05:13 / Marcel Hlopko " ! +_java_lang_Class_getDeclaredClasses0: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_lang_Class_getDeclaredConstructors0: aJavaContext @@ -4034,6 +4171,13 @@ "Modified: / 11-02-2011 / 08:35:19 / Jan Vrany " ! +_java_lang_Class_getEnclosingMethod0: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_lang_Class_getInterfaces: nativeContext @@ -4103,6 +4247,13 @@ "Modified: / 03-02-2011 / 21:43:34 / Jan Vrany " ! +_java_lang_Class_getProtectionDomain0: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_lang_Class_getRawAnnotations: aJavaContext @@ -4201,6 +4352,57 @@ "Modified: / 05-02-2011 / 23:38:15 / Jan Vrany " ! +_java_lang_Class_isInstance: nativeContext + + + + " + /** + * Determines if the specified {@code Object} is assignment-compatible + * with the object represented by this {@code Class}. This method is + * the dynamic equivalent of the Java language {@code instanceof} + * operator. The method returns {@code true} if the specified + * {@code Object} argument is non-null and can be cast to the + * reference type represented by this {@code Class} object without + * raising a {@code ClassCastException.} It returns {@code false} + * otherwise. + * + *

Specifically, if this {@code Class} object represents a + * declared class, this method returns {@code true} if the specified + * {@code Object} argument is an instance of the represented class (or + * of any of its subclasses); it returns {@code false} otherwise. If + * this {@code Class} object represents an array class, this method + * returns {@code true} if the specified {@code Object} argument + * can be converted to an object of the array class by an identity + * conversion or by a widening reference conversion; it returns + * {@code false} otherwise. If this {@code Class} object + * represents an interface, this method returns {@code true} if the + * class or any superclass of the specified {@code Object} argument + * implements this interface; it returns {@code false} otherwise. If + * this {@code Class} object represents a primitive type, this method + * returns {@code false}. + * + * @param obj the object to check + * @return true if {@code obj} is an instance of this class + * + * @since JDK1.1 + */ + public native boolean isInstance(Object obj); + " + + |jClass cls obj| + + obj := nativeContext argAt:1. + obj isNil ifTrue:[^ 0]. + jClass := nativeContext receiver. + cls := self reflection classForJavaClassObject:jClass. + ^self _INSTANCEOF:obj _:cls + + "Modified: / 09-02-1998 / 14:56:23 / cg" + "Modified: / 28-01-2011 / 14:12:42 / Marcel Hlopko " + "Modified: / 25-02-2011 / 18:37:07 / Jan Vrany " +! + _java_lang_Class_isInterface: nativeContext @@ -4301,9 +4503,44 @@ (f = 0.0) ifTrue:[^0]. (f = -0.0) ifTrue:[^(1 bitShift: 63)]. - self halt:'Not yet implemented'. + self error:'Not yet implemented since I''m lazy'. "Created: / 10-11-2010 / 14:48:46 / Jan Vrany " + "Modified: / 31-05-2011 / 10:13:32 / Jan Vrany " +! + +_java_lang_Double_longBitsToDouble: nativeContext + + + + |i aFloat| + + i := nativeContext argAt:1. + + aFloat := Float new. + UninterpretedBytes isBigEndian ifTrue:[ + aFloat basicAt:1 put:((i bitShift:-56) bitAnd:16rFF). + aFloat basicAt:2 put:((i bitShift:-48) bitAnd:16rFF). + aFloat basicAt:3 put:((i bitShift:-40) bitAnd:16rFF). + aFloat basicAt:4 put:((i bitShift:-32) bitAnd:16rFF). + aFloat basicAt:5 put:((i bitShift:-24) bitAnd:16rFF). + aFloat basicAt:6 put:((i bitShift:-16) bitAnd:16rFF). + aFloat basicAt:7 put:((i bitShift:-8) bitAnd:16rFF). + aFloat basicAt:8 put:(i bitAnd:16rFF). + ] ifFalse:[ + aFloat basicAt:1 put:(i bitAnd:16rFF). + aFloat basicAt:2 put:((i bitShift:-8) bitAnd:16rFF). + aFloat basicAt:3 put:((i bitShift:-16) bitAnd:16rFF). + aFloat basicAt:4 put:((i bitShift:-24) bitAnd:16rFF). + aFloat basicAt:5 put:((i bitShift:-32) bitAnd:16rFF). + aFloat basicAt:6 put:((i bitShift:-40) bitAnd:16rFF). + aFloat basicAt:7 put:((i bitShift:-48) bitAnd:16rFF). + aFloat basicAt:8 put:((i bitShift:-56) bitAnd:16rFF). + ]. + + ^ aFloat. + + "Created: / 4.1.1998 / 01:45:00 / cg" ! _java_lang_Float_floatToRawIntBits: aJavaContext @@ -4352,10 +4589,10 @@ (f = 0.0) ifTrue:[^0]. (f = -0.0) ifTrue:[^(1 bitShift: 31) ]. - self halt. + self error: 'Not yet implemented since I''m bit lazy'. "Created: / 09-11-2010 / 20:59:20 / Jan Vrany " - "Modified: / 10-11-2010 / 14:47:41 / Jan Vrany " + "Modified: / 31-05-2011 / 10:13:10 / Jan Vrany " ! _java_lang_Object_clone: nativeContext @@ -4406,6 +4643,26 @@ "Created: / 4.1.1998 / 19:40:26 / cg" ! +_java_lang_Object_notify: nativeContext + + + + "wakeup" + + self wakeup:(nativeContext receiver). + + "Created: / 6.1.1998 / 21:09:26 / cg" +! + +_java_lang_Object_notifyAll: nativeContext + + + + self wakeupAll:(nativeContext receiver). + + "Created: / 3.1.1998 / 03:06:56 / cg" +! + _java_lang_Object_registerNatives: aJavaContext @@ -4442,6 +4699,46 @@ "Modified: / 01-05-2011 / 13:26:26 / Jan Vrany " ! +_java_lang_Package_getSystemPackage0: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_lang_Runtime_gc: nativeContext + + + + "Runs the garbage collector. + Ignored, since the ST-gc runs all the time." + + ^ self + + "Modified: / 12.1.1998 / 12:58:32 / cg" +! + +_java_lang_Runtime_runFinalization0: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_lang_StrictMath_cos: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_java_lang_StrictMath_sin: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + _java_lang_String_intern: nativeContext @@ -4522,6 +4819,19 @@ "Modified: / 23.12.1998 / 21:54:50 / cg" ! +_java_lang_System_identityHashCode: nativeContext + + + + |obj| + + obj := nativeContext argAt:1. + ^ obj identityHash + + "Modified: / 12.11.1998 / 18:52:07 / cg" + "Created: / 12.11.1998 / 18:54:00 / cg" +! + _java_lang_System_initProperties: nativeContext @@ -4716,6 +5026,20 @@ "Modified: / 01-05-2011 / 13:25:23 / Jan Vrany " ! +_java_lang_Thread_sleep: nativeContext + + + + "sleep for some milliseconds " + + |millis| + + millis := nativeContext argAt:1. + self waitFor:nil state:nil timeOut:(millis max:50) + + "Modified: / 8.1.1999 / 16:42:52 / cg" +! + _java_lang_Thread_start0: nativeContext @@ -4821,6 +5145,33 @@ "Created: / 17-12-2010 / 14:49:02 / Jan Vrany " "Modified: / 19-12-2010 / 17:54:51 / Jan Vrany " "Modified: / 28-01-2011 / 15:18:50 / Marcel Hlopko " +! + +_java_lang_reflect_Proxy_defineClass0: nativeContext + + + + " + private static native Class defineClass0(ClassLoader loader, String name, + byte[] b, int off, int len); + " + | loader name b off len bs cls | + loader := nativeContext argAt: 1. + name := nativeContext argAt: 2. + b := nativeContext argAt: 3. + off := nativeContext argAt: 4. + len := nativeContext argAt: 5. + + bs := (off = 0 and: [len = b size]) + ifTrue:[b readStream] + ifFalse:[(b copyFrom: off + 1 to: off + len) readStream]. + + cls := JavaClassReader readStream: bs. + cls classLoader: loader. + + ^self reflection javaClassObjectForClass: cls. + + "Created: / 06-02-2011 / 16:55:31 / Jan Vrany " ! ! !JavaVM class methodsFor:'native - java.security'! @@ -4850,6 +5201,15 @@ "Created: / 27.1.1998 / 18:22:15 / cg" ! ! +!JavaVM class methodsFor:'native - java.util.jar'! + +_java_util_jar_JarFile_getMetaInfEntryNames: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! ! + !JavaVM class methodsFor:'native - java.util.zip'! _java_util_zip_Inflater_inflateBytes: nativeContext @@ -5789,54 +6149,6 @@ "Created: / 12.11.1998 / 18:55:01 / cg" ! -_Class_isInstance:nativeContext - " - /** - * Determines if the specified {@code Object} is assignment-compatible - * with the object represented by this {@code Class}. This method is - * the dynamic equivalent of the Java language {@code instanceof} - * operator. The method returns {@code true} if the specified - * {@code Object} argument is non-null and can be cast to the - * reference type represented by this {@code Class} object without - * raising a {@code ClassCastException.} It returns {@code false} - * otherwise. - * - *

Specifically, if this {@code Class} object represents a - * declared class, this method returns {@code true} if the specified - * {@code Object} argument is an instance of the represented class (or - * of any of its subclasses); it returns {@code false} otherwise. If - * this {@code Class} object represents an array class, this method - * returns {@code true} if the specified {@code Object} argument - * can be converted to an object of the array class by an identity - * conversion or by a widening reference conversion; it returns - * {@code false} otherwise. If this {@code Class} object - * represents an interface, this method returns {@code true} if the - * class or any superclass of the specified {@code Object} argument - * implements this interface; it returns {@code false} otherwise. If - * this {@code Class} object represents a primitive type, this method - * returns {@code false}. - * - * @param obj the object to check - * @return true if {@code obj} is an instance of this class - * - * @since JDK1.1 - */ - public native boolean isInstance(Object obj); - " - - |jClass cls obj| - - obj := nativeContext argAt:1. - obj isNil ifTrue:[^ 0]. - jClass := nativeContext receiver. - cls := self reflection classForJavaClassObject:jClass. - ^self _INSTANCEOF:obj _:cls - - "Modified: / 09-02-1998 / 14:56:23 / cg" - "Modified: / 28-01-2011 / 14:12:42 / Marcel Hlopko " - "Modified: / 25-02-2011 / 18:37:07 / Jan Vrany " -! - _Class_newInstance:nativeContext "get an instance for a java.lang.Class" @@ -5990,37 +6302,6 @@ "Created: / 4.1.1998 / 01:39:12 / cg" ! -_Double_longBitsToDouble:nativeContext - |i aFloat| - - i := nativeContext argAt:1. - - aFloat := Float new. - UninterpretedBytes isBigEndian ifTrue:[ - aFloat basicAt:1 put:((i bitShift:-56) bitAnd:16rFF). - aFloat basicAt:2 put:((i bitShift:-48) bitAnd:16rFF). - aFloat basicAt:3 put:((i bitShift:-40) bitAnd:16rFF). - aFloat basicAt:4 put:((i bitShift:-32) bitAnd:16rFF). - aFloat basicAt:5 put:((i bitShift:-24) bitAnd:16rFF). - aFloat basicAt:6 put:((i bitShift:-16) bitAnd:16rFF). - aFloat basicAt:7 put:((i bitShift:-8) bitAnd:16rFF). - aFloat basicAt:8 put:(i bitAnd:16rFF). - ] ifFalse:[ - aFloat basicAt:1 put:(i bitAnd:16rFF). - aFloat basicAt:2 put:((i bitShift:-8) bitAnd:16rFF). - aFloat basicAt:3 put:((i bitShift:-16) bitAnd:16rFF). - aFloat basicAt:4 put:((i bitShift:-24) bitAnd:16rFF). - aFloat basicAt:5 put:((i bitShift:-32) bitAnd:16rFF). - aFloat basicAt:6 put:((i bitShift:-40) bitAnd:16rFF). - aFloat basicAt:7 put:((i bitShift:-48) bitAnd:16rFF). - aFloat basicAt:8 put:((i bitShift:-56) bitAnd:16rFF). - ]. - - ^ aFloat. - - "Created: / 4.1.1998 / 01:45:00 / cg" -! - _Double_valueOf0:nativeContext |s d| @@ -6296,60 +6577,6 @@ "Modified: / 4.2.1998 / 15:20:46 / cg" ! -_FileInputStream_open:nativeContext - |fs fd fn name stream fileNo| - - fs := nativeContext receiver. - fd := fs instVarNamed:'fd'. - (fileNo := fd instVarNamed:'fd') ~~ 0 ifTrue:[ - fileNo ~~ -1 ifTrue:[ - self halt:'file already open'. - self internalError:'file already open'. - ^ self. - ] - ]. - - name := nativeContext argAt:1. - name := Java as_ST_String:name. - - name := self fixFilename:name. - - FileOpenTrace ifTrue:[ - ('JAVA: opening ' , name) infoPrintCR. - ]. - - stream := self fileStreamForReading:name. - stream isNil ifTrue:[ - FileOpenTrace ifTrue:[ - ('JAVA: failed to open ''' , name , ''' for reading.') infoPrintCR. - ]. - - self throwIOExceptionWithMessage:('cannot open ' , name , ' for reading'). - - ^ self. - ]. - stream buffered:false. - -"/ FileOpenConfirmation ifTrue:[ -"/ (self confirm:('JAVA Security check\\Opening ''' , name , ''' for reading.\Grant permission ?') withCRs) -"/ ifFalse:[ -"/ self throwIOExceptionWithMessage:('no permission to open ' , name , ' for reading'). -"/ ^ self -"/ ] -"/ ]. - - fileNo := self addOpenFile:stream. - - FileOpenTrace ifTrue:[ - ('JAVA: opened ' , name , ' as FD ' , fileNo printString) infoPrintCR. - ]. - - fd instVarNamed:'fd' put:fileNo. - - "Created: / 4.1.1998 / 16:47:12 / cg" - "Modified: / 28.1.1999 / 17:24:07 / cg" -! - _FileInputStream_read:nativeContext |file byte| @@ -6413,12 +6640,6 @@ "Modified: / 4.2.1998 / 15:20:53 / cg" ! -_FileOutputStream_open:nativeContext - ^ self commonOpen:nativeContext forAppend:false - - "Modified: / 7.4.1998 / 19:14:31 / cg" -! - _FileOutputStream_openAppend:nativeContext ^ self commonOpen:nativeContext forAppend:true @@ -8406,20 +8627,6 @@ "Created: / 12.11.1998 / 19:05:53 / cg" ! -_Object_notify:nativeContext - "wakeup" - - self wakeup:(nativeContext receiver). - - "Created: / 6.1.1998 / 21:09:26 / cg" -! - -_Object_notifyAll:nativeContext - self wakeupAll:(nativeContext receiver). - - "Created: / 3.1.1998 / 03:06:56 / cg" -! - _OffScreenImageSource_sendPixels:nativeContext "/ self halt. "/ UnimplementedNativeMethodSignal raise @@ -8875,30 +9082,6 @@ "Created: / 27.1.2000 / 03:00:20 / cg" ! -_Proxy_defineClass0:nativeContext - " - private static native Class defineClass0(ClassLoader loader, String name, - byte[] b, int off, int len); - " - | loader name b off len bs cls | - loader := nativeContext argAt: 1. - name := nativeContext argAt: 2. - b := nativeContext argAt: 3. - off := nativeContext argAt: 4. - len := nativeContext argAt: 5. - - bs := (off = 0 and: [len = b size]) - ifTrue:[b readStream] - ifFalse:[(b copyFrom: off + 1 to: off + len) readStream]. - - cls := JavaClassReader readStream: bs. - cls classLoader: loader. - - ^self reflection javaClassObjectForClass: cls. - - "Created: / 06-02-2011 / 16:55:31 / Jan Vrany " -! - _RandomAccessFile_close:nativeContext ^ self anyStream_close:nativeContext @@ -9168,15 +9351,6 @@ "Created: / 12.1.1998 / 12:59:53 / cg" ! -_Runtime_gc:nativeContext - "Runs the garbage collector. - Ignored, since the ST-gc runs all the time." - - ^ self - - "Modified: / 12.1.1998 / 12:58:32 / cg" -! - _Runtime_initializeLinkerInternal:nativeContext "init sharedLib linker, return searchPath as javaString" @@ -9579,16 +9753,6 @@ "Modified: / 27.1.1998 / 18:33:13 / cg" ! -_System_identityHashCode:nativeContext - |obj| - - obj := nativeContext argAt:1. - ^ obj identityHash - - "Modified: / 12.11.1998 / 18:52:07 / cg" - "Created: / 12.11.1998 / 18:54:00 / cg" -! - _System_validateSecurityManager:nativeContext "void validateSecurityManager (java.lang.SecurityManager)" @@ -9670,17 +9834,6 @@ "Modified: / 6.2.1998 / 02:15:08 / cg" ! -_Thread_sleep:nativeContext - "sleep for some milliseconds " - - |millis| - - millis := nativeContext argAt:1. - self waitFor:nil state:nil timeOut:(millis max:50) - - "Modified: / 8.1.1999 / 16:42:52 / cg" -! - _Thread_start:nativeContext "start the thread" @@ -10057,51 +10210,6 @@ "Created: / 12.11.1998 / 19:23:43 / cg" ! -_Unsafe_allocateInstance:nativeContext - " - /** Allocate an instance but do not run any constructor. - Initializes the class if it has not yet been. */ - public native Object allocateInstance(Class cls) - throws InstantiationException; - " - | cls | - cls := self reflection classForJavaClassObject: (nativeContext argAt:1). - cls classInit. - ^cls newCleared - - "Created: / 05-02-2011 / 23:10:04 / Jan Vrany " -! - -_Unsafe_defineClass: nativeContext - " - /** - * Tell the VM to define a class, without security checks. By default, the - * class loader and protection domain come from the caller's class. - */ - public native Class defineClass(String name, byte[] b, int off, int len, - ClassLoader loader, - ProtectionDomain protectionDomain); - " - | name b off len loader protectionDomain bs cls | - name := nativeContext argAt: 1. - b := nativeContext argAt: 2. - off := nativeContext argAt: 3. - len := nativeContext argAt: 4. - loader := nativeContext argAt: 5. - protectionDomain := nativeContext argAt: 6. - - bs := (off = 0 and: [len = b size]) - ifTrue:[b readStream] - ifFalse:[(b copyFrom: off + 1 to: off + len) readStream]. - - cls := JavaClassReader readStream: bs. - cls classLoader: loader. - - ^self reflection javaClassObjectForClass: cls. - - "Created: / 05-02-2011 / 22:57:36 / Jan Vrany " -! - _VM_getState:nativeContext "/ int getState () UnimplementedNativeMethodSignal raise @@ -13355,6 +13463,54 @@ "Modified: / 05-02-2011 / 23:38:15 / Jan Vrany " ! +_Class_isInstance:nativeContext + " + /** + * Determines if the specified {@code Object} is assignment-compatible + * with the object represented by this {@code Class}. This method is + * the dynamic equivalent of the Java language {@code instanceof} + * operator. The method returns {@code true} if the specified + * {@code Object} argument is non-null and can be cast to the + * reference type represented by this {@code Class} object without + * raising a {@code ClassCastException.} It returns {@code false} + * otherwise. + * + *

Specifically, if this {@code Class} object represents a + * declared class, this method returns {@code true} if the specified + * {@code Object} argument is an instance of the represented class (or + * of any of its subclasses); it returns {@code false} otherwise. If + * this {@code Class} object represents an array class, this method + * returns {@code true} if the specified {@code Object} argument + * can be converted to an object of the array class by an identity + * conversion or by a widening reference conversion; it returns + * {@code false} otherwise. If this {@code Class} object + * represents an interface, this method returns {@code true} if the + * class or any superclass of the specified {@code Object} argument + * implements this interface; it returns {@code false} otherwise. If + * this {@code Class} object represents a primitive type, this method + * returns {@code false}. + * + * @param obj the object to check + * @return true if {@code obj} is an instance of this class + * + * @since JDK1.1 + */ + public native boolean isInstance(Object obj); + " + + |jClass cls obj| + + obj := nativeContext argAt:1. + obj isNil ifTrue:[^ 0]. + jClass := nativeContext receiver. + cls := self reflection classForJavaClassObject:jClass. + ^self _INSTANCEOF:obj _:cls + + "Modified: / 09-02-1998 / 14:56:23 / cg" + "Modified: / 28-01-2011 / 14:12:42 / Marcel Hlopko " + "Modified: / 25-02-2011 / 18:37:07 / Jan Vrany " +! + _Class_isInterface:nativeContext "return true, if this class is an interface" @@ -13448,6 +13604,37 @@ "Created: / 10-11-2010 / 14:48:46 / Jan Vrany " ! +_Double_longBitsToDouble:nativeContext + |i aFloat| + + i := nativeContext argAt:1. + + aFloat := Float new. + UninterpretedBytes isBigEndian ifTrue:[ + aFloat basicAt:1 put:((i bitShift:-56) bitAnd:16rFF). + aFloat basicAt:2 put:((i bitShift:-48) bitAnd:16rFF). + aFloat basicAt:3 put:((i bitShift:-40) bitAnd:16rFF). + aFloat basicAt:4 put:((i bitShift:-32) bitAnd:16rFF). + aFloat basicAt:5 put:((i bitShift:-24) bitAnd:16rFF). + aFloat basicAt:6 put:((i bitShift:-16) bitAnd:16rFF). + aFloat basicAt:7 put:((i bitShift:-8) bitAnd:16rFF). + aFloat basicAt:8 put:(i bitAnd:16rFF). + ] ifFalse:[ + aFloat basicAt:1 put:(i bitAnd:16rFF). + aFloat basicAt:2 put:((i bitShift:-8) bitAnd:16rFF). + aFloat basicAt:3 put:((i bitShift:-16) bitAnd:16rFF). + aFloat basicAt:4 put:((i bitShift:-24) bitAnd:16rFF). + aFloat basicAt:5 put:((i bitShift:-32) bitAnd:16rFF). + aFloat basicAt:6 put:((i bitShift:-40) bitAnd:16rFF). + aFloat basicAt:7 put:((i bitShift:-48) bitAnd:16rFF). + aFloat basicAt:8 put:((i bitShift:-56) bitAnd:16rFF). + ]. + + ^ aFloat. + + "Created: / 4.1.1998 / 01:45:00 / cg" +! + _FileDescriptor_initIDs:nativeContext "/ introduced with jdk1.2 ... (sigh) @@ -13460,12 +13647,72 @@ "Created: / 27.1.1998 / 18:15:51 / cg" ! +_FileInputStream_open:nativeContext + |fs fd fn name stream fileNo| + + fs := nativeContext receiver. + fd := fs instVarNamed:'fd'. + (fileNo := fd instVarNamed:'fd') ~~ 0 ifTrue:[ + fileNo ~~ -1 ifTrue:[ + self halt:'file already open'. + self internalError:'file already open'. + ^ self. + ] + ]. + + name := nativeContext argAt:1. + name := Java as_ST_String:name. + + name := self fixFilename:name. + + FileOpenTrace ifTrue:[ + ('JAVA: opening ' , name) infoPrintCR. + ]. + + stream := self fileStreamForReading:name. + stream isNil ifTrue:[ + FileOpenTrace ifTrue:[ + ('JAVA: failed to open ''' , name , ''' for reading.') infoPrintCR. + ]. + + self throwIOExceptionWithMessage:('cannot open ' , name , ' for reading'). + + ^ self. + ]. + stream buffered:false. + +"/ FileOpenConfirmation ifTrue:[ +"/ (self confirm:('JAVA Security check\\Opening ''' , name , ''' for reading.\Grant permission ?') withCRs) +"/ ifFalse:[ +"/ self throwIOExceptionWithMessage:('no permission to open ' , name , ' for reading'). +"/ ^ self +"/ ] +"/ ]. + + fileNo := self addOpenFile:stream. + + FileOpenTrace ifTrue:[ + ('JAVA: opened ' , name , ' as FD ' , fileNo printString) infoPrintCR. + ]. + + fd instVarNamed:'fd' put:fileNo. + + "Created: / 4.1.1998 / 16:47:12 / cg" + "Modified: / 28.1.1999 / 17:24:07 / cg" +! + _FileOutputStream_initIDs:nativeContext "/ introduced with jdk1.2 ... (sigh) "Created: / 27.1.1998 / 18:16:40 / cg" ! +_FileOutputStream_open:nativeContext + ^ self commonOpen:nativeContext forAppend:false + + "Modified: / 7.4.1998 / 19:14:31 / cg" +! + _FileOutputStream_writeBytes:nativeContext ^ self anyStream_writeBytes:nativeContext @@ -13647,6 +13894,20 @@ "Created: / 4.1.1998 / 19:40:26 / cg" ! +_Object_notify:nativeContext + "wakeup" + + self wakeup:(nativeContext receiver). + + "Created: / 6.1.1998 / 21:09:26 / cg" +! + +_Object_notifyAll:nativeContext + self wakeupAll:(nativeContext receiver). + + "Created: / 3.1.1998 / 03:06:56 / cg" +! + _Object_registerNatives:aJavaContext "Nothing to do, native method are bound lazily" @@ -13678,6 +13939,30 @@ "Modified: / 30.12.1998 / 19:20:43 / cg" ! +_Proxy_defineClass0:nativeContext + " + private static native Class defineClass0(ClassLoader loader, String name, + byte[] b, int off, int len); + " + | loader name b off len bs cls | + loader := nativeContext argAt: 1. + name := nativeContext argAt: 2. + b := nativeContext argAt: 3. + off := nativeContext argAt: 4. + len := nativeContext argAt: 5. + + bs := (off = 0 and: [len = b size]) + ifTrue:[b readStream] + ifFalse:[(b copyFrom: off + 1 to: off + len) readStream]. + + cls := JavaClassReader readStream: bs. + cls classLoader: loader. + + ^self reflection javaClassObjectForClass: cls. + + "Created: / 06-02-2011 / 16:55:31 / Jan Vrany " +! + _Reflection_getCallerClass:aJavaContext | framesToSkip framesSkipped frame | @@ -13704,6 +13989,15 @@ "Modified: / 28-01-2011 / 15:19:28 / Marcel Hlopko " ! +_Runtime_gc:nativeContext + "Runs the garbage collector. + Ignored, since the ST-gc runs all the time." + + ^ self + + "Modified: / 12.1.1998 / 12:58:32 / cg" +! + _Signal_findSignal:aJavaContext | input signame | @@ -13792,6 +14086,16 @@ "Modified: / 23.12.1998 / 21:54:50 / cg" ! +_System_identityHashCode:nativeContext + |obj| + + obj := nativeContext argAt:1. + ^ obj identityHash + + "Modified: / 12.11.1998 / 18:52:07 / cg" + "Created: / 12.11.1998 / 18:54:00 / cg" +! + _System_initProperties:nativeContext |props stProps| @@ -13960,6 +14264,17 @@ "Modified: / 6.2.1998 / 02:28:18 / cg" ! +_Thread_sleep:nativeContext + "sleep for some milliseconds " + + |millis| + + millis := nativeContext argAt:1. + self waitFor:nil state:nil timeOut:(millis max:50) + + "Modified: / 8.1.1999 / 16:42:52 / cg" +! + _Thread_start0:nativeContext ^self threadStart: nativeContext @@ -14075,6 +14390,21 @@ "Modified: / 10-12-2010 / 20:58:11 / Jan Vrany " ! +_Unsafe_allocateInstance:nativeContext + " + /** Allocate an instance but do not run any constructor. + Initializes the class if it has not yet been. */ + public native Object allocateInstance(Class cls) + throws InstantiationException; + " + | cls | + cls := self reflection classForJavaClassObject: (nativeContext argAt:1). + cls classInit. + ^cls newCleared + + "Created: / 05-02-2011 / 23:10:04 / Jan Vrany " +! + _Unsafe_allocateMemory:aJavaContext | size | @@ -14115,6 +14445,36 @@ "Modified: / 06-02-2011 / 12:10:34 / Jan Vrany " ! +_Unsafe_defineClass: nativeContext + " + /** + * Tell the VM to define a class, without security checks. By default, the + * class loader and protection domain come from the caller's class. + */ + public native Class defineClass(String name, byte[] b, int off, int len, + ClassLoader loader, + ProtectionDomain protectionDomain); + " + | name b off len loader protectionDomain bs cls | + name := nativeContext argAt: 1. + b := nativeContext argAt: 2. + off := nativeContext argAt: 3. + len := nativeContext argAt: 4. + loader := nativeContext argAt: 5. + protectionDomain := nativeContext argAt: 6. + + bs := (off = 0 and: [len = b size]) + ifTrue:[b readStream] + ifFalse:[(b copyFrom: off + 1 to: off + len) readStream]. + + cls := JavaClassReader readStream: bs. + cls classLoader: loader. + + ^self reflection javaClassObjectForClass: cls. + + "Created: / 05-02-2011 / 22:57:36 / Jan Vrany " +! + _Unsafe_ensureClassInitialized:aJavaContext |class| @@ -14347,6 +14707,24 @@ "Created: / 11-12-2010 / 16:33:38 / Jan Kurs " ! +_sun_misc_Unsafe_allocateInstance: nativeContext + + + + " + /** Allocate an instance but do not run any constructor. + Initializes the class if it has not yet been. */ + public native Object allocateInstance(Class cls) + throws InstantiationException; + " + | cls | + cls := self reflection classForJavaClassObject: (nativeContext argAt:1). + cls classInit. + ^cls newCleared + + "Created: / 05-02-2011 / 23:10:04 / Jan Vrany " +! + _sun_misc_Unsafe_allocateMemory: aJavaContext @@ -14393,6 +14771,46 @@ "Modified: / 06-02-2011 / 12:10:34 / Jan Vrany " ! +_sun_misc_Unsafe_compareAndSwapObject: nativeContext + + + + ^ UnimplementedNativeMethodSignal raise +! + +_sun_misc_Unsafe_defineClass: nativeContext + + + + " + /** + * Tell the VM to define a class, without security checks. By default, the + * class loader and protection domain come from the caller's class. + */ + public native Class defineClass(String name, byte[] b, int off, int len, + ClassLoader loader, + ProtectionDomain protectionDomain); + " + | name b off len loader protectionDomain bs cls | + name := nativeContext argAt: 1. + b := nativeContext argAt: 2. + off := nativeContext argAt: 3. + len := nativeContext argAt: 4. + loader := nativeContext argAt: 5. + protectionDomain := nativeContext argAt: 6. + + bs := (off = 0 and: [len = b size]) + ifTrue:[b readStream] + ifFalse:[(b copyFrom: off + 1 to: off + len) readStream]. + + cls := JavaClassReader readStream: bs. + cls classLoader: loader. + + ^self reflection javaClassObjectForClass: cls. + + "Created: / 05-02-2011 / 22:57:36 / Jan Vrany " +! + _sun_misc_Unsafe_ensureClassInitialized: aJavaContext @@ -14782,12 +15200,13 @@ _ARRAYLENGTH:arr arr isNil ifTrue:[ - self halt:'should not happen'. - self throwNullPointerException. + "/self halt:'should not happen'. + self throwNullPointerException. ]. ^ arr size - "Created: / 8.1.1999 / 14:38:27 / cg" + "Created: / 08-01-1999 / 14:38:27 / cg" + "Modified: / 31-05-2011 / 10:09:00 / Jan Vrany " ! _ATHROW:aJavaException diff -r 8d12f019746b -r 26e719a7e88c src/TestletTestCaseProxy.st --- a/src/TestletTestCaseProxy.st Tue May 31 09:28:43 2011 +0000 +++ b/src/TestletTestCaseProxy.st Tue May 31 09:32:24 2011 +0000 @@ -156,20 +156,29 @@ ! performTest - | harnessMock | + | harnessMock handlerBlock | + + handlerBlock := [:ex | TestResult failure sunitSignalWith: ex description]. harnessMock := self harnessMock. - [ self javaClass new - perform: 'test(Lgnu/testlet/TestHarness;)V' sunitAsSymbol - with: harnessMock ] on: JavaError - do: - [:ex | TestResult failure sunitSignalWith: ex description]. + [ JavaVM unimplementedNativeMethodSignal + handle: + handlerBlock + do: [ + self javaClass new + perform: 'test(Lgnu/testlet/TestHarness;)V' sunitAsSymbol + with: harnessMock + ]. + ] on: JavaError do: [:ex | + TestResult failure sunitSignalWith: ex description + ]. + ((harnessMock instVarNamed: 'passed') = 0 ) ifTrue: [ TestResult failure sunitSignalWith: 'Test failed' ]. "Created: / 01-03-2011 / 14:50:32 / Jan Vrany " - "Modified: / 04-03-2011 / 00:07:15 / Jan Vrany " "Modified: / 29-05-2011 / 23:19:07 / Marcel Hlopko " + "Modified: / 31-05-2011 / 10:07:55 / Jan Vrany " ! ! !TestletTestCaseProxy class methodsFor:'documentation'!