[strongtalk] r172 committed - Merge Aliens changes into SVN

2 views
Skip to first unread message

codesite...@google.com

unread,
Sep 13, 2009, 6:00:04 PM9/13/09
to strongta...@googlegroups.com
Revision: 172
Author: StephenLRees
Date: Sun Sep 13 14:52:44 2009
Log: Merge Aliens changes into SVN
http://code.google.com/p/strongtalk/source/detail?r=172

Added:
/branches/gcc-linux/StrongtalkSource/Alien.dlt
/branches/gcc-linux/StrongtalkSource/Alien.gr
/branches/gcc-linux/StrongtalkSource/AlienClassTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienDemoTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienFalseTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienFunctionTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienLibraryTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienStringTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienTrueTest.dlt
/branches/gcc-linux/StrongtalkSource/AlienWeakTable.dlt
/branches/gcc-linux/StrongtalkSource/Aliens test.gr
/branches/gcc-linux/StrongtalkSource/Aliens tests.gr
/branches/gcc-linux/StrongtalkSource/Aliens.gr
/branches/gcc-linux/StrongtalkSource/CallbackTest.dlt
/branches/gcc-linux/StrongtalkSource/CharacterTest.dlt
/branches/gcc-linux/StrongtalkSource/DeltaTuple.dlt
/branches/gcc-linux/StrongtalkSource/DictionaryTest.dlt
/branches/gcc-linux/StrongtalkSource/DirectAlienTest.dlt
/branches/gcc-linux/StrongtalkSource/FFICallbackReturnValue.dlt
/branches/gcc-linux/StrongtalkSource/FFICallbackReturnValueTest.dlt
/branches/gcc-linux/StrongtalkSource/IndirectAlienTest.dlt
/branches/gcc-linux/StrongtalkSource/LargeIntegerTest.dlt
/branches/gcc-linux/StrongtalkSource/NotFoundError.dlt
/branches/gcc-linux/StrongtalkSource/PointerAlienTest.dlt
/branches/gcc-linux/StrongtalkSource/StringTest.dlt
/branches/gcc-linux/StrongtalkSource/TestAlien.dlt
/branches/gcc-linux/StrongtalkSource/TestInvokeArgs.dlt
/branches/gcc-linux/StrongtalkSource/UndefinedObjectTest.dlt
/branches/gcc-linux/StrongtalkSource/UnsafeAlien.dlt
/branches/gcc-linux/test/memory/proxyPrimsTest.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout0Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout1Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout2Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout3Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout4Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout5Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout6Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCallout7Tests.cpp
/branches/gcc-linux/test/prims/alienIntegerCalloutWithArgumentsTests.cpp
/branches/gcc-linux/test/prims/directAlienPrimsTests.cpp
/branches/gcc-linux/test/prims/indirectAlienPrimsTests.cpp
/branches/gcc-linux/test/prims/pointerAlienPrimsTest.cpp
/branches/gcc-linux/test/utilities/testUtils.hpp
Modified:
/branches/gcc-linux/StrongtalkSource/ASTtoRichTextTool.dlt
/branches/gcc-linux/StrongtalkSource/Array.dlt
/branches/gcc-linux/StrongtalkSource/Block.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithEightArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithFiveArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithFourArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithNineArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithOneArgument.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithSevenArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithSixArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithThreeArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithTwoArguments.dlt
/branches/gcc-linux/StrongtalkSource/BlockWithoutArguments.dlt
/branches/gcc-linux/StrongtalkSource/ByteArray.dlt
/branches/gcc-linux/StrongtalkSource/CallBack.dlt
/branches/gcc-linux/StrongtalkSource/Character.dlt
/branches/gcc-linux/StrongtalkSource/ClassMirror.dlt
/branches/gcc-linux/StrongtalkSource/DeltaASTLocationTool.dlt
/branches/gcc-linux/StrongtalkSource/DeltaASTPrinter.dlt
/branches/gcc-linux/StrongtalkSource/DeltaASTTool.dlt
/branches/gcc-linux/StrongtalkSource/DeltaParser.dlt
/branches/gcc-linux/StrongtalkSource/DeltaReferenceGatherer.dlt
/branches/gcc-linux/StrongtalkSource/DeltaRewriter.dlt
/branches/gcc-linux/StrongtalkSource/Error.dlt
/branches/gcc-linux/StrongtalkSource/Exception.dlt
/branches/gcc-linux/StrongtalkSource/ExternalProxy.dlt
/branches/gcc-linux/StrongtalkSource/False.dlt
/branches/gcc-linux/StrongtalkSource/GenericMirror.dlt
/branches/gcc-linux/StrongtalkSource/HashedCollection.dlt
/branches/gcc-linux/StrongtalkSource/MacOSXPlatform.dlt
/branches/gcc-linux/StrongtalkSource/Mirror.dlt
/branches/gcc-linux/StrongtalkSource/MixinDeclMirror.dlt
/branches/gcc-linux/StrongtalkSource/Object.dlt
/branches/gcc-linux/StrongtalkSource/ProtocolMirror.dlt
/branches/gcc-linux/StrongtalkSource/ReadString.dlt
/branches/gcc-linux/StrongtalkSource/String.dlt
/branches/gcc-linux/StrongtalkSource/TestCase.dlt
/branches/gcc-linux/StrongtalkSource/True.dlt
/branches/gcc-linux/StrongtalkSource/Unclassified.gr
/branches/gcc-linux/StrongtalkSource/UndefinedObject.dlt
/branches/gcc-linux/StrongtalkSource/UnixPlatform.dlt
/branches/gcc-linux/StrongtalkSource/Win32Platform.dlt
/branches/gcc-linux/StrongtalkSource/ast.gr
/branches/gcc-linux/StrongtalkSource/base.gr
/branches/gcc-linux/StrongtalkSource/world.gr
/branches/gcc-linux/test/prims/byteArrayPrimsTests.cpp
/branches/gcc-linux/test/prims/systemPrims.cpp
/branches/gcc-linux/vm/code/stubRoutines.cpp
/branches/gcc-linux/vm/code/stubRoutines.hpp
/branches/gcc-linux/vm/deps/includeDB
/branches/gcc-linux/vm/memory/handle.hpp
/branches/gcc-linux/vm/memory/vmSymbols.hpp
/branches/gcc-linux/vm/oops/klass.hpp
/branches/gcc-linux/vm/oops/klassOop.hpp
/branches/gcc-linux/vm/prims/byteArray_prims.cpp
/branches/gcc-linux/vm/prims/byteArray_prims.hpp
/branches/gcc-linux/vm/prims/integerOps.cpp
/branches/gcc-linux/vm/prims/integerOps.hpp
/branches/gcc-linux/vm/prims/prim_impl.hpp
/branches/gcc-linux/vm/prims/prims.inc
/branches/gcc-linux/vm/prims/proxy_prims.cpp
/branches/gcc-linux/vm/prims/system_prims.cpp
/branches/gcc-linux/vm/prims/system_prims.hpp

=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/Alien.dlt Sun Sep 13 14:52:44 2009
@@ -0,0 +1,648 @@
+Delta define: #Alien as: (
+(Class subclassOf: 'ByteArray' instanceVariables: '')
classVariables: 'GCMallocedAliens LoadedLibraries') !
+
+(Delta mirrorFor: #Alien) revision: '$Revision:$'!
+
+(Delta mirrorFor: #Alien) group: 'Aliens'!
+
+(Delta mirrorFor: #Alien)
+comment:
+''!
+
+! (Delta mirrorFor: #Alien) classSide methodsFor: 'class initialization' !
+
+
+initialize
+
+ LoadedLibraries isNil ifTrue:
+ [LoadedLibraries := Dictionary new].
+ GCMallocedAliens isNil ifTrue:
+ [GCMallocedAliens := AlienWeakTable newForOwner: self]! !
+
+! (Delta mirrorFor: #Alien) classSide methodsFor: 'instance creation' !
+
+
+atAddress: pointer <Integer> ^<X>
+
+ ^(self primitiveNew: 8)
+ size: self dataSize negated;
+ addressField: pointer;
+ yourself!
+
+atAddress: pointer <Integer> dataSize: dataSize <Integer> ^<X>
+
+ ^(self primitiveNew: 8)
+ size: dataSize negated;
+ addressField: pointer;
+ yourself!
+
+autoFreeAfter: action <[X, ^ Y]>
+ "Evaluate the action, which must be a 1-argument block.
+ The argument passed to the action is a block the action
+ can use to register Aliens created inside the action.
+ Such aliens will be freed as soon as the action completes.
+ Return the value returned from the action. See usage
+ example at the bottom of the method. "
+
+ | toFree |
+ toFree := OrderedCollection new.
+ ^[action value: [:alien | toFree add: alien]]
+ ensure: [toFree do: [:each | each free]]
+
+"
+ Alien autoFreeAfter:
+ [:autoFree | | foo bar |
+ foo := autoFree value: (Alien newCString: 'foo').
+ bar := autoFree value: (Alien newCString: 'bar').
+ ...]
+"!
+
+dataSize
+
+ ^self subclassResponsibility!
+
+ensureLoaded: libraryName
+
+ ^self loadedLibraries
+ at: libraryName
+ ifAbsentPut: [(Alien new: 4)
+ unsignedLongAt: 1 put: (self primLoadLibrary: libraryName);
+ yourself]!
+
+forPointer: pointer <Integer> ^<X>
+
+ ^(self primitiveNew: 8)
+ size: 0;
+ addressField: pointer;
+ yourself!
+
+new
+
+ ^self new: self dataSize!
+
+new: size <Integer> ^ <X>
+
+ ^(self primitiveNew: size + 4)
+ size: size;
+ initialize!
+
+newC
+
+ ^self newC: self dataSize!
+
+newC: size <Integer> ^ <X>
+
+ ^(self primitiveNew: 8)
+ size: size negated;
+ addressField: (self Ccalloc: size);
+ initialize!
+
+newCString: string <String> ^ <Alien>
+
+ ^(Alien rawNewC: string size + 1)
+ replaceFrom: 1
+ to: string size
+ with: string
+ startingAt: 1;
+ unsignedByteAt: string size + 1 put: 0;
+ yourself!
+
+newForCallbackArgs
+
+ ^(self new: 8)
+ size: self dataSize negated;
+ yourself!
+
+newGC
+
+ ^self newGC: self dataSize!
+
+newGC: size <Integer> ^<X>
+
+ | alien address |
+ self unimplemented.
+ alien := self primitiveNew: 8.
+ alien size: size negated.
+ address := self Ccalloc: size.
+ GCMallocedAliens add: alien finalizing: address.
+ ^alien
+ addressField: address;
+ initialize
+ !
+
+rawNewC: size <Integer> ^ <X>
+
+ ^(self primitiveNew: 8)
+ size: size negated;
+ addressField: (self Cmalloc: size);
+ initialize! !
+
+! (Delta mirrorFor: #Alien) classSide methodsFor: 'libraries' !
+
+
+lookup: symbolName <String> inLibrary: libraryName <String> ^ <Alien>
+
+ ^self forPointer: ((Alien ensureLoaded: libraryName)
+ primFindSymbol: symbolName)!
+
+lookupOrNil: symbolName <String> inLibrary: libraryName <String> ^ <Alien>
+
+ ^[self lookup: symbolName inLibrary: libraryName]
+ on: NotFoundError
+ do: [:err| nil]!
+
+primLoadLibrary: libraryName
+
+ |proxy|
+ proxy := ExternalProxy new.
+ {{primitiveDLLLoad: libraryName result: proxy ifFail: [:err|] }}.
+ ^proxy asInteger! !
+
+! (Delta mirrorFor: #Alien) classSide methodsFor: 'private - accessing' !
+
+
+loadedLibraries
+
+ LoadedLibraries isNil ifTrue:
+ [LoadedLibraries := Dictionary new].
+ ^LoadedLibraries! !
+
+! (Delta mirrorFor: #Alien) classSide methodsFor: 'private - memory
allocation' !
+
+
+Ccalloc: size <Integer> ^ <Integer>
+
+ ^{{self primitiveAlienCalloc: size
+ ifFail: [:err| self error: 'Failed to calloc alien: ', err]}}!
+
+Cmalloc: size <Integer> ^ <Integer>
+
+ ^{{self primitiveAlienMalloc: size
+ ifFail: [:err| self error: 'Failed to malloc alien: ', err]}}! !
+
+! (Delta mirrorFor: #Alien) methodsFor: 'accessing' !
+
+
+address ^<Integer>
+
+ ^self size <= 0
+ ifTrue: [self addressField]
+ ifFalse: [self error: 'One cannot take the address of direct Alien
instances; they may move']!
+
+boolAt: index <Integer> ^<Boolean>
+
+ ^(self at: 1) ~~ 0!
+
+boolAt: index <Integer> put: value <Boolean> ^<Boolean>
+
+ self at: 1 put: (value ifTrue: [1] ifFalse: [0]).
+ ^value!
+
+dataSize ^<Integer>
+
+ ^self size abs!
+
+doubleAt: index <Integer> ^<Float>
+
+ ^{{self primitiveAlienDoubleAt: index
+ ifFail: [:err| self error: 'Unable to get double ', err] }}!
+
+doubleAt: index <Integer> put: double <Float> ^<Float>
+
+ ^{{self primitiveAlienDoubleAt: index
+ put: double
+ ifFail: [:err| self error: 'Unable to set double ', err] }}!
+
+floatAt: index <Integer> ^<Double>
+
+ ^{{self primitiveAlienFloatAt: index
+ ifFail: [:err| self error: 'Unable to get float ', err] }}!
+
+floatAt: index <Integer> put: double <Float> ^<Float>
+
+ ^{{self primitiveAlienFloatAt: index
+ put: double
+ ifFail: [:err| self error: 'Unable to set float ', err] }}!
+
+pointer
+
+ self isPointer ifTrue: [self error: 'One cannot take the address of
pointer Alien instances; they may move, and are already pointers'].
+ ^self class forPointer: self address!
+
+signedByteAt: index <Integer> ^<Integer>
+
+ ^{{self primitiveAlienSignedByteAt: index
+ ifFail: [:err| self error: 'Unable to get signed byte ', err] }}!
+
+signedByteAt: index <Integer> put: byte <Integer> ^<Integer>
+
+ ^{{self primitiveAlienSignedByteAt: index
+ put: byte
+ ifFail: [:err| self error: 'Unable to set signed byte ', err] }}!
+
+signedLongAt: index <Integer> ^<Integer>
+
+ ^{{self primitiveAlienSignedLongAt: index
+ ifFail: [:err| self error: 'Unable to get signed long ', err] }}!
+
+signedLongAt: index <Integer> put: long <Integer>^<Integer>
+
+ ^{{self primitiveAlienSignedLongAt: index
+ put: long
+ ifFail: [:err| self error: 'Unable to get signed long ', err] }}!
+
+signedShortAt: index <Integer> ^<Integer>
+
+ ^{{self primitiveAlienSignedShortAt: index
+ ifFail: [:err| self error: 'Unable to get signed short ', err] }}!
+
+signedShortAt: index <Integer> put: short <Integer> ^<Integer>
+
+ ^{{self primitiveAlienSignedShortAt: index
+ put: short
+ ifFail: [:err| self error: 'Unable to set signed short ', err] }}!
+
+strcpy
+
+ ^self strcpyFrom: 1!
+
+strcpyFrom: startIndex
+
+ |string length offset|
+ length := self strlenStartingAt: startIndex.
+ string := String new: length.
+ offset := startIndex - 1.
+ 1 to: length do: [:i|
+ string at: i put: (Character value: (self unsignedByteAt: i + offset))].
+ ^string!
+
+strcpyUTF8
+
+ ^self strcpyUTF8From: 1!
+
+strcpyUTF8From: startIndex
+
+ ^self unimplemented!
+
+strlen
+
+ ^self strlenStartingAt: 1!
+
+strlenStartingAt: startIndex
+
+ self dataSize == 0
+ ifTrue: [^self rawStrlenStartingAt: startIndex].
+ startIndex to: self dataSize do: [:i| (self unsignedByteAt: i) == 0
+ ifTrue: [^ i - startIndex]].
+ ^self dataSize - startIndex + 1!
+
+unsignedByteAt: index <Integer> ^<Integer>
+
+ ^{{self primitiveAlienUnsignedByteAt: index
+ ifFail: [:err| self error: 'Unable to get unsigned byte ', err] }}!
+
+unsignedByteAt: index <Integer> put: byte <Integer|Character> ^<Integer>
+
+ |c|
+ c := byte isCharacter
+ ifTrue: [byte asciiValue]
+ ifFalse: [byte].
+ ^{{self primitiveAlienUnsignedByteAt: index
+ put: c
+ ifFail: [:err| self error: 'Unable to set unsigned byte ', err] }}!
+
+unsignedLongAt: index <Integer> ^<Integer>
+
+ ^{{self primitiveAlienUnsignedLongAt: index
+ ifFail: [:err| self error: 'Unable to get unsigned long ', err] }}!
+
+unsignedLongAt: index <Integer> put: long <Integer>^<Integer>
+
+ ^{{self primitiveAlienUnsignedLongAt: index
+ put: long
+ ifFail: [:err| self error: 'Unable to set unsigned long ', err] }}!
+
+unsignedShortAt: index <Integer> ^<Integer>
+
+ ^{{self primitiveAlienUnsignedShortAt: index
+ ifFail: [:err| self error: 'Unable to get unsigned short ', err] }}!
+
+unsignedShortAt: index <Integer> put: short <Integer>^<Integer>
+
+ ^{{self primitiveAlienUnsignedShortAt: index
+ put: short
+ ifFail: [:err| self error: 'Unable to set unsigned short ', err] }}! !
+
+! (Delta mirrorFor: #Alien) methodsFor: 'callouts' !
+
+
+primFFICallResult: result <Alien>
+
+ {{self primitiveAlienCallResult: result ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject> with: arg1 <Alien|
SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ with: arg1
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject> with: arg1 <Alien|
SmallInteger> with: arg2 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ with: arg1
+ with: arg2
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ with: arg1
+ with: arg2
+ with: arg3
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ with: arg1
+ with: arg2
+ with: arg3
+ with: arg4
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ with: arg1
+ with: arg2
+ with: arg3
+ with: arg4
+ with: arg5
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger>
+with: arg6 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ with: arg1
+ with: arg2
+ with: arg3
+ with: arg4
+ with: arg5
+ with: arg6
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger>
+with: arg6 <Alien|SmallInteger>
+with: arg7 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ with: arg1
+ with: arg2
+ with: arg3
+ with: arg4
+ with: arg5
+ with: arg6
+ with: arg7
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger>
+with: arg6 <Alien|SmallInteger>
+with: arg7 <Alien|SmallInteger>
+with: arg8 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ withArguments: { arg1. arg2. arg3. arg4. arg5. arg6. arg7. arg8 }
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger>
+with: arg6 <Alien|SmallInteger>
+with: arg7 <Alien|SmallInteger>
+with: arg8 <Alien|SmallInteger>
+with: arg9 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ withArguments: { arg1. arg2. arg3. arg4. arg5. arg6. arg7. arg8. arg9 }
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger>
+with: arg6 <Alien|SmallInteger>
+with: arg7 <Alien|SmallInteger>
+with: arg8 <Alien|SmallInteger>
+with: arg9 <Alien|SmallInteger>
+with: arg10 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ withArguments: { arg1. arg2. arg3. arg4. arg5. arg6. arg7. arg8. arg9.
arg10 }
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger>
+with: arg6 <Alien|SmallInteger>
+with: arg7 <Alien|SmallInteger>
+with: arg8 <Alien|SmallInteger>
+with: arg9 <Alien|SmallInteger>
+with: arg10 <Alien|SmallInteger>
+with: arg11 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ withArguments: { arg1. arg2. arg3. arg4. arg5. arg6. arg7. arg8. arg9.
arg10. arg11 }
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+with: arg1 <Alien|SmallInteger>
+with: arg2 <Alien|SmallInteger>
+with: arg3 <Alien|SmallInteger>
+with: arg4 <Alien|SmallInteger>
+with: arg5 <Alien|SmallInteger>
+with: arg6 <Alien|SmallInteger>
+with: arg7 <Alien|SmallInteger>
+with: arg8 <Alien|SmallInteger>
+with: arg9 <Alien|SmallInteger>
+with: arg10 <Alien|SmallInteger>
+with: arg11 <Alien|SmallInteger>
+with: arg12 <Alien|SmallInteger> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ withArguments: { arg1. arg2. arg3. arg4. arg5. arg6. arg7. arg8. arg9.
arg10. arg11. arg12 }
+ ifFail: [:err| self error: err]}}!
+
+primFFICallResult: result <Alien|UndefinedObject>
+withArguments: arguments <Array[Alien|SmallInteger]> ^ <Alien>
+
+ {{self primitiveAlienCallResult: result
+ withArguments: arguments
+ ifFail: [:err| self error: err]}}! !
+
+! (Delta mirrorFor: #Alien) methodsFor: 'converting' !
+
+
+asAlien
+
+ ^self!
+
+asExternalProxy ^<ExternalProxy>
+
+ ^ExternalProxy
+ forHigh: (self unsignedShortAt: 3)
+ low: (self unsignedShortAt: 1)!
+
+asSignedByte
+
+ ^self signedByteAt: 1!
+
+asSignedLong
+
+ ^self signedLongAt: 1!
+
+asSignedShort
+
+ ^self signedShortAt: 1!
+
+asUnsignedByte
+
+ ^self unsignedByteAt: 1!
+
+asUnsignedLong
+
+ ^self unsignedLongAt: 1!
+
+asUnsignedShort
+
+ ^self unsignedShortAt: 1! !
+
+! (Delta mirrorFor: #Alien) methodsFor: 'instance initialization' !
+
+
+initialize
+ "Subclasses may override to perform specific initialization"! !
+
+! (Delta mirrorFor: #Alien) methodsFor: 'memory management' !
+
+
+free
+
+ {{primitiveAlienFree: self addressField
+ ifFail: [:err| self error: 'Could not free alien: ', err]}}.
+ self addressField: 0!
+
+freeAfter: aBlock <[Alien]>
+
+ [aBlock value: self]
+ ensure: [self free]! !
+
+! (Delta mirrorFor: #Alien) methodsFor: 'private - accessing' !
+
+
+addressField ^<Integer>
+
+ ^{{ self primitiveAlienAddressIfFail: [:err| self error: 'failed to get
address of alien ', err] }}!
+
+addressField: anInteger <Integer>
+
+ ^{{ self primitiveAlienAddress: anInteger
+ ifFail: [:err| self error: 'failed to set address of alien ', err] }}!
+
+at: index <Integer> ^ <SmallInteger>
+
+ ^self unsignedByteAt: index!
+
+at: index <Integer> put: byte <SmallInteger> ^ <SmallInteger>
+
+ ^self unsignedByteAt: index put: byte!
+
+primFindSymbol: symbolName <String> ^ <Integer>
+
+ |result library|
+ result := ExternalProxy new.
+ library := self asExternalProxy.
+ {{primitiveDLLLookup: symbolName asSymbol
+ in: library
+ result: result
+ ifFail: [:err | err == #NotFound
+ ifTrue: [NotFoundError signal]
+ ifFalse: [self error: err]]}}.
+ ^result asInteger !
+
+rawStrlenStartingAt: startIndex
+
+ |index|
+ index := startIndex.
+ [(self unsignedByteAt: index) == 0]
+ whileFalse: [index := index + 1].
+ ^index - startIndex!
+
+signedFourByteLimit
+
+ ^self smallIntLimit * 4!
+
+size ^<Integer>
+
+ ^{{self primitiveAlienSizeIfFail: [:err| self error: 'failed to get alien
size: ', err] }}!
+
+size: anInteger <Integer>
+
+ {{self primitiveAlienSize: anInteger
+ ifFail: [:err| self error: 'failed to set alien size: ', err] }}!
+
+smallIntLimit
+
+ ^SmallInteger maxVal + 1!
+
+strlenThroughPointerAt: index
+
+ ^(Alien forPointer: (self unsignedLongAt: index))
+ rawStrlenStartingAt: 1!
+
+unsignedFourByteLimit
+
+ ^self smallIntLimit * 8! !
+
+! (Delta mirrorFor: #Alien) methodsFor: 'testing' !
+
+
+isPointer
+
+ ^self size == 0! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/Alien.gr Sun Sep 13 14:52:44 2009
@@ -0,0 +1,2 @@
+$Revision:$!
+Delta fileIn: 'UnsafeAlien.dlt' !
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienClassTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,94 @@
+Delta define: #AlienClassTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #AlienClassTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienClassTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #AlienClassTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienClassTest) methodsFor: 'private - test support' !
+
+
+libcName
+
+ Platform == Win32Platform
+ ifTrue: [^'msvcrt.dll'].
+ Platform == MacOSXPlatform
+ ifTrue: [^'libc.dylib'].
+ Platform == UnixPlatform
+ ifTrue: [^'libc.so.6'].
+ self error: 'Platform set incorrectly'!
+
+unimplementedText
+
+ [self unimplemented]
+ on: Error
+ do: [:ex|^ex messageText]! !
+
+! (Delta mirrorFor: #AlienClassTest) methodsFor: 'testing' !
+
+
+testEnsureLoadedWin32
+
+ |library proxy|
+ Platform == Win32Platform ifFalse: [^self].
+ proxy := Platform DLLLoad: 'user'.
+ library := Alien ensureLoaded: 'USER32.DLL'.
+ self assert: library asUnsignedLong = proxy asInteger.
+ self assert: library == (Alien ensureLoaded: 'USER32.DLL')!
+
+testLookupClockWin32
+
+ |function result|
+ function := Alien lookup: 'clock' inLibrary: self libcName.
+ result := Alien new: 8.
+ function primFFICallResult: result!
+
+testLookupInLibraryWin32
+
+ |function proxy|
+ Platform == Win32Platform ifFalse: [^self].
+ proxy := Platform DLLLookup: 'sprintf' in: 'msvcrt.dll'.
+ function := Alien lookup: 'sprintf' inLibrary: 'msvcrt.dll'.
+ self assert: function address = proxy asInteger!
+
+testLookupOrNilInLibraryWin32
+
+ |function proxy|
+ Platform == Win32Platform ifFalse: [^self].
+ proxy := Platform DLLLookup: 'sprintf' in: 'msvcrt.dll'.
+ function := Alien lookupOrNil: 'sprintf' inLibrary: 'msvcrt.dll'.
+ self assert: function address = proxy asInteger.
+ self assert: (Alien lookupOrNil: 'unknown' inLibrary: 'msvcrt.dll') isNil!
+
+testNewCString
+
+ (Alien newCString: '12345678')
+ freeAfter: [:pointer|
+ self assert: 8 = pointer strlen.
+ self assert: '12345678' = pointer strcpy]!
+
+testNewForCallbackArgs
+
+ |alien|
+ alien := TestAlien newForCallbackArgs.
+ self assert: alien size == TestAlien dataSize negated.
+ self assert: alien address == 0!
+
+testNewGCUnimplemented
+
+ self should: [Alien newGC: 4]
+ raise: Error
+ withExceptionDo: [:ex| self assert: self unimplementedText = ex
messageText]!
+
+testPrimLoadLibraryWin32
+
+ |library proxy|
+ Platform == Win32Platform ifFalse: [^self].
+ proxy := Platform DLLLoad: 'user'.
+ library := Alien primLoadLibrary: 'USER32.DLL'.
+ self assert: library = proxy asInteger! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienDemoTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,61 @@
+Delta define: #AlienDemoTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #AlienDemoTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienDemoTest) group: 'Unclassified'!
+
+(Delta mirrorFor: #AlienDemoTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienDemoTest) methodsFor: 'test-support' !
+
+
+libcName
+
+ Platform == Win32Platform
+ ifTrue: [^'msvcrt.dll'].
+ Platform == MacOSXPlatform
+ ifTrue: [^'libc.dylib'].
+ Platform == UnixPlatform
+ ifTrue: [^'libc.so.6'].
+ self error: 'Unknow platform'! !
+
+! (Delta mirrorFor: #AlienDemoTest) methodsFor: 'testing' !
+
+
+testCqsort
+ "Call the libc qsort function (which requires a callback)."
+ | cb rand nElements sizeofDouble values orig sort |
+ rand:= Random new.
+ values:= Alien newC: (nElements:= 100) * (sizeofDouble:= 8).
+" 1 to: values dataSize by: sizeofDouble do:
+ [:i| values doubleAt: i put: rand next].
+ orig:= (1 to: values dataSize by: sizeofDouble) collect: [:i| values
doubleAt: i].
+ cb:= Callback
+ block: [:args :result|
+ result returnInteger: ((args first doubleAt: 1) - (args second
doubleAt: 1)) sign]
+ argsClass: QsortCompare.
+ (Alien lookup: 'qsort' inLibrary: libcName)
+ primFFICallResult: nil
+ with: values pointer
+ with: nElements
+ with: sizeofDouble
+ with: cb thunk.
+ sort:= (1 to: values dataSize by: sizeofDouble) collect: [:i| values
doubleAt: i].
+ values free.
+ ^orig -> sort"!
+
+testSprintf
+
+ | r s actual |
+ (Alien lookup: 'sprintf' inLibrary: self libcName)
+ primFFICallResult: (r := Alien new: 4)
+ withArguments: { UnsafeAlien forPointerTo: (s := ByteArray new: 1024).
+ UnsafeAlien forPointerTo: ('Hello World %d %x !!!!', (String
with: Character nul)) asSymbol. "only works for symbols"
+ 123.
+ 48879}.
+ actual := (s copyFrom: 1 to: (r signedLongAt: 1)) asString.
+ self assert: 'Hello World 123 beef !!!!' = actual! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienFalseTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,18 @@
+Delta define: #AlienFalseTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #AlienFalseTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienFalseTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #AlienFalseTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienFalseTest) methodsFor: 'testing' !
+
+
+testAsAlien
+
+ self assert: false asAlien == 0! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienFunctionTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,249 @@
+Delta define: #AlienFunctionTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: 'sprintf
+labs
+result
+formattedString')) !
+
+(Delta mirrorFor: #AlienFunctionTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienFunctionTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #AlienFunctionTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienFunctionTest) methodsFor: 'fixture' !
+
+
+libcName
+
+ Platform == Win32Platform
+ ifTrue: [^'msvcrt.dll'].
+ Platform == MacOSXPlatform
+ ifTrue: [^'libc.dylib'].
+ Platform == UnixPlatform
+ ifTrue: [^'libc.so.6']
+ self error: 'Unsupported platform'!
+
+setUp
+
+ sprintf := Alien lookup: 'sprintf' inLibrary: self libcName.
+ labs := Alien lookup: 'labs' inLibrary: self libcName.
+ result := Alien new: 4.
+ formattedString := Alien newC: 200!
+
+tearDown
+
+ formattedString free! !
+
+! (Delta mirrorFor: #AlienFunctionTest) methodsFor: 'testing' !
+
+
+testCallLabsWithOneArg
+
+ labs primFFICallResult: result
+ with: -1.
+ self assert: 1 == result asSignedLong!
+
+testCallSprintfWithArguments
+
+ Alien autoFreeAfter: [:free|
+ |formatString|
+ formatString := '%d' asString.
+ sprintf primFFICallResult: nil
+ withArguments: { formattedString pointer.
+ (free value: formatString asAlien) pointer.
+ 1 } ].
+ self assert: '1' asString = formattedString strcpy!
+
+testCallSprintfWithEightArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d %d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3
+ with: 4
+ with: 5
+ with: 6].
+ self assert: '1 2 3 4 5 6' asString = formattedString strcpy.
+ self assert: 11 == result asUnsignedLong!
+
+testCallSprintfWithElevenArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d %d %d %d %d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3
+ with: 4
+ with: 5
+ with: 6
+ with: 7
+ with: 8
+ with: 9].
+ self assert: '1 2 3 4 5 6 7 8 9' asString = formattedString strcpy.
+ self assert: 17 == result asUnsignedLong!
+
+testCallSprintfWithFiveArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3].
+ self assert: '1 2 3' asString = formattedString strcpy.
+ self assert: 5 == result asUnsignedLong!
+
+testCallSprintfWithFourArgs
+
+ Alien
+ autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: ((free value: (Alien newC: 4))
+ signedLongAt: 1 put: 1;
+ yourself)
+ with: 2.
+ self assert: '1 2' asString = formattedString strcpy.
+ self assert: 3 == result asUnsignedLong]!
+
+testCallSprintfWithNineArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d %d %d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3
+ with: 4
+ with: 5
+ with: 6
+ with: 7].
+ self assert: '1 2 3 4 5 6 7' asString = formattedString strcpy.
+ self assert: 13 == result asUnsignedLong!
+
+testCallSprintfWithSevenArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3
+ with: 4
+ with: 5].
+ self assert: '1 2 3 4 5' asString = formattedString strcpy.
+ self assert: 9 == result asUnsignedLong!
+
+testCallSprintfWithSixArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3
+ with: 4].
+ self assert: '1 2 3 4' asString = formattedString strcpy.
+ self assert: 7 == result asUnsignedLong!
+
+testCallSprintfWithTenArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d %d %d %d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3
+ with: 4
+ with: 5
+ with: 6
+ with: 7
+ with: 8].
+ self assert: '1 2 3 4 5 6 7 8' asString = formattedString strcpy.
+ self assert: 15 == result asUnsignedLong!
+
+testCallSprintfWithThreeArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString|
+ formatString := '%d' asString.
+ sprintf primFFICallResult: nil
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1].
+ self assert: '1' asString = formattedString strcpy!
+
+testCallSprintfWithTwelveArgs
+
+ Alien autoFreeAfter: [:free|
+ |formatString |
+ formatString := '%d %d %d %d %d %d %d %d %d %d' asString.
+ sprintf primFFICallResult: result
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer
+ with: 1
+ with: 2
+ with: 3
+ with: 4
+ with: 5
+ with: 6
+ with: 7
+ with: 8
+ with: 9
+ with: 10].
+ self assert: '1 2 3 4 5 6 7 8 9 10' asString = formattedString strcpy.
+ self assert: 20 == result asUnsignedLong!
+
+testCallSprintfWithTwoArgs
+
+ Alien
+ autoFreeAfter: [:free|
+ |formatString|
+ formatString := '12345' asString.
+ sprintf primFFICallResult: nil
+ with: formattedString pointer
+ with: (free value: formatString asAlien) pointer.
+ self assert: formatString = formattedString strcpy]!
+
+testCallSprintfWithUnsafeAlienTarget
+
+ Alien
+ autoFreeAfter: [:free|
+ |formatString bytes string unsafe|
+ bytes := ByteArray new: 6.
+ unsafe := UnsafeAlien forPointerTo: bytes.
+ formatString := '12345' asString.
+ sprintf primFFICallResult: nil
+ with: unsafe
+ with: (free value: formatString asAlien) pointer.
+ self assert: formatString = (bytes copyWithSize: 5) asString]! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienLibraryTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,42 @@
+Delta define: #AlienLibraryTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: 'library proxy
address')) !
+
+(Delta mirrorFor: #AlienLibraryTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienLibraryTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #AlienLibraryTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienLibraryTest) methodsFor: 'fixture' !
+
+
+setUp
+
+ self ensureWin32Or: [^self].
+ library := Alien ensureLoaded: 'msvcrt.dll'! !
+
+! (Delta mirrorFor: #AlienLibraryTest) methodsFor: 'private - test
support' !
+
+
+ensureWin32Or: block
+
+ Platform == Win32Platform
+ ifFalse: [block value]! !
+
+! (Delta mirrorFor: #AlienLibraryTest) methodsFor: 'testing' !
+
+
+testPrimFindSymbol
+
+ self ensureWin32Or: [^self].
+ self assert: (library primFindSymbol: 'sprintf')
+ = (Platform DLLLookup: 'sprintf' in: 'msvcrt.dll') asInteger!
+
+testPrimFindSymbolUnknown
+
+ self ensureWin32Or: [^self].
+ self should: [library primFindSymbol: 'unknownSymbol']
+ raise: NotFoundError! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienStringTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,23 @@
+Delta define: #AlienStringTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #AlienStringTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienStringTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #AlienStringTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienStringTest) methodsFor: 'testing' !
+
+
+testAsAlien
+
+ |alien string|
+ string := '123456' asString.
+ alien := string asAlien.
+ self assert: (alien size abs = 7).
+ self assert: string = alien strcpy
+ ! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienTest.dlt Sun Sep 13 14:52:44
2009
@@ -0,0 +1,216 @@
+Delta define: #AlienTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: 'alien')) !
+
+(Delta mirrorFor: #AlienTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #AlienTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienTest) classSide methodsFor: 'test case' !
+
+
+isAbstract
+
+ ^self == AlienTest! !
+
+! (Delta mirrorFor: #AlienTest) methodsFor: 'fixture' !
+
+
+dataSize
+
+ ^8! !
+
+! (Delta mirrorFor: #AlienTest) methodsFor: 'testing' !
+
+
+testAsAlien
+
+ self assert: alien asAlien == alien!
+
+testBoolAccess
+
+ self assert: (alien boolAt: 1 put: true).
+ self assert: (alien boolAt: 1).
+ self deny: (alien boolAt: 1 put: false).
+ self deny: (alien boolAt: 1)!
+
+testDataSize
+
+ self assert: alien dataSize == self dataSize!
+
+testDoubleAccess
+
+ alien doubleAt: 1 put: 1.0.
+ self assert: (alien doubleAt: 1) = 1.0.
+ alien doubleAt: 1 put: 1.23456.
+ self assert: ((alien doubleAt: 1) - 1.23456) abs < 0.000000000001!
+
+testDoubleIndexOutOfRange
+
+ self should: [alien doubleAt: 0 put: 1.0] raise: Error.
+ self should: [alien doubleAt: self dataSize - 6 put: 1.0] raise: Error.
+ self should: [alien doubleAt: self dataSize - 6] raise: Error.
+ self should: [alien doubleAt: 0] raise: Error!
+
+testFloatAccess
+
+ alien floatAt: 1 put: 1.0.
+ self assert: (alien floatAt: 1) = 1.0.
+ alien floatAt: 1 put: 1.23456.
+ self assert: ((alien floatAt: 1) - 1.23456) abs < 0.0000001.
+ self deny: ((alien floatAt: 1) - 1.23456) abs < 0.00000001!
+
+testFloatIndexOutOfRange
+
+ self should: [alien doubleAt: 0 put: 1.0] raise: Error.
+ self should: [alien doubleAt: self dataSize - 6 put: 1.0] raise: Error.
+ self should: [alien doubleAt: self dataSize - 6] raise: Error.
+ self should: [alien doubleAt: 0] raise: Error!
+
+testReplaceFromToWithStartingAt
+
+ |replacement|
+ replacement := ByteArray withAll: #(1 2 255).
+
+ alien replaceFrom: 1 to: 3 with: replacement startingAt: 1.
+ 1 to: 3 do: [:i|
+ self assert: (replacement at: i) == (alien unsignedByteAt: i)
+ description: 'Wrong value at ', i printString].
+
+ alien replaceFrom: 2 to: 4 with: replacement startingAt: 1.
+ 1 to: 3 do: [:i|
+ self assert: (replacement at: i) == (alien unsignedByteAt: i + 1)
+ description: 'Wrong value at ', i printString].!
+
+testReplaceFromToWithStartingAtWithString
+
+ |replacement|
+ replacement := '1234'.
+
+ alien replaceFrom: 1 to: 4 with: replacement startingAt: 1.
+ self assert: replacement = alien strcpy!
+
+testSignedByteAccess
+
+ 1 to: 4 do: [:index|
+ self assert: (alien signedByteAt: index put: index) == index].
+ 1 to: 4 do: [:index|
+ self assert: (alien signedByteAt: index) == index].
+ 1 to: 4 do: [:index|
+ alien signedByteAt: index put: index negated].
+ 1 to: 4 do: [:index|
+ self assert: (alien signedByteAt: index) == index negated].
+ self assert: alien asSignedByte == -1!
+
+testSignedByteIndexOutOfRange
+
+ self should: [alien signedByteAt: 0] raise: Error.
+ self should: [alien signedByteAt: self dataSize + 1] raise: Error.
+ self should: [alien signedByteAt: 0 put: 1] raise: Error.
+ self should: [alien signedByteAt: self dataSize + 1 put: 1] raise: Error!
+
+testSignedLongAccess
+
+ |long|
+ long := (256 * 256 + 1) negated.
+ self assert: (alien signedLongAt: 1 put: long) = long.
+ self assert: (alien signedLongAt: 1) = long.
+ self assert: (alien unsignedByteAt: 1) == 255.
+ self assert: (alien unsignedByteAt: 3) == 254.
+ self assert: alien asSignedLong = long!
+
+testSignedLongIndexOutOfRange
+
+ self should: [alien signedLongAt: 0] raise: Error.
+ self should: [alien signedLongAt: self dataSize - 2] raise: Error.
+ self should: [alien signedLongAt: 0 put: 1] raise: Error.
+ self should: [alien signedLongAt: self dataSize - 2 put: 1] raise: Error!
+
+testSignedShortAccess
+
+ 1 to: 4 do: [:index|
+ alien unsignedByteAt: index put: 255].
+ self assert: (alien signedShortAt: 1) == -1.
+ self assert: (alien signedShortAt: 1 put: 255) == 255.
+ self assert: (alien signedShortAt: 1) == 255.
+ self assert: alien asSignedShort == 255!
+
+testSignedShortIndexOutOfRange
+
+ self should: [alien signedShortAt: 0 put: 1] raise: Error.
+ self should: [alien signedShortAt: self dataSize put: 1] raise: Error.
+ self should: [alien signedShortAt: 0] raise: Error.
+ self should: [alien signedShortAt: self dataSize] raise: Error!
+
+testStrcpyUTF8FromUnimplemented
+
+ |replacement|
+ replacement := '1234'.
+
+ alien replaceFrom: 1 to: 4 with: replacement startingAt: 1.
+ self should: [alien strcpyUTF8From: 1]
+ raise: Error
+ withExceptionDo: [:ex| self assert: 'A hook for unimplemented code has
been encountered' = ex messageText]!
+
+testStrcpyUTF8Unimplemented
+
+ |replacement|
+ replacement := '1234'.
+
+ alien replaceFrom: 1 to: 4 with: replacement startingAt: 1.
+ self should: [alien strcpyUTF8]
+ raise: Error
+ withExceptionDo: [:ex| self assert: 'A hook for unimplemented code has
been encountered' = ex messageText]!
+
+testUnsignedByteAccess
+
+ 1 to: 4 do: [:index|
+ self assert: (alien unsignedByteAt: index put: index) == index].
+ 1 to: 4 do: [:index|
+ self assert: (alien unsignedByteAt: index) == index].
+ self assert: (alien asUnsignedByte == 1)!
+
+testUnsignedByteIndexOutOfRange
+
+ self should: [alien unsignedByteAt: 0] raise: Error.
+ self should: [alien unsignedByteAt: self dataSize + 1] raise: Error.
+ self should: [alien unsignedByteAt: 0 put: 1] raise: Error.
+ self should: [alien unsignedByteAt: self dataSize + 1 put: 1] raise:
Error!
+
+testUnsignedLongAccess
+
+ |long|
+ long := 256 * 256 + 1.
+ self assert: (alien unsignedLongAt: 1 put: long) == long.
+ self assert: (alien unsignedLongAt: 1) == long.
+ self assert: (alien unsignedByteAt: 1) == 1.
+ self assert: (alien unsignedByteAt: 3) == 1.
+ self assert: alien asUnsignedLong = long!
+
+testUnsignedLongIndexOutOfRange
+
+ self should: [alien unsignedLongAt: 0] raise: Error.
+ self should: [alien unsignedLongAt: self dataSize - 2] raise: Error.
+ self should: [alien unsignedLongAt: 0 put: 1] raise: Error.
+ self should: [alien unsignedLongAt: self dataSize - 2 put: 1] raise:
Error!
+
+testUnsignedShortAccess
+
+ 1 to: 4 do: [:index|
+ alien unsignedByteAt: index put: index].
+ self assert: (alien unsignedShortAt: 1) == (2 * 256 + 1).
+ self assert: (alien unsignedShortAt: 2 put: 65535) == 65535.
+ self assert: (alien unsignedByteAt: 2) == 255.
+ self assert: (alien unsignedByteAt: 3) == 255.
+ self assert: alien asUnsignedShort == (255 * 256 + 1)!
+
+testUnsignedShortIndexOutOfRange
+
+ self should: [self unsignedShortAt: 0 put: 1] raise: Error.
+ self should: [self unsignedShortAt: self dataSize put: 1] raise: Error.
+ self should: [self unsignedShortAt: 0] raise: Error.
+ self should: [self unsignedShortAt: self dataSize] raise: Error! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienTrueTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,18 @@
+Delta define: #AlienTrueTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #AlienTrueTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienTrueTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #AlienTrueTest)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienTrueTest) methodsFor: 'testing' !
+
+
+testAsAlien
+
+ self assert: true asAlien == 1! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/AlienWeakTable.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,67 @@
+Delta define: #AlienWeakTable as: (
+(Class subclassOf: 'Object' instanceVariables: 'accessProtect <Semaphore>
+firstUnusedIndex <Integer>
+lastUsedIndex <Integer>
+weakArray <WeakArray>
+strongArray <Array>
+owner <Object>')) !
+
+(Delta mirrorFor: #AlienWeakTable) revision: '$Revision:$'!
+
+(Delta mirrorFor: #AlienWeakTable) group: 'Aliens'!
+
+(Delta mirrorFor: #AlienWeakTable)
+comment:
+''!
+
+! (Delta mirrorFor: #AlienWeakTable) classSide methodsFor: 'instance
creation' !
+
+
+newForOwner: owner
+ ^self new initializeWithOwner: owner! !
+
+! (Delta mirrorFor: #AlienWeakTable) methodsFor: 'adding' !
+
+
+add: anObject finalizing: postMortemFinalizationTag
+ "Register a new object in the table, with the associated tag.
+ The object is held onto weakly, the tag--strongly. The tag
+ will be passed to the owner as the argument of #finalize:
+ some time after the object is garbage collected."
+
+ | size start delta |
+ accessProtect critical:
+ [size := strongArray size.
+ start := firstUnusedIndex].
+ start to: size do:
+ [:i|
+ (strongArray at: i) == nil ifTrue:
+ [accessProtect critical:
+ [weakArray at: i put: anObject.
+ strongArray at: i put: postMortemFinalizationTag.
+ firstUnusedIndex := i + 1.
+ i > lastUsedIndex ifTrue: [lastUsedIndex := i]].
+ ^anObject]].
+ delta := size min: 4096.
+ accessProtect critical:
+ [(weakArray := weakArray copyGrownBy: delta)
+ at: size + 1 put: anObject.
+ (strongArray := strongArray copyGrownBy: delta)
+ at: size put: postMortemFinalizationTag.
+ firstUnusedIndex := size + 1.
+ lastUsedIndex := size].
+ ^anObject! !
+
+! (Delta mirrorFor: #AlienWeakTable) methodsFor: 'initialization' !
+
+
+initializeWithOwner: anOwner
+
+ accessProtect := Semaphore forMutualExclusion.
+ firstUnusedIndex := 1.
+ lastUsedIndex := 0.
+ weakArray := WeakArray new: 1024.
+ strongArray := Array new: 1024.
+ owner := anOwner.
+ ! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/Aliens test.gr Sun Sep 13 14:52:44
2009
@@ -0,0 +1,16 @@
+$Revision:$!
+Delta fileIn: 'AlienClassTest.dlt' !
+Delta fileIn: 'AlienFalseTest.dlt' !
+Delta fileIn: 'AlienFunctionTest.dlt' !
+Delta fileIn: 'AlienLibraryTest.dlt' !
+Delta fileIn: 'AlienStringTest.dlt' !
+Delta fileIn: 'AlienTest.dlt' !
+Delta fileIn: 'AlienTrueTest.dlt' !
+Delta fileIn: 'CallbackTest.dlt' !
+Delta fileIn: 'DirectAlienTest.dlt' !
+Delta fileIn: 'FFICallbackReturnValueTest.dlt' !
+Delta fileIn: 'IndirectAlienTest.dlt' !
+Delta fileIn: 'PointerAlienTest.dlt' !
+Delta fileIn: 'TestAlien.dlt' !
+Delta fileIn: 'TestInvokeArgs.dlt' !
+Delta fileIn: 'UndefinedObjectTest.dlt' !
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/Aliens tests.gr Sun Sep 13
14:52:44 2009
@@ -0,0 +1,2 @@
+$Revision:$!
+Delta fileIn: 'AlienTest.dlt' !
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/Aliens.gr Sun Sep 13 14:52:44 2009
@@ -0,0 +1,6 @@
+$Revision:$!
+Delta fileIn: 'Alien.dlt' !
+Delta fileIn: 'AlienWeakTable.dlt' !
+Delta fileIn: 'Callback.dlt' !
+Delta fileIn: 'FFICallbackReturnValue.dlt' !
+Delta fileIn: 'NotFoundError.dlt' !
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/CallbackTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,96 @@
+Delta define: #CallbackTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: 'callback
+stack
+wasCalled')) !
+
+(Delta mirrorFor: #CallbackTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #CallbackTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #CallbackTest)
+comment:
+''!
+
+! (Delta mirrorFor: #CallbackTest) methodsFor: 'fixture' !
+
+
+setUp
+
+ wasCalled := false.
+ (stack := ExternalProxy new)
+ malloc: 4.
+!
+
+tearDown
+
+ (callback isNil or: [callback isNull])
+ ifFalse: [callback free]! !
+
+! (Delta mirrorFor: #CallbackTest) methodsFor: 'testing' !
+
+
+invokeCCallbackWithNLR
+
+ callback := Callback
+ block: [:args :result| ^#nlr]
+ argsClass: TestInvokeArgs.
+ CCallBack invoke: callback
+ !
+
+invokeStdcallCallbackWithNLR
+
+ callback := Callback
+ block: [:args :result| ^#nlr]
+ stdcallArgsClass: TestInvokeArgs.
+ APICallBack invoke: callback
+ !
+
+testBlockArgsClass
+
+ callback := Callback
+ block: [:args :result|
+ wasCalled := true.
+ self assert: args address == stack asInteger.
+ result returnInteger: -3]
+ argsClass: TestAlien.
+ stack smallIntegerAt: 1 put: 1.
+ self assert: (callback evaluate: stack) == -3.
+ self assert: (CallBackArray at: callback index) == callback.
+ self assert: callback thunk address = callback asInteger!
+
+testInvokeCCallback
+
+ callback := Callback
+ block: [:args :result|
+ wasCalled := true.
+ self assert: args first == 10.
+ self assert: args second == 5.
+ result returnInteger: args first + args second]
+ argsClass: TestInvokeArgs.
+ self assert: (CCallBack invoke: callback) == 15.
+ self assert: wasCalled
+ !
+
+testInvokeCCallbackWithNLR
+
+ self assert: #nlr == self invokeCCallbackWithNLR
+ !
+
+testInvokeStdcallCallback
+
+ callback := Callback
+ block: [:args :result|
+ wasCalled := true.
+ self assert: args first == 10.
+ self assert: args second == 5.
+ result returnInteger: args first + args second]
+ stdcallArgsClass: TestInvokeArgs.
+ self assert: (APICallBack invoke: callback) == 15.
+ self assert: wasCalled
+ !
+
+testInvokeStdcallCallbackWithNLR
+
+ self assert: #nlr == self invokeStdcallCallbackWithNLR
+ ! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/CharacterTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,19 @@
+Delta define: #CharacterTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #CharacterTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #CharacterTest) group: 'Unclassified'!
+
+(Delta mirrorFor: #CharacterTest)
+comment:
+''!
+
+! (Delta mirrorFor: #CharacterTest) methodsFor: 'testing' !
+
+
+testIsCharacter
+
+ self assert: $A isCharacter.
+ self deny: 1 isCharacter! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/DeltaTuple.dlt Sun Sep 13 14:52:44
2009
@@ -0,0 +1,26 @@
+Delta define: #DeltaTuple as: (
+(Class subclassOf: 'DeltaArray' instanceVariables: '')) !
+
+(Delta mirrorFor: #DeltaTuple) revision: '$Revision:$'!
+
+(Delta mirrorFor: #DeltaTuple) group: 'ast'!
+
+(Delta mirrorFor: #DeltaTuple)
+comment:
+''!
+
+! (Delta mirrorFor: #DeltaTuple) methodsFor: 'a new category' !
+
+
+apply: aTool <DeltaTool > ^ <Self>
+ aTool tupleNode: self!
+
+elements ^ <OrderedCollection[ASTNode]>
+ ^self value!
+
+isArrayNode
+ ^ false!
+
+isTupleNode
+ ^ true! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/DictionaryTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,25 @@
+Delta define: #DictionaryTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #DictionaryTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #DictionaryTest) group: 'Unclassified'!
+
+(Delta mirrorFor: #DictionaryTest)
+comment:
+''!
+
+! (Delta mirrorFor: #DictionaryTest) methodsFor: 'testing' !
+
+
+testAtIfAbsentPut
+
+ |dict|
+ dict := Dictionary new.
+ self assert: (dict at: 'a' ifAbsent: []) isNil.
+ self assert: (dict at: 'a'
+ ifAbsentPut: ['b']) = 'b'.
+ self assert: (dict at: 'a'
+ ifAbsentPut: ['c']) = 'b'
+ ! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/DirectAlienTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,25 @@
+Delta define: #DirectAlienTest as: (
+(Class subclassOf: 'AlienTest' instanceVariables: '')) !
+
+(Delta mirrorFor: #DirectAlienTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #DirectAlienTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #DirectAlienTest)
+comment:
+''!
+
+! (Delta mirrorFor: #DirectAlienTest) methodsFor: 'fixture' !
+
+
+setUp
+
+ alien := Alien new: self dataSize! !
+
+! (Delta mirrorFor: #DirectAlienTest) methodsFor: 'testing' !
+
+
+testPointer
+
+ self should: [alien pointer] raise: Error! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/FFICallbackReturnValue.dlt Sun Sep
13 14:52:44 2009
@@ -0,0 +1,57 @@
+Delta define: #FFICallbackReturnValue as: (
+(Class subclassOf: 'Alien' instanceVariables: '')) !
+
+(Delta mirrorFor: #FFICallbackReturnValue) revision: '$Revision:$'!
+
+(Delta mirrorFor: #FFICallbackReturnValue) group: 'Aliens'!
+
+(Delta mirrorFor: #FFICallbackReturnValue)
+comment:
+''!
+
+! (Delta mirrorFor: #FFICallbackReturnValue) classSide
methodsFor: 'instance creation' !
+
+
+dataSize
+
+ ^16! !
+
+! (Delta mirrorFor: #FFICallbackReturnValue) methodsFor: 'accessing' !
+
+
+returnDouble: value <Integer>
+
+ self type: 1.
+ self doubleAt: self dataOffset put: value!
+
+returnInteger: value <Integer>
+
+ self type: 0.
+ self signedLongAt: self dataOffset put: value!
+
+type: type <Integer>
+
+ self unsignedByteAt: self typeOffset put: type! !
+
+! (Delta mirrorFor: #FFICallbackReturnValue)
methodsFor: 'restricted-accessing' !
+
+
+dataOffset
+
+ ^9!
+
+type
+
+ ^self unsignedByteAt: self typeOffset!
+
+typeOffset
+
+ ^1!
+
+value
+
+ self type == 0
+ ifTrue: [^self signedLongAt: self dataOffset].
+ self type == 1
+ ifTrue: [^self doubleAt: self dataOffset] ! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/FFICallbackReturnValueTest.dlt Sun
Sep 13 14:52:44 2009
@@ -0,0 +1,28 @@
+Delta define: #FFICallbackReturnValueTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #FFICallbackReturnValueTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #FFICallbackReturnValueTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #FFICallbackReturnValueTest)
+comment:
+''!
+
+! (Delta mirrorFor: #FFICallbackReturnValueTest) methodsFor: 'testing' !
+
+
+testValueShouldReturnFloatWhenFloat
+
+ |alien value|
+ alien := FFICallbackReturnValue new.
+ alien returnDouble: 1.0.
+ self assert: 1.0 = alien value!
+
+testValueShouldReturnIntegerWhenInteger
+
+ |alien|
+ alien := FFICallbackReturnValue new.
+ alien returnInteger: 1.
+ self assert: 1 == alien value! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/IndirectAlienTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,92 @@
+Delta define: #IndirectAlienTest as: (
+(Class subclassOf: 'AlienTest' instanceVariables: '')) !
+
+(Delta mirrorFor: #IndirectAlienTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #IndirectAlienTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #IndirectAlienTest)
+comment:
+''!
+
+! (Delta mirrorFor: #IndirectAlienTest) methodsFor: 'fixture' !
+
+
+setUp
+
+ alien := Alien newC: self dataSize!
+
+tearDown
+
+ [alien free]
+ on: Error
+ do: [:ignore|]! !
+
+! (Delta mirrorFor: #IndirectAlienTest) methodsFor: 'testing' !
+
+
+testAutoFreeAfter
+
+ |wasCalled toFree|
+ Alien autoFreeAfter: [:autoFree|
+ wasCalled := true.
+ autoFree value: alien.
+ self deny: alien address == 0.
+ autoFree value: (toFree := Alien newC:4).
+ self deny: alien address == 0].
+ self assert: alien address == 0.
+ self assert: alien address == 0.
+ self assert: wasCalled!
+
+testFreeAfter
+
+ |arg|
+ self deny: alien address == 0.
+ alien freeAfter: [:buf| arg := buf].
+ self assert: alien == arg.
+ self assert: alien address == 0!
+
+testPointer
+
+ |pointer|
+ pointer := alien pointer.
+ self assert: pointer address == alien address.
+ self assert: pointer size == 0!
+
+testStrcpy
+
+ |contents|
+ contents := #'12345678'.
+ alien replaceFrom: 1 to: 8 with: (contents collect: [:c| c asciiValue])
startingAt: 1.
+ self assert: (contents asString = alien strcpy).
+
+ alien unsignedByteAt: 5 put: 0.
+ self assert: (contents asString copyFrom: 1 to: 4) = alien strcpy!
+
+testStrcpyFrom
+
+ |contents shortContents actual|
+ contents := '12345678'.
+ shortContents := contents asString copyFrom: 5 to: 8.
+ alien replaceFrom: 1 to: 8 with: (contents collect: [:c| c asciiValue])
startingAt: 1.
+ actual := alien strcpyFrom: 5.
+ self assert: shortContents asString = actual
+ description: 'Expected :''',shortContents, ''', but was: ''',actual,''''!
+
+testStrlen
+
+ |contents|
+ contents := #'12345678'.
+ alien replaceFrom: 1 to: 8 with: (contents collect: [:c| c asciiValue])
startingAt: 1.
+ self assert: alien strlen = 8!
+
+testStrlenThroughPointerAt
+
+ |contents|
+ contents := '1234567'.
+ alien replaceFrom: 1 to: 7 with: contents startingAt: 1.
+ alien unsignedByteAt: 8 put: 0.
+ (Alien newC: 4) freeAfter: [:pointer|
+ pointer unsignedLongAt: 1 put: alien address.
+ self assert: (pointer strlenThroughPointerAt: 1) == 7]! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/LargeIntegerTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,18 @@
+Delta define: #LargeIntegerTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #LargeIntegerTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #LargeIntegerTest) group: 'Unclassified'!
+
+(Delta mirrorFor: #LargeIntegerTest)
+comment:
+''!
+
+! (Delta mirrorFor: #LargeIntegerTest) methodsFor: 'testing' !
+
+
+testUnderflow
+
+ self deny: SmallInteger maxVal + 1 * 8 + 1 negated = -1! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/NotFoundError.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,11 @@
+Delta define: #NotFoundError as: (
+(Class subclassOf: 'Error' instanceVariables: '')) !
+
+(Delta mirrorFor: #NotFoundError) revision: '$Revision:$'!
+
+(Delta mirrorFor: #NotFoundError) group: 'Aliens'!
+
+(Delta mirrorFor: #NotFoundError)
+comment:
+''!
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/PointerAlienTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,108 @@
+Delta define: #PointerAlienTest as: (
+(Class subclassOf: 'AlienTest' instanceVariables: '')) !
+
+(Delta mirrorFor: #PointerAlienTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #PointerAlienTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #PointerAlienTest)
+comment:
+''!
+
+! (Delta mirrorFor: #PointerAlienTest) methodsFor: 'fixture' !
+
+
+setUp
+
+ alien := Alien forPointer: (Alien Ccalloc: self dataSize)!
+
+tearDown
+
+ [alien free]
+ on: Error
+ do: [:ignore|]! !
+
+! (Delta mirrorFor: #PointerAlienTest) methodsFor: 'testing' !
+
+
+testDataSize
+
+ self assert: alien dataSize == 0!
+
+testDoubleIndexOutOfRange
+
+ self should: [alien doubleAt: 0 put: 1.0] raise: Error.
+ self should: [alien doubleAt: 0] raise: Error!
+
+testFloatIndexOutOfRange
+
+ self should: [alien doubleAt: 0 put: 1.0] raise: Error.
+ self should: [alien doubleAt: 0] raise: Error!
+
+testFreeingTwiceShouldFail
+
+ alien free.
+ self should: [alien free] raise: Error!
+
+testIsPointer
+
+ self assert: alien isPointer!
+
+testPointer
+
+ self should: [alien pointer] raise: Error!
+
+testSignedByteIndexOutOfRange
+
+ self should: [alien signedByteAt: 0] raise: Error.
+ self should: [alien signedByteAt: 0 put: 1] raise: Error!
+
+testSignedLongIndexOutOfRange
+
+ self should: [alien signedLongAt: 0] raise: Error.
+ self should: [alien signedLongAt: 0 put: 1] raise: Error!
+
+testSignedShortIndexOutOfRange
+
+ self should: [alien signedShortAt: 0 put: 1] raise: Error.
+ self should: [alien signedShortAt: 0] raise: Error!
+
+testStrcpy
+
+ |contents actual expected|
+ contents := #'12345678'.
+ alien replaceFrom: 1 to: 7 with: (contents collect: [:c| c asciiValue])
startingAt: 1.
+ alien unsignedByteAt: 8 put: 0.
+
+ actual := alien strcpy.
+ expected := contents asString copyFrom: 1 to: 7.
+ self assert: expected = actual
+ description: 'Expected: ''',expected,''', but was: ''',actual,''''!
+
+testStrcpyFrom
+
+ |contents actual expected|
+ contents := #'12345678'.
+ alien replaceFrom: 1 to: 7 with: (contents collect: [:c| c asciiValue])
startingAt: 1.
+ alien unsignedByteAt: 8 put: 0.
+
+ actual := alien strcpyFrom: 3.
+ expected := contents asString copyFrom: 3 to: 7.
+ self assert: expected = actual
+ description: 'Expected: ''',expected,''', but was: ''',actual,''''!
+
+testUnsignedByteIndexOutOfRange
+
+ self should: [alien unsignedByteAt: 0] raise: Error.
+ self should: [alien unsignedByteAt: 0 put: 1] raise: Error!
+
+testUnsignedLongIndexOutOfRange
+
+ self should: [alien unsignedLongAt: 0] raise: Error.
+ self should: [alien unsignedLongAt: 0 put: 1] raise: Error!
+
+testUnsignedShortIndexOutOfRange
+
+ self should: [alien unsignedShortAt: 0 put: 1] raise: Error.
+ self should: [alien unsignedShortAt: 0] raise: Error! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/StringTest.dlt Sun Sep 13 14:52:44
2009
@@ -0,0 +1,34 @@
+Delta define: #StringTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #StringTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #StringTest) group: 'Unclassified'!
+
+(Delta mirrorFor: #StringTest)
+comment:
+''!
+
+! (Delta mirrorFor: #StringTest) methodsFor: 'testing' !
+
+
+testEndsWith
+
+ | source |
+ source := 'Elvis' asString.
+ self assert: (source endsWith: 'vis').
+ self assert: ('Elvis' endsWith: 'vis').
+ self deny: (source endsWith: 'El').
+ self deny: (source endsWith: 'the').!
+
+testIndexOfSubCollectionStartingAtIfAbsent
+
+ | source |
+ source := 'Elvis' asString.
+ self assert: (source indexOfSubCollection: 'vis'
+ startingAt: 1
+ ifAbsent: [self fail]) = 3.
+ self assert: (source indexOfSubCollection: 'lv'
+ startingAt: 1
+ ifAbsent: [self fail]) = 2.! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/TestAlien.dlt Sun Sep 13 14:52:44
2009
@@ -0,0 +1,18 @@
+Delta define: #TestAlien as: (
+(Class subclassOf: 'Alien' instanceVariables: '')) !
+
+(Delta mirrorFor: #TestAlien) revision: '$Revision:$'!
+
+(Delta mirrorFor: #TestAlien) group: 'Aliens test'!
+
+(Delta mirrorFor: #TestAlien)
+comment:
+''!
+
+! (Delta mirrorFor: #TestAlien) classSide methodsFor: 'instance creation' !
+
+
+dataSize
+
+ ^8! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/TestInvokeArgs.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,29 @@
+Delta define: #TestInvokeArgs as: (
+(Class subclassOf: 'Alien' instanceVariables: '')) !
+
+(Delta mirrorFor: #TestInvokeArgs) revision: '$Revision:$'!
+
+(Delta mirrorFor: #TestInvokeArgs) group: 'Aliens test'!
+
+(Delta mirrorFor: #TestInvokeArgs)
+comment:
+''!
+
+! (Delta mirrorFor: #TestInvokeArgs) classSide methodsFor: 'instance
creation' !
+
+
+dataSize
+
+ ^8! !
+
+! (Delta mirrorFor: #TestInvokeArgs) methodsFor: 'accessing' !
+
+
+first
+
+ ^self signedLongAt: 1!
+
+second
+
+ ^self signedLongAt: 5! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/UndefinedObjectTest.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,18 @@
+Delta define: #UndefinedObjectTest as: (
+(Class subclassOf: 'TestCase' instanceVariables: '')) !
+
+(Delta mirrorFor: #UndefinedObjectTest) revision: '$Revision:$'!
+
+(Delta mirrorFor: #UndefinedObjectTest) group: 'Aliens test'!
+
+(Delta mirrorFor: #UndefinedObjectTest)
+comment:
+''!
+
+! (Delta mirrorFor: #UndefinedObjectTest) methodsFor: 'testing' !
+
+
+testAsAlien
+
+ self assert: nil asAlien == 0! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/StrongtalkSource/UnsafeAlien.dlt Sun Sep 13
14:52:44 2009
@@ -0,0 +1,35 @@
+Delta define: #UnsafeAlien as: (
+(Class subclassOf: 'Object' instanceVariables: 'nonPointerObject
<IndexedByteInstanceVariables>')) !
+
+(Delta mirrorFor: #UnsafeAlien) revision: '$Revision:$'!
+
+(Delta mirrorFor: #UnsafeAlien) group: 'Alien'!
+
+(Delta mirrorFor: #UnsafeAlien)
+comment:
+''!
+
+! (Delta mirrorFor: #UnsafeAlien) classSide methodsFor: 'instance
creation' !
+
+
+forPointerTo: bytes <IndexedByteInstanceVariables> ^ <UnsafeAlien>
+
+ ^self new
+ nonPointerObject: bytes;
+ yourself
+ ! !
+
+! (Delta mirrorFor: #UnsafeAlien) methodsFor: 'accessing' !
+
+
+object
+
+ ^nonPointerObject! !
+
+! (Delta mirrorFor: #UnsafeAlien) methodsFor: 'initialization' !
+
+
+nonPointerObject: bytes <IndexedByteInstanceVariables>
+
+ nonPointerObject := bytes! !
+
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/memory/proxyPrimsTest.cpp Sun Sep 13 14:52:44
2009
@@ -0,0 +1,194 @@
+# include "incls/_precompiled.incl"
+# include "incls/_proxy_prims.cpp.incl"
+#include "test.h"
+#include "handle.hpp"
+#include "testUtils.hpp"
+
+using namespace easyunit;
+
+extern "C" int expansion_count;
+DECLARE(ProxyPrimsTests)
+ proxyOop proxy, subProxy, validProxy;
+ doubleOop doubleValue;
+ smiOop smi0, smi1;
+ int address;
+
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+ }
+END_DECLARE
+
+SETUP(ProxyPrimsTests) {
+ PersistentHandle proxyClass(Universe::find_global("ExternalProxy"));
+ PersistentHandle
proxyHandle(proxyClass.as_klassOop()->klass_part()->allocateObject());
+ PersistentHandle
subProxyHandle(proxyClass.as_klassOop()->klass_part()->allocateObject());
+ PersistentHandle
validProxyHandle(proxyClass.as_klassOop()->klass_part()->allocateObject());
+
+ doubleValue = oopFactory::new_double(1.2345);
+
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ address = 0;
+
+ proxy = proxyOop(proxyHandle.as_oop());
+ subProxy = proxyOop(subProxyHandle.as_oop());
+ validProxy = proxyOop(validProxyHandle.as_oop());
+ validProxy->set_pointer(&address);
+}
+
+TEARDOWN(ProxyPrimsTests){
+}
+
+TESTF(ProxyPrimsTests, smiAtPutShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::smiAtPut(smi1, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, smiAtShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::smiAt(smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, byteAtPutShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::byteAtPut(smi1, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, byteAtShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::byteAt(smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, doubleByteAtPutShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::doubleByteAtPut(smi1, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, doubleByteAtShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::doubleByteAt(smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, subProxyAtShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::subProxyAt(subProxy, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+ ASSERT_TRUE_M(subProxy->is_null(), "subproxy should have null pointer");
+}
+
+TESTF(ProxyPrimsTests, proxyAtShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::proxyAt(subProxy, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+ ASSERT_TRUE_M(subProxy->is_null(), "subproxy should have null pointer");
+}
+
+TESTF(ProxyPrimsTests, proxyAtPutShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::proxyAtPut(subProxy, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+ ASSERT_TRUE_M(subProxy->is_null(), "subproxy should have null pointer");
+}
+
+TESTF(ProxyPrimsTests, proxyAtPutShouldFailWhenValuePointerIsNULL) {
+ int addr;
+ proxy->set_pointer(&addr);
+ addr = 1;
+ oop result = proxyOopPrimitives::proxyAtPut(subProxy, smi0, proxy);
+ ASSERT_EQUALS_M(0, addr, "Should overwrite value");
+}
+
+TESTF(ProxyPrimsTests, singlePrecisionFloatAtShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::singlePrecisionFloatAt(smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests,
singlePrecisionFloatAtPutShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::singlePrecisionFloatAtPut(doubleValue,
smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, doublePrecisionFloatAtShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::doublePrecisionFloatAt(smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests,
doublePrecisionFloatAtPutShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::doublePrecisionFloatAtPut(doubleValue,
smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, callout0ShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::callOut0(subProxy, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, callout1ShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::callOut1(subProxy, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, callout2ShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::callOut2(subProxy, smi0, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, callout3ShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::callOut3(subProxy, smi0, smi0, smi0,
proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, callout4ShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::callOut4(subProxy, smi0, smi0, smi0,
smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, callout5ShouldFailWhenPointerIsNULL) {
+ oop result = proxyOopPrimitives::callOut5(subProxy, smi0, smi0, smi0,
smi0, smi0, proxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::illegal_state());
+}
+
+TESTF(ProxyPrimsTests, callout5ShouldFailWhenReceiverNotProxy) {
+ oop result = proxyOopPrimitives::callOut5(subProxy, smi0, smi0, smi0,
smi0, smi0, smi0);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout4ShouldFailWhenReceiverNotProxy) {
+ oop result = proxyOopPrimitives::callOut4(subProxy, smi0, smi0, smi0,
smi0, smi0);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout3ShouldFailWhenReceiverNotProxy) {
+ oop result = proxyOopPrimitives::callOut3(subProxy, smi0, smi0, smi0,
smi0);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout2ShouldFailWhenReceiverNotProxy) {
+ oop result = proxyOopPrimitives::callOut2(subProxy, smi0, smi0, smi0);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout1ShouldFailWhenReceiverNotProxy) {
+ oop result = proxyOopPrimitives::callOut1(subProxy, smi0, smi0);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout0ShouldFailWhenReceiverNotProxy) {
+ oop result = proxyOopPrimitives::callOut0(subProxy, smi0);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout3ShouldFailWhenResultNotProxy) {
+ oop result = proxyOopPrimitives::callOut3(smi0, smi0, smi0, smi0,
validProxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::fourth_argument_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout4ShouldFailWhenResultNotProxy) {
+ oop result = proxyOopPrimitives::callOut4(smi0, smi0, smi0, smi0, smi0,
validProxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::fifth_argument_has_wrong_type());
+}
+
+TESTF(ProxyPrimsTests, callout5ShouldFailWhenResultNotProxy) {
+ oop result = proxyOopPrimitives::callOut5(smi0, smi0, smi0, smi0, smi0,
smi0, validProxy);
+ checkMarkedSymbol("receiver invalid", result,
vmSymbols::sixth_argument_has_wrong_type());
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout0Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,129 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+#include <time.h>
+
+using namespace easyunit;
+
+
+DECLARE(AlienIntegerCallout0Tests)
+ byteArrayOop fnAlien;
+ byteArrayOop invalidFunctionAlien;
+ byteArrayOop resultAlien, addressAlien, pointerAlien, argumentAlien;
+ smiOop smi0, smi1;
+ char address[8];
+
+ byteArrayOop allocateAlien(int arraySize, int alienSize) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ return alien;
+ }
+ void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+ }
+ void checkIntResult(char* message, int expected, int actual) {
+ char text[200];
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+ }
+ int asInt(bool &ok, oop intOop) {
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+ }
+END_DECLARE
+
+SETUP(AlienIntegerCallout0Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+
+ PersistentHandle ca(allocateAlien(8, 0));
+ PersistentHandle ifa(allocateAlien(8, 0));
+ PersistentHandle ra(allocateAlien(12, 8));
+ PersistentHandle aa(allocateAlien(8, -8));
+ PersistentHandle pa(allocateAlien(8, 0));
+
+ resultAlien = byteArrayOop(ra.as_oop());
+ invalidFunctionAlien = byteArrayOop(ifa.as_oop());
+ byteArrayPrimitives::alienSetAddress(smi0, invalidFunctionAlien);
+
+ fnAlien = byteArrayOop(ca.as_oop());
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)&clock), fnAlien);
+
+ addressAlien = byteArrayOop(aa.as_oop());
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)&address),
addressAlien);
+
+ pointerAlien = byteArrayOop(pa.as_oop());
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)&address),
pointerAlien);
+}
+
+TEARDOWN(AlienIntegerCallout0Tests){
+}
+
+TESTF(AlienIntegerCallout0Tests, alienCallResult0ShouldReturnAlien) {
+ oop result = byteArrayPrimitives::alienCallResult0(resultAlien, fnAlien);
+ ASSERT_TRUE_M(result == fnAlien, "should return receiver");
+}
+
+TESTF(AlienIntegerCallout0Tests,
alienCallResult0ShouldReturnMarkedResultForNonAlien) {
+ oop result = byteArrayPrimitives::alienCallResult0(resultAlien, smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout0Tests,
alienCallResult0ShouldReturnMarkedResultForDirectAlien) {
+ oop result = byteArrayPrimitives::alienCallResult0(resultAlien,
resultAlien);
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout0Tests,
alienCallResult0ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = byteArrayPrimitives::alienCallResult0(resultAlien,
invalidFunctionAlien);
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout0Tests,
alienCallResult0ShouldReturnMarkedResultWhenResultNotAlien) {
+ oop result = byteArrayPrimitives::alienCallResult0(smi0, fnAlien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout0Tests, alienCallResult0ShouldCallClock) {
+ clock_t clockResult = clock();
+ byteArrayPrimitives::alienCallResult0(resultAlien, fnAlien);
+
+ ASSERT_TRUE_M(sizeof(clock_t) == 4, "wrong size");
+ oop alienClockResult = byteArrayPrimitives::alienUnsignedLongAt(smi1,
resultAlien);
+ ASSERT_TRUE_M(clockResult == smiOop(alienClockResult)->value(), "wrong
result");
+}
+
+TESTF(AlienIntegerCallout0Tests,
alienCallResult0ShouldSetResultInPointerAlien) {
+ clock_t clockResult = clock();
+ byteArrayPrimitives::alienCallResult0(pointerAlien, fnAlien);
+
+ oop alienClockResult = byteArrayPrimitives::alienUnsignedLongAt(smi1,
pointerAlien);
+ ASSERT_TRUE_M(clockResult == smiOop(alienClockResult)->value(), "wrong
result");
+}
+
+TESTF(AlienIntegerCallout0Tests,
alienCallResult0ShouldSetResultInAddressAlien) {
+ clock_t clockResult = clock();
+ byteArrayPrimitives::alienCallResult0(addressAlien, fnAlien);
+
+ oop alienClockResult = byteArrayPrimitives::alienUnsignedLongAt(smi1,
addressAlien);
+ ASSERT_TRUE_M(clockResult == smiOop(alienClockResult)->value(), "wrong
result");
+}
+
+TESTF(AlienIntegerCallout0Tests,
alienCallResult0ShouldIgnoreResultWhenResultArgZero) {
+ oop result = byteArrayPrimitives::alienCallResult0(nilObj, fnAlien);
+ ASSERT_TRUE_M(!result->is_mark(), "Should not be marked");
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout1Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,245 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+#include <time.h>
+#include <stdlib.h>
+
+using namespace easyunit;
+
+typedef struct _size5 {
+ int ignore;
+ char byte;
+} size5_t;
+extern "C" int PRIM_API callLabs(int*ptr) {
+ return labs(*ptr);
+}
+
+extern "C" int PRIM_API size5(size5_t arg) {
+ return arg.byte == -1 ? 0 : -1;
+}
+
+extern "C" oop PRIM_API forceScavenge1(int ignore) {
+ Universe::scavenge();
+ return vmSymbols::completed();
+}
+
+extern "C" int PRIM_API argAlignment(int a) {
+ return ((int) &a) & 0xF;
+}
+
+extern "C" char* PRIM_API argUnsafe1(char* a) {
+ return a;
+}
+
+DECLARE(AlienIntegerCallout1Tests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien, *unsafeAlien,
*unsafeContents;
+smiOop smi0, smi1;
+char address[16];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void allocateUnsafe(PersistentHandle* &handle, PersistentHandle*
&contents) {
+ klassOop unsafeKlass = klassOop(Universe::find_global("UnsafeAlien"));
+ unsafeAlien = new PersistentHandle(unsafeKlass->primitive_allocate());
+ int offset =
unsafeKlass->klass_part()->lookup_inst_var(oopFactory::new_symbol("nonPointerObject"));
+
+ contents = new
PersistentHandle(Universe::byteArrayKlassObj()->primitive_allocate_size(12));
+ memOop(unsafeAlien->as_oop())->instVarAtPut(offset, contents->as_oop());
+}
+void setAddress(void* p, PersistentHandle* alien) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)p), alien->as_oop());
+}
+END_DECLARE
+
+SETUP(AlienIntegerCallout1Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ handles = new(true) GrowableArray<PersistentHandle**>(5);
+
+ allocateAlien(functionAlien, 8, 0, &labs);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+ allocateUnsafe(unsafeAlien, unsafeContents);
+
+ memset(address, 0, 8);
+}
+
+TEARDOWN(AlienIntegerCallout1Tests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+
+TESTF(AlienIntegerCallout1Tests, alienCallResult1ShouldCallFunction) {
+ byteArrayPrimitives::alienCallResult1(as_smiOop(-1),
resultAlien->as_oop(), functionAlien->as_oop());
+
+ checkIntResult("wrong result", labs(-1), resultAlien);
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1WithUnsafeAlienShouldCallFunction) {
+ setAddress(&argUnsafe1, functionAlien);
+ byteArrayPrimitives::alienCallResult1(unsafeAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+
+ checkIntResult("wrong result",
(int)byteArrayOop(unsafeContents->as_oop())->bytes(), resultAlien);
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1ShouldCallFunctionAndIgnoreResultWhenResultAlienNil) {
+ oop result = byteArrayPrimitives::alienCallResult1(as_smiOop(-1),
nilObj, functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "shoult not be marked");
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1WithIndirectArgumentShouldCallFunction) {
+ byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(-1), smi1,
addressAlien->as_oop());
+ byteArrayPrimitives::alienCallResult1(addressAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+
+ checkIntResult("wrong result", labs(-1), resultAlien);
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1WithDirectArgumentShouldCallFunction) {
+ byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(-1), smi1,
directAlien->as_oop());
+ byteArrayPrimitives::alienCallResult1(directAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+
+ checkIntResult("wrong result", labs(-1), resultAlien);
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1WithPointerArgumentShouldCallFunction) {
+ oop address = asOop((int)&callLabs);
+ byteArrayPrimitives::alienSetAddress(address, functionAlien->as_oop());
+ byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(-1), smi1,
pointerAlien->as_oop());
+ byteArrayPrimitives::alienCallResult1(pointerAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+
+ checkIntResult("wrong result", labs(-1), resultAlien);
+}
+
+TESTF(AlienIntegerCallout1Tests, alienCallResult1Should16ByteAlignArgs) {
+ oop fnAddress = asOop((int)&argAlignment);
+ byteArrayPrimitives::alienSetAddress(fnAddress, functionAlien->as_oop());
+
+ oop result =
byteArrayPrimitives::alienCallResult1(addressAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "Should not be marked");
+ checkIntResult("wrong result", 0, resultAlien);
+
+ byteArrayPrimitives::alienSetSize(as_smiOop(-8), addressAlien->as_oop());
+ byteArrayPrimitives::alienCallResult1(addressAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+ checkIntResult("wrong result", 0, resultAlien);
+
+ byteArrayPrimitives::alienSetSize(as_smiOop(-12),
addressAlien->as_oop());
+ byteArrayPrimitives::alienCallResult1(addressAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+ checkIntResult("wrong result", 0, resultAlien);
+
+ byteArrayPrimitives::alienSetSize(as_smiOop(-16),
addressAlien->as_oop());
+ byteArrayPrimitives::alienCallResult1(addressAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+ checkIntResult("wrong result", 0, resultAlien);
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1WithOddSizedArgumentShouldCallFunction) {
+ oop address = asOop((int)&size5);
+ byteArrayPrimitives::alienSetAddress(address, functionAlien->as_oop());
+ byteArrayPrimitives::alienSetSize(as_smiOop(5), directAlien->as_oop());
+ byteArrayPrimitives::alienUnsignedLongAtPut(smi0, smi1,
directAlien->as_oop());
+ byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-1), as_smiOop(5),
directAlien->as_oop());
+
+ byteArrayPrimitives::alienCallResult1(directAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+
+ checkIntResult("wrong result", 0, resultAlien);
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1WithScavengeShouldReturnCorrectResult) {
+ oop address = asOop((int)&forceScavenge1);
+ byteArrayPrimitives::alienSetAddress(address, functionAlien->as_oop());
+ byteArrayPrimitives::alienCallResult1(directAlien->as_oop(),
resultAlien->as_oop(), functionAlien->as_oop());
+
+ bool ok;
+ oop result = (oop) asInt(ok,
byteArrayPrimitives::alienUnsignedLongAt(smi1,
+
resultAlien->as_oop()));
+
+ ASSERT_TRUE_M(ok, "unsigned long at failed");
+ ASSERT_TRUE_M(vmSymbols::completed() == result, "wrong result");
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1ShouldReturnMarkedResultForNonAlien) {
+ oop result = byteArrayPrimitives::alienCallResult1(resultAlien->as_oop(),
+ smi0,
+ smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1ShouldReturnMarkedResultForDirectAlien) {
+ oop result =
byteArrayPrimitives::alienCallResult1(resultAlien->as_oop(), smi0,
+ resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = byteArrayPrimitives::alienCallResult1(resultAlien->as_oop(),
+ smi0,
+
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1ShouldReturnMarkedResultWhenResultNotAlien) {
+ oop result = byteArrayPrimitives::alienCallResult1(smi0, smi0,
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout1Tests,
alienCallResult1ShouldReturnMarkedResultWhenFunctionParameterNotAlienOrSMI)
{
+ oop result =
byteArrayPrimitives::alienCallResult1(Universe::byteArrayKlassObj(),
+ resultAlien->as_oop(),
+
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout2Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,217 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+#include <time.h>
+#include <stdlib.h>
+
+using namespace easyunit;
+
+extern "C" int PRIM_API returnFirst(int a, int b) {
+ return a;
+}
+
+extern "C" int PRIM_API returnFirstPointer(int *a, int b) {
+ return *a;
+}
+
+extern "C" int PRIM_API returnSecond(int a, int b) {
+ return b;
+}
+
+extern "C" int PRIM_API returnSecondPointer(int a, int *b) {
+ return *b;
+}
+
+extern "C" int PRIM_API forceScavenge2(int ignore1, int ignore2) {
+ Universe::scavenge();
+ return -1;
+}
+
+//extern "C" int PRIM_API size5(int ignore, char byte) {
+// return byte == -1 ? 0 : -1;
+//}
+//
+//extern "C" oop PRIM_API forceScavenge(int ignore) {
+// Universe::scavenge();
+// return vmSymbols::completed();
+//}
+
+DECLARE(AlienIntegerCallout2Tests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien;
+smiOop smi0, smi1, smim1;
+static const int argCount = 2;
+void* intCalloutFunctions[argCount];
+void* intPointerCalloutFunctions[argCount];
+char address[8];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void setAddress(PersistentHandle* handle, void* argument) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)argument),
handle->as_oop());
+}
+void checkArgnPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg0 = argIndex == 0 ? asOop(argValue) : smi0;
+ oop arg1 = argIndex == 1 ? asOop(argValue) : smi0;
+ oop result = byteArrayPrimitives::alienCallResult2(arg1, arg0,
resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+void checkArgnPtrPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(argValue), smi1,
pointerAlien->as_oop());
+ oop arg0 = argIndex == 0 ? pointerAlien->as_oop() : smi0;
+ oop arg1 = argIndex == 1 ? pointerAlien->as_oop() : smi0;
+ oop result = byteArrayPrimitives::alienCallResult2(arg1, arg0,
resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+END_DECLARE
+
+SETUP(AlienIntegerCallout2Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ smim1 = as_smiOop(-1);
+ handles = new(true) GrowableArray<PersistentHandle**>(5);
+
+ allocateAlien(functionAlien, 8, 0, &returnFirst);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+
+ memset(address, 0, 8);
+
+ intCalloutFunctions[0] = returnFirst;
+ intCalloutFunctions[1] = returnSecond;
+ intPointerCalloutFunctions[0] = returnFirstPointer;
+ intPointerCalloutFunctions[1] = returnSecondPointer;
+}
+
+TEARDOWN(AlienIntegerCallout2Tests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+TESTF(AlienIntegerCallout2Tests, alienCallResult2ShouldCallIntArgFunction)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPassed(arg, -1, intCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldCallIntPointerArgFunctionWithArg2) {
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPtrPassed(arg, -1, intPointerCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldCallFunctionAndIgnoreResultWhenResultAlienNil) {
+ oop result = byteArrayPrimitives::alienCallResult2(smi0, smim1, nilObj,
functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "should not be marked");
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2WithScavengeShouldReturnCorrectResult) {
+ setAddress(functionAlien, &forceScavenge2);
+ checkIntResult("incorrect initialization", 0, resultAlien);
+ byteArrayPrimitives::alienCallResult2(smi0, smi0, resultAlien->as_oop(),
functionAlien->as_oop());
+ checkIntResult("result alien not updated", -1, resultAlien);
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldReturnMarkedResultForNonAlien) {
+ oop result = byteArrayPrimitives::alienCallResult2(smi0,
+ smi0,
+ resultAlien->as_oop(),
+ smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldReturnMarkedResultForDirectAlien) {
+ oop result = byteArrayPrimitives::alienCallResult2(smi0,
+ smi0,
+ resultAlien->as_oop(),
+
resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = byteArrayPrimitives::alienCallResult2(smi0,
+ smi0,
+ resultAlien->as_oop(),
+
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldReturnMarkedResultWhenResultNotAlienOrNil) {
+ oop result = byteArrayPrimitives::alienCallResult2(smi0, smi0, trueObj,
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldReturnMarkedResultWhenFunctionParameter1NotAlienOrSMI)
{
+ oop result = byteArrayPrimitives::alienCallResult2(smi0,
+ trueObj,
+ resultAlien->as_oop(),
+
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout2Tests,
alienCallResult2ShouldReturnMarkedResultWhenFunctionParameter2NotAlienOrSMI)
{
+ oop result = byteArrayPrimitives::alienCallResult2(trueObj,
+ smi0,
+ resultAlien->as_oop(),
+
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::third_argument_has_wrong_type());
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout3Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,235 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+#include <time.h>
+#include <stdlib.h>
+
+using namespace easyunit;
+
+extern "C" int PRIM_API returnFirst3(int a, int b, int c) {
+ return a;
+}
+
+extern "C" int PRIM_API returnFirstPointer3(int *a, int b, int c) {
+ return *a;
+}
+
+extern "C" int PRIM_API returnSecond3(int a, int b, int c) {
+ return b;
+}
+
+extern "C" int PRIM_API returnSecondPointer3(int a, int *b, int c) {
+ return *b;
+}
+
+extern "C" int PRIM_API returnThird3(int a, int b, int c) {
+ return c;
+}
+
+extern "C" int PRIM_API returnThirdPointer3(int a, int b, int *c) {
+ return *c;
+}
+
+extern "C" int PRIM_API forceScavenge3(int ignore1, int ignore2, int
ignore3) {
+ Universe::scavenge();
+ return -1;
+}
+
+DECLARE(AlienIntegerCallout3Tests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien;
+smiOop smi0, smi1, smim1;
+static const int argCount = 3;
+void* intCalloutFunctions[argCount];
+void* intPointerCalloutFunctions[argCount];
+char address[8];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void setAddress(PersistentHandle* handle, void* argument) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)argument),
handle->as_oop());
+}
+void checkArgnPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg0 = argIndex == 0 ? asOop(argValue) : smi0;
+ oop arg1 = argIndex == 1 ? asOop(argValue) : smi0;
+ oop arg2 = argIndex == 2 ? asOop(argValue) : smi0;
+ oop result = byteArrayPrimitives::alienCallResult3(arg2, arg1, arg0,
resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+void checkArgnPtrPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(argValue), smi1,
pointerAlien->as_oop());
+ oop arg0 = argIndex == 0 ? pointerAlien->as_oop() : smi0;
+ oop arg1 = argIndex == 1 ? pointerAlien->as_oop() : smi0;
+ oop arg2 = argIndex == 2 ? pointerAlien->as_oop() : smi0;
+ oop result = byteArrayPrimitives::alienCallResult3(arg2, arg1, arg0,
resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+END_DECLARE
+
+SETUP(AlienIntegerCallout3Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ smim1 = as_smiOop(-1);
+ handles = new(true) GrowableArray<PersistentHandle**>(5);
+
+ allocateAlien(functionAlien, 8, 0, &returnFirst3);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+
+ memset(address, 0, 8);
+
+ intCalloutFunctions[0] = returnFirst3;
+ intCalloutFunctions[1] = returnSecond3;
+ intCalloutFunctions[2] = returnThird3;
+ intPointerCalloutFunctions[0] = returnFirstPointer3;
+ intPointerCalloutFunctions[1] = returnSecondPointer3;
+ intPointerCalloutFunctions[2] = returnThirdPointer3;
+}
+
+TEARDOWN(AlienIntegerCallout3Tests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+TESTF(AlienIntegerCallout3Tests, alienCallResult3ShouldCallIntArgFunction)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPassed(arg, -1, intCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldCallIntPointerArgFunction) {
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPtrPassed(arg, -1, intPointerCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldCallFunctionAndIgnoreResultWhenResultAlienNil) {
+ oop result = byteArrayPrimitives::alienCallResult3(smi0, smi0, smim1,
nilObj, functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "should not be marked");
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3WithScavengeShouldReturnCorrectResult) {
+ setAddress(functionAlien, &forceScavenge3);
+ checkIntResult("incorrect initialization", 0, resultAlien);
+ byteArrayPrimitives::alienCallResult3(smi0, smi0, smi0,
resultAlien->as_oop(), functionAlien->as_oop());
+ checkIntResult("result alien not updated", -1, resultAlien);
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldReturnMarkedResultForNonAlien) {
+ oop result = byteArrayPrimitives::alienCallResult3(smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+ smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldReturnMarkedResultForDirectAlien) {
+ oop result = byteArrayPrimitives::alienCallResult3(smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = byteArrayPrimitives::alienCallResult3(smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldReturnMarkedResultWhenResultNotAlienOrNil) {
+ oop result = byteArrayPrimitives::alienCallResult3(smi0, smi0, smi0,
trueObj, functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldReturnMarkedResultWhenFunctionParameter1NotAlienOrSMI)
{
+ oop result = byteArrayPrimitives::alienCallResult3(smi0,
+ smi0,
+ trueObj,
+ resultAlien->as_oop(),
+
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldReturnMarkedResultWhenFunctionParameter2NotAlienOrSMI)
{
+ oop result = byteArrayPrimitives::alienCallResult3(smi0,
+ trueObj,
+ smi0,
+ resultAlien->as_oop(),
+
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::third_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout3Tests,
alienCallResult3ShouldReturnMarkedResultWhenFunctionParameter3NotAlienOrSMI)
{
+ oop result = byteArrayPrimitives::alienCallResult3(trueObj,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::fourth_argument_has_wrong_type());
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout4Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,251 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+#include <time.h>
+#include <stdlib.h>
+
+using namespace easyunit;
+
+extern "C" int PRIM_API returnFirst4(int a, int b, int c, int d) {
+ return a;
+}
+
+extern "C" int PRIM_API returnFirstPointer4(int *a, int b, int c, int d) {
+ return *a;
+}
+
+extern "C" int PRIM_API returnSecond4(int a, int b, int c, int d) {
+ return b;
+}
+
+extern "C" int PRIM_API returnSecondPointer4(int a, int *b, int c, int d) {
+ return *b;
+}
+
+extern "C" int PRIM_API returnThird4(int a, int b, int c, int d) {
+ return c;
+}
+
+extern "C" int PRIM_API returnThirdPointer4(int a, int b, int *c, int d) {
+ return *c;
+}
+
+extern "C" int PRIM_API returnFourth4(int a, int b, int c, int d) {
+ return d;
+}
+
+extern "C" int PRIM_API returnFourthPointer4(int a, int b, int c, int *d) {
+ return *d;
+}
+
+extern "C" int PRIM_API forceScavenge4(int ignore1, int ignore2, int
ignore3, int d) {
+ Universe::scavenge();
+ return -1;
+}
+
+DECLARE(AlienIntegerCallout4Tests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien;
+smiOop smi0, smi1, smim1;
+static const int argCount = 4;
+void* intCalloutFunctions[argCount];
+void* intPointerCalloutFunctions[argCount];
+char address[8];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"%s. Should be: %s, was: %s", message,
expected->as_string(), unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void setAddress(PersistentHandle* handle, void* argument) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)argument),
handle->as_oop());
+}
+void checkArgnPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg0 = argIndex == 0 ? asOop(argValue) : smi0;
+ oop arg1 = argIndex == 1 ? asOop(argValue) : smi0;
+ oop arg2 = argIndex == 2 ? asOop(argValue) : smi0;
+ oop arg3 = argIndex == 3 ? asOop(argValue) : smi0;
+ oop result = byteArrayPrimitives::alienCallResult4(arg3, arg2, arg1,
arg0, resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+void checkArgnPtrPassed(int argIndex, oop pointer, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg0 = argIndex == 0 ? pointer : smi0;
+ oop arg1 = argIndex == 1 ? pointer : smi0;
+ oop arg2 = argIndex == 2 ? pointer : smi0;
+ oop arg3 = argIndex == 3 ? pointer : smi0;
+ oop result = byteArrayPrimitives::alienCallResult4(arg3, arg2, arg1,
arg0, resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", -1, resultAlien);
+}
+void checkIllegalArgnPassed(int argIndex, oop pointer) {
+ oop arg0 = argIndex == 0 ? pointer : smi0;
+ oop arg1 = argIndex == 1 ? pointer : smi0;
+ oop arg2 = argIndex == 2 ? pointer : smi0;
+ oop arg3 = argIndex == 3 ? pointer : smi0;
+ oop result = byteArrayPrimitives::alienCallResult4(arg3, arg2, arg1,
arg0, resultAlien->as_oop(), functionAlien->as_oop());
+
+ symbolOop symbol;
+ switch (argIndex) {
+ case 0:
+ symbol = vmSymbols::second_argument_has_wrong_type();
+ break;
+ case 1:
+ symbol = vmSymbols::third_argument_has_wrong_type();
+ break;
+ case 2:
+ symbol = vmSymbols::fourth_argument_has_wrong_type();
+ break;
+ case 3:
+ symbol = vmSymbols::fifth_argument_has_wrong_type();
+ break;
+ default:
+ symbol = vmSymbols::argument_has_wrong_type();
+ }
+ checkMarkedSymbol("wrong type", result, symbol);
+}
+END_DECLARE
+
+SETUP(AlienIntegerCallout4Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ smim1 = as_smiOop(-1);
+ handles = new(true) GrowableArray<PersistentHandle**>(5);
+
+ allocateAlien(functionAlien, 8, 0, &returnFirst4);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+
+ memset(address, 0, 8);
+
+ intCalloutFunctions[0] = returnFirst4;
+ intCalloutFunctions[1] = returnSecond4;
+ intCalloutFunctions[2] = returnThird4;
+ intCalloutFunctions[3] = returnFourth4;
+ intPointerCalloutFunctions[0] = returnFirstPointer4;
+ intPointerCalloutFunctions[1] = returnSecondPointer4;
+ intPointerCalloutFunctions[2] = returnThirdPointer4;
+ intPointerCalloutFunctions[3] = returnFourthPointer4;
+}
+
+TEARDOWN(AlienIntegerCallout4Tests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+TESTF(AlienIntegerCallout4Tests, alienCallResult4ShouldCallIntArgFunction)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPassed(arg, -1, intCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4ShouldCallIntPointerArgFunction) {
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(-1), smi1,
pointerAlien->as_oop());
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPtrPassed(arg, pointerAlien->as_oop(),
intPointerCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4ShouldCallFunctionAndIgnoreResultWhenResultAlienNil) {
+ oop result = byteArrayPrimitives::alienCallResult4(smi0, smi0, smi0,
smim1, nilObj, functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "should not be marked");
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4WithScavengeShouldReturnCorrectResult) {
+ setAddress(functionAlien, &forceScavenge4);
+ checkIntResult("incorrect initialization", 0, resultAlien);
+ byteArrayPrimitives::alienCallResult4(smi0, smi0, smi0, smi0,
resultAlien->as_oop(), functionAlien->as_oop());
+ checkIntResult("result alien not updated", -1, resultAlien);
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4ShouldReturnMarkedResultForNonAlien) {
+ oop result = byteArrayPrimitives::alienCallResult4(smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+ smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4ShouldReturnMarkedResultForDirectAlien) {
+ oop result = byteArrayPrimitives::alienCallResult4(smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = byteArrayPrimitives::alienCallResult4(smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4ShouldReturnMarkedResultWhenResultNotAlienOrNil) {
+ oop result = byteArrayPrimitives::alienCallResult4(smi0, smi0, smi0,
smi0, trueObj, functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout4Tests,
alienCallResult4ShouldReturnMarkedResultWhenFunctionParameterNotAlienOrSMI)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkIllegalArgnPassed(arg, trueObj);
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout5Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,264 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+#include <time.h>
+#include <stdlib.h>
+
+using namespace easyunit;
+
+extern "C" int PRIM_API returnFirst5(int a, int b, int c, int d, int e) {
+ return a;
+}
+
+extern "C" int PRIM_API returnFirstPointer5(int *a, int b, int c, int d,
int e) {
+ return *a;
+}
+
+extern "C" int PRIM_API returnSecond5(int a, int b, int c, int d, int e) {
+ return b;
+}
+
+extern "C" int PRIM_API returnSecondPointer5(int a, int *b, int c, int d,
int e) {
+ return *b;
+}
+
+extern "C" int PRIM_API returnThird5(int a, int b, int c, int d, int e) {
+ return c;
+}
+
+extern "C" int PRIM_API returnThirdPointer5(int a, int b, int *c, int d,
int e) {
+ return *c;
+}
+
+extern "C" int PRIM_API returnFourth5(int a, int b, int c, int d, int e) {
+ return d;
+}
+
+extern "C" int PRIM_API returnFourthPointer5(int a, int b, int c, int *d,
int e) {
+ return *d;
+}
+
+extern "C" int PRIM_API returnFifth5(int a, int b, int c, int d, int e) {
+ return e;
+}
+
+extern "C" int PRIM_API returnFifthPointer5(int a, int b, int c, int d,
int *e) {
+ return *e;
+}
+
+extern "C" int PRIM_API forceScavenge5(int ignore1, int ignore2, int
ignore3, int d, int e) {
+ Universe::scavenge();
+ return -1;
+}
+
+DECLARE(AlienIntegerCallout5Tests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien;
+smiOop smi0, smi1, smim1;
+static const int argCount = 5;
+void* intCalloutFunctions[argCount];
+void* intPointerCalloutFunctions[argCount];
+char address[8];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"%s. Should be: %s, was: %s", message,
expected->as_string(), unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void setAddress(PersistentHandle* handle, void* argument) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)argument),
handle->as_oop());
+}
+void checkArgnPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? asOop(argValue) : smi0;
+ oop result = byteArrayPrimitives::alienCallResult5(arg[4], arg[3],
arg[2], arg[1], arg[0], resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+void checkArgnPtrPassed(int argIndex, oop pointer, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = byteArrayPrimitives::alienCallResult5(arg[4], arg[3],
arg[2], arg[1], arg[0], resultAlien->as_oop(), functionAlien->as_oop());
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", -1, resultAlien);
+}
+void checkIllegalArgnPassed(int argIndex, oop pointer) {
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = byteArrayPrimitives::alienCallResult5(arg[4], arg[3],
arg[2], arg[1], arg[0], resultAlien->as_oop(), functionAlien->as_oop());
+
+ symbolOop symbol;
+ switch (argIndex) {
+ case 0:
+ symbol = vmSymbols::second_argument_has_wrong_type();
+ break;
+ case 1:
+ symbol = vmSymbols::third_argument_has_wrong_type();
+ break;
+ case 2:
+ symbol = vmSymbols::fourth_argument_has_wrong_type();
+ break;
+ case 3:
+ symbol = vmSymbols::fifth_argument_has_wrong_type();
+ break;
+ case 4:
+ symbol = vmSymbols::sixth_argument_has_wrong_type();
+ break;
+ default:
+ symbol = vmSymbols::argument_has_wrong_type();
+ }
+ checkMarkedSymbol("wrong type", result, symbol);
+}
+END_DECLARE
+
+SETUP(AlienIntegerCallout5Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ smim1 = as_smiOop(-1);
+ handles = new(true) GrowableArray<PersistentHandle**>(5);
+
+ allocateAlien(functionAlien, 8, 0, &returnFirst5);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+
+ memset(address, 0, 8);
+
+ intCalloutFunctions[0] = returnFirst5;
+ intCalloutFunctions[1] = returnSecond5;
+ intCalloutFunctions[2] = returnThird5;
+ intCalloutFunctions[3] = returnFourth5;
+ intCalloutFunctions[4] = returnFifth5;
+ intPointerCalloutFunctions[0] = returnFirstPointer5;
+ intPointerCalloutFunctions[1] = returnSecondPointer5;
+ intPointerCalloutFunctions[2] = returnThirdPointer5;
+ intPointerCalloutFunctions[3] = returnFourthPointer5;
+ intPointerCalloutFunctions[4] = returnFifthPointer5;
+}
+
+TEARDOWN(AlienIntegerCallout5Tests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+TESTF(AlienIntegerCallout5Tests, alienCallResult5ShouldCallIntArgFunction)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPassed(arg, -1, intCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5ShouldCallIntPointerArgFunction) {
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(-1), smi1,
pointerAlien->as_oop());
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPtrPassed(arg, pointerAlien->as_oop(),
intPointerCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5ShouldCallFunctionAndIgnoreResultWhenResultAlienNil) {
+ oop result = byteArrayPrimitives::alienCallResult5(smi0, smi0, smi0,
smi0, smim1, nilObj, functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "should not be marked");
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5WithScavengeShouldReturnCorrectResult) {
+ setAddress(functionAlien, &forceScavenge5);
+ checkIntResult("incorrect initialization", 0, resultAlien);
+ byteArrayPrimitives::alienCallResult5(smi0, smi0, smi0, smi0, smi0,
resultAlien->as_oop(), functionAlien->as_oop());
+ checkIntResult("result alien not updated", -1, resultAlien);
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5ShouldReturnMarkedResultForNonAlien) {
+ oop result = byteArrayPrimitives::alienCallResult5(smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+ smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5ShouldReturnMarkedResultForDirectAlien) {
+ oop result = byteArrayPrimitives::alienCallResult5(smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = byteArrayPrimitives::alienCallResult5(smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5ShouldReturnMarkedResultWhenResultNotAlienOrNil) {
+ oop result = byteArrayPrimitives::alienCallResult5(smi0, smi0, smi0,
smi0, smi0, trueObj, functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout5Tests,
alienCallResult5ShouldReturnMarkedResultWhenFunctionParameterNotAlienOrSMI)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkIllegalArgnPassed(arg, trueObj);
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout6Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,281 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+
+using namespace easyunit;
+
+extern "C" int PRIM_API returnFirst6(int a, int b, int c, int d, int e,
int f) {
+ return a;
+}
+
+extern "C" int PRIM_API returnFirstPointer6(int *a, int b, int c, int d,
int e, int f) {
+ return *a;
+}
+
+extern "C" int PRIM_API returnSecond6(int a, int b, int c, int d, int e,
int f) {
+ return b;
+}
+
+extern "C" int PRIM_API returnSecondPointer6(int a, int *b, int c, int d,
int e, int f) {
+ return *b;
+}
+
+extern "C" int PRIM_API returnThird6(int a, int b, int c, int d, int e,
int f) {
+ return c;
+}
+
+extern "C" int PRIM_API returnThirdPointer6(int a, int b, int *c, int d,
int e, int f) {
+ return *c;
+}
+
+extern "C" int PRIM_API returnFourth6(int a, int b, int c, int d, int e,
int f) {
+ return d;
+}
+
+extern "C" int PRIM_API returnFourthPointer6(int a, int b, int c, int *d,
int e, int f) {
+ return *d;
+}
+
+extern "C" int PRIM_API returnFifth6(int a, int b, int c, int d, int e,
int f) {
+ return e;
+}
+
+extern "C" int PRIM_API returnFifthPointer6(int a, int b, int c, int d,
int *e, int f) {
+ return *e;
+}
+
+extern "C" int PRIM_API returnSixth6(int a, int b, int c, int d, int e,
int f) {
+ return f;
+}
+
+extern "C" int PRIM_API returnSixthPointer6(int a, int b, int c, int d,
int e, int *f) {
+ return *f;
+}
+
+extern "C" int PRIM_API forceScavenge6(int ignore1, int ignore2, int
ignore3, int d, int e) {
+ Universe::scavenge();
+ return -1;
+}
+
+DECLARE(AlienIntegerCallout6Tests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien;
+smiOop smi0, smi1, smim1;
+static const int argCount = 6;
+void* intCalloutFunctions[argCount];
+void* intPointerCalloutFunctions[argCount];
+char address[8];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"%s. Should be: %s, was: %s", message,
expected->as_string(), unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void setAddress(PersistentHandle* handle, void* argument) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)argument),
handle->as_oop());
+}
+oop callout(oop arg[]) {
+ return byteArrayPrimitives::alienCallResult6(arg[5], arg[4], arg[3],
arg[2], arg[1], arg[0], resultAlien->as_oop(), functionAlien->as_oop());
+}
+void checkArgnPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? asOop(argValue) : smi0;
+ oop result = callout(arg);
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+void checkArgnPtrPassed(int argIndex, oop pointer, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = callout(arg);
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", -1, resultAlien);
+}
+void checkIllegalArgnPassed(int argIndex, oop pointer) {
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = callout(arg);
+
+ symbolOop symbol;
+ switch (argIndex) {
+ case 0:
+ symbol = vmSymbols::second_argument_has_wrong_type();
+ break;
+ case 1:
+ symbol = vmSymbols::third_argument_has_wrong_type();
+ break;
+ case 2:
+ symbol = vmSymbols::fourth_argument_has_wrong_type();
+ break;
+ case 3:
+ symbol = vmSymbols::fifth_argument_has_wrong_type();
+ break;
+ case 4:
+ symbol = vmSymbols::sixth_argument_has_wrong_type();
+ break;
+ case 5:
+ symbol = vmSymbols::seventh_argument_has_wrong_type();
+ break;
+ default:
+ symbol = vmSymbols::argument_has_wrong_type();
+ }
+ checkMarkedSymbol("wrong type", result, symbol);
+}
+END_DECLARE
+
+SETUP(AlienIntegerCallout6Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ smim1 = as_smiOop(-1);
+ handles = new(true) GrowableArray<PersistentHandle**>(6);
+
+ allocateAlien(functionAlien, 8, 0, &returnFirst6);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+
+ memset(address, 0, 8);
+
+ intCalloutFunctions[0] = returnFirst6;
+ intCalloutFunctions[1] = returnSecond6;
+ intCalloutFunctions[2] = returnThird6;
+ intCalloutFunctions[3] = returnFourth6;
+ intCalloutFunctions[4] = returnFifth6;
+ intCalloutFunctions[5] = returnSixth6;
+ intPointerCalloutFunctions[0] = returnFirstPointer6;
+ intPointerCalloutFunctions[1] = returnSecondPointer6;
+ intPointerCalloutFunctions[2] = returnThirdPointer6;
+ intPointerCalloutFunctions[3] = returnFourthPointer6;
+ intPointerCalloutFunctions[4] = returnFifthPointer6;
+ intPointerCalloutFunctions[5] = returnSixthPointer6;
+}
+
+TEARDOWN(AlienIntegerCallout6Tests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+TESTF(AlienIntegerCallout6Tests, alienCallResult6ShouldCallIntArgFunction)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPassed(arg, -1, intCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6ShouldCallIntPointerArgFunction) {
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(-1), smi1,
pointerAlien->as_oop());
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPtrPassed(arg, pointerAlien->as_oop(),
intPointerCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6ShouldCallFunctionAndIgnoreResultWhenResultAlienNil) {
+ oop result = byteArrayPrimitives::alienCallResult6(smi0, smi0, smi0,
smi0, smi0, smim1, nilObj, functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "should not be marked");
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6WithScavengeShouldReturnCorrectResult) {
+ setAddress(functionAlien, &forceScavenge6);
+ checkIntResult("incorrect initialization", 0, resultAlien);
+ byteArrayPrimitives::alienCallResult6(smi0, smi0, smi0, smi0, smi0,
smi0, resultAlien->as_oop(), functionAlien->as_oop());
+ checkIntResult("result alien not updated", -1, resultAlien);
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6ShouldReturnMarkedResultForNonAlien) {
+ oop result = byteArrayPrimitives::alienCallResult6(smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+ smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6ShouldReturnMarkedResultForDirectAlien) {
+ oop result = byteArrayPrimitives::alienCallResult6(smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = byteArrayPrimitives::alienCallResult6(smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ smi0,
+ resultAlien->as_oop(),
+
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6ShouldReturnMarkedResultWhenResultNotAlienOrNil) {
+ oop result = byteArrayPrimitives::alienCallResult6(smi0, smi0, smi0,
smi0, smi0, smi0, trueObj, functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout6Tests,
alienCallResult6ShouldReturnMarkedResultWhenFunctionParameterNotAlienOrSMI)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkIllegalArgnPassed(arg, trueObj);
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/alienIntegerCallout7Tests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,294 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+
+using namespace easyunit;
+
+extern "C" int PRIM_API sum7(int a, int b, int c, int d, int e, int f, int
g) {
+ return (a) + (b) + (c) + (d) + (e) + (f) + (g);
+}
+
+extern "C" int PRIM_API returnFirst7(int a, int b, int c, int d, int e,
int f, int g) {
+ return a;
+}
+
+extern "C" int PRIM_API returnFirstPointer7(int *a, int b, int c, int d,
int e, int f, int g) {
+ return *a;
+}
+
+extern "C" int PRIM_API returnSecond7(int a, int b, int c, int d, int e,
int f, int g) {
+ return b;
+}
+
+extern "C" int PRIM_API returnSecondPointer7(int a, int *b, int c, int d,
int e, int f, int g) {
+ return *b;
+}
+
+extern "C" int PRIM_API returnThird7(int a, int b, int c, int d, int e,
int f, int g) {
+ return c;
+}
+
+extern "C" int PRIM_API returnThirdPointer7(int a, int b, int *c, int d,
int e, int f, int g) {
+ return *c;
+}
+
+extern "C" int PRIM_API returnFourth7(int a, int b, int c, int d, int e,
int f, int g) {
+ return d;
+}
+
+extern "C" int PRIM_API returnFourthPointer7(int a, int b, int c, int *d,
int e, int f, int g) {
+ return *d;
+}
+
+extern "C" int PRIM_API returnFifth7(int a, int b, int c, int d, int e,
int f, int g) {
+ return e;
+}
+
+extern "C" int PRIM_API returnFifthPointer7(int a, int b, int c, int d,
int *e, int f, int g) {
+ return *e;
+}
+
+extern "C" int PRIM_API returnSixth7(int a, int b, int c, int d, int e,
int f, int g) {
+ return f;
+}
+
+extern "C" int PRIM_API returnSixthPointer7(int a, int b, int c, int d,
int e, int *f) {
+ return *f;
+}
+
+extern "C" int PRIM_API returnSeventh7(int a, int b, int c, int d, int e,
int f, int g) {
+ return g;
+}
+
+extern "C" int PRIM_API returnSeventhPointer7(int a, int b, int c, int d,
int e, int f, int *g) {
+ return *g;
+}
+
+extern "C" int PRIM_API forceScavenge7(int ignore1, int ignore2, int
ignore3, int d, int e) {
+ Universe::scavenge();
+ return -1;
+}
+
+DECLARE(AlienIntegerCallout7Tests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien;
+smiOop smi0, smi1, smim1;
+static const int argCount = 7;
+void* intCalloutFunctions[argCount];
+void* intPointerCalloutFunctions[argCount];
+oop zeroes[argCount];
+char address[8];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"%s. Should be: %s, was: %s", message,
expected->as_string(), unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void setAddress(PersistentHandle* handle, void* argument) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)argument),
handle->as_oop());
+}
+oop callout(oop arg[], oop result, oop address) {
+ return byteArrayPrimitives::alienCallResult7(arg[6], arg[5], arg[4],
arg[3], arg[2], arg[1], arg[0], result, address);
+}
+oop callout(oop arg[]) {
+ return callout(arg, resultAlien->as_oop(), functionAlien->as_oop());
+}
+void checkArgnPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? asOop(argValue) : smi0;
+ oop result = callout(arg);
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+void checkArgnPtrPassed(int argIndex, oop pointer, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = callout(arg);
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", -1, resultAlien);
+}
+void checkIllegalArgnPassed(int argIndex, oop pointer) {
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = callout(arg);
+
+ symbolOop symbol;
+ switch (argIndex) {
+ case 0:
+ symbol = vmSymbols::second_argument_has_wrong_type();
+ break;
+ case 1:
+ symbol = vmSymbols::third_argument_has_wrong_type();
+ break;
+ case 2:
+ symbol = vmSymbols::fourth_argument_has_wrong_type();
+ break;
+ case 3:
+ symbol = vmSymbols::fifth_argument_has_wrong_type();
+ break;
+ case 4:
+ symbol = vmSymbols::sixth_argument_has_wrong_type();
+ break;
+ case 5:
+ symbol = vmSymbols::seventh_argument_has_wrong_type();
+ break;
+ case 6:
+ symbol = vmSymbols::eighth_argument_has_wrong_type();
+ break;
+ default:
+ symbol = vmSymbols::argument_has_wrong_type();
+ }
+ checkMarkedSymbol("wrong type", result, symbol);
+}
+END_DECLARE
+
+SETUP(AlienIntegerCallout7Tests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ smim1 = as_smiOop(-1);
+ handles = new(true) GrowableArray<PersistentHandle**>(7);
+
+ allocateAlien(functionAlien, 8, 0, &returnFirst7);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+
+ memset(address, 0, 8);
+
+ intCalloutFunctions[0] = returnFirst7;
+ intCalloutFunctions[1] = returnSecond7;
+ intCalloutFunctions[2] = returnThird7;
+ intCalloutFunctions[3] = returnFourth7;
+ intCalloutFunctions[4] = returnFifth7;
+ intCalloutFunctions[5] = returnSixth7;
+ intCalloutFunctions[6] = returnSeventh7;
+
+ intPointerCalloutFunctions[0] = returnFirstPointer7;
+ intPointerCalloutFunctions[1] = returnSecondPointer7;
+ intPointerCalloutFunctions[2] = returnThirdPointer7;
+ intPointerCalloutFunctions[3] = returnFourthPointer7;
+ intPointerCalloutFunctions[4] = returnFifthPointer7;
+ intPointerCalloutFunctions[5] = returnSixthPointer7;
+ intPointerCalloutFunctions[6] = returnSeventhPointer7;
+
+ for (int index = 0; index < argCount; index++)
+ zeroes[index] = smi0;
+}
+
+TEARDOWN(AlienIntegerCallout7Tests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+TESTF(AlienIntegerCallout7Tests, alienCallResult7ShouldCallIntArgFunction)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPassed(arg, -1, intCalloutFunctions);
+}
+TESTF(AlienIntegerCallout7Tests, alienCallResult7ShouldCallSumFunction) {
+ oop arg[argCount];
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(-1), smi1,
addressAlien->as_oop());
+ for (int index = 0; index < argCount; index++)
+ arg[index] = addressAlien->as_oop();
+ byteArrayPrimitives::alienSetAddress(asOop((int)&sum7),
functionAlien->as_oop());
+ callout(arg);
+ checkIntResult("wrong result", -1 * argCount, resultAlien);
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7ShouldCallIntPointerArgFunction) {
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(-1), smi1,
pointerAlien->as_oop());
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPtrPassed(arg, pointerAlien->as_oop(),
intPointerCalloutFunctions);
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7ShouldCallFunctionAndIgnoreResultWhenResultAlienNil) {
+ oop result = callout(zeroes, nilObj, functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "should not be marked");
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7WithScavengeShouldReturnCorrectResult) {
+ setAddress(functionAlien, &forceScavenge7);
+ checkIntResult("incorrect initialization", 0, resultAlien);
+ oop result = callout(zeroes, resultAlien->as_oop(),
functionAlien->as_oop());
+ checkIntResult("result alien not updated", -1, resultAlien);
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7ShouldReturnMarkedResultForNonAlien) {
+ oop result = callout(zeroes, resultAlien->as_oop(), smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7ShouldReturnMarkedResultForDirectAlien) {
+oop result = callout(zeroes, resultAlien->as_oop(),
resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7ShouldReturnMarkedResultForNullFunctionPointer) {
+ oop result = callout(zeroes, resultAlien->as_oop(),
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7ShouldReturnMarkedResultWhenResultNotAlienOrNil) {
+ oop result = callout(zeroes, trueObj, functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCallout7Tests,
alienCallResult7ShouldReturnMarkedResultWhenFunctionParameterNotAlienOrSMI)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkIllegalArgnPassed(arg, trueObj);
+}
=======================================
--- /dev/null
+++
/branches/gcc-linux/test/prims/alienIntegerCalloutWithArgumentsTests.cpp
Sun Sep 13 14:52:44 2009
@@ -0,0 +1,224 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+#include <time.h>
+#include <stdlib.h>
+
+using namespace easyunit;
+
+extern "C" int PRIM_API returnFirst2(int a, int b) {
+ return a;
+}
+
+extern "C" int PRIM_API returnFirstPointer2(int *a, int b) {
+ return *a;
+}
+
+extern "C" int PRIM_API returnSecond2(int a, int b) {
+ return b;
+}
+
+extern "C" int PRIM_API returnSecondPointer2(int a, int *b) {
+ return *b;
+}
+
+extern "C" int PRIM_API forceScavengeWA(int a, int b) {
+ Universe::scavenge();
+ return -1;
+}
+
+extern "C" int PRIM_API argAlignment2(int a, int b) {
+ return ((int) &a) & 0xF;
+}
+
+DECLARE(AlienIntegerCalloutWithArgumentsTests)
+GrowableArray<PersistentHandle**> *handles;
+PersistentHandle *resultAlien, *addressAlien, *pointerAlien,
*functionAlien;
+PersistentHandle *directAlien, *invalidFunctionAlien;
+smiOop smi0, smi1, smim1;
+static const int argCount = 2;
+void* intCalloutFunctions[argCount];
+void* intPointerCalloutFunctions[argCount];
+oop zeroes[argCount];
+char address[16];
+
+void allocateAlien(PersistentHandle* &alienHandle, int arraySize, int
alienSize, void* ptr = NULL) {
+ byteArrayOop alien =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(arraySize));
+ byteArrayPrimitives::alienSetSize(as_smiOop(alienSize), alien);
+ if (ptr)
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)ptr), alien);
+ alienHandle = new PersistentHandle(alien);
+ handles->append(&alienHandle);
+}
+void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+}
+void checkIntResult(char* message, int expected, PersistentHandle* alien) {
+ char text[200];
+ bool ok;
+ int actual = asInt(ok, byteArrayPrimitives::alienSignedLongAt(smi1,
alien->as_oop()));
+ ASSERT_TRUE_M(ok, "not an integer result");
+ sprintf(text,"Should be: %d, was: %d", expected, actual);
+ ASSERT_TRUE_M(actual == expected, text);
+}
+int asInt(bool &ok, oop intOop) {
+ ok = true;
+ if (intOop->is_smi())
+ return smiOop(intOop)->value();
+ if (!intOop->is_byteArray()) {
+ ok = false;
+ return 0;
+ }
+ return byteArrayOop(intOop)->number().as_int(ok);
+}
+oop asOop(int value) {
+ int size = IntegerOps::int_to_Integer_result_size_in_bytes(value);
+ byteArrayOop valueOop =
byteArrayOop(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(size));
+ IntegerOps::int_to_Integer(value, valueOop->number());
+ bool ok;
+ oop result = valueOop->number().as_smi(ok);
+ return ok ? result : valueOop;
+}
+void release(PersistentHandle** handle) {
+ delete *handle;
+ *handle = NULL;
+}
+void setAddress(PersistentHandle* handle, void* argument) {
+ byteArrayPrimitives::alienSetAddress(asOop((int)argument),
handle->as_oop());
+}
+oop callout(oop arg[], oop result, oop address) {
+ objArrayOop argOops = oopFactory::new_objArray(2);
+ for (int index = 0; index < 2; index++)
+ argOops->obj_at_put(index + 1, arg[index]);
+ return byteArrayPrimitives::alienCallResultWithArguments(argOops,
result, address);
+}
+oop callout(oop arg[]) {
+ return callout(arg, resultAlien->as_oop(), functionAlien->as_oop());
+}
+void checkArgnPassed(int argIndex, int argValue, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? asOop(argValue) : smi0;
+ oop result = callout(arg);
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", argValue, resultAlien);
+}
+void checkArgnPtrPassed(int argIndex, oop pointer, void**functionArray) {
+ setAddress(functionAlien, functionArray[argIndex]);
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = callout(arg);
+
+ ASSERT_TRUE_M(result == functionAlien->as_oop(), "Should return
receiver");
+ checkIntResult("wrong result", -1, resultAlien);
+}
+void checkIllegalArgnPassed(int argIndex, oop pointer) {
+ oop arg[argCount];
+ for (int index = 0; index < argCount; index++)
+ arg[index] = argIndex == index ? pointer : smi0;
+ oop result = callout(arg);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+END_DECLARE
+
+SETUP(AlienIntegerCalloutWithArgumentsTests) {
+ smi0 = as_smiOop(0);
+ smi1 = as_smiOop(1);
+ smim1 = as_smiOop(-1);
+ handles = new(true) GrowableArray<PersistentHandle**>(5);
+
+ allocateAlien(functionAlien, 8, 0, &returnFirst2);
+ allocateAlien(resultAlien, 12, 8);
+ allocateAlien(directAlien, 12, 4);
+ allocateAlien(addressAlien, 8, -4, &address);
+ allocateAlien(pointerAlien, 8, 0, &address);
+ allocateAlien(invalidFunctionAlien, 8, 0);
+
+ memset(address, 0, 8);
+
+ intCalloutFunctions[0] = returnFirst2;
+ intCalloutFunctions[1] = returnSecond2;
+ intPointerCalloutFunctions[0] = returnFirstPointer2;
+ intPointerCalloutFunctions[1] = returnSecondPointer2;
+}
+
+TEARDOWN(AlienIntegerCalloutWithArgumentsTests){
+ while(!handles->isEmpty())
+ release(handles->pop());
+ free(handles);
+ handles = NULL;
+}
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldCallIntArgFunction) {
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPassed(arg, -1, intCalloutFunctions);
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResult1Should16ByteAlignArgs) {
+ oop fnAddress = asOop((int)&argAlignment2);
+ byteArrayPrimitives::alienSetAddress(fnAddress, functionAlien->as_oop());
+
+ oop arg[argCount];
+ arg[1] = smi0;
+ for (int size = -4; size > -20; size -= 4) {
+ arg[0] = addressAlien->as_oop();
+ byteArrayPrimitives::alienSetSize(as_smiOop(size),
addressAlien->as_oop());
+ callout(arg);
+ checkIntResult("wrong result", 0, resultAlien);
+ }
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldCallIntPointerArgFunction) {
+ byteArrayPrimitives::alienSignedLongAtPut(asOop(-1), smi1,
pointerAlien->as_oop());
+ for (int arg = 0; arg < argCount; arg++)
+ checkArgnPtrPassed(arg, pointerAlien->as_oop(),
intPointerCalloutFunctions);
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldCallFunctionAndIgnoreResultWhenResultAlienNil)
{
+ oop result = callout(zeroes, nilObj, functionAlien->as_oop());
+ ASSERT_TRUE_M(!result->is_mark(), "should not be marked");
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsWithScavengeShouldReturnCorrectResult) {
+ setAddress(functionAlien, &forceScavengeWA);
+ checkIntResult("incorrect initialization", 0, resultAlien);
+ oop result = callout(zeroes, resultAlien->as_oop(),
functionAlien->as_oop());
+ checkIntResult("result alien not updated", -1, resultAlien);
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldReturnMarkedResultForNonAlien) {
+ oop result = callout(zeroes, resultAlien->as_oop(), smi0);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldReturnMarkedResultForDirectAlien) {
+oop result = callout(zeroes, resultAlien->as_oop(),
resultAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldReturnMarkedResultForNullFunctionPointer)
{
+ oop result = callout(zeroes, resultAlien->as_oop(),
invalidFunctionAlien->as_oop());
+
+ checkMarkedSymbol("illegal state", result, vmSymbols::illegal_state());
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldReturnMarkedResultWhenResultNotAlienOrNil)
{
+ oop result = callout(zeroes, trueObj, functionAlien->as_oop());
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(AlienIntegerCalloutWithArgumentsTests,
alienCallResultWithArgumentsShouldReturnMarkedResultWhenFunctionParameterNotAlienOrSMI)
{
+ for (int arg = 0; arg < argCount; arg++)
+ checkIllegalArgnPassed(arg, trueObj);
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/directAlienPrimsTests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,710 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+
+using namespace easyunit;
+
+extern "C" int expansion_count;
+DECLARE(DirectAlienPrimsTests)
+ byteArrayOop alien;
+ byteArrayOop largeUnsignedInteger;
+ byteArrayOop largeUnsignedInteger2;
+ byteArrayOop veryLargeUnsignedInteger;
+ byteArrayOop largeSignedInteger;
+ doubleOop doubleValue;
+
+ void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+ }
+ void checkLargeInteger(oop result, int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_byteArray(), "Should be integer");
+ bool ok;
+ int actual = byteArrayOop(result)->number().as_int(ok);
+ ASSERT_TRUE_M(ok, "should be integer");
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkLargeUnsigned(oop result, unsigned int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_byteArray(), "Should be integer");
+ bool ok;
+ unsigned int actual =
byteArrayOop(result)->number().as_unsigned_int(ok);
+ ASSERT_TRUE_M(ok, "should be integer");
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkSmallInteger(oop result, int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_smi(), "Should be small integer");
+ int actual = smiOop(result)->value();
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+END_DECLARE
+
+SETUP(DirectAlienPrimsTests) {
+ PersistentHandle bac(Universe::byteArrayKlassObj());
+ PersistentHandle
ah(klassOop(bac.as_oop())->klass_part()->allocateObjectSize(12));
+ PersistentHandle
lu(klassOop(bac.as_oop())->klass_part()->allocateObjectSize(8));
+ PersistentHandle
lu2(klassOop(bac.as_oop())->klass_part()->allocateObjectSize(8));
+ PersistentHandle
vlu(klassOop(bac.as_oop())->klass_part()->allocateObjectSize(12));
+ PersistentHandle
ls(klassOop(bac.as_oop())->klass_part()->allocateObjectSize(8));
+
+ alien = byteArrayOop(ah.as_oop());
+ largeUnsignedInteger = byteArrayOop(lu.as_oop());
+ largeUnsignedInteger2 = byteArrayOop(lu2.as_oop());
+ veryLargeUnsignedInteger = byteArrayOop(vlu.as_oop());
+ largeSignedInteger = byteArrayOop(ls.as_oop());
+ doubleValue =
doubleOop(Universe::doubleKlassObj()->klass_part()->allocateObject());
+ doubleValue->set_value(1.625);
+
+ IntegerOps::unsigned_int_to_Integer((unsigned int)0xFFFFFFFF,
byteArrayOop(largeUnsignedInteger)->number());
+ IntegerOps::int_to_Integer(1 << 30,
byteArrayOop(largeUnsignedInteger2)->number());
+ IntegerOps::int_to_Integer(-1 << 31,
byteArrayOop(largeSignedInteger)->number());
+ IntegerOps::mul(largeUnsignedInteger->number(),
largeUnsignedInteger->number(), veryLargeUnsignedInteger->number());
+ byteArrayPrimitives::alienSetSize(as_smiOop(8), alien);
+}
+
+TEARDOWN(DirectAlienPrimsTests){
+ MarkSweep::collect();
+}
+
+TESTF(DirectAlienPrimsTests, alienUnsignedByteAtPutShouldSetUnsignedByte) {
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedByteAt(as_smiOop(1),
alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "result should be SmallInteger");
+ ASSERT_EQUALS_M(255, smiOop(result)->value(), "Should set value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedByteAtPutShouldReturnAssignedByte) {
+ oop result = byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ ASSERT_TRUE_M(result->is_smi(), "result should be SmallInteger");
+ ASSERT_EQUALS_M(255, smiOop(result)->value(), "Should return value");
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedByteAtShouldReturnSignedValue) {
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "result should be SmallInteger");
+ ASSERT_EQUALS_M(-1, smiOop(result)->value(), "Should return correct
value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1),
as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtShouldReturnMarkedSymbolWhenIndexNotSmallInteger) {
+ oop result = byteArrayPrimitives::alienSignedByteAt(alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(0), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(9), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedByteAtPutShouldReturnSignedValue) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-1),
as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "result should be SmallInteger");
+ ASSERT_EQUALS_M(-1, smiOop(result)->value(), "Should return correct
value");
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedByteAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "result should be SmallInteger");
+ ASSERT_EQUALS_M(-1, smiOop(result)->value(), "Should return correct
value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldSetCorrectValueWhenPositive) {
+ byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "result should be SmallInteger");
+ ASSERT_EQUALS_M(1, smiOop(result)->value(), "Should return correct
value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(1),
as_smiOop(1), as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenIndexNotSmallInteger) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(1),
alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenValieNotSmallInteger) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(alien,
as_smiOop(1), alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(0),
as_smiOop(0), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenIndexTooBig) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(0),
as_smiOop(9), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenValueTooSmall) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-129),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("invalid value", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenValueTooBig) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(128),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("invalid value", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests, alienUnsignedShortAtShouldReturnCorrectValue)
{
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(2), alien);
+
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
alien);
+ ASSERT_TRUE_M(result->is_smi(), "should be smi");
+ ASSERT_EQUALS_M(65535, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(0),
alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtShouldReturnMarkedSymbolWhenIndexTooBig) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(8),
alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnCorrectValue) {
+ oop result =
byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "should be smi");
+ ASSERT_EQUALS_M(65535, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests, alienUnsignedShortAtPutShouldSetCorrectValue)
{
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "should be smi");
+ ASSERT_EQUALS_M(65535, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(1),
as_smiOop(1), as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(1),
alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenValueNotSMI) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(alien,
as_smiOop(1), alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(1),
as_smiOop(0), alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenIndexTooBig) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(1),
as_smiOop(8), alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenValueTooSmall) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(-1),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("value too small", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenValueTooBig) {
+ oop result =
byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65536),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("value too small", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedShortAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
alien);
+ ASSERT_TRUE_M(result->is_smi(), "should be smi");
+ ASSERT_EQUALS_M(-1, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienSignedShortAt(alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(0),
alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtShouldReturnMarkedSymbolWhenIndexTooBig) {
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(8),
alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnCorrectValue) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(-1),
as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "should be smi");
+ ASSERT_EQUALS_M(-1, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedShortAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(-1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "should be smi");
+ ASSERT_EQUALS_M(-1, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(1),
as_smiOop(1), as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(1),
alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenValueNotSMI) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(alien,
as_smiOop(1), alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(1),
as_smiOop(0), alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenIndexTooBig) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(1),
as_smiOop(8), alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenValueTooSmall) {
+ oop result =
byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(-32769), as_smiOop(1),
alien);
+
+ checkMarkedSymbol("value too small", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenValueTooBig) {
+ oop result =
byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(32768), as_smiOop(1),
alien);
+
+ checkMarkedSymbol("value too small", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests, alienUnsignedLongAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(3), alien);
+
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ checkLargeUnsigned(result, 0xFFFFFFFF);
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtShouldReturnSmallIntegerWhenResultSmall) {
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(1), as_smiOop(1),
alien);
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(0), as_smiOop(3),
alien);
+
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "Should be small integer");
+ ASSERT_EQUALS_M(1, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(0),
alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtShouldReturnMarkedSymbolWhenIndexTooBig) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(6),
alien);
+
+ checkMarkedSymbol("index invalid", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnCorrectValue) {
+ oop result =
byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger,
as_smiOop(1), alien);
+
+ checkLargeUnsigned(result, 0xFFFFFFFF);
+}
+
+TESTF(DirectAlienPrimsTests, alienUnsignedLongAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ checkLargeUnsigned(result, 0xFFFFFFFF);
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenValueTooLarge) {
+ oop result =
byteArrayPrimitives::alienUnsignedLongAtPut(veryLargeUnsignedInteger,
as_smiOop(1), alien);
+
+ checkMarkedSymbol("invalid value", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldSetCorrectValueWithSMI) {
+ byteArrayPrimitives::alienUnsignedLongAtPut(as_smiOop(1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "Should be small integer");
+ ASSERT_TRUE_M(1 == smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAtPut(as_smiOop(1),
as_smiOop(1), as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAtPut(as_smiOop(1),
alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenValueNotInteger) {
+ oop result =
byteArrayPrimitives::alienUnsignedLongAtPut(Universe::byteArrayKlassObj(),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAtPut(as_smiOop(1),
as_smiOop(0), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAtPut(as_smiOop(1),
as_smiOop(6), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedLongAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_smi(), "Should be integer");
+ ASSERT_EQUALS_M(-1, smiOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedLongAtShouldReturnLargeInteger) {
+ byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger2,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ checkLargeInteger(result, 1 << 30);
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1),
as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienSignedLongAt(alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(0), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(6), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedLongAtPutShouldReturnCorrectValue)
{
+ oop result =
byteArrayPrimitives::alienSignedLongAtPut(largeSignedInteger, as_smiOop(1),
alien);
+
+ checkLargeInteger(result, -1 << 31);
+}
+
+TESTF(DirectAlienPrimsTests, alienSignedLongAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienSignedLongAtPut(largeSignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ checkLargeInteger(result, -1 << 31);
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtPutWithSMIShouldSetCorrectValue) {
+ byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, 1);
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(1),
as_smiOop(1), as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(1),
alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenValueNotInteger) {
+ oop result =
byteArrayPrimitives::alienSignedLongAtPut(Universe::byteArrayKlassObj(),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(1),
as_smiOop(0), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(1),
as_smiOop(6), alien);
+
+ checkMarkedSymbol("invalid index", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenValueTooLarge) {
+ oop result =
byteArrayPrimitives::alienSignedLongAtPut(veryLargeUnsignedInteger,
as_smiOop(1), alien);
+
+ checkMarkedSymbol("invalid value", result,
vmSymbols::argument_is_invalid());
+}
+
+TESTF(DirectAlienPrimsTests, alienDoubleAtPutShouldReturnValue) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(doubleValue,
as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests, alienDoubleAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienDoubleAtPut(doubleValue, as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625, ((double*)(alien->bytes() + 4))[0], "value not
set");
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtPutShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(doubleValue,
as_smiOop(1), as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(1),
as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtPutShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(doubleValue, alien,
alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienDoubleAt(alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtPutShouldReturnMarkedSymbolWhenValueNotDouble) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(as_smiOop(1),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtPutShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(doubleValue,
as_smiOop(0), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(0), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtPutShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(doubleValue,
as_smiOop(2), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienDoubleAtShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(2), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests, alienFloatAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienFloatAtPut(doubleValue, as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625F, ((float*)(alien->bytes() + 4))[0], "value not
set");
+}
+
+TESTF(DirectAlienPrimsTests, alienFloatAtPutShouldSetCorrectValueAt2) {
+ byteArrayPrimitives::alienFloatAtPut(doubleValue, as_smiOop(2), alien);
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(2), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625F, ((float*)(alien->bytes() + 5))[0], "value not
set");
+}
+
+TESTF(DirectAlienPrimsTests, alienFloatAtPutShouldReturnCorrectValue) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(doubleValue,
as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtPutShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(doubleValue,
as_smiOop(1), as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtShouldReturnMarkedSymbolWhenNotAlien) {
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(1),
as_smiOop(0));
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::receiver_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtPutShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(doubleValue, alien,
alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::first_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtShouldReturnMarkedSymbolWhenIndexNotSMI) {
+ oop result = byteArrayPrimitives::alienFloatAt(alien, alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtPutShouldReturnMarkedSymbolWhenValueNotDouble) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(as_smiOop(1),
as_smiOop(1), alien);
+
+ checkMarkedSymbol("wrong type", result,
vmSymbols::second_argument_has_wrong_type());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(0), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtPutShouldReturnMarkedSymbolWhenIndexTooSmall) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(doubleValue,
as_smiOop(0), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtPutShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(doubleValue,
as_smiOop(6), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
+
+TESTF(DirectAlienPrimsTests,
alienFloatAtShouldReturnMarkedSymbolWhenIndexTooLarge) {
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(6), alien);
+
+ checkMarkedSymbol("wrong type", result, vmSymbols::index_not_valid());
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/indirectAlienPrimsTests.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,311 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+
+using namespace easyunit;
+
+extern "C" int expansion_count;
+DECLARE(IndirectAlienPrimsTests)
+ klassOop byteArrayClass;
+ byteArrayOop alien, invalidAlien;
+ byteArrayOop largeUnsignedInteger;
+ byteArrayOop largeSignedInteger;
+ u_char alien_byte_region[16];
+ doubleOop doubleValue;
+
+ int asInteger(oop largeInteger, bool& ok) {
+ Integer* number = &byteArrayOop(largeInteger)->number();
+ return number->as_int(ok);
+ }
+ void checkLargeInteger(oop result, int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_byteArray(), "Should be integer");
+ bool ok;
+ int actual = asInteger(result, ok);
+ ASSERT_TRUE_M(ok, "should be integer");
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkLargeUnsigned(oop result, unsigned int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_byteArray(), "Should be integer");
+ bool ok;
+ unsigned int actual =
byteArrayOop(result)->number().as_unsigned_int(ok);
+ ASSERT_TRUE_M(ok, "should be integer");
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkSmallInteger(oop result, int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_smi(), "Should be small integer");
+ int actual = smiOop(result)->value();
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+ }
+END_DECLARE
+
+SETUP(IndirectAlienPrimsTests) {
+ klassOop byteArrayClass = Universe::byteArrayKlassObj();
+ PersistentHandle ah(byteArrayClass->klass_part()->allocateObjectSize(8));
+ PersistentHandle
iah(byteArrayClass->klass_part()->allocateObjectSize(8));
+ PersistentHandle lu(byteArrayClass->klass_part()->allocateObjectSize(8));
+ PersistentHandle ls(byteArrayClass->klass_part()->allocateObjectSize(8));
+
+ doubleValue =
doubleOop(Universe::doubleKlassObj()->klass_part()->allocateObject());
+ doubleValue->set_value(1.625);
+
+ largeUnsignedInteger = byteArrayOop(lu.as_oop());
+ largeSignedInteger = byteArrayOop(ls.as_oop());
+
+ IntegerOps::unsigned_int_to_Integer((unsigned int)0xFFFFFFFF,
byteArrayOop(largeUnsignedInteger)->number());
+ IntegerOps::int_to_Integer(-1 << 31,
byteArrayOop(largeSignedInteger)->number());
+
+ alien = byteArrayOop(ah.as_oop());
+ byteArrayPrimitives::alienSetSize(as_smiOop(-16), alien);
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)alien_byte_region),
alien);
+ memset(alien_byte_region, 0, 16);
+
+ invalidAlien = byteArrayOop(iah.as_oop());
+ byteArrayPrimitives::alienSetSize(as_smiOop(-16), invalidAlien);
+ byteArrayPrimitives::alienSetAddress(as_smiOop(0), invalidAlien);
+}
+
+TEARDOWN(IndirectAlienPrimsTests){
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedByteAtPutShouldSetUnsignedByte) {
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedByteAt(as_smiOop(1),
alien);
+
+ checkSmallInteger(result, 255);
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedByteAtPutShouldReturnAssignedByte) {
+ oop result = byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+
+ checkSmallInteger(result, 255);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedByteAtShouldReturnCorrectByte) {
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(IndirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnCorrectByte) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-1),
as_smiOop(1), alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedByteAtPutShouldSetCorrectByte) {
+ byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedByteAtPutShouldSetMaxValue) {
+ byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(127), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, 127);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedByteAtPutShouldSetMinValue) {
+ byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-128), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, -128);
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedShortAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(2), alien);
+
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
alien);
+ checkSmallInteger(result, 65535);
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedShortAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
alien);
+
+ checkSmallInteger(result, 65535);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedShortAtShouldReturnCorrectValue)
{
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
alien);
+ checkSmallInteger(result, -1);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedShortAtPutShouldSetCorrectValue)
{
+ byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(-1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedLongAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(3), alien);
+
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ checkLargeUnsigned(result, 0xFFFFFFFF);
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedLongAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ checkLargeUnsigned(result, 0xFFFFFFFF);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedLongAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(IndirectAlienPrimsTests, alienSignedLongAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienSignedLongAtPut(largeSignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ checkLargeInteger(result, -1 << 31);
+}
+
+TESTF(IndirectAlienPrimsTests, alienDoubleAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienDoubleAtPut(doubleValue, as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625, ((double*)alien_byte_region)[0], "value not set");
+}
+
+TESTF(IndirectAlienPrimsTests, alienDoubleAtPutShouldSetValueAtSecondByte)
{
+ byteArrayPrimitives::alienDoubleAtPut(doubleValue, as_smiOop(2), alien);
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(2), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625, ((double*)(alien_byte_region + 1))[0], "value not
set");
+}
+
+TESTF(IndirectAlienPrimsTests, alienFloatAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienFloatAtPut(doubleValue, as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625F, ((float*)(alien_byte_region))[0], "value not
set");
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedByteAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedByteAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedByteAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienSignedByteAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedShortAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienSignedShortAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedLongAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienSignedLongAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienDoubleAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienDoubleAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(doubleValue,
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienFloatAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(IndirectAlienPrimsTests,
alienFloatAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(doubleValue,
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/prims/pointerAlienPrimsTest.cpp Sun Sep 13
14:52:44 2009
@@ -0,0 +1,279 @@
+# include "incls/_precompiled.incl"
+# include "incls/_byteArray_prims.cpp.incl"
+#include "test.h"
+#include "delta.hpp"
+#include "testUtils.hpp"
+
+using namespace easyunit;
+
+DECLARE(PointerAlienPrimsTests)
+ byteArrayOop alien, invalidAlien;
+ byteArrayOop largeUnsignedInteger;
+ byteArrayOop largeSignedInteger;
+ u_char alien_byte_region[16];
+ doubleOop doubleValue;
+
+ int asInteger(oop largeInteger, bool& ok) {
+ Integer* number = &byteArrayOop(largeInteger)->number();
+ return number->as_int(ok);
+ }
+ void checkLargeInteger(oop result, int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_byteArray(), "Should be integer");
+ bool ok;
+ int actual = asInteger(result, ok);
+ ASSERT_TRUE_M(ok, "should be integer");
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkLargeUnsigned(oop result, unsigned int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_byteArray(), "Should be integer");
+ bool ok;
+ unsigned int actual =
byteArrayOop(result)->number().as_unsigned_int(ok);
+ ASSERT_TRUE_M(ok, "should be integer");
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkSmallInteger(oop result, int expected) {
+ char message[200];
+ ASSERT_TRUE_M(result->is_smi(), "Should be small integer");
+ int actual = smiOop(result)->value();
+ sprintf(message, "wrong value. expected: %d, was: %d", expected,
actual);
+ ASSERT_EQUALS_M(expected, actual, message);
+ }
+ void checkMarkedSymbol(char* message, oop result, symbolOop expected) {
+ char text[200];
+ ASSERT_TRUE_M(result->is_mark(), "Should be marked");
+ sprintf(text,"Should be: %s, was: %s", message,
unmarkSymbol(result)->as_string());
+ ASSERT_TRUE_M(unmarkSymbol(result) == expected, text);
+ }
+END_DECLARE
+
+SETUP(PointerAlienPrimsTests) {
+ PersistentHandle
ah(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(8));
+ PersistentHandle
iah(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(8));
+ PersistentHandle
lu(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(8));
+ PersistentHandle
ls(Universe::byteArrayKlassObj()->klass_part()->allocateObjectSize(8));
+
+ largeUnsignedInteger = byteArrayOop(lu.as_oop());
+ largeSignedInteger = byteArrayOop(ls.as_oop());
+
+ doubleValue =
doubleOop(Universe::doubleKlassObj()->klass_part()->allocateObject());
+ doubleValue->set_value(1.625);
+
+ IntegerOps::unsigned_int_to_Integer((unsigned int)0xFFFFFFFF,
byteArrayOop(largeUnsignedInteger)->number());
+ IntegerOps::int_to_Integer(-1 << 31,
byteArrayOop(largeSignedInteger)->number());
+
+ alien = byteArrayOop(ah.as_oop());
+ byteArrayPrimitives::alienSetSize(as_smiOop(0), alien);
+ byteArrayPrimitives::alienSetAddress(as_smiOop((int)alien_byte_region),
alien);
+ memset(alien_byte_region, 0, 16);
+
+ invalidAlien = byteArrayOop(iah.as_oop());
+ byteArrayPrimitives::alienSetSize(as_smiOop(0), invalidAlien);
+ byteArrayPrimitives::alienSetAddress(as_smiOop(0), invalidAlien);
+}
+
+TEARDOWN(PointerAlienPrimsTests){
+}
+
+TESTF(PointerAlienPrimsTests, alienUnsignedByteAtPutShouldSetUnsignedByte)
{
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedByteAt(as_smiOop(1),
alien);
+
+ checkSmallInteger(result, 255);
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedByteAtPutShouldReturnAssignedByte) {
+ oop result = byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+
+ checkSmallInteger(result, 255);
+}
+
+TESTF(PointerAlienPrimsTests, alienSignedByteAtShouldReturnCorrectByte) {
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(PointerAlienPrimsTests, alienSignedByteAtPutShouldSetCorrectByte) {
+ byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(-1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedShortAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(1), alien);
+ byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(255),
as_smiOop(2), alien);
+
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
alien);
+ checkSmallInteger(result, 65535);
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedShortAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
alien);
+
+ checkSmallInteger(result, 65535);
+}
+
+TESTF(PointerAlienPrimsTests, alienSignedShortAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
alien);
+ checkSmallInteger(result, -1);
+}
+
+TESTF(PointerAlienPrimsTests, alienSignedShortAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(-1), as_smiOop(1),
alien);
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(PointerAlienPrimsTests, alienUnsignedLongAtShouldReturnCorrectValue)
{
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(1), alien);
+ byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(65535),
as_smiOop(3), alien);
+
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ checkLargeUnsigned(result, 0xFFFFFFFF);
+}
+
+TESTF(PointerAlienPrimsTests, alienUnsignedLongAtPutShouldSetCorrectValue)
{
+ byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
alien);
+
+ checkLargeUnsigned(result, 0xFFFFFFFF);
+}
+
+TESTF(PointerAlienPrimsTests, alienSignedLongAtShouldReturnCorrectValue) {
+ byteArrayPrimitives::alienUnsignedLongAtPut(largeUnsignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ checkSmallInteger(result, -1);
+}
+
+TESTF(PointerAlienPrimsTests, alienSignedLongAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienSignedLongAtPut(largeSignedInteger,
as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1), alien);
+
+ checkLargeInteger(result, -1 << 31);
+}
+
+TESTF(PointerAlienPrimsTests, alienDoubleAtPutShouldSetValueAtSecondByte) {
+ byteArrayPrimitives::alienDoubleAtPut(doubleValue, as_smiOop(2), alien);
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(2), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625, ((double*)(alien_byte_region + 1))[0], "value not
set");
+}
+
+TESTF(PointerAlienPrimsTests, alienFloatAtPutShouldSetCorrectValue) {
+ byteArrayPrimitives::alienFloatAtPut(doubleValue, as_smiOop(1), alien);
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(1), alien);
+
+ ASSERT_TRUE_M(result->is_double(), "should be double");
+ ASSERT_EQUALS_M(1.625, doubleOop(result)->value(), "wrong value");
+ ASSERT_EQUALS_M(1.625F, ((float*)(alien_byte_region))[0], "value not
set");
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedByteAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedByteAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedByteAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedByteAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienSignedByteAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedByteAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienSignedByteAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedByteAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedShortAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedShortAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedShortAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienSignedShortAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedShortAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienSignedShortAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedShortAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedLongAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienUnsignedLongAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienUnsignedLongAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienSignedLongAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedLongAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienSignedLongAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienSignedLongAtPut(as_smiOop(1),
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienDoubleAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienDoubleAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienDoubleAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienDoubleAtPut(doubleValue,
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienFloatAtShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienFloatAt(as_smiOop(1),
invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
+
+TESTF(PointerAlienPrimsTests,
alienFloatAtPutShouldReturnMarkedSymbolWhenAddressInvalid) {
+ oop result = byteArrayPrimitives::alienFloatAtPut(doubleValue,
as_smiOop(1),invalidAlien);
+
+ checkMarkedSymbol("invalid address", result, vmSymbols::illegal_state());
+}
=======================================
--- /dev/null
+++ /branches/gcc-linux/test/utilities/testUtils.hpp Sun Sep 13 14:52:44
2009
@@ -0,0 +1,3 @@
+
+#define as_large_integer(value) \
+ byteArrayPrimitives::largeIntegerFromSmallInteger(as_smiOop(value),
klassOop(Universe::find_global("LargeInteger")))
=======================================
--- /branches/gcc-linux/StrongtalkSource/ASTtoRichTextTool.dlt Sat Nov 1
12:10:49 2008
+++ /branches/gcc-linux/StrongtalkSource/ASTtoRichTextTool.dlt Sun Sep 13
14:52:44 2009
@@ -303,7 +303,10 @@

self deltaHack.
node isIntroducedByRewriter ifTrue: [ ^ self ]. "ignore temporaries
introduced by rewriter"
- self varNode: node! !
+ self varNode: node!
+
+tupleNode: node <DeltaTule>
+ node elements do:[:e | e apply: self]! !

! (Delta mirrorFor: #ASTtoRichTextTool) methodsFor: 'private' !

=======================================
--- /branches/gcc-linux/StrongtalkSource/Array.dlt Sat Nov 1 12:10:49 2008
+++ /branches/gcc-linux/StrongtalkSource/Array.dlt Sun Sep 13 14:52:44 2009
@@ -144,6 +144,11 @@
! (Delta mirrorFor: #Array) methodsFor: 'copying' !


+copyGrownBy: delta <Integer> ^<Array[EX]>
+ {where EX is returnType of #anElement message of receiverType}
+
+ ^self copyWithSize: self size + delta!
+
copyWithSize: s <Int> ^<Array[EX]>
{where EX is returnType of #anElement message of receiverType}

=======================================
--- /branches/gcc-linux/StrongtalkSource/Block.dlt Sat Nov 1 12:10:49 2008
+++ /branches/gcc-linux/StrongtalkSource/Block.dlt Sun Sep 13 14:52:44 2009
@@ -26,6 +26,12 @@
fileOutSignature ^<Integer>
^75! !

+! (Delta mirrorFor: #Block) methodsFor: 'arity' !
+
+
+arity
+ self subclassResponsibility! !
+
! (Delta mirrorFor: #Block) methodsFor: 'debugging' !


@@ -42,7 +48,10 @@

value ^<Object>

- self error: 'Block with arguments invoked with none'! !
+ self error: 'Block with arguments invoked with none'!
+
+valueWithArguments: a <Array[Object]> ^ <Object>
+ ^self subclassResponsibility! !

! (Delta mirrorFor: #Block) methodsFor: 'file out' !

@@ -50,3 +59,9 @@
fileOutOn: d <Dumper>
self error: 'should not file out blocks'! !

+! (Delta mirrorFor: #Block) methodsFor: 'private' !
+
+
+validateValues: a <Array[Object]>
+ self assert:[a size = self arity].! !
+
=======================================
--- /branches/gcc-linux/StrongtalkSource/BlockWithEightArguments.dlt Mon
Sep 25 12:14:30 2006
+++ /branches/gcc-linux/StrongtalkSource/BlockWithEightArguments.dlt Sun
Sep 13 14:52:44 2009
@@ -10,10 +10,22 @@
'(c) 1996-1997 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
Use and distribution of this software is subject to the terms of the
attached source license. $Revision: 1.2 $'!

+! (Delta mirrorFor: #BlockWithEightArguments) methodsFor: 'arity' !
+
+
+arity ^ <Integer>
+ ^8! !
+
! (Delta mirrorFor: #BlockWithEightArguments) methodsFor: 'evaluating' !


value: arg1 <A1> value: arg2 <A2> value: arg3 <A3> value: arg4 <A4> value:
arg5 <A5> value: arg6 <A6> value: arg7 <A7> value: arg8 <A8>
"Block dispatch method (vm generated)"
- ^{{self primitiveValue: arg1 value: arg2 value: arg3 value: arg4
value: arg5 value: arg6 value: arg7 value: arg8}}! !
-
+ ^{{self primitiveValue: arg1 value: arg2 value: arg3 value: arg4
value: arg5 value: arg6 value: arg7 value: arg8}}!
+
+valueWithArguments: a <Array[Object]> ^ <R>
+ self validateValues: a.
+ ^self value: (a at: 1) value: (a at: 2) value: (a at: 3)
+ value: (a at: 4) value: (a at: 5) value: (a at: 6)
+ value: (a at: 7) value: (a at: 8)! !
+
=======================================
--- /branches/gcc-linux/StrongtalkSource/BlockWithFiveArguments.dlt Mon Sep
25 12:14:30 2006
+++ /branches/gcc-linux/StrongtalkSource/BlockWithFiveArguments.dlt Sun Sep
13 14:52:44 2009
@@ -10,10 +10,21 @@
'(c) 1996-1997 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
Use and distribution of this software is subject to the terms of the
attached source license. $Revision: 1.2 $'!

+! (Delta mirrorFor: #BlockWithFiveArguments) methodsFor: 'arity' !
+
+
+arity ^ <Integer>
+ ^5! !
+
! (Delta mirrorFor: #BlockWithFiveArguments) methodsFor: 'evaluating' !


value: arg1 <A1> value: arg2 <A2> value: arg3 <A3> value: arg4 <A4> value:
arg5 <A5>
"Block dispatch method (vm generated)"
- ^{{self primitiveValue: arg1 value: arg2 value: arg3 value: arg4
value: arg5}}! !
-
+ ^{{self primitiveValue: arg1 value: arg2 value: arg3 value: arg4
value: arg5}}!
+
+valueWithArguments: a <Array[Object]> ^ <R>
+ self validateValues: a.
+ ^self value: (a at: 1) value: (a at: 2) value: (a at: 3)
+ value: (a at: 4) value: (a at: 5)! !
+
=======================================
--- /branches/gcc-linux/StrongtalkSource/BlockWithFourArguments.dlt Mon Sep
25 12:14:30 2006
+++ /branches/gcc-linux/StrongtalkSource/BlockWithFourArguments.dlt Sun Sep
13 14:52:44 2009
@@ -10,11 +10,22 @@
'(c) 1996-1997 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
Use and distribution of this software is subject to the terms of the
attached source license. $Revision: 1.2 $'!

+! (Delta mirrorFor: #BlockWithFourArguments) methodsFor: 'arity' !
+
+
+arity ^ <Integer>
+ ^4! !
+
! (Delta mirrorFor: #BlockWithFourArguments) methodsFor: 'evaluating' !


value: arg1 <A1> value: arg2 <A2> value: arg3 <A3> value: arg4 <A4>

"Block dispatch method (vm generated)"
- ^{{self primitiveValue: arg1 value: arg2 value: arg3 value: arg4}}! !
-
+ ^{{self primitiveValue: arg1 value: arg2 value: arg3 value: arg4}}!
+
+valueWithArguments: a <Array[Object]> ^ <R>
+ self validateValues: a.
+ ^self value: (a at: 1) value: (a at: 2) value: (a at: 3)
+ value: (a at: 4)! !
+
=======================================
***Additional files exist in this changeset.***

Reply all
Reply to author
Forward
0 new messages