[Vm-dev] VM Maker: VMMaker.oscog-eem.3068.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Sep 11 23:17:19 UTC 2021


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.3068.mcz

==================== Summary ====================

Name: VMMaker.oscog-eem.3068
Author: eem
Time: 11 September 2021, 4:17:05.327753 pm
UUID: f00f2700-05d1-45ac-bcd7-8703af0c9192
Ancestors: VMMaker.oscog-eem.3067

ThreadedFFIPlugin: pass any kind of non-pointer object to non-byte */char * args.  We could insist on void *, but let's see how we get on with this.

=============== Diff against VMMaker.oscog-eem.3067 ===============

Item was changed:
  ----- Method: ThreadedFFIPlugin>>ffiAtomicArgByReference:Class:in: (in category 'callout support') -----
  ffiAtomicArgByReference: oop Class: oopClass in: calloutState
  	<var: #calloutState type: #'CalloutState *'>
  	"Support for generic callout. Prepare a pointer reference to an atomic type for callout.
  	 Note: 
  		for type 'void*' we allow ByteArray/String/Symbol, wordVariableSubclass, Alien or ExternalAddress.
  		for other types we allow ByteArray, wordVariableSubclass, Alien or ExternalAddress."
+ 	| atomicType isExternalAddress isString isAlien |
- 	| atomicType isString argIsAlien |
  	<inline: #always>
  	atomicType := self atomicTypeOf: calloutState ffiArgHeader.
+ 	atomicType = FFITypeBool ifTrue: "No bools on input"
- 	(atomicType = FFITypeBool) ifTrue: "No bools on input"
  		[^FFIErrorCoercionFailed].
+ 	(isExternalAddress := oopClass = interpreterProxy classExternalAddress)
+ 		ifTrue: [isAlien := isString := false]
+ 		ifFalse:
+ 			[(isString := interpreterProxy 
- 	argIsAlien := (isString := interpreterProxy 
- 								includesBehavior: oopClass 
- 								ThatOf: interpreterProxy classString)
- 					ifTrue: [false]
- 					ifFalse:
- 						[interpreterProxy 
  							includesBehavior: oopClass 
+ 							ThatOf: interpreterProxy classString)
+ 				ifTrue: [isAlien := false]
+ 				ifFalse:
+ 					[isAlien := interpreterProxy 
+ 									includesBehavior: oopClass 
+ 									ThatOf: interpreterProxy classAlien]].
+ 	(atomicType >> 1) = (FFITypeSignedChar8 >> 1) ifTrue:"string value (char*)"
- 							ThatOf: interpreterProxy classAlien].
- 	((atomicType >> 1) = (FFITypeSignedChar8 >> 1)) ifTrue:"string value (char*)"
  		"note: the only types allowed for passing into char* types are
  		ByteArray, String, Symbol, Alien and *no* other byte indexed objects
  		(e.g., CompiledMethod, LargeInteger). We only check for strings
  		here and fall through to the byte* check otherwise."
  		[isString ifTrue:"String/Symbol"
  			"Strings must be allocated by the ffi support code"
  			[^self ffiPushString: (interpreterProxy firstIndexableField: oop)
  				OfLength: (interpreterProxy byteSizeOf: oop)
  				in: calloutState].
  		"Fall through to byte* test"
  		atomicType := FFITypeUnsignedInt8].
  
  	self cppIf: COGMTVM ifTrue:
  	["Since all the following pass the address of the first indexable field we need to fail
  	 the call if it is threaded and the object is young, since it may move during the call."
+ 	(isExternalAddress not
+ 	and: [(calloutState callFlags anyMask: FFICallFlagThreaded)
+ 	and: [(isAlien not or: [self isDirectAlien: oop])
+ 	and: [self cppIf: #SPURVM
+ 			ifTrue: [(interpreterProxy isPinned: oop) not]
+ 			ifFalse: [interpreterProxy isYoung: oop]]]]) ifTrue:
- 	((calloutState callFlags anyMask: FFICallFlagThreaded)
- 	and: [(argIsAlien not or: [self isDirectAlien: oop])
- 	and: [interpreterProxy isYoung: oop]]) ifTrue:
  		[^PrimErrObjectMayMove negated]].
  
+ 	(atomicType >> 1) = (FFITypeSignedInt8 >> 1) ifTrue:
- 	(atomicType = FFITypeVoid or:[(atomicType >> 1) = (FFITypeSignedInt8 >> 1)]) ifTrue:
  		"byte* -- see comment on string above"
  		[(isString or: [oopClass = interpreterProxy classByteArray]) ifTrue: "String/Symbol/ByteArray"
  			[^self ffiPushPointer: (interpreterProxy firstIndexableField: oop) in: calloutState].
+ 		isExternalAddress ifTrue: 
- 		(oopClass = interpreterProxy classExternalAddress) ifTrue: 
  			[^self ffiPushPointer: (self longAt: oop + interpreterProxy baseHeaderSize) in: calloutState].
+ 		isAlien ifTrue:
- 		argIsAlien ifTrue:
  			[^self ffiPushPointer: (self pointerForOop: (self startOfData: oop)) in: calloutState].
  		atomicType = FFITypeVoid ifFalse:
  			[^FFIErrorCoercionFailed]].
  		"note: type void falls through"
  
  	"I can push pointers to any type (take for instance calls who receive int* output arguments, etc.)
  	 but I need to store them into a ByteArray, ExternalAddress or Alien"
  	(atomicType <= FFITypeDoubleFloat) ifTrue:
+ 		[isExternalAddress ifTrue: 
- 		[((interpreterProxy isWords: oop) or: [oopClass = interpreterProxy classByteArray]) ifTrue:
- 			[^self ffiPushPointer: (interpreterProxy firstIndexableField: oop) in: calloutState].
- 		(oopClass = interpreterProxy classExternalAddress) ifTrue: 
  			[^self ffiPushPointer: (self longAt: oop + interpreterProxy baseHeaderSize) in: calloutState].
+ 		isAlien ifTrue:
+ 			[^self ffiPushPointer: (self pointerForOop: (self startOfData: oop)) in: calloutState].
+ 		(interpreterProxy isWordsOrBytes: oop) ifTrue:
+ 			[^self ffiPushPointer: (interpreterProxy firstIndexableField: oop) in: calloutState]].
- 		argIsAlien ifTrue:
- 			[^self ffiPushPointer: (self pointerForOop: (self startOfData: oop)) in: calloutState]].
  
  	^FFIErrorCoercionFailed!



More information about the Vm-dev mailing list