[squeak-dev] Re: FFI callout generator benchmarks

Igor Stasenko siguctua at gmail.com
Sun Apr 11 22:26:30 UTC 2010

Okay, i found one (but with just two arguments)...

Its a windoze kernel's IsBadWritePtr() function:

The IsBadWritePtr function verifies that the calling process has write
access to the specified range of memory.

BOOL IsBadWritePtr(
  LPVOID lp,
  UINT_PTR ucb

NBFFICalloutTests new benchFFITest2

#(967 325 286 200)

here, as before
 967 - ffi callout
 325 - native code callout
 286 - calling an empty method with same number arguments in a loop
 200 - just a loop with empty block

so, a difference:
(967/325) asFloat 2.975384615384615
(967-200) / (325-200) asFloat 6.136
(967-286) / (325-286) asFloat  17.46153846153846

pick the one, which you like most ;)

Here is how the FFI code looks like:

ffiIsBadWritePtr: ptr size: blockSize
	<apicall: long 'IsBadWritePtr' (long long) module: 'Kernel32.dll' >
	self primitiveFailed

and here is how native code callout looks like:

nbIsBadWritePtr: ptr size: blockSize
	<primitive: 'primitiveNativeCall' module: 'NativeBoostPlugin'>
	^ NBFFICallout apiCall: #( long 'IsBadWritePtr' (long long)) module:

As you may see, i made it very similar to an original syntax, but need
to conform with smalltalk syntax.
Both methods calling the same function. The first is made through FFI plugin,
while second using some clever tricks:
 - initially a method is just a regular method without a native code in trailer.
 - a primitive detects that there is no native code to run, and fails
 - next its going into NBFFICallout code which checking the reason of failure,
  and if it sees that method doesn't having native code, it generating
it and changing the method's trailer and then calling this method
 If primitive fails for some other reason - it simply throws an error.

Best regards,
Igor Stasenko AKA sig.

More information about the Squeak-dev mailing list